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", 1000, 1);
check for player position near the object:
PHP код:
forward OneSLoop();
public OneSLoop(){
for(new i; i < MAX_PLAYERS; i++){
if(IsPlayerInRangeOfPoint(i, 2.0, x, y, z){
DestroyPlayerObject(i, Object[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", 1000, 1);
check for player position near the object:
PHP код:
forward OneSLoop();
public OneSLoop(){
for(new i; i < MAX_PLAYERS; i++){
if(IsPlayerInRangeOfPoint(i, 2.0, x, y, z){
DestroyPlayerObject(i, Object[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:x, Float:y, Float:size, worldid = -1, interiorid = -1, playerid = -1)
and
PHP код:
IsPlayerInDynamicArea(playerid, areaid, recheck = 0)
to check if he got into it or no..
Then add your normal code which is
PHP код:
for(new i; i < MAX_PLAYERS; i++){
if(IsPlayerInRangeOfPoint(i, 2.0, x, y, z){
DestroyPlayerObject(i, Object[i]);
SendClientMessage(playerid, -1, "You have collected the object! :D");
}
}