Is this possible?
#4

You could use a timer to update the distance check between the player and the object and second I've just made a stock to get the distance between a player ID and an object ID.

pawn Код:
stock GetPlayerDistanceToObject(playerid, toobjectid, &Float:Distance)
{
    new Float:pX, Float:pY, Float:pZ, Float:oX, Float:oY, Float:oZ;
    GetPlayerPos(playerid,pX,pY,pZ);
    GetObjectPos(toobjectid,oX,oY,oZ);
    Distance = floatsqroot((oX-pX)*(oX-pX)+(oY-pY)*(oY-pY)+(oZ-pZ)*(oZ-pZ));
}
Usage:

pawn Код:
new object;
//...
stock GetPlayerDistanceToObject(playerid, toobjectid, &Float:Distance)
{
    new Float:pX, Float:pY, Float:pZ, Float:oX, Float:oY, Float:oZ;
    GetPlayerPos(playerid,pX,pY,pZ);
    GetObjectPos(toobjectid,oX,oY,oZ);
    Distance = floatsqroot((oX-pX)*(oX-pX)+(oY-pY)*(oY-pY)+(oZ-pZ)*(oZ-pZ));
}
//...
public OnGameModeInit()
{
    //Your stuff...
    object = CreateObject(3851, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 300.0);

    //Timer stuff
    SetTimer("CheckPos", 40, true);
    //...
}

//Somewhere in your script
MoveObject(object, 400.0, 100.0, 10.0);

//Then..
forward CheckPos()
public CheckPos()
{
    for(new playerid = 0; playerd < MAX_PLAYERS; playerid++)
    {
        if(IsPlayerConnected(playerid))
        {
            new Float:distance;
            GetPlayerDistanceToObject(playerid, object, distance);
            if(distance < 20.0)
            {
                if(GetPVarInt(playerid, "IsNearObject") == 0)
                {
                    SetPVarInt(playerid, "IsNearObject", 1);
                    SendClientMessage(playerid, 0xFF0000FF, "The Object is in your near.");
                }
            }
            else if(GetPVarInt(playerid, "IsNearObject") == 1)
            {
                SetPVarInt(playerid, "IsNearObject", 0);
                SendClientMessage(playerid, 0xFF0000FF, "The object is now far away.")
            }
        }
    }
}
Reply


Messages In This Thread
Is this possible? - by AgentZero - 01.07.2011, 03:28
Re: Is this possible? - by Shadoww5 - 01.07.2011, 03:38
Re: Is this possible? - by AgentZero - 01.07.2011, 03:42
Re: Is this possible? - by BigETI - 01.07.2011, 03:55
Re: Is this possible? - by AgentZero - 01.07.2011, 04:12

Forum Jump:


Users browsing this thread: 1 Guest(s)