SA-MP Forums Archive
Prevent 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: Prevent OnPlayerUpdate . (/showthread.php?tid=534375)



Prevent OnPlayerUpdate . - Rudy_ - 29.08.2014

Hey, I've a script, What it does is that When you are crouching an object is attached to you in x,y,z rotation, But if you stand up it attaches to you in x1,y1,z1 rotation. It works fine, but the problem is that i used OnPlayerUpdate, which keeps doing the proccess again and again, I have a message when object is attached and it just keeps showing the message again and again. ANy idea what to do with it?


Re: Prevent OnPlayerUpdate . - Abagail - 29.08.2014

Well, you need to show the code. You obviously screwed up somewhere.


Re: Prevent OnPlayerUpdate . - Clad - 29.08.2014

You mean it will send a message when ever the rotation or coords changes ?


Re: Prevent OnPlayerUpdate . - Rudy_ - 29.08.2014

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(crateobject[playerid] == 0)
    {
        if((newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH) && (newkeys & KEY_WALK) && !(oldkeys & KEY_WALK))
        {
            if(GetPlayerTeam(playerid) == team_prop)
            {
                crateobject[playerid] = 1;
            }
        }
    }
    return 1;
}

public OnPlayerUpdate(playerid)
{
    if(crateobject[playerid] == 1)
    {
        if(GetPlayerTeam(playerid) == team_prop)
        {
            if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_NONE) //Standing
             {
                if(IsPlayerInRangeOfPoint(playerid,20,563.57324, -2470.08301, 20.67800))
                {
                    RemovePlayerAttachedObject(playerid, 1);
                    SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,606.86298, -2462.64893, 19.05400))
                {
                    RemovePlayerAttachedObject(playerid, 1);
                    SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,627.73499, -2469.07202, 19.05400))
                {
                    RemovePlayerAttachedObject(playerid, 1);
                    SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,636.60498, -2455.44092, 19.04200))
                {
                    RemovePlayerAttachedObject(playerid, 1);
                    SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20, 523.91101, -2466.34595, 16.76800))
                {
                    RemovePlayerAttachedObject(playerid, 1);
                    SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
            }
            else if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK) //Crouching
            {
                if(IsPlayerInRangeOfPoint(playerid,20,563.57324, -2470.08301, 20.67800))
                {
                    RemovePlayerAttachedObject(playerid, 0);
                    SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,606.86298, -2462.64893, 19.05400))
                {
                    RemovePlayerAttachedObject(playerid, 0);
                    SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,627.73499, -2469.07202, 19.05400))
                {
                    RemovePlayerAttachedObject(playerid, 0);
                    SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,636.60498, -2455.44092, 19.04200))
                {
                    RemovePlayerAttachedObject(playerid, 0);
                    SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");

                }
                else if(IsPlayerInRangeOfPoint(playerid,20, 523.91101, -2466.34595, 16.76800))
                {
                    RemovePlayerAttachedObject(playerid, 0);
                    SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
            }
            return 1;
        }
    }
    return 0;
}



Re: Prevent OnPlayerUpdate . - Abagail - 29.08.2014

Well, - you never tell the code to not occur again, try this,

pawn Код:
public OnPlayerUpdate(playerid)
{
    if(crateobject[playerid] == 1)
    {
        if(GetPlayerTeam(playerid) == team_prop)
        {
            if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_NONE) //Standing
             {
                if(IsPlayerInRangeOfPoint(playerid,20,563.57324, -2470.08301, 20.67800))
                {
                    RemovePlayerAttachedObject(playerid, 1);
                    SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,606.86298, -2462.64893, 19.05400))
                {
                    RemovePlayerAttachedObject(playerid, 1);
                    SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,627.73499, -2469.07202, 19.05400))
                {
                    RemovePlayerAttachedObject(playerid, 1);
                    SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,636.60498, -2455.44092, 19.04200))
                {
                    RemovePlayerAttachedObject(playerid, 1);
                    SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20, 523.91101, -2466.34595, 16.76800))
                {
                    RemovePlayerAttachedObject(playerid, 1);
                    SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
            }
            else if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK) //Crouching
            {
                if(IsPlayerInRangeOfPoint(playerid,20,563.57324, -2470.08301, 20.67800))
                {
                    RemovePlayerAttachedObject(playerid, 0);
                    SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,606.86298, -2462.64893, 19.05400))
                {
                    RemovePlayerAttachedObject(playerid, 0);
                    SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,627.73499, -2469.07202, 19.05400))
                {
                    RemovePlayerAttachedObject(playerid, 0);
                    SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                else if(IsPlayerInRangeOfPoint(playerid,20,636.60498, -2455.44092, 19.04200))
                {
                    RemovePlayerAttachedObject(playerid, 0);
                    SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");

                }
                else if(IsPlayerInRangeOfPoint(playerid,20, 523.91101, -2466.34595, 16.76800))
                {
                    RemovePlayerAttachedObject(playerid, 0);
                    SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
                    SendClientMessage(playerid,-1,"Object Attached");
                }
                createobject[playerid] = 0;
            }
            return 1;
        }
    }
    return 0;
}
Basically, - the createobject variable is set to 0 after the object is attached.


