SA-MP Forums Archive
Stopping every player getting something when they log in. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Stopping every player getting something when they log in. (/showthread.php?tid=348699)



Stopping every player getting something when they log in. - cloudysky - 06.06.2012

Hello, recently come across a really really really annoying bug and have just deleted almost everything in my script to find it. (Back up of course :P) Basically if a player is in the game and they get something, then the next player who logs in also gets it. Can someone help me?


Re: Stopping every player getting something when they log in. - AndreT - 06.06.2012

If you mean that the next player with the same ID gets the same properties that the last player, then your script is most likely just not resetting some variables in OnPlayerDisconnect.


Re: Stopping every player getting something when they log in. - cloudysky - 06.06.2012

Thanks for the response. No what is happening is that when I log in, and then my friend logs in, logs out, and join again they have my items. I'll try adding something to reset the variable on disconnect though and see if it works


Re: Stopping every player getting something when they log in. - cloudysky - 06.06.2012

No it doesn't work Here is the code if it helps:

OnPlayerConnect
EDIT:
pawn Код:
ResetPlayerVariables(playerid);
OnPlayerDisconnect
pawn Код:
ResetPlayerVariables(playerid);
pawn Код:
stock ResetPlayerVariables(playerid)
{
    IsLogged[playerid] = 0;
    PlayerInfo[playerid][Admin] = 0;
    PlayerInfo[playerid][Survivor] = 0;
    PlayerInfo[playerid][Zombie] = 0;
    PlayerInfo[playerid][Money] = 0;
    PlayerInfo[playerid][Death] = 0;
    PlayerInfo[playerid][Infected] = 0;
    PlayerInfo[playerid][New] = 0;
    PlayerInfo[playerid][Skin] = 0;
}



Re: Stopping every player getting something when they log in. - MadeMan - 06.06.2012

Quote:
Originally Posted by cloudysky
Посмотреть сообщение
Basically if a player is in the game and they get something, then the next player who logs in also gets it.
What is this "something" ?

Show how you load/save data from file/database


Re: Stopping every player getting something when they log in. - cloudysky - 06.06.2012

The something is Money for example, or their skin. Anything that is saved to their account.

pawn Код:
public SaveUser(playerid)
{
    if(IsLogged[playerid] == 0) return 0;

    GetPlayerHealth(playerid, PlayerInfo[playerid][Health]);
    GetPlayerArmour(playerid, PlayerInfo[playerid][Armour]);

    PlayerInfo[playerid][Skin] = GetPlayerSkin(playerid);
    PlayerInfo[playerid][Money] = GetPlayerMoney(playerid);

    dini_IntSet(Userfile, "Admin", PlayerInfo[playerid][Admin]);
    dini_IntSet(Userfile, "Survivor", PlayerInfo[playerid][Survivor]);
    dini_IntSet(Userfile, "Zombie", PlayerInfo[playerid][Zombie]);
    dini_IntSet(Userfile, "Money", PlayerInfo[playerid][Money]);
    dini_IntSet(Userfile, "Death", PlayerInfo[playerid][Death]);
    dini_IntSet(Userfile, "Infected", PlayerInfo[playerid][Infected]);
    dini_IntSet(Userfile, "New", PlayerInfo[playerid][New]);
    dini_IntSet(Userfile, "Skin", PlayerInfo[playerid][Skin]);

    if(PlayerInfo[playerid][Health] != 0) dini_FloatSet(Userfile, "Health", PlayerInfo[playerid][Health]);
    if(PlayerInfo[playerid][Armour] != 0) dini_FloatSet(Userfile, "Armour", PlayerInfo[playerid][Armour]);
    return 1;
}
pawn Код:
stock LoginUser(playerid)
{
    format(Userfile, sizeof(Userfile), "users/%s.ini", GetName(playerid));
    IsLogged[playerid] = 1;
    JustLogged[playerid] = 1;
    PlayerInfo[playerid][Admin] = dini_Int(Userfile, "Admin");
    PlayerInfo[playerid][Survivor] = dini_Int(Userfile, "Survivor");
    PlayerInfo[playerid][Zombie] = dini_Int(Userfile, "Zombie");
    PlayerInfo[playerid][Money] = dini_Int(Userfile, "Money");
    PlayerInfo[playerid][Death] = dini_Int(Userfile, "Death");
    PlayerInfo[playerid][Infected] = dini_Int(Userfile, "Infected");
    PlayerInfo[playerid][New] = dini_Int(Userfile, "New");
    PlayerInfo[playerid][Skin] = dini_Int(Userfile, "Skin");

    PlayerInfo[playerid][Health] = dini_Float(Userfile, "Health");
    PlayerInfo[playerid][Armour] = dini_Float(Userfile, "Armour");

    GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
    SetPlayerHealth(playerid, PlayerInfo[playerid][Health]);
    SetPlayerArmour(playerid, PlayerInfo[playerid][Armour]);
    // Timers
    SaveTimer[playerid] = SetTimerEx("SaveUser", 1000, true, "i", playerid);
    return SendClientMessage(playerid, COLOUR_GREEN, "Logged in.");
}



Re: Stopping every player getting something when they log in. - MadeMan - 06.06.2012

You should use this

pawn Код:
format(Userfile, sizeof(Userfile), "users/%s.ini", GetName(playerid));
in SaveUser too.


Re: Stopping every player getting something when they log in. - Horrible - 06.06.2012

i think there is some wrong code on load and save playerinfo

mademan was right !
pawn Код:
public SaveUser(playerid)
{
    if(IsLogged[playerid] == 0) return 0;
    format(Userfile, sizeof(Userfile), "users/%s.ini", GetName(playerid));
    GetPlayerHealth(playerid, PlayerInfo[playerid][Health]);
    GetPlayerArmour(playerid, PlayerInfo[playerid][Armour]);

    PlayerInfo[playerid][Skin] = GetPlayerSkin(playerid);
    PlayerInfo[playerid][Money] = GetPlayerMoney(playerid);

    dini_IntSet(Userfile, "Admin", PlayerInfo[playerid][Admin]);
    dini_IntSet(Userfile, "Survivor", PlayerInfo[playerid][Survivor]);
    dini_IntSet(Userfile, "Zombie", PlayerInfo[playerid][Zombie]);
    dini_IntSet(Userfile, "Money", PlayerInfo[playerid][Money]);
    dini_IntSet(Userfile, "Death", PlayerInfo[playerid][Death]);
    dini_IntSet(Userfile, "Infected", PlayerInfo[playerid][Infected]);
    dini_IntSet(Userfile, "New", PlayerInfo[playerid][New]);
    dini_IntSet(Userfile, "Skin", PlayerInfo[playerid][Skin]);

    if(PlayerInfo[playerid][Health] != 0) dini_FloatSet(Userfile, "Health", PlayerInfo[playerid][Health]);
    if(PlayerInfo[playerid][Armour] != 0) dini_FloatSet(Userfile, "Armour", PlayerInfo[playerid][Armour]);
    return 1;
}



Re: Stopping every player getting something when they log in. - MadeMan - 06.06.2012

Quote:
Originally Posted by Horrible
Посмотреть сообщение
i think there is some wrong code on load and save playerinfo
Captain Obvious, is that you?


Re: Stopping every player getting something when they log in. - Horrible - 06.06.2012

Quote:
Originally Posted by MadeMan
Посмотреть сообщение
Captain Obvious, is that you?
honestly i dont understand

but maybe it's kind of joke