How to get enum id from sql id
#1

Код:
stock GetCellIDFromSQLID(sqlid)
{
	for(new h = 0; h < MAX_CELLS; h++)
	{
		if(CellSystem[h][ID] == sqlid)
		{
			return h;
		}
	}
	return -1;
}
I did this but it does not seem to work it just gives me the first enum id that links to the first cell
Reply
#2

Have you tried debugging it a bit more? Perhaps printing the loop, comparing the two numbers?
Reply
#3

I can't see why its not working tho because I have the same loop on the /enter command for the cells and that works perfectly?
Reply
#4

Anyone got any ideas??
Reply
#5

Maybe your code cause it.
Recheck it or post all code relate to Cell ID, so that we can help u.
Reply
#6

ENUM

Код:
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

Код:
stock GetCellIDFromSQLID(sqlid)
{
	for(new h = 0; h < MAX_CELLS; h++)
	{
		if(CellSystem[h][ID] == sqlid)
		{
			return h;
		}
	}
	return -1;
}
Command

Код:
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;
}
When you do /sellcell confirm it will sell the first cell in my case its A101 not the cell that you own
Reply
#7

You never check if returned cell is valid ( c != -1 )
Also
pawn Код:
GetCellIDFromSQLID(PlayerStat[playerid][Cell]);
To me that looks like PlayerStat[playerid][Cell] might care actuall cell not sql id.

Im sorry but we are going blind here since we can not see the whole system.
Reply
#8

It diffidently holds the cell sql id

Код:
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;
}
Reply
#9

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
You never check if returned cell is valid ( c != -1 )
Also
pawn Код:
GetCellIDFromSQLID(PlayerStat[playerid][Cell]);
To me that looks like PlayerStat[playerid][Cell] might care actuall cell not sql id.

Im sorry but we are going blind here since we can not see the whole system.
What is it you would like me to show you tho?
Reply
#10

Just done some debugging seems like this function

Код:
stock GetCellIDFromSQLID(sqlid)
{
	for(new i = 0; i < sizeof(CellSystem); i ++)
	{
		if(CellSystem[i][ID] == sqlid)
		{
			return i;
		}
	}
	return -1;
}
is returning 0 and not the enum id of the found enum??



Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)