Re: Prevent OnPlayerUpdate . - Rudy_ - 29.08.2014

Well that's what i had before, it won't work, I tested it now. The object attached, But when i'm crouching it's fine when i stand up the objects rotation dosen't change to the one i applied above.


Re: Prevent OnPlayerUpdate . - Clad - 29.08.2014

So you want it when the player stand up the attached object moves with it ?


Re: Prevent OnPlayerUpdate . - Rudy_ - 29.08.2014

Not move, but change rotation as i've added in the script.
There are 2 if and else if, 1 for standing and 1 for crouching.

Edit: if i tell the code to not occur again, it won't respond when i stand up.


Re: Prevent OnPlayerUpdate . - BroZeus - 29.08.2014

So u want to send message when right after he stands up or crouch?


AW: Prevent OnPlayerUpdate . - CutX - 29.08.2014

i've edited the code a little bit so i could do a quick test-run
works as it should. press c at zero point of the map and an object gets attached.
press c again, so that thou stand & rotation gets applied just as it should.

works fine as fs
pawn Код:
#define FILTERSCRIPT
#include "a_samp"
#define team_prop (0)

new bool:xX;

public OnFilterScriptInit()
{
    SetPlayerTeam(0,team_prop);
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if((newkeys & KEY_CROUCH) && !(oldkeys & KEY_CROUCH))// && (newkeys & KEY_WALK) && !(oldkeys & KEY_WALK))
        if(GetPlayerTeam(playerid) == team_prop)
            takeObject(playerid);
    return 1;
}

takeObject(playerid)
{
    //if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_NONE) //Standing
    if(xX)
     {
        xX=false;
        //if(IsPlayerInRangeOfPoint(playerid,20,563.57324, -2470.08301, 20.67800))
        if(IsPlayerInRangeOfPoint(playerid,20,0,0,0))
        {
            SendClientMessage(playerid,-1,"PROP added STANDING");
            RemovePlayerAttachedObject(playerid, 1);
            SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
            SendClientMessage(playerid,-1,"Object Attached");
        }
        else if(IsPlayerInRangeOfPoint(playerid,20,606.86298, -2462.64893, 19.05400))
        {
            RemovePlayerAttachedObject(playerid, 1);
            SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
            SendClientMessage(playerid,-1,"Object Attached");
        }
        else if(IsPlayerInRangeOfPoint(playerid,20,627.73499, -2469.07202, 19.05400))
        {
            RemovePlayerAttachedObject(playerid, 1);
            SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
            SendClientMessage(playerid,-1,"Object Attached");
        }
        else if(IsPlayerInRangeOfPoint(playerid,20,636.60498, -2455.44092, 19.04200))
        {
            RemovePlayerAttachedObject(playerid, 1);
            SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
            SendClientMessage(playerid,-1,"Object Attached");
        }
        else if(IsPlayerInRangeOfPoint(playerid,20, 523.91101, -2466.34595, 16.76800))
        {
            RemovePlayerAttachedObject(playerid, 1);
            SetPlayerAttachedObject( playerid, 0, 18260, 10, -1.463145, 0.003660, -0.010768, 344.867675, 271.720306, 0.000000, 1.000000, 1.000000, 1.000000 );
            SendClientMessage(playerid,-1,"Object Attached");
        }
    }
    else// if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK) //Crouching
    {
        xX=true;
        //if(IsPlayerInRangeOfPoint(playerid,20,563.57324, -2470.08301, 20.67800))
        if(IsPlayerInRangeOfPoint(playerid,20,0, 0, 0))
        {
            RemovePlayerAttachedObject(playerid, 0);
            SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
            SendClientMessage(playerid,-1,"Object Attached");
        }
        else if(IsPlayerInRangeOfPoint(playerid,20,606.86298, -2462.64893, 19.05400))
        {
            RemovePlayerAttachedObject(playerid, 0);
            SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
            SendClientMessage(playerid,-1,"Object Attached");
        }
        else if(IsPlayerInRangeOfPoint(playerid,20,627.73499, -2469.07202, 19.05400))
        {
            RemovePlayerAttachedObject(playerid, 0);
            SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
            SendClientMessage(playerid,-1,"Object Attached");
        }
        else if(IsPlayerInRangeOfPoint(playerid,20,636.60498, -2455.44092, 19.04200))
        {
            RemovePlayerAttachedObject(playerid, 0);
            SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
            SendClientMessage(playerid,-1,"Object Attached");

        }
        else if(IsPlayerInRangeOfPoint(playerid,20, 523.91101, -2466.34595, 16.76800))
        {
            RemovePlayerAttachedObject(playerid, 0);
            SetPlayerAttachedObject( playerid, 1, 18260, 10, 0.169341, -1.406103, 0.218262, 86.945274, 5.285029, 343.219879, 1.000000, 1.000000, 1.000000 );
            SendClientMessage(playerid,-1,"Object Attached");
        }
    }//you could also make the function return a value to checkfor errors.
}
HOWEVER, people are able to stand up from crouching without pressing c,
they press the jump-key. This could mess things up a little, in case it's not dealt with correctly that is.