Player position, Bo...
 
Notifications
Clear all

Player position, Boolean, Inventry

2 Posts
2 Users
0 Reactions
660 Views
(@eycus)
Posts: 1
New Member
Topic starter
 
 

I just bought the Unity Package, Package works perfect, I assigned all the Options in the Game, and gone through the
Documentation, very nice, But i don't know how to fix this in CB

1, How to Store the Player position(x,y,z) in database/field and get back to C#
2, How to store Boolean(true/false) in database/field and get back to c#
3, How to add more or different weapons(Shot gun, rocket launcher..etc)  in the Inventory class/ Data base,
is there any expansion options available.

 
Posted : 01/01/2014 6:44 pm
(@skaredcreations)
Posts: 805
Prominent Member Admin
 

Hi,

 

About player's position and other custom properties you can use customData from CBUser:

public class MyUser : CBUser {
   public Vector3 Position { get { return toVector3(customData["Position"].ToString()); } set { customData["Position"] = fromVector3(value); } }
   string fromVector3 (Vector3 vec) {
      return string.Format("{0}|{1}|{2}", vec.x, vec.y, vec.z);
   }
   Vector3 toVector3 (string text) {
      if (string.IsNullOrEmpty(text)) return Vector3.zero;
      string[] data = text.Split('|');
      return new Vector3(float.Parse(data[0]), float.Parse(data[1]), float.Parse(data[2]));
   }
}

 

 

So you will use this class to login or register:

CBManager.instance.Login<MyUser>(username, password);

About your second question, you can do something similar to the above but using a conversion to/from bool instead of Vector3 (yourBooleanValue.ToString() to set and bool.Parse(yourTextString) or TryParse to load).

About your third question, you will use CBInventory, I usually store the weapon class name in CBInventory.name and eventually use the hashtable CBInventory.customData to store extra info if needed.

FRANCESCO CROCETTI @ SKARED CREATIONS

 
Posted : 01/01/2014 7:14 pm
Share: