How to store item information with user variables?

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Ninjaoninja2
Posts: 189
Joined: 22 Sep 2013, 23:33

How to store item information with user variables?

Postby Ninjaoninja2 » 28 Sep 2014, 22:45

Hey there,
I can't seem to find the doc that shows you how to store information on the server side with user variables but I need to store item information with it so when the user logs back in they will still have there outfit on. Can somebody point me in the right direction?
User avatar
zachofthegolden1
Posts: 89
Joined: 05 Sep 2011, 19:31

Re: How to store item information with user variables?

Postby zachofthegolden1 » 29 Sep 2014, 02:25

Ninjaoninja2 wrote:Hey there,
I can't seem to find the doc that shows you how to store information on the server side with user variables but I need to store item information with it so when the user logs back in they will still have there outfit on. Can somebody point me in the right direction?



This can be done by saving the var to the database. I don't know the struture of your game so i will use an example as if this is the avatar chat so other people using the default version can also get help from this.

On my server on my client side (Inside the flash) i set it up as recieving the var from the database by number.

So one outfit is frame 3 on the disc movieclip. So i set the code as this after successful login.

Code: Select all

if(resObj._cmd == "logOK")
   {
         _global.myName=resObj.name;
         smartfox.myUserName=resObj.name;
         smartfox.myUserId=resObj.id;
         getAvatar=resObj.avatar;
         smartfox.getRoomList();
   }



I then set the coding inside the flash to call an extension named "setAvatar"
on click soon the databse will update so if they click on a look itl save it streight to the database


Code: Select all

on(release){
   var userName=userList_lb.getSelectedItem().data;
   var dataObj={};
   dataObj.avatar=3;
   smartfox.sendXtMessage("myextensionname","setAvatar",dataObj);
}


Here below we cna find the coding used for the extension to handle the request
Please note that on my game the username is the users id as in their databse id.

Code: Select all

function setAvatar (params, user, dataObj) {
   
   
   
   
   
     userAvatar = params.avatar
   
   newUser = user.getName();
   var sql = "UPDATE users SET col = '"+userAvatar+"' WHERE id='"+newUser+"'";
    var queryRes = dbase.executeCommand(sql)
   //_server.sendResponse (vResp,-1,null,ul);
   trace("avatar set for "+newUser)
   trace("was set to>"+userAvatar)
   
   
   
}



Ok now we need the server to give us the param on login.

Code: Select all

response.avatar = Row.getItem("col");
      trace("users avatar is> "+Row.getItem("col"))


Ok this is on the successful login line in the extension.

Now we need users to see people wearing their outfits so we change the coding for the join rooms.



FIrst we make it so when we login we can see out outfit.

Code: Select all

function setupMyAvatar()
{
   if(!inited)
   {
         var _loc7_=int(Math.random() * 8) + 1;
         myAvatar=avatarMC.attachMovie("avatar","avatar_" + smartfox.myUserId,99999);
        myAvatar.disc.gotoAndStop(getAvatar);



WHen we scrool down and see "smartfox.onJoinRoom=function(roomObj)"

We look for the avatar disc coding

we change the coding for the disc go to and stop to

disc.gotoAndStop(getAvatar);

This will make sure that we can see the avatar. Right now thats done we want other users to see our lovely looks so we change the enter room coding
we look for smartfox.onUserEnterRoom=function(fromRoom, user)

and change the disc coding

Code: Select all

disc.gotoAndStop(user.variables.col);


This will read the server and change to that frame number to whatever number that outfit is on the movieclip

Im alays avalible on pm if you need help with code you do not wish to be posted on the forum
-ZG1
Ninjaoninja2
Posts: 189
Joined: 22 Sep 2013, 23:33

Re: How to store item information with user variables?

Postby Ninjaoninja2 » 29 Sep 2014, 16:50

Thanks a lot, very informational!

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 20 guests