Near object
#1

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?
Reply
#2

https://sampwiki.blast.hk/wiki/Control_Structures#Loops
Reply
#3

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
    }
}
Reply
#4

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.
Reply
#5

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+
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)