weapons loads with twice as much bullets
#1

Well, after player spawns, they get the gun they left with, but with twice as much bullets.

I get no error or warnings in script, but this is something like script bug.

When player disconnects and SaveUser_data function has been called:
PHP код:
for (new 013++) if (playerData[playerid][gun][i] != && playerData[playerid][ammo][i] != 0){
    
format(wep_strsizeof(wep_str), "gun%d"i);
    
INI_WriteInt(Filewep_strplayerData[playerid][gun][i]);
    
    
format(wep_strsizeof(wep_str), "ammo%d"i);
    
INI_WriteInt(Filewep_strplayerData[playerid][ammo][i]);

When player connects (Clears the variables and player data):
PHP код:
ResetPlayerWeapons(playerid);
for (new 
013++) {
    
playerData[playerid][gun][i] = 0;
    
playerData[playerid][ammo][i] = 0;

OnPLayerSpawn:
PHP код:
SetTimerEx("LoadUserSpawn_data"500false"i"playerid); 
LoadUserSpawn_data:
PHP код:
forward LoadUserSpawn_data(playerid);
public 
LoadUserSpawn_data(playerid)
{
    new 
str[124];
    
// --------------------------
    
GivePlayerMoney(playeridplayerData[playerid][cash]);
    
SetPlayerHealth(playeridplayerData[playerid][health]);
    
SetPlayerArmour(playeridplayerData[playerid][armour]);
    
// --------------------------
    
format(strsizeof(str), "Health: %.1f Armour: %.1f\n%s [%i]"ReturnHealth(playerid), ReturnArmour(playerid), ReturnName(playerid0), playerid);
    
NameTag[playerid] = CreateDynamic3DTextLabel(strCOLOR_GRAY0.00.00.28.0playeridINVALID_VEHICLE_ID0, -1, -1, -18.0);
    
Attach3DTextLabelToPlayer(NameTag[playerid], playerid0.00.00.2);
    
// --------------------------
    
SetWeapons(playerid);
    
// --------------------------
    
playerSpawned[playerid] = true;
    return 
1;

SetWeapons:
PHP код:
SetWeapons(playerid)
{
    for (new 
013i++) {
        
GivePlayerWeapon(playeridplayerData[playerid][gun][i], playerData[playerid][ammo][i]);
    }
    return 
1;

Reply
#2

Did you check the ini file after the save function was called to see if it actually saves double ammo in the file?
Reply
#3

Quote:
Originally Posted by rappy93
Посмотреть сообщение
Did you check the ini file after the save function was called to see if it actually saves double ammo in the file?
Yes, and in .ini file it doesn't double.
Reply
#4

So the problem is somewhere with the loading function.

Let's debug it.

SetWeapons(playerid)
{
for (new i = 0; i < 13; i++) {
GivePlayerWeapon(playerid, playerData[playerid][gun][i], playerData[playerid][ammo][i]);
}
print("SetWeapons called!");
return 1;
}

Now please compile. Clear your server log before joining. Join the server and then exit. Post the logs here afterwards.
Reply
#5

Quote:
Originally Posted by rappy93
Посмотреть сообщение
So the problem is somewhere with the loading function.

Let's debug it.

SetWeapons(playerid)
{
for (new i = 0; i < 13; i++) {
GivePlayerWeapon(playerid, playerData[playerid][gun][i], playerData[playerid][ammo][i]);
}
print("SetWeapons called!");
return 1;
}

Now please compile. Clear your server log before joining. Join the server and then exit. Post the logs here afterwards.
Yes, thanks for that. The function is called twice, I'll check the script later, but thanks for this.

Код:
[16:08:27] SetWeapons called!
[16:08:27] SetWeapons called!
Reply
#6

No problem, basic debugging . Using 'print' like this will help you a lot. Cheers.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)