SA-MP Forums Archive
Loops under 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: Loops under OnPlayerUpDate? (/showthread.php?tid=472616)



Loops under OnPlayerUpDate? - knackworst - 29.10.2013

Hello

Because I find the SAMP pickup system quite annoying to work with (no offence) because the types are limited and none of the spawn types fit my needs I was trying to make a new custom pickup system.

So in this system I could create pickups with custom respawn time or respawn types.

The thing is, to do that I need to check whether a player is near the pickup or not, if he is then OnPlayerPickupNewPickupType should be called.
I tried making a timer that would run every quarter of a second, however it was to slow to handle me rushing through one in a vehicle. So the only way of doing this would be using OnPlayerUpdate.
But since that callback is called so frequently would it be a good idea to loop through all my created pickups and check if the player is near one?


Re: Loops under OnPlayerUpDate? - cyber_punk - 29.10.2013

NO! OnPlayerUpdate needs to be fast as possible adding loops can create massive lag.


Re: Loops under OnPlayerUpDate? - Pottus - 29.10.2013

Just use the streamer plugin and dynamic areas.


Re: Loops under OnPlayerUpDate? - knackworst - 29.10.2013

Well I would still need to check if a player is in an area too...
But I can use the areas for time zones


Re: Loops under OnPlayerUpDate? - Patrick - 29.10.2013

Use streamer and use IsPlayerInDynamicArea

pawn Код:
native CreateDynamicCircle(Float:x, Float:y, Float:size, worldid = -1, interiorid = -1, playerid = -1);
native CreateDynamicRectangle(Float:minx, Float:miny, Float:maxx, Float:maxy, worldid = -1, interiorid = -1, playerid = -1);
native CreateDynamicSphere(Float:x, Float:y, Float:z, Float:size, worldid = -1, interiorid = -1, playerid = -1);
native CreateDynamicCube(Float:minx, Float:miny, Float:minz, Float:maxx, Float:maxy, Float:maxz, worldid = -1, interiorid = -1, playerid = -1);
native CreateDynamicPolygon(Float:points[], Float:minz = -FLOAT_INFINITY, Float:maxz = FLOAT_INFINITY, maxpoints = sizeof points, worldid = -1, interiorid = -1, playerid = -1);
For more information about these natives check this link out: https://sampforum.blast.hk/showthread.php?tid=102865

EDIT: also if you're using zone, it would look something like this
pawn Код:
public IsPlayerInDynamicArea(playerid, areaid);
{
    new zoneid = GetZoneName(playerid); //If you're using a_zones, this is an example
    if(areaid == 1 && zoneid == 192)
    {
        //function
    }
    return 1;
}