09.04.2013, 13:56
pawn Код:
Float:distanceP2P(playerid, toplayerid)
{
new Float:p1pos[3], Float: p2pos[3];
GetPlayerPos(playerid, p1pos[0], p1pos[1], p1pos[2]);
GetPlayerPos(toplayerid, 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: distancetmp = 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;
}