Losing server-side gun OnPlayerSpawn
#1

Well, I've been having a lot of problems with my weapon system lately (I have backups which I could go back to but unfortunately I've done a fair amount of work on the script since then). Somewhat luckily, I've pinpointed a very clear cut problem.

On respawn, the player would lose their weapon.


OnPlayerSpawn callback relevant code:

pawn Код:
public OnPlayerSpawn(playerid)
{

    giveweapon(playerid);
       
    return 1;
}

Example of when player receives weapon (it is from a /giveweapon command, 'ID' refers to the player on the receiving end):

pawn Код:
if (weapon == 18)
{
    PlayerInfo[ID][Weapon8] = 18;
    PlayerInfo[ID][Ammo8] = 5;
    giveweapon(ID);

    return 1;

}
NOTE: The player does receive the gun sucessfully, however, I made a debug command and it seems the variable is always 0 after I give myself the gun which surely should not be the case.


Custom givegun function:

pawn Код:
forward giveweapon(playerid);
public giveweapon(playerid)
{

    if(PlayerInfo[playerid][Weapon1] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon1], PlayerInfo[playerid][Ammo1]);
        GetPlayerWeaponData(playerid, 1, PlayerInfo[playerid][Weapon1], PlayerInfo[playerid][Ammo1]);
    }
    if(PlayerInfo[playerid][Weapon2] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon2], PlayerInfo[playerid][Ammo2]);
        GetPlayerWeaponData(playerid, 2, PlayerInfo[playerid][Weapon2], PlayerInfo[playerid][Ammo2]);
    }
    if(PlayerInfo[playerid][Weapon3] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon3], PlayerInfo[playerid][Ammo3]);
        GetPlayerWeaponData(playerid, 3, PlayerInfo[playerid][Weapon3], PlayerInfo[playerid][Ammo3]);
    }
    if(PlayerInfo[playerid][Weapon4] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon4], PlayerInfo[playerid][Ammo4]);
        GetPlayerWeaponData(playerid, 4, PlayerInfo[playerid][Weapon4], PlayerInfo[playerid][Ammo4]);
    }
    if(PlayerInfo[playerid][Weapon5] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon5], PlayerInfo[playerid][Ammo5]);
        GetPlayerWeaponData(playerid, 5, PlayerInfo[playerid][Weapon5], PlayerInfo[playerid][Ammo5]);
    }
    if(PlayerInfo[playerid][Weapon6] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon6], PlayerInfo[playerid][Ammo6]);
        GetPlayerWeaponData(playerid, 6, PlayerInfo[playerid][Weapon6], PlayerInfo[playerid][Ammo6]);
    }
    if(PlayerInfo[playerid][Weapon7] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon7], PlayerInfo[playerid][Ammo7]);
        GetPlayerWeaponData(playerid, 7, PlayerInfo[playerid][Weapon7], PlayerInfo[playerid][Ammo7]);
    }
    if(PlayerInfo[playerid][Weapon8] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon8], PlayerInfo[playerid][Ammo8]);
        GetPlayerWeaponData(playerid, 8, PlayerInfo[playerid][Weapon8], PlayerInfo[playerid][Ammo8]);
    }
    if(PlayerInfo[playerid][Weapon9] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon9], PlayerInfo[playerid][Ammo9]);
        GetPlayerWeaponData(playerid, 9, PlayerInfo[playerid][Weapon9], PlayerInfo[playerid][Ammo9]);
    }
    if(PlayerInfo[playerid][Weapon10] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon10], PlayerInfo[playerid][Ammo10]);
        GetPlayerWeaponData(playerid, 10, PlayerInfo[playerid][Weapon10], PlayerInfo[playerid][Ammo10]);
    }
    if(PlayerInfo[playerid][Weapon11] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon11], PlayerInfo[playerid][Ammo11]);
        GetPlayerWeaponData(playerid, 11, PlayerInfo[playerid][Weapon11], PlayerInfo[playerid][Ammo11]);
    }
    if(PlayerInfo[playerid][Weapon12] > 0)
    {
        GivePlayerWeapon(playerid, PlayerInfo[playerid][Weapon12], PlayerInfo[playerid][Ammo12]);
        GetPlayerWeaponData(playerid, 12, PlayerInfo[playerid][Weapon12], PlayerInfo[playerid][Ammo12]);
    }

}
Script is errorless and warningless.

I can't help but think I am doing something really simple wrong. Multiple eyes are better than one. If you want more code, I will post it happily.
Reply
#2

Can you show me the giveweapon code?
Reply
#3

Quote:
Originally Posted by Macronix
Посмотреть сообщение
Can you show me the giveweapon code?
I posted the relevant code above, also I do not think this is the problem actually, seeing as my custom function does work (hence it gives the gun initially), and the problem is also occurring with the gun shop, where it does not even require another player ("ID)".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)