Posts: 53
Threads: 4
Joined: Jun 2011
Quote:
Originally Posted by BigETI
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.") } } } }
|
very very nice thank you