Ask about OnPlayerUpdate !
#1

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
Reply
#2

It shouldn't cause any damage to server's performance
Reply
#3

It probably will, I think a timer is faster.
Reply
#4

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.
Reply
#5

So this is the prob ?

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

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);
    }
Reply
#7

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
Reply
#8

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;
}
Reply
#9

Thanks guys for your suggest :S
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)