02.03.2017, 04:22
Код:
stock GetCellIDFromSQLID(sqlid) { for(new h = 0; h < MAX_CELLS; h++) { if(CellSystem[h][ID] == sqlid) { return h; } } return -1; }
stock GetCellIDFromSQLID(sqlid) { for(new h = 0; h < MAX_CELLS; h++) { if(CellSystem[h][ID] == sqlid) { return h; } } return -1; }
enum CellInfo { ID, CellName[128], CellLocked, CellOwner, CellPrice, CellLevel, CellWeaponOne, CellWeaponTwo, CellWeed, CellCoke, Float:CellEntPosX, Float:CellEntPosY, Float:CellEntPosZ, Float:CellExtPosX, Float:CellExtPosY, Float:CellExtPosZ, CellPickup, CellLabel, CellLoaded, } new CellSystem[MAX_CELLS][CellInfo];
stock GetCellIDFromSQLID(sqlid) { for(new h = 0; h < MAX_CELLS; h++) { if(CellSystem[h][ID] == sqlid) { return h; } } return -1; }
CMD:sellcell(playerid, params[]) { if(PlayerStat[playerid][Logged] != 1 || !IsPlayerConnected(playerid)) return SendErrorMessage(playerid, "Seems like you are not logged in!"); if(PlayerStat[playerid][Cuffed] == 1 || PlayerStat[playerid][Dead] == 1 || PlayerStat[playerid][InHospital] == 1) return SendErrorMessage(playerid, "You cannot use this command at the moment!"); if(PlayerStat[playerid][HasCell] == 0) return SendErrorMessage(playerid, "You don't have a cell you can sell!"); new c = GetCellIDFromSQLID(PlayerStat[playerid][Cell]); new Confirmation[7], msg[255]; if(sscanf(params,"s[128]", Confirmation))return SendClientMessage(playerid, GREY, "Are you SURE you want to sell your cell? if yes, type this: /sellcell confirm"); else if(!strcmp(Confirmation, "confirm", true)) { if(IsPlayerInRangeOfPoint(playerid, 1, CellSystem[c][CellEntPosX], CellSystem[c][CellEntPosY], CellSystem[c][CellEntPosZ])) { new cellPrice = CellSystem[c][CellPrice] / 2; CellSystem[c][CellOwner] = -1; CellSystem[c][CellLocked] = 1; PlayerStat[playerid][HasCell] = 0; PlayerStat[playerid][Cell] = -1; CellSystem[c][CellLevel] = 0; CellSystem[c][CellWeed] = 0; CellSystem[c][CellCoke] = 0; CellSystem[c][CellWeaponOne] = 0; CellSystem[c][CellWeaponTwo] = 0; GiveMoney(playerid, cellPrice); DestroyDynamicPickup(CellSystem[c][CellPickup]); DestroyDynamic3DTextLabel(Text3D:CellSystem[c][CellLabel]); format(msg, sizeof(msg),"You have sold your cell (%s) for $%d.",CellSystem[c][CellName], cellPrice); SendClientMessage(playerid,COLOR_GOLD,msg); UpdateCellDetails©; SaveCells©; } } return true; }
GetCellIDFromSQLID(PlayerStat[playerid][Cell]);
CMD:buycell(playerid, params[]) { if(PlayerStat[playerid][Logged] != 1 || !IsPlayerConnected(playerid)) return SendErrorMessage(playerid, "Seems like you are not logged in!"); if(PlayerStat[playerid][Cuffed] == 1 || PlayerStat[playerid][Dead] == 1 || PlayerStat[playerid][InHospital] == 1) return SendErrorMessage(playerid, "You cannot use this command at the moment!"); if(PlayerStat[playerid][HasCell] != 0) return SendErrorMessage(playerid, "You can't own anymore cells"); for(new c = 0; c < MAX_CELLS; c++) { if (IsPlayerInRangeOfPoint(playerid, 1, CellSystem[c][CellEntPosX], CellSystem[c][CellEntPosY], CellSystem[c][CellEntPosZ])) { if(CellSystem[c][CellOwner] == -1) { if(PlayerStat[playerid][Money] < CellSystem[c][CellPrice]) return SendErrorMessage(playerid, "You don't have enough money for this cell"); GiveMoney(playerid, -CellSystem[c][CellPrice]); MySQLUpdateInt(CellSystem[c][ID], "Cell_Owner", PlayerStat[playerid][ID], "samp_cells"); MySQLUpdateInt(PlayerStat[playerid][ID], "HasCell", 1, "samp_users"); MySQLUpdateInt(PlayerStat[playerid][ID], "Cell", CellSystem[c][ID], "samp_users"); PlayerStat[playerid][HasCell] = 1; PlayerStat[playerid][Cell] = CellSystem[c][ID]; DestroyDynamicPickup(CellSystem[c][CellPickup]); DestroyDynamic3DTextLabel(Text3D:CellSystem[c][CellLabel]); SendServerMessage(playerid, "You have purchased %s for $%d.", CellSystem[c][CellName], CellSystem[c][CellPrice]); UpdateCellDetails©; return true; } else return SendErrorMessage(playerid, "This cell already has a owner!"); } } return true; }
You never check if returned cell is valid ( c != -1 )
Also pawn Код:
Im sorry but we are going blind here since we can not see the whole system. |
stock GetCellIDFromSQLID(sqlid) { for(new i = 0; i < sizeof(CellSystem); i ++) { if(CellSystem[i][ID] == sqlid) { return i; } } return -1; }