SA-MP Forums Archive
[help]OnPlayerUpdate uses - 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: [help]OnPlayerUpdate uses (/showthread.php?tid=422636)



[help]OnPlayerUpdate uses - Mrich - 14.03.2013

Anyone know what can we do in OnPlayerUpdate ? I give example : I want apply something when a variable changes , so should I do codes under OnPlayerUpdate ?


Re: [help]OnPlayerUpdate uses - LarzI - 14.03.2013

I'd recommend making a function that you'll call when changing the variable, and inside that function do whatever you want to do.

Example:

pawn Код:
MyVariableChangeFunction(newvalue)
{
    MyVariable = newvalue;
   
    // my stuff
}

// Somewhere when I'm changing the variable:

MyVariableChangeFunction( HERETHEVALUEYOUWANTITTOCHANGETO );



Re: [help]OnPlayerUpdate uses - MP2 - 14.03.2013

If a variable changes, you KNOW when it changes (because YOU changed it with an operation) so why would you want to check thousands of times a second if it was changed? Just call a function to set the variable, and in that function do whatever.

EDIT: @LarzI beat me by a max of 15 seconds :/


Re: [help]OnPlayerUpdate uses - [ABK]Antonio - 14.03.2013

It depends on what you want to do. If you need to call something for a player roughly 25 times per second (which stacks, so 10 players = 25*10 calls per second) then you would use OnPlayerUpdate.


Re: [help]OnPlayerUpdate uses - Mrich - 14.03.2013

thank you , I really wanna do like killingstreak system
pawn Код:
if(kill=x)
{
//made a triple kill!
}
else if(...)
.
.



Re: [help]OnPlayerUpdate uses - Vince - 14.03.2013

That's what OnPlayerDeath is for.


Re: [help]OnPlayerUpdate uses - Mrich - 14.03.2013

ok ,but on question : Is adding conditions in OnPlayerDeath will abord the server readin other codes ?
pawn Код:
Public onplayerdeath
{
//I will here add killing streak with condiitions

//and here are +score &  others thing that are called on player death
}
so will it read the conditions only & stop or contunues?
}


Re: [help]OnPlayerUpdate uses - LarzI - 14.03.2013

The code will only stop if you return a value or if you use goto(confirm this, please, as I am not entirely sure). If you don't do either, the code will run until it reaches the end of the callback (The last closing brace)


Re: [help]OnPlayerUpdate uses - Mrich - 14.03.2013

thank you ! so it will contunue (cause I have no returns or 'contunue'.. only conditions)