OnPlayerUpdate
#1

I just have some questions: i work on a project and again i need your help with something.
1. So i created an weapon saving systems for 3 weapons: throwable weapon ( grenades, gas, molotov), secundary weapon ( pistols), primary weapons ( guns ) it work perfectly no errors/warnings, but when i set myself a grenade, it doesn't disappear when ammo is 0 ( in database), and it save the variable to 1:
So when i enter again on my server i get a grenade that should've disappear last date.

I used this under OnPlayerUpdate
pawn Код:
public OnPlayerUpdate(playerid)
{
    SetPlayerScore(playerid, Z_Info[playerid][Level]);
    //weapons and ammos
    new w_ammo = GetPlayerAmmo(playerid);
    new weapon = GetPlayerWeapon(playerid);
    if(weapon == Z_Info[playerid][Weapon1])
    {
       Z_Info[playerid][Weapon1Ammo] = w_ammo;
    }
    if(weapon == Z_Info[playerid][Weapon2])
    {
       Z_Info[playerid][Weapon2Ammo] = w_ammo;
    }
    if(weapon == Z_Info[playerid][Weapon3])
    {
       Z_Info[playerid][Weapon3Ammo] = w_ammo;
    }
    if(Z_Info[playerid][Weapon1Ammo] <= 0)
    {
       Z_Info[playerid][Weapon1] = 0;
    }
    if(Z_Info[playerid][Weapon2Ammo] <= 0)
    {
       Z_Info[playerid][Weapon2] = 0;
    }
    if(Z_Info[playerid][Weapon3Ammo] <= 0)
    {
       Z_Info[playerid][Weapon3] = 0;
    }
    //position saver
    if(fexist(GetFile(playerid) ) && IsSpawned[playerid] == 1 )
    {
       new Float: X, Float:Y, Float:Z;
       new interior = GetPlayerInterior(playerid);
       new vworld = GetPlayerVirtualWorld(playerid);
       GetPlayerPos(playerid, X, Y, Z);
       Z_Info[playerid][PosX] = X;
       Z_Info[playerid][PosY] = Y;
       Z_Info[playerid][PosZ] = Z;
       Z_Info[playerid][VWorld] = vworld;
       Z_Info[playerid][Interior] = interior;
    }

    return 1;
}
2. I should use a timer for this or continue to use OnPlayerUpdate?
Reply
#2

Definitely use a timer - OnPlayerUpdate is called very frequently per second.

In code you provided there isn't anything about saving/loading weapons.
Reply
#3

I know it isn't but it works for guns that shoot: i mean ak47, m4 ....etc...
But it doesn't for the grenades... what's wrong with this
Anyway i'll show you the code for saving
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)