SA-MP Forums Archive
Ask about OnPlayerUpdate ! - 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: Ask about OnPlayerUpdate ! (/showthread.php?tid=497473)



Ask about OnPlayerUpdate ! - VenomMancer - 27.02.2014

Hello guys

This will make my SERVER Lag ?

pawn Код:
public OnPlayerUpdate(playerid)
{
    if(!IsPlayerConnected(playerid)) return 0;
//--------------------------------------------
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        SetPlayerArmedWeapon(playerid, 0);
    }
//--------------------------------------------
    if(PlayerInfo[playerid][God] == 0 && mini[playerid] == 0 )
    {
        new Float:pHealth;
        GetPlayerHealth(playerid, pHealth);
        if(pHealth >= 99)
        {
            Kick(playerid);
        }
        new Float:pArmour;
        GetPlayerArmour(playerid, pArmour);
        if(pArmour >= 99)
        {
            Kick(playerid);
        }
    }
//--------------------------------------------
    new weap = GetPlayerWeapon(playerid);
    if(mini[playerid] == 0)
    {
        if(weap == 36)
        {
            ShowPlayerDialog(playerid,5,DIALOG_STYLE_MSGBOX, "Server...", "{FFFFFF}Kamu telah di{48A4FF}Kick {FFFFFF}dari server\nAlasan: Weapon hack!", "Ok", "");
            return 1;
        }
        if(weap == 35)
        {
            ShowPlayerDialog(playerid,5,DIALOG_STYLE_MSGBOX, "Server...", "{FFFFFF}Kamu telah di{48A4FF}Kick {FFFFFF}dari server\nAlasan: Weapon hack!", "Ok", "");
            SetTimerEx("KickPlayer", 1000, 0, "d", playerid);
            return 1;
        }
        if(weap == 38)
        {
            ShowPlayerDialog(playerid,5,DIALOG_STYLE_MSGBOX, "Server...", "{FFFFFF}Kamu telah di{48A4FF}Kick {FFFFFF}dari server\nAlasan: Weapon hack!", "", "Ok");
            SetTimerEx("KickPlayer", 1000, 0, "d", playerid);
            return 1;
        }
    }
    return 1;
}
Thank for your Reply's +REP1


Re: Ask about OnPlayerUpdate ! - ikey07 - 27.02.2014

It shouldn't cause any damage to server's performance


Re: Ask about OnPlayerUpdate ! - Onfroi - 27.02.2014

It probably will, I think a timer is faster.


Re: Ask about OnPlayerUpdate ! - Kwarde - 27.02.2014

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        SetPlayerArmedWeapon(playerid, 0);
    }
You could put this in OnPlayerEnterVehicle or the OnPlayerStateChange ; once you are in a vehicle you can't switch weapons. So it doesn't re-check all the time which isn't needed (as far as I know!)

Also, why are you checking if the player is connected?
Quote:
Originally Posted by SAMP Wiki
This callback is called everytime a client/player updates the server with their status.
So a disconnected player is not calling the callback (off course).

Futher I don't see what'd be wrong. And I wouldn't use a timer to check this. Why use a timer when there's OnPlayerUpdate? (@Onfroi)

- Kwarde

p.s.
Wrong section . This should be in the scripting help section.


Re: Ask about OnPlayerUpdate ! - VenomMancer - 27.02.2014

So this is the prob ?

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        SetPlayerArmedWeapon(playerid, 0);
    }
Help me guys


Re: Ask about OnPlayerUpdate ! - Pottus - 27.02.2014

Remove this if(!IsPlayerConnected(playerid)) return 0; obviously they're connected if they're updating.

This belongs in OnPlayerStateChange()
pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        SetPlayerArmedWeapon(playerid, 0);
    }



Re: Ask about OnPlayerUpdate ! - Jefff - 27.02.2014

and change to this

pawn Код:
if(mini[playerid] == 0)
    {
        if(weap == 36)
        {
            ShowPlayerDialog(playerid,5,DIALOG_STYLE_MSGBOX, "Server...", "{FFFFFF}Kamu telah di{48A4FF}Kick {FFFFFF}dari server\nAlasan: Weapon hack!", "Ok", "");
            return 1;
        }
        if(weap == 35)
        {
            mini[playerid] = 1;
            ShowPlayerDialog(playerid,5,DIALOG_STYLE_MSGBOX, "Server...", "{FFFFFF}Kamu telah di{48A4FF}Kick {FFFFFF}dari server\nAlasan: Weapon hack!", "Ok", "");
            SetTimerEx("KickPlayer", 1000, 0, "d", playerid);
            return 1;
        }
        if(weap == 38)
        {
            mini[playerid] = 1;
            ShowPlayerDialog(playerid,5,DIALOG_STYLE_MSGBOX, "Server...", "{FFFFFF}Kamu telah di{48A4FF}Kick {FFFFFF}dari server\nAlasan: Weapon hack!", "", "Ok");
            SetTimerEx("KickPlayer", 1000, 0, "d", playerid);
            return 1;
        }
    }
and now SetTimerEx("KickPlayer", 1000, 0, "d", playerid); is called only one time


Re: Ask about OnPlayerUpdate ! - Djole1337 - 27.02.2014

Why don't you use OnPlayerKeyStateChange?
pawn Код:
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(PRESSED(KEY_FIRE))
    {
        switch(GetPlayerWeapon(playerid))
        {
            case 35, 36, 38:
            {
                // do whatever you want.
            }
        }
    }
    return 1;
}



Re: Ask about OnPlayerUpdate ! - VenomMancer - 27.02.2014

Thanks guys for your suggest :S