17.05.2016, 12:02
Hello , I want to ask what is wrong with the code below , because already check killerid is valid before using it in an array.
code onplayerdeath:
errors arising:
please help me to be able to fix this error, thanks
code onplayerdeath:
Код:
public OnPlayerDeath(playerid, killerid, reason) { new pname[MAX_PLAYER_NAME], reasonMsg[32], string[128], deathreason[20], killer[MAX_PLAYER_NAME]; if(killerid != INVALID_PLAYER_ID) { GetPlayerName(killerid, killer, sizeof(killer)); } SendDeathMessage(killerid,playerid,reason); GetPlayerName(playerid, pname, sizeof(pname)); if(reason != 255) GetWeaponName(reason, deathreason, 20); SetPlayerWorldBounds(playerid,20000.0000,-20000.0000,20000.0000,-20000.0000); //Reset world to player //--------------------------------Death Reasons--------------------------------- if(killerid != INVALID_PLAYER_ID && killerid != playerid && reason != 255) { switch(reason) { case 0: { reasonMsg = "Unarmed"; } case 1: { reasonMsg = "Brass Knuckles"; } case 2: { reasonMsg = "Golf Club"; } case 3: { reasonMsg = "Day Stick"; } case 4: { reasonMsg = "Knife"; } case 5: { reasonMsg = "Baseball Bat"; } case 6: { reasonMsg = "Shovel"; } case 7: { reasonMsg = "Pool Cue"; } case 8: { reasonMsg = "Katana"; } case 9: { reasonMsg = "Chainsaw"; } case 10: { reasonMsg = "Dildo"; } case 11: { reasonMsg = "Dildo"; } case 12: { reasonMsg = "Vibrator"; } case 13: { reasonMsg = "Vibrator"; } case 14: { reasonMsg = "Flowers"; } case 15: { reasonMsg = "Cane"; } case 22: { reasonMsg = "Pistol"; } case 23: { reasonMsg = "Silenced Pistol"; } case 24: { reasonMsg = "Desert Eagle"; } case 25: { reasonMsg = "Shotgun"; } case 26: { reasonMsg = "Sawn-off Shotgun"; } case 27: { reasonMsg = "Combat Shotgun"; } case 28: { reasonMsg = "MAC-10"; } case 29: { reasonMsg = "MP5"; } case 30: { reasonMsg = "AK-47"; } case 31: { if (GetPlayerState(killerid) == PLAYER_STATE_DRIVER) { switch (GetVehicleModel(GetPlayerVehicleID(killerid))) { case 447: { reasonMsg = "Sea Sparrow Machine Gun"; } default: { reasonMsg = "M4"; } } } else { reasonMsg = "M4"; } } case 32: { reasonMsg = "TEC-9"; } case 33: { reasonMsg = "Rifle"; } case 34: { reasonMsg = "Sniper Rifle"; } case 37: { reasonMsg = "Fire"; } case 38: { if (GetPlayerState(killerid) == PLAYER_STATE_DRIVER) { switch (GetVehicleModel(GetPlayerVehicleID(killerid))) { case 425: { reasonMsg = "Hunter Machine Gun"; } default: { reasonMsg = "Minigun"; } } } else { reasonMsg = "Minigun"; } } case 41: { reasonMsg = "Spraycan"; } case 42: { reasonMsg = "Fire Extinguisher"; } case 49: { reasonMsg = "Vehicle Collision"; } case 50: { if (GetPlayerState(killerid) == PLAYER_STATE_DRIVER) { switch (GetVehicleModel(GetPlayerVehicleID(killerid))) { case 417, 425, 447, 465, 469, 487, 488, 497, 501, 548, 563: { reasonMsg = "Helicopter Blades"; } default: { reasonMsg = "Vehicle Collision"; } } } else { reasonMsg = "Vehicle Collision"; } } case 51: { if (GetPlayerState(killerid) == PLAYER_STATE_DRIVER) { switch (GetVehicleModel(GetPlayerVehicleID(killerid))) { case 425: { reasonMsg = "Hunter Rockets"; } case 432: { reasonMsg = "Rhino Turret"; } case 520: { reasonMsg = "Hydra Rockets"; } default: { reasonMsg = "Explosion"; } } } else { reasonMsg = "Explosion"; } } default: { reasonMsg = "Unknown"; } } format(string, sizeof(string), "*** %s killed %s. (%s)", killer, pname, reasonMsg); } else { switch (reason) { case 53: { format(string, sizeof(string), "*** %s died. (Drowned)", pname); } case 54: { format(string, sizeof(string), "*** %s died. (Collision)", pname); } default: { format(string, sizeof(string), "*** %s died.", pname); } } } //---------------------------------LAdmin--------------------------------------- InDuel[playerid] = 0; if(killerid != INVALID_PLAYER_ID && killerid != playerid && IsPlayerConnected(killerid)) { if(InDuel[playerid] == 1 && InDuel[killerid] == 1) { GameTextForPlayer(playerid,"Loser !",3000,3); GameTextForPlayer(killerid,"Winner !",3000,3); InDuel[killerid] = 0; SetPlayerPos(killerid, 0.0, 0.0, 0.0); SpawnPlayer(killerid); } else if(InDuel[playerid] == 1 && InDuel[killerid] == 0) { GameTextForPlayer(playerid,"Loser !",3000,3); } } #if defined ENABLE_SPEC for(new x = 0, j = GetPlayerPoolSize(); x <= j; x++) { if(GetPlayerState(x) == PLAYER_STATE_SPECTATING && PlayerInfo[x][SpecID] == playerid) { AdvanceSpectate(x); } } #endif //-------------------------------------Normal----------------------------------- if(killerid != INVALID_PLAYER_ID) { PlayerInfo[killerid][Kills]++; SetPlayerScore(killerid, GetPlayerScore(killerid) + 1); } SetPlayerScore(playerid, GetPlayerScore(playerid) - 1); PlayerInfo[playerid][Deaths]++; new moneytemp; moneytemp = GetPlayerCash(playerid)/8; if(moneytemp<=5000) { if(killerid != INVALID_PLAYER_ID) { GivePlayerCash(killerid,moneytemp); } GivePlayerCash(playerid,-moneytemp); } else if(moneytemp>5000) { if(killerid != INVALID_PLAYER_ID) { GivePlayerCash(killerid,5000); } GivePlayerCash(playerid,-5000); } SendClientMessageToAll(red, string); DropWeapons(playerid); IsSpawned[playerid] = 0; JailTime[playerid] = 0; OutRun[playerid] = 0; Anti_heal[playerid] = 0; Anti_armour[playerid] = 0; weaponpackage[playerid] = 0; rankusage[playerid] = 0; InRent[playerid] = 0; //---------------------------------Job System----------------------------------- DisablePlayerCheckpoint(playerid); RemovePlayerAttachedObject(playerid, 9); PizzaJob[playerid] = 0; HotdogJob[playerid] = 0; SweeperJob[playerid] = 0; HackerJob[playerid] = 0; TerroristBomb[playerid] = 0; KillTimer(TLimitTimer); KillTimer(PLimitTimer); KillTimer(HLimitTimer); KillTimer(SLimitTimer); KillTimer(HJLimitTimer); //------------------------------------------------------------------------------ Worms[playerid] = 0; FishWeight[playerid] = 0; Fishes[playerid] = 0; FishingTool[playerid] = 0; //-------------------------------Vehicle System--------------------------------- if(GetPVarInt(playerid, "YEAH") == 1) { DestroyObject(GPSObject[playerid]); SetPVarInt(playerid, "YEAH",0); DeletePVar(playerid, "Spongebob"); DeletePVar(playerid, "Mario"); DeletePVar(playerid, "SpiderPig"); DeletePVar(playerid, "FAIL"); } //----------------------------------Gang System--------------------------------- if(Player[playerid][PlayerGang] != -1) { new zone = Gang[Player[playerid][PlayerGang]][CurrentZone], total = -1; if(zone != -1) { total = 0; foreach(new p : Player) { if(Player[p][PlayerGang] == Player[playerid][PlayerGang]) { if(Area_GetPlayerAreas(p, 0) == GangZone[zone][ZoneArea]) total++; } } } if(total == 0) { new msg[128]; format(msg, sizeof(msg), "{FF0000}** %s gang failed to capture %s zone!", Gang[Player[playerid][PlayerGang]][GangName], GangZone[zone][ZoneName]); SendClientMessageToAll(-1, msg); format(msg, sizeof(msg), "{FF0000}** %s zone will be locked for %d minutes!", GangZone[zone][ZoneName], LOCKED_MINUTES); SendClientMessageToAll(-1, msg); Gang[Player[playerid][PlayerGang]][CurrentZone] = -1; GangZone[zone][ZoneLocked] = GetTickCount(); GangZone[zone][ZoneStatus] = false; GangZoneStopFlashForAll(GangZone[zone][ZoneHolder]); } } //----------------------------Killing Spree Point Blank------------------------- if(killerid != INVALID_PLAYER_ID && killerid != playerid) { GetPlayerName(killerid, PBKName, sizeof(PBKName)); PlayerTotalKills[killerid] = PlayerTotalKills[killerid] +1; PlayerTotalKills[playerid] = 0; if(PlayerTotalKills[killerid] == 1) { PlayAudioStreamForPlayer(killerid, "http://khususgaming.ga/music/Ohyeah.mp3"); PlayAudioStreamForPlayer(playerid, "http://khususgaming.ga/music/Ohyeah.mp3"); format(pbstring, sizeof(pbstring), "~r~OH YEAH"); GameTextForPlayer(killerid, pbstring, 10000,3); format(pbstring, sizeof(pbstring), "~r~%s: OH YEAH", PBKName); GameTextForPlayer(playerid, pbstring, 10000,3); } else if(PlayerTotalKills[killerid] == 2) { PlayAudioStreamForPlayer(killerid, "http://khususgaming.ga/music/Doublekill.mp3"); PlayAudioStreamForPlayer(playerid, "http://khususgaming.ga/music/Doublekill.mp3"); format(pbstring, sizeof(pbstring), "~r~DOUBLE KILL"); GameTextForPlayer(killerid, pbstring, 10000,3); format(pbstring, sizeof(pbstring), "~r~%s: DOUBLE KILL",PBKName); GameTextForPlayer(playerid, pbstring, 10000,3); } else if(PlayerTotalKills[killerid] == 3) { PlayAudioStreamForPlayer(killerid, "http://khususgaming.ga/music/Triplekill.mp3"); PlayAudioStreamForPlayer(playerid, "http://khususgaming.ga/music/Triplekill.mp3"); format(pbstring, sizeof(pbstring), "~r~TRIPLE KILL"); GameTextForPlayer(killerid, pbstring, 10000,3); format(pbstring, sizeof(pbstring), "~r~%s: TRIPLE KILL",PBKName); GameTextForPlayer(playerid, pbstring, 10000,3); } else if(PlayerTotalKills[killerid] > 3) { PlayAudioStreamForPlayer(killerid, "http://khususgaming.ga/music/Chainkiller.mp3"); PlayAudioStreamForPlayer(playerid, "http://khususgaming.ga/music/Chainkiller.mp3"); format(pbstring, sizeof(pbstring), "~r~CHAIN KILLER"); GameTextForPlayer(killerid, pbstring, 10000,3); format(pbstring, sizeof(pbstring), "~r~%s: CHAIN KILLER",PBKName); GameTextForPlayer(playerid, pbstring, 10000,3); } } //-----------------------------------Most Wanted-------------------------------- if(killerid != INVALID_PLAYER_ID && killerid != playerid) { MostKill[killerid] = MostKill[killerid] +1; if(MostKill[killerid] == 1) { SetPlayerWantedLevel(killerid, 1); } else if(MostKill[killerid] == 2) { SetPlayerWantedLevel(killerid, 2); } else if(MostKill[killerid] == 3) { SetPlayerWantedLevel(killerid, 3); } else if(MostKill[killerid] == 4) { SetPlayerWantedLevel(killerid, 4); } else if(MostKill[killerid] == 5) { SetPlayerWantedLevel(killerid, 5); } else if(MostKill[killerid] == 6) { SetPlayerWantedLevel(killerid, 6); new str[256], xName[MAX_PLAYER_NAME]; GetPlayerName(killerid,xName,MAX_PLAYER_NAME); format(str,256,"{F81414}[SERVER] {FFFFFF}%s (%i) now is Most Wanted, kill him and get reward.",xName,killerid); SendClientMessageToAll(-1,str); SendClientMessage(killerid,0xFFFF00AA,"You get $10000 for killing 6 player (Most Wanted)."); GivePlayerCash(killerid, 10000); SetPlayerArmour(killerid,100); SetPlayerHealth(killerid,100); MWTD[killerid] = CreateDynamic3DTextLabel("{00FF00}(Most Wanted)", -1, 0.0, 0.0, -0.9, 20, killerid, INVALID_VEHICLE_ID, 0, -1, -1, -1, 25.0); } else if(MostKill[killerid] > 6) { } if(MostKill[playerid] > 6) { GivePlayerCash(killerid, 10000); SendClientMessage(killerid,0xFFFF00AA,"You get $10000 for killing MostWanted."); } } MostKill[playerid] = 0; if(MostKill[playerid] == 0) { SetPlayerWantedLevel(playerid,0); DestroyDynamic3DTextLabel(MWTD[playerid]); } //------------------------------------Outrun------------------------------------ if(GetPVarInt(playerid, "LRRequest") != -1) { SendClientMessage(playerid, COLOR_BRIGHTRED, "You lost the Outrun race.."); SetPVarInt(playerid, "ORLoser", 1); } //------------------------------------------------------------------------------ if(PlayerinMMDM[killerid] == 1 && killerid != INVALID_PLAYER_ID) { rInfo[killerid][rxp] += 1; } //------------------------------------------------------------------------------ if(gettime() - GetPVarInt(playerid,"PlayerLastDeath") < 1) { Kick(playerid); } SetPVarInt(playerid,"PlayerLastDeath",gettime()); //---------------------------------Duel System---------------------------------- if(InDual[playerid] == 1 || InDual[killerid] == 1) { new dstring[256]; new killername[MAX_PLAYER_NAME]; new playername[MAX_PLAYER_NAME]; if(killerid != INVALID_PLAYER_ID && killerid != playerid) { GetPlayerName(killerid, killername, sizeof(killername)); GetPlayerName(playerid, playername, sizeof(playername)); if(DualRoom1 == playerid || DualRoom1 == killerid) { invitation[playerid] = -1; invitationSent[playerid] = -1; invitation[killerid] = -1; invitationSent[killerid] = -1; InDual[playerid] = 0; InDual[killerid] = 0; format(dstring, sizeof(dstring), "[DUEL PLAYER] %s defeated %s in a duel and wins $%d +1 score.", killername, playername, DualRoom1price); SendClientMessageToAll(COLOR_GREEN, dstring); GivePlayerCash(killerid, (DualRoom1price*2)); SetPlayerScore(killerid, GetPlayerScore(killerid) + 1); SpawnPlayer(killerid); SetPlayerVirtualWorld(playerid,0); SetPlayerVirtualWorld(killerid,0); DualRoom1 = -1; rInfo[killerid][rxp] += 1; return 1; } else if(DualRoom2 == playerid || DualRoom2 == killerid) { invitation[playerid] = -1; invitationSent[playerid] = -1; invitation[killerid] = -1; invitationSent[killerid] = -1; InDual[playerid] = 0; InDual[killerid] = 0; format(dstring, sizeof(dstring), "[DUEL PLAYER] %s defeated %s in a duel and wins $%d +1 score.", killername, playername, DualRoom2price); SendClientMessageToAll(COLOR_GREEN, dstring); GivePlayerCash(killerid, (DualRoom2price*2)); SetPlayerScore(killerid, GetPlayerScore(killerid) + 1); SpawnPlayer(killerid); SetPlayerVirtualWorld(playerid,0); SetPlayerVirtualWorld(killerid,0); DualRoom2 = -1; rInfo[killerid][rxp] += 1; return 1; } else if(DualRoom3 == playerid || DualRoom3 == killerid) { invitation[playerid] = -1; invitationSent[playerid] = -1; invitation[killerid] = -1; invitationSent[killerid] = -1; InDual[playerid] = 0; InDual[killerid] = 0; format(dstring, sizeof(dstring), "[DUEL PLAYER] %s defeated %s in a duel and wins $%d +1 score.", killername, playername, DualRoom3price); SendClientMessageToAll(COLOR_GREEN, dstring); GivePlayerCash(killerid, (DualRoom3price*2)); SetPlayerScore(killerid, GetPlayerScore(killerid) + 1); SpawnPlayer(killerid); SetPlayerVirtualWorld(playerid,0); SetPlayerVirtualWorld(killerid,0); DualRoom3 = -1; rInfo[killerid][rxp] += 1; return 1; } else if(DualRoom4 == playerid || DualRoom4 == killerid) { invitation[playerid] = -1; invitationSent[playerid] = -1; invitation[killerid] = -1; invitationSent[killerid] = -1; InDual[playerid] = 0; InDual[killerid] = 0; format(dstring, sizeof(dstring), "[DUEL PLAYER] %s defeated %s in a duel and wins $%d +1 score.", killername, playername, DualRoom4price); SendClientMessageToAll(COLOR_GREEN, dstring); GivePlayerCash(killerid, (DualRoom4price*2)); SetPlayerScore(killerid, GetPlayerScore(killerid) + 1); SpawnPlayer(killerid); SetPlayerVirtualWorld(playerid,0); SetPlayerVirtualWorld(killerid,0); DualRoom4 = -1; rInfo[killerid][rxp] += 1; return 1; } } return 1; } new mgstring[256]; if(playerintdm[playerid] == 1) { new tdmPlayerName[MAX_PLAYER_NAME]; GetPlayerName(playerid, tdmPlayerName, sizeof(tdmPlayerName)); if(GetPlayerColor(playerid) == 0x0000BBAA) { format(mgstring, sizeof(mgstring), "[MINIGAMES] %s has been dropped out of the Team DM, team blue", tdmPlayerName); blueplayers = blueplayers-1; } else { format(mgstring, sizeof(mgstring), "[MINIGAMES] %s has been dropped out of the Team DM, team red", tdmPlayerName); redplayers = redplayers-1; } SendClientMessageToAll(0x33AA33AA, string); playerintdm[playerid] = 0; playerinminigame[playerid] = 0; if(tdmrank == 0) { tdmplaying = 0; tdmrank = 0; tdmon = 0; KillTimer(tdmtimer); return 1; } if((blueplayers == 0 || redplayers == 0) && tdmplaying == 1) { if(blueplayers == 0) { format(mgstring, sizeof(mgstring), "[MINIGAMES] Team red has won the Team DM"); } else if(redplayers == 0) { format(mgstring, sizeof(mgstring), "[MINIGAMES] Team blue has won the Team DM"); } SendClientMessageToAll(0x33AA33AA, mgstring); for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) { if (IsPlayerConnected(i) && playerintdm[i] == 1) { playerintdm[i] = 0; playerinminigame[i] = 0; SetPlayerVirtualWorld(i,0); SetPlayerInterior(playerid, 0); SetPlayerColor(i,oldplayercolor[i]); SpawnPlayer(i); } } tdmplaying = 0; tdmrank = 0; tdmon = 0; KillTimer(tdmtimer); return 1; } tdmrank--; } else if(playerindm[playerid] == 1) { new dmPlayerName[MAX_PLAYER_NAME]; GetPlayerName(playerid, dmPlayerName, sizeof(dmPlayerName)); format(string, sizeof(string), "[MINIGAMES] %s has been dropped out of the LVDM, rank: %d", dmPlayerName, dmrank); SendClientMessageToAll(0x33AA33AA, string); playerindm[playerid] = 0; playerinminigame[playerid] = 0; SetPlayerVirtualWorld(playerid,0); if(dmrank <= 2) { for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) { if (IsPlayerConnected(i) && playerindm[i] == 1) { new dmwinnername[256]; GetPlayerName(i,dmwinnername, sizeof(dmwinnername)); RewardCalc(i,10000,20000); format(string, sizeof(string), "[MINIGAMES] %s has won the LVDM for $%d", dmwinnername, reward); SendClientMessageToAll(0x33AA33AA, string); GivePlayerCash(i,reward); rInfo[i][rxp] += 1; playerindm[i] = 0; playerinminigame[i] = 0; SetPlayerVirtualWorld(i,0); SetPlayerInterior(playerid, 0); SpawnPlayer(i); } } dmplaying = 0; dmrank = 0; dmon = 0; KillTimer(dmtimer); return 1; } dmrank--; } else if(playerinbox[playerid] == 1) { new boxPlayerName[MAX_PLAYER_NAME]; GetPlayerName(playerid, boxPlayerName, sizeof(boxPlayerName)); format(string, sizeof(string), "[MINIGAMES] %s has been dropped out of the Boxing Fight, rank: %d", boxPlayerName, boxrank); SendClientMessageToAll(0x33AA33AA, string); playerinbox[playerid] = 0; playerinminigame[playerid] = 0; SetPlayerVirtualWorld(playerid,0); if(boxrank <= 2) { for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) { if (IsPlayerConnected(i) && playerinbox[i] == 1) { new boxwinnername[256]; GetPlayerName(i,boxwinnername, sizeof(boxwinnername)); RewardCalc(i,10000,20000); format(string, sizeof(string), "[MINIGAMES] %s has won the Boxing Fight for $%d", boxwinnername, reward); SendClientMessageToAll(0x33AA33AA, string); GivePlayerCash(i,reward); rInfo[i][rxp] += 1; playerinbox[i] = 0; playerinminigame[i] = 0; SetPlayerVirtualWorld(i,0); SetPlayerInterior(playerid, 0); SpawnPlayer(i); } } boxplaying = 0; boxrank = 0; KillTimer(boxtimer); return 1; } boxrank--; } else if(playerinsd[playerid] == 1) { new SkydivePlayerName[MAX_PLAYER_NAME]; GetPlayerName(playerid, SkydivePlayerName, sizeof(SkydivePlayerName)); format(string, sizeof(string), "[MINIGAMES] %s has been dropped out of the Skydive", SkydivePlayerName); SendClientMessageToAll(0x33AA33AA, string); playerinsd[playerid] = 0; playerinminigame[playerid] = 0; SetPlayerVirtualWorld(playerid,0); if(sdrank <= 1) { for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) { if (IsPlayerConnected(i) && playerinsd[i] == 1) { playerinsd[i] = 0; playerinminigame[i] = 0; SetPlayerVirtualWorld(i,0); SetPlayerInterior(playerid, 0); SpawnPlayer(i); } } sdplaying = 0; sdrank = 0; sdon = 0; sdfirst = 0; KillTimer(sdtimer); return 1; } sdrank--; } //------------------------------------------------------------------------------ assert(AntiFlood_Check(playerid)); new fkstr[128]; GetPlayerName(playerid,fkstr,sizeof(fkstr)); SetPVarInt(playerid, "KilledFlood", GetPVarInt(playerid, "KilledFlood") + 1); if(GetPVarInt(playerid, "KilledFlood")> 1) { Kick(playerid); format(fkstr,sizeof(fkstr),"%s was auto kicked. (Reason: Fake-Kill Flood)",fkstr); SendClientMessageToAll(0xDC143CAA, fkstr); } //----------------------------------Rank System--------------------------------- if(killerid != INVALID_PLAYER_ID) rInfo[killerid][rxp] += 1; new INI:rfile = INI_Open(RPath(playerid)); INI_SetTag(rfile,"Player Levels"); INI_WriteInt(rfile,"XP",rInfo[playerid][rxp]); INI_WriteInt(rfile,"Level",rInfo[playerid][rlevel]); INI_Close(rfile); return 1; }
Код:
[18:46:16] [debug] Run time error 4: "Array index out of bounds" [18:46:16] [debug] Accessing element at index 65535 past array upper bound 98 [18:46:16] [debug] AMX backtrace: [18:46:16] [debug] #0 000b31fc in ?? (0, 65535, 255) from KGTDM-VehMysql.amx [18:46:16] [debug] #1 0000b27c in public OnPlayerDeath (0, 65535, 255) from KGTDM-VehMysql.amx