Quote:
Originally Posted by [XST]O_x
pawn Код:
Float:distanceP2P(playerid, toplayerid) { new Float:p1pos[3], Float: p2pos[3]; GetPlayerPos(playerid, p1pos[0], p1pos[1], p1pos[2]); GetPlayerPos(playerid, p2pos[0], p2pos[1], p2pos[2]); return float(floatround(floatsqroot( ((p1pos[0] - p2pos[0]) ^2) + ((p1pos[1] - p2pos[1]) ^ 2) + ((p1pos[2] - p2pos[2]) ^ 2)))); }
GetClosestPlayer(toplayerid) { new cur = INVALID_PLAYER_ID, Float: distance = 99999.99; for(new i = 0; i < MAX_PLAYERS; i++) { if( (distanceP2P(toplayerid, i) < distancetmp) && (i != toplayerid) && (i != INVALID_PLAYER_ID) ) cur = i; } return cur; }
public OnPlayerCommandText(playerid, cmdtext[]) { if(!strcmp(cmdtext, "/rob")) { new amount = 1500 + random(500); // A random amount of robbed money between 1500 and 2000$ new success = random(2); GivePlayerMoney(GetClosestPlayer(playerid), (success == 1) ? -amount : 0); GivePlayerMoney(playerid, (success == 1) ? amount : 0); return 1; } return 0; }
|
Where exactly do I place this?
Float:distanceP2P(playerid, toplayerid)
{
new Float
1pos[3], Float: p2pos[3];
GetPlayerPos(playerid, p1pos[0], p1pos[1], p1pos[2]);
GetPlayerPos(playerid, p2pos[0], p2pos[1], p2pos[2]);
return float(floatround(floatsqroot( ((p1pos[0] - p2pos[0]) ^2) + ((p1pos[1] - p2pos[1]) ^ 2) + ((p1pos[2] - p2pos[2]) ^ 2))));
}
GetClosestPlayer(toplayerid)
{
new cur = INVALID_PLAYER_ID, Float: distance = 99999.99;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if( (distanceP2P(toplayerid, i) < distancetmp) && (i != toplayerid) && (i != INVALID_PLAYER_ID) ) cur = i;
}
return cur;
}