#define MAX_ROB_DISTANCES 6.0 //Make sure it is a float #define MIN_ROB_WAIT 50000 //In miliseconds #define COLOR_LIGHTBLUE 0x00CCFFAA #define COLOR_RED 0xFF0000AA new gPlayerLastRob[MAX_PLAYERS]; //Tick count of last time they tried /rob public OnPlayerCommandText(playerid, cmdtext[]) { if (strcmp(cmdtext, "/rob", true)==0) //By Us3r { if ((GetTickCount() - gPlayerLastRob[playerid]) < MIN_ROB_WAIT) { //Please wait SendClientMessage(playerid, COLOR_RED, "Please wait before attempting to rob someone again."); return 1; } new Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, name[MAX_PLAYER_NAME], rand, Float:distance, str[256], amount; rand = random(20); GetPlayerPos(playerid, x1, y1, z1); for(new i=0; i < MAX_PLAYERS; i++) { if (i != playerid && IsPlayerConnected(i) && GetPlayerState(i) == PLAYER_STATE_ONFOOT) { GetPlayerPos(i, x2, y2, z2); distance = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2)); if (distance < MAX_ROB_DISTANCE) { if (GetPlayerMoney(i) <= 0) { //Victim has no money GetPlayerName(i, name, MAX_PLAYER_NAME); format(str, sizeof(str), "Cannot attempt to rob %s (%d) as he/she has no money.", name, playerid); SendClientMessage(playerid, COLOR_RED, str); } else if (rand < 10) { //Robbery failed //Message for victim GetPlayerName(playerid, name, MAX_PLAYER_NAME); format(str, sizeof(str), "%s (%d) has attempted to rob you but failed.", name, playerid); SendClientMessage(i, COLOR_LIGHTBLUE, str); //Message for robber GetPlayerName(i, name, MAX_PLAYER_NAME); format(str, sizeof(str), "%s (%d) has noticed you trying to rob him/her. Failed.", name, i); SendClientMessage(playerid, COLOR_LIGHTBLUE, str); gPlayerLastRob[playerid] = GetTickCount(); } else { //Robbery succesful amount = floatround(GetPlayerMoney(i) / rand); //Get robbed amount (it's the rand% of the victim's cash) //Victim GetPlayerName(playerid, name, MAX_PLAYER_NAME); format(str, sizeof(str), "%s (%d) has robbed you $%d.", name, playerid, amount); SendClientMessage(i, COLOR_LIGHTBLUE, str); GivePlayerMoney(i, (amount * -1)); //Robber GetPlayerName(playerid, name, MAX_PLAYER_NAME); format(str, sizeof(str), "You have robbed $%d from %s (%d).", amount, name, playerid); SendClientMessage(playerid, COLOR_LIGHTBLUE, str); GivePlayerMoney(playerid, amount); gPlayerLastRob[playerid] = GetTickCount(); } return 1; } } } //No players in range SendClientMessage(playerid, COLOR_RED, "No players in range to rob."); return 1; } return 0; }