Interaction with objects
#1

Hello,

I would like to know if i can create an automatic interaction with object X, where object X is an object ID chosen by me.
Rather then defining a rangeofpoint for object X with coordonates xyz, i would the player to start an automatic action when approaching that object, everywhere on map.

So it would be like this:
when near/around object X
do "some action"

Can it be done ?
Reply
#2

Yes it can be done, sorry but don't really have time to be more detailed since I'm going out the door.
Reply
#3

Ok ) . Please let me know when you come back
Reply
#4

Use GetObjectPos to get the position of an object ID.
To check if a player is near the object, you could run a repeating 1-sec timer in OnGameModeInit that would look something like this:
pawn Код:
forward MyTimer();
public MyTimer()
{
    new Float:x, Float:y, Float:z; // Declares 3 floats, we're gonna store the XYZ coordinates of the object in these
    GetObjectPos(objectid, x, y, z); // Stores the object id's coordinates in the XYZ floats, change "objectid" to what you want
    foreach(new i : Player) // Loops through all players, and defines them as "i"
    {
        if(IsPlayerInRangeOfPoint(i, 5, x, y, z)) // If "i" is in range of those coordinates
            // The range is here "5", change to what you want the max distance to be
        {
            // Do whatever you want here when the player is close enough
        }
    }
}
Reply
#5

I don't want with position....i already specified that..
Reply
#6

Yes, and i told you could create a 1-sec repeating timer to check if the player is in range of the object, and then do your special action.
Here's an example of setting the timer:
pawn Код:
public OnGameModeInit()
{
    SetTimer("MyTimer", 1000, true);
    // "MyTimer" is the public function to call, etc. "public MyTimer()"
    // 1000 is the time it takes for the timer to end in milliseconds - 1 second = 1000 milliseconds
    // True/False if the timer should repeat or not
        // Since we wanna continue checking if the player is in range of the object, it should be repeating (true)
}
Reply
#7

What you give me is for only one object.

I want to be for every object X found anywhere on the map, nomatter the position.
Reply
#8

It's just a simple timer ... Calvin u are right , but it's more easly if him do something like that:

Код:
new Object[5];

forward Timer();

public OnGameModeInit()
{
	SetTimer("Timer",999,true);
	Object[0] = CreateObject();
	Object[1] = CreateObject();
	Object[2] = CreateObject();
	Object[3] = CreateObject();
	Object[4] = CreateObject();
	return 1;
}

public Timer()
{
	new Float:oPos[3];
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(!IsPlayerConnected(i))
            continue;
            
		for(new obj=0;obj<5;obj++)
		{
		    GetObjectPos(Object[obj],oPos[0],oPos[1],oPos[2]);
		    if(IsPlayerInRangeOfPoint(i,5,oPos[0],oPos[1],oPos[2]))
		    {
		        // Write what you want to do here :) gl
		    }
		}
    }
	return 1;
}
Reply
#9

Well in that case you'll have to create them, and declare them a name, like:
pawn Код:
new Objectid[4];
Objectid[0] = CreateObject( ... );
Objectid[1] = CreateObject( ... );
Objectid[2] = CreateObject( ... );
Objectid[3] = CreateObject( ... );
Pretty sure you can't detect by the model id.
Reply
#10

Let me give you an example.

When i am near a GARBAGE object, i want a menu to popup. The garbage object is already there in the map, i don't need to create it and GARBAGE object is everywhere on the map.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)