SA-MP Forums Archive
pickup an object - 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: pickup an object (/showthread.php?tid=653515)



pickup an object - ShadowBlack - 06.05.2018

how to pickup an object? i have a createplayerobject and i want when i enter in him, destroy him. how i can do this?


Re: pickup an object - Vennox - 19.05.2018

make a timer that loops:
PHP код:
SetTimer("OneSLoop"10001); 
check for player position near the object:
PHP код:
forward OneSLoop();
public 
OneSLoop(){
    for(new 
iMAX_PLAYERSi++){
        if(
IsPlayerInRangeOfPoint(i2.0xyz){
            
DestroyPlayerObject(iObject[i]);
            
SendClientMessage(playerid, -1"You have collected the object! :D");
        }
    }




Re: pickup an object - JasonRiggs - 19.05.2018

Quote:
Originally Posted by Vennox
Посмотреть сообщение
make a timer that loops:
PHP код:
SetTimer("OneSLoop"10001); 
check for player position near the object:
PHP код:
forward OneSLoop();
public 
OneSLoop(){
    for(new 
iMAX_PLAYERSi++){
        if(
IsPlayerInRangeOfPoint(i2.0xyz){
            
DestroyPlayerObject(iObject[i]);
            
SendClientMessage(playerid, -1"You have collected the object! :D");
        }
    }

The timer sucks in such cases and would cause much problems, Why not create a small dynamic area around the object and when the player enter it, destroy the object and give it to the player via attachment, or you can make a large dynamic area and loop through all the players inside it to see who is near / in the same place of the object..

You can use
PHP код:
 CreateDynamicCircle(Float:xFloat:yFloat:sizeworldid = -1interiorid = -1playerid = -1
and
PHP код:
 IsPlayerInDynamicArea(playeridareaidrecheck 0
to check if he got into it or no..

Then add your normal code which is
PHP код:
for(new iMAX_PLAYERSi++){
        if(
IsPlayerInRangeOfPoint(i2.0xyz){
            
DestroyPlayerObject(iObject[i]);
            
SendClientMessage(playerid, -1"You have collected the object! :D");
        }
    }