SA-MP Forums Archive
after spawning, player doesn't get his/her weapons - 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: after spawning, player doesn't get his/her weapons (/showthread.php?tid=589304)



after spawning, player doesn't get his/her weapons - thaKing - 17.09.2015

Tile says almost everything.

Well, basically I made a timer, so after player spawns, they get health and armour (saves on logout) and should be the same with guns, but they don't get them.

OnPlayerSpawn:
PHP код:
SetTimerEx("LoadUserSpawn_data"500false"i"playerid); 
LoadUserSpawn_data:
PHP код:
forward LoadUserSpawn_data(playerid);
public 
LoadUserSpawn_data(playerid)
{
    new 
str[128];
    
// --------------------------
    
ResetPlayerMoney(playerid);
    
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); // <-- LOOK HERE
    // --------------------------
    
playerSpawned[playerid] = true;
    return 
1;

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

P.S. I already checked, and yes, weapons are saving.

Prove:



Re: after spawning, player doesn't get his/her weapons - thaKing - 17.09.2015

Still doesn't work.


Re: after spawning, player doesn't get his/her weapons - JordanZaundd - 18.09.2015

Whats the point of "if (playerData[playerid][gun][i] > 0 && playerData[playerid][ammo][i] > 0)"?

It's going to skip the GivePlayerWeapon since i=0.

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

Try that.


Re: after spawning, player doesn't get his/her weapons - Threshold - 18.09.2015

Where do you load all your values?


Re: after spawning, player doesn't get his/her weapons - thaKing - 18.09.2015

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Where do you load all your values?
OnPLayerFullyConnected. I use Emmet_'s "noclass.inc"

Quote:
Originally Posted by JordanZaundd
Посмотреть сообщение
Whats the point of "if (playerData[playerid][gun][i] > 0 && playerData[playerid][ammo][i] > 0)"?

It's going to skip the GivePlayerWeapon since i=0.

Код:
SetWeapons(playerid)
{
    for (new i = 0; i < 13; i ++)
   		GivePlayerWeapon(playerid, playerData[playerid][gun][i], playerData[playerid][ammo][i]);
    return 1;
}
Try that.
Just tried, nothing. The guns are loading, but not giving. Because I checked the user_file.ini all the time, I even registered a few times more. Nothing.


Re: after spawning, player doesn't get his/her weapons - -=Dar[K]Lord=- - 18.09.2015

Echo the variables(weapon variables) and check if all the variables are assigned correctly on load.
If not there is some problem while assigning the weapon ids to variables


Re: after spawning, player doesn't get his/her weapons - thaKing - 18.09.2015

Quote:
Originally Posted by -=Dar[K]Lord=-
Посмотреть сообщение
Echo the variables(weapon variables) and check if all the variables are assigned correctly on load.
If not there is some problem while assigning the weapon ids to variables
Yep, there was a mistake in loading function.

PHP код:
new str[24];
    for (new 
013++) // if (playerData[playerid][gun][i] > 0 ...
    
{
        
format(strsizeof(str), "gun%d"i);
        
INI_Int(strplayerData[playerid][gun][i]);
        
        
format(strsizeof(str), "ammo%d"i);
        
INI_Int(strplayerData[playerid][ammo][i]);
    } 
Now works.