Near 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: Near object (
/showthread.php?tid=485162)
Near object -
Stereotype - 03.01.2014
Hello guys .. I have around 150 objects.. There are made like
object[1] = CreateDynamicObject(params)
object[2] = ...
etc..
Now im making sweeper job, that will check if player is near object.. and when player press Ctrl that server destroy thath object .. I mean its stupid that i make 150 lines IsPlayerInRangeOfPoint.. I need other way, any help?
Re: Near object -
Bakr - 03.01.2014
https://sampwiki.blast.hk/wiki/Control_Structures#Loops
Re: Near object -
Sk1lleD - 03.01.2014
pawn Код:
for(new i=0; i < 150; i++)
{
new Float:x, Float:y, Float:z;
GetObjectPos(object[i], x, y, z);
if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
{
//Your Code Here
}
}
Re: Near object -
Lordzy - 03.01.2014
You could run a loop in finding those 'object' arrayed Dynamic Objects and then remove the one which is near player's range. Here's an example:
pawn Код:
#include <a_samp>
#include <streamer>
#define OBJECT_RANGE 3.5 //The range between player and the object.
new Swp_Object[150];
public OnFilterScriptInit()
{
Swp_Object[0] = CreateDynamicObject(...);
Swp_Object[1] = CreateDynamicObject(...);
return 1;
}
stock GetSwpObjectNearPlayer(playerid)
{
returnobject = -1, counts=0, Float:X, Float:Y, Float:Z;
for(new i; i< 150; i++)
{
if(counts >= 1) break;
GetDynamicObjectPos(Swp_Object[0], X, Y, Z);
if(!IsPlayerInRangeOfPoint(playerid, OBJECT_RANGE, X, Y, Z)) continue;
returnobject = Swp_Object[i];
counts++;
}
return returnobject;
}
//In case if there's multiple object, it will return the first object which has been found.
Re: Near object -
Stereotype - 03.01.2014
Quote:
Originally Posted by Lordz™
You could run a loop in finding those 'object' arrayed Dynamic Objects and then remove the one which is near player's range. Here's an example:
pawn Код:
#include <a_samp> #include <streamer>
#define OBJECT_RANGE 3.5 //The range between player and the object.
new Swp_Object[150];
public OnFilterScriptInit() { Swp_Object[0] = CreateDynamicObject(...); Swp_Object[1] = CreateDynamicObject(...); return 1; }
stock GetSwpObjectNearPlayer(playerid) { returnobject = -1, counts=0, Float:X, Float:Y, Float:Z; for(new i; i< 150; i++) { if(counts >= 1) break; GetDynamicObjectPos(Swp_Object[0], X, Y, Z); if(!IsPlayerInRangeOfPoint(playerid, OBJECT_RANGE, X, Y, Z)) continue; returnobject = Swp_Object[i]; counts++; } return returnobject; } //In case if there's multiple object, it will return the first object which has been found.
|
That is best way .. Ty r+