01.08.2013, 07:21
Hi guys, I have this command
EDIT: Another Command
The command is so long, how can I make it more shorter and more simpler?
Quote:
Код:
dcmd_taze(playerid, params[]) { new taze = strval(params); if(!strlen(params)) { SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze [ID]"); } else { if(gTeam[playerid] == COP || gTeam[playerid] == SWAT || gTeam[playerid] == ARMY || gTeam[playerid] == FBI) { if(IsPlayerConnected(taze)) { if(GetDistanceBetweenPlayers(playerid, taze) <= 6) { if(tazetime[playerid] == 0) { new tehtaze = random(5); if(tehtaze == 1 || tehtaze == 2 || tehtaze == 3 || tehtaze == 4) { new string[256], Float:thlth; format(string, sizeof(string), "%s (%i) has tazed you.",ReturnPlayerName(playerid), playerid); SendClientMessage(taze, COLOR_MSG, string); format(string, sizeof(string), "You have tazed %s (%i).",ReturnPlayerName(taze), taze); SendClientMessage(playerid, COLOR_MSG, string); GetPlayerHealth(taze, thlth); new Float:tehtaze3 = thlth-15-random(30); SetPlayerHealth(taze, tehtaze3); if(thlth < tehtaze3) { format(string, sizeof(string), "%s (%i) has been tazed to death", ReturnPlayerName(taze), taze); SendClientMessageToAll(COLOR_KILLED, string); } else { SendClientMessage(taze, COLOR_MSG, "You are stunned for a while."); TogglePlayerControllable(taze, 0); stunned[taze] = 1; tazetime[playerid] = 1; SetTimerEx("tazetimer", ANTISPAM*1000, 0, "i", playerid); SetTimerEx("stuntimer", STUNNED_TIME*1000, 0, "i", taze); } } else { new string[256], Float:phlth; format(string, sizeof(string), "%s (%i) has accidentally held the tazer the wrong way and tazed himself",ReturnPlayerName(playerid), playerid); SendClientMessage(taze, COLOR_MSG, string); SendClientMessage(playerid, COLOR_MSG, "You accidentally held the tazer the wrong way and tazed yourself"); GetPlayerHealth(playerid, phlth); new Float:tehtaze2 = phlth-25-random(30); SetPlayerHealth(playerid, tehtaze2); if(phlth < tehtaze2) { format(string, sizeof(string), "%s (%i) has been tazed to death",ReturnPlayerName(playerid), playerid); SendClientMessageToAll(COLOR_KILLED, string); } else { SendClientMessage(playerid, COLOR_MSG, "You are stunned for a while."); TogglePlayerControllable(playerid, 0); stunned[playerid] = 1; SetTimerEx("stuntimer", STUNNED_TIME*1000, 0, "i", playerid); SetTimerEx("tazetimer", ANTISPAM*1000, 0, "i", playerid); tazetime[playerid] = 1; } } } else { SendClientMessage(playerid, COLOR_MSG, "Please wait before tazing someone again!"); } } else { new string[256]; format(string, sizeof(string), "%s (%i) is not close enough to taze!", ReturnPlayerName(taze), taze); } } else { SendClientMessage(playerid, COLOR_MSG, "[ERROR] The player is not connected!"); } } else { SendClientMessage(playerid, COLOR_MSG, "[ERROR] You are not a Police Officer!"); } } return 1; } |
Quote:
Код:
if(strcmp(cmd, "/heal", true) == 0) { tmp = strtok(cmdtext, idx); new Float:health; if(strlen(tmp) == 0) return SendClientMessage(playerid, ERROR, "Use /heal [id] to heal."); else { GetPlayerHealth(strlen(tmp), health); if(IsPlayerSpawned(playerid)) { if(gTeam[playerid] == Medic) { if(strval(tmp) != playerid) { if(!IsPlayerInAnyVehicle(playerid)) { if(!IsPlayerInAnyVehicle(strval(tmp))) { if(IsPlayerConnected(strval(tmp))) { if(GetPlayerMoney(strval(tmp) > 499)) { if(GetDistanceBetweenPlayers(playerid, strval(tmp)) <= 3) { if(health < 100) { new string[250], string2[250], healedname[MAX_PLAYER_NAME], medicname[MAX_PLAYER_NAME]; GetPlayerName(playerid, medicname, sizeof(medicname)); GetPlayerName(strval(tmp), healedname, sizeof(healedname)); format(string, sizeof(string), "You have healed from %s (%d)! You give him $ 500!", medicname, playerid); SendClientMessage(strval(tmp), SERVER_COLOR, string); format(string2, sizeof(string2), "You heal %s (%d)! You received $ 500", healedname, strval(tmp)); SendClientMessage(playerid, SERVER_COLOR, string2); GivePlayerMoney(playerid, 500); GivePlayerMoney(strval(tmp), -500); SetPlayerHealth(strval(tmp), 100); GivePlayerScore(playerid, 1); } else if(health == 100) return SendClientMessage(playerid, ERROR, "You seem OK to me."); } else { new string[250], faraway[MAX_PLAYER_NAME]; GetPlayerName(strval(tmp), faraway, sizeof(faraway)); format(string, sizeof(string), "%s (%d) is too far away.", faraway, strval(tmp)); return SendClientMessage(playerid, ERROR, string); } } else if(GetPlayerMoney(strval(tmp)) == 0) { new string[250], poor[MAX_PLAYER_NAME]; GetPlayerName(strval(tmp), poor, sizeof(poor)); format(string, sizeof(string), "%s (%d) does not have any money.", poor, strval(tmp)); return SendClientMessage(playerid, ERROR, string); } } } else if(!IsPlayerConnected(strval(tmp))) { new string[250]; format(string, sizeof(string), "ID %d is not connected.", strval(tmp)); return SendClientMessage(playerid, ERROR, string); } } else if(IsPlayerInAnyVehicle(strval(tmp))) { new string[250], invehicle[MAX_PLAYER_NAME]; GetPlayerName(strval(tmp), invehicle, sizeof(invehicle)); format(string, sizeof(string), "%s (%d) is in a vehicle. You cannot heal him.", invehicle, strval(tmp)); return SendClientMessage(playerid, ERROR, string); } } else if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, ERROR, "You cannot heal anyone from inside a vehicle."); } else return SendClientMessage(playerid, ERROR, "You cannot heal yourself."); } else return SendClientMessage(playerid, ERROR, "Only Medics can use this command!"); } return 1; } |
Quote:
Код:
if(strcmp(cmd, "/arrest", true) == 0 || strcmp(cmd, "/ar", true) == 0) { new string[250]; if(IsSpawned[playerid] == 0) { SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command"); return 1; } if(gTeam[playerid] != COP && gTeam[playerid] != SWAT && gTeam[playerid] != ARMY && gTeam[playerid] != FBI) { SendClientMessage(playerid,COLOR_ERROR,"You are not a Law Enforcement officer "); return 1; } tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, COLOR_ERROR, "USAGE: /ar (id)"); return 1; } giveplayerid = strval(tmp); if(!IsNumeric(tmp)) { SendClientMessage(playerid, COLOR_ERROR, "USAGE: /ar (id)"); return 1; } if(!IsPlayerConnected(giveplayerid)) { format(string, sizeof(string), "ID (%d) is not an active player", giveplayerid); SendClientMessage(playerid, COLOR_ERROR, string); return 1; } new oname[24]; new pname[24]; GetPlayerName(playerid,oname, 24); GetPlayerName(giveplayerid, pname, 24); if(GetPlayerWantedLevel(giveplayerid) <= 3) { format(string, sizeof(string), "%s(%d) Does not have a warrant. You cannot arrest a player without a warrant",pname,giveplayerid); SendClientMessage(playerid,COLOR_ERROR,string); return 1; } if(IsPlayerInAnyVehicle(playerid)) { SendClientMessage(playerid,COLOR_ERROR,"You cannot arrest a suspect if you are in a car"); return 1; } if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 10) { format(string, sizeof(string), "%s(%d) Is too far away. You cannot arrest that player",pname,giveplayerid); SendClientMessage(playerid,COLOR_ERROR,string); return 1; } if(IsSpawned[giveplayerid] == 0) { format(string, sizeof(string), "%s(%d) Is dead. You cannot arrest a dead body",pname,giveplayerid); SendClientMessage(playerid,COLOR_ERROR,string); return 1; } SetPlayerVirtualWorld(giveplayerid,0); if(GetPlayerWantedLevel(playerid) >=1) { SendClientMessage(playerid,COLOR_ERROR,"You cannot use this command if you are wanted by the police"); return 1; } if(giveplayerid == playerid) { SendClientMessage(playerid,COLOR_ERROR,"You cannot arrest yourself"); return 1; } new spawn = random(sizeof(PrisonSpawn)), string2[250], Float:health, copname[MAX_PLAYER_NAME], arrested[MAX_PLAYER_NAME]; GetPlayerName(playerid, copname, sizeof(copname)); GetPlayerName(strval(tmp), arrested, sizeof(arrested)); GetPlayerHealth(strval(tmp), health); SendClientMessage(strval(tmp), GREY, "|_| San Andreas Police Dept. |_|"); format(string, sizeof(string), "You have been arrested by Law Enforcement Officer %s (%d).", copname); SendClientMessage(strval(tmp), WHITE, string); ResetPlayerWeapons(strval(tmp)); SetPlayerPos(strval(tmp), PrisonSpawn[spawn][0], PrisonSpawn[spawn][1], PrisonSpawn[spawn][2]); SetPlayerFacingAngle(strval(tmp), PrisonSpawn[spawn][3]); SetCameraBehindPlayer(strval(tmp)); if(GetPlayerWantedLevel(strval(tmp)) >= 4 && GetPlayerWantedLevel(strval(tmp)) <= 5) { PrisonTime[strval(tmp)] = 60; GivePlayerMoney(playerid,25000); GivePlayerScore(playerid,1); } else if(GetPlayerWantedLevel(strval(tmp)) >= 6 && GetPlayerWantedLevel(strval(tmp)) <= 8) { PrisonTime[strval(tmp)] = 120; GivePlayerMoney(playerid,35000); GivePlayerScore(playerid,1); } else if(GetPlayerWantedLevel(strval(tmp)) >= 9 && GetPlayerWantedLevel(playerid) <= 11) { PrisonTime[strval(tmp)] = 180; GivePlayerMoney(playerid,45000); GivePlayerScore(playerid,2); } else if(GetPlayerWantedLevel(strval(tmp)) >= 12 && GetPlayerWantedLevel(strval(tmp)) <= 14) { PrisonTime[strval(tmp)] = 240; GivePlayerMoney(playerid,55000); GivePlayerScore(playerid,2); } else if(GetPlayerWantedLevel(strval(tmp)) >= 15) { PrisonTime[strval(tmp)] = 300; GivePlayerMoney(playerid,65000); GivePlayerScore(playerid,3); } SetPlayerWantedLevel(strval(tmp), 0); SetPlayerInterior(strval(tmp),3); SetPlayerHealth(strval(tmp),99999); TogglePlayerControllable(strval(tmp), true); SetPlayerJailed(strval(tmp), true); format(string2, sizeof(string2), "Law Enforcement Officer %s (%d) has arrested Wanted Suspect %s (%d).", copname, playerid, arrested, strval(tmp)); Announce(string2); if(health <= 90) { SendClientMessage(strval(tmp), GREY, "|_| San Andreas Police Dept. |_|"); SendClientMessage(strval(tmp), WHITE, "SAPD has given you some food."); SetPlayerHealth(strval(tmp), health+10); ApplyAnimation(strval(tmp), "FOOD", "EAT_Burger", 4.0, 0, 0, 0, 0, 0); } return 1; } |