All pastes #497411 Raw Edit

Untitled

public text v1 · immutable
·published 2007-05-19 20:53 UTC
rendered paste body

#define COLOR_GROUPTALK 0x87CEEBAA  // SKYBLUE
#define COLOR_MENU 0xFFFFFFAA		// WHITE (FFFFFF) menu's (/help)
#define COLOR_SYSTEM_PM 0x66CC00AA	// LIGHT GREEN
#define COLOR_SYSTEM_PW 0xFFFF33AA	// YELLOW
//--/rob command by orderph -- SETTINGS >
#define ROB_MAX_DISTANCE                      6.0    //Make sure it is a float. Keep it small to avoid complications while getting the nearest player.
#define ROB_MIN_WAIT             0     //Time that players have to wait between /rob attempts in miliseconds.
#define ROB_SUCCESS_PERCENTAGE   60             //Chances of a player to succeed in a /rob attempt.
#define ROB_AMOUNT_MIN_PERCENTAGE       5       //Min % of a victims money the robber can get if they succeed.
#define ROB_AMOUNT_MAX_PERCENTAGE       10      //Max % of a victims money the robber can get if they succeed.

//--/rob command by orderph -- COLORS >
#define COLOR_ROB_SUCCESS 0x00CCFFAA
#define COLOR_ROB_FAILURE 0xCCCCFFAA
#define COLOR_ROB_ERROR 0xFF0000AA



RobCmd(playerid) //by orderph
{
        if ((GetTickCount() - gPlayerLastRob[playerid]) >= ROB_MIN_WAIT) {
               new victim = INVALID_PLAYER_ID;
                if (IsPlayerInAnyVehicle(playerid)) {
                    new vehicle = GetPlayerVehicleID(playerid);
                for(new i=0; i < MAX_PLAYERS; i++) {
            if(i != playerid && IsPlayerConnected(i) && IsPlayerInAnyVehicle(i) && GetPlayerVehicleID(i) == vehicle) {
                              victim = i;
                    break;
                                }
                        }
                }
                else if (GetPlayerState(playerid) == PLAYER_STATE_ONFOOT) {
                  new Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, Float:distance;
          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 < ROB_MAX_DISTANCE) {
                             victim = i;
                       break;
                                        }
                                }
                        }
                }
                if (victim != INVALID_PLAYER_ID) {
                    new cash = GetPlayerMoney(victim);
                    new name[MAX_PLAYER_NAME], str[256];
                    GetPlayerName(victim, name, MAX_PLAYER_NAME);
                    if (cash > 0) {
                                new rand = random(100);
                       gPlayerLastRob[playerid] = GetTickCount();
                                if (rand <= ROB_SUCCESS_PERCENTAGE) {
                                        rand = random(ROB_AMOUNT_MAX_PERCENTAGE - ROB_AMOUNT_MIN_PERCENTAGE) + ROB_AMOUNT_MIN_PERCENTAGE;
                            new amount = floatround((rand * cash) / 100);
                            GetPlayerName(playerid, name, MAX_PLAYER_NAME);
                   format(str, sizeof(str), "%s (%d) has robbed you $%d.", name, playerid, amount);
                  SendClientMessage(victim, COLOR_ROB_SUCCESS, str);
                  format(str, sizeof(str), "~y~Robbed by %s: $%d.", name, amount);
                  GameTextForPlayer(victim, str, 3000, 3);
                        GivePlayerMoney(victim, 0 - amount);
                            GetPlayerName(victim, name, MAX_PLAYER_NAME);
                   format(str, sizeof(str), "You have robbed $%d from %s (%d)", amount, name, victim);
                  SendClientMessage(playerid, COLOR_ROB_SUCCESS, str);
                  format(str, sizeof(str), "~y~Robbed %s: $%d.", name, amount);
                  GameTextForPlayer(playerid, str, 3000, 3);
                        GivePlayerMoney(playerid, amount);
                                 }
                                 else {
                            GetPlayerName(playerid, name, MAX_PLAYER_NAME);
                   format(str, sizeof(str), "%s (%d) has attempted to rob you but failed.", name, playerid);
                  SendClientMessage(victim, COLOR_ROB_FAILURE, str);
                  format(str, sizeof(str), "~y~%s attempted to rob you", name);
                  GameTextForPlayer(victim, str, 3000, 3);
                            GetPlayerName(victim, name, MAX_PLAYER_NAME);
                   format(str, sizeof(str), "Your attempt to rob %s (%d) has failed.", name, victim);
                  SendClientMessage(playerid, COLOR_ROB_FAILURE, str);
                  format(str, sizeof(str), "~y~Attempt to rob %s failed", name);
                  GameTextForPlayer(playerid, str, 3000, 3);
                                }
                        }
                        else {
                          GetPlayerName(playerid, name, MAX_PLAYER_NAME);
                format(str, sizeof(str), "Cannot attempt to rob %s (%d) as he/she has no money.", name, victim);
              SendClientMessage(playerid, COLOR_ROB_ERROR, str);
                        }
                }
                else {
                        SendClientMessage(playerid, COLOR_ROB_ERROR, "No players close enough to rob.");
                }
        }
        else {
        SendClientMessage(playerid, COLOR_ROB_ERROR, "Please wait before attempting to rob someone again.");
        }
}



This goes on top of your page underneath the #include etc



if (strcmp(cmdtext, "/rob", true)==0)
{
RobCmd(playerid);
return 1;
}

This goes underneath public OnPlayerCommandText(playerid ,cmdtext[]){