Repair ID
#1

I have a problem with saving repair id and which it won't load.

prints in database,

Код:
PickupID	pux	puy	puz 	
-1 	-2030.85 	179.518 	28.8359

-1 	-2027.27 	172.638 	28.8359

-1 	-2033.39 	175.956 	28.8429
which it keep using -1

Код:
public OnGameModeInit()
{

    for(new i = 0; i != sizeof(ARepairPickups); i++)
	ARepairPickups[i][PickupID] = -1;
	mysql_tquery(MySQL, "SELECT * FROM repair_pickups", "OnLoadRepairPickups");
}


Код:
forward OnLoadRepairPickups(playerid);
public OnLoadRepairPickups()
{
	new count;
	cache_get_row_count(count); // Get total rows
    for(new i; i < count; i++)
	{
        cache_get_value_name_int(0, "PickupID", ARepairPickups[i][PickupID]);
        cache_get_value_float(0, "pux",ARepairPickups[i][pux]);
        cache_get_value_float(0, "puy",ARepairPickups[i][puy]);
        cache_get_value_float(0, "puz",ARepairPickups[i][puz]);
	}
	return 1;
}

AddARepairPickups(Float:x, Float:y, Float:z)
{
	for (new i; i < sizeof(ARepairPickups); i++)
	{
		if (ARepairPickups[i][PickupID] == -1)
		{
			ARepairPickups[i][PickupID] = CreatePickup(3096, 1, x, y, z, 0);
			ARepairPickups[i][pux] = x;
			ARepairPickups[i][puy] = y;
			ARepairPickups[i][puz] = z;
			Create3DTextLabel("{FFFF00}Type {00FF00}/repair {FFFF00}to repair your vehicle!", -1, x, y, z +0.5, 50.0, 0);
			CreateDynamicMapIcon(x, y, z, 27, 0, 0, 0, -1, 300.0);
			printf("PickupID: %d, PosX: %.4f, PosY: %.4f, PosZ: %.4f",ARepairPickups[i][PickupID],x,y,z);
			break;
		}
	}
}

bool:IsPlayerAtRepair(playerid)
{
	for(new i; i != sizeof(ARepairPickups); i++)
	{
		if(ARepairPickups[i][PickupID] != -1)
		{
			printf("IsPlayerAtRepair: PosX: %.4f, PosY: %.4f, PosZ: %.4f",ARepairPickups[i][pux], ARepairPickups[i][puy], ARepairPickups[i][puz]);
		}

		if(ARepairPickups[i][PickupID] != -1 && IsPlayerInRangeOfPoint(playerid, 5.0, ARepairPickups[i][pux], ARepairPickups[i][puy], ARepairPickups[i][puz]))
			return true;
	}

	return false;
}

CMD:createrepair(playerid, params[])
{
   new Float:x, Float:y, Float:z;
   new query[128];
   if(PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playerid, COLOUR_RED, "Administrator status required.");
   GetPlayerPos(playerid, x, y, z);
   AddARepairPickups(x, y, z);
   mysql_format(MySQL, query, 128, "INSERT INTO `repair_system` (`PickupID`, `pux`,`puy`,`puz`) VALUES (%d, %f, %f, %f)",ARepairPickups[playerid][PickupID], x, y, z); // Use %f specifier here, because we insert float for pux puy puz
   mysql_tquery(MySQL, query, "AddARepairPickups", "ffff", ARepairPickups[playerid][PickupID], x, y, z); // AddARepairPickups must be a public function
   return 1;
}
Reply
#2

Код:
cache_get_value_name_int(0, "PickupID", ARepairPickups[i][PickupID]); // use i instead 0
don't save pickup id, because samp generate new when you create it again

regenerate pickups on OnLoadRepairPickups
Reply
#3

Quote:
Originally Posted by iorp
Посмотреть сообщение
Код:
cache_get_value_name_int(0, "PickupID", ARepairPickups[i][PickupID]); // use i instead 0
don't save pickup id, because samp generate new when you create it again

regenerate pickups on OnLoadRepairPickups
still returns -1
Reply
#4

Quote:
Originally Posted by DerickClark
Посмотреть сообщение
still returns -1
update the code

Код:
AddARepairPickups(Float:x, Float:y, Float:z)
{
	for (new i; i < sizeof(ARepairPickups); i++)
	{
		if (ARepairPickups[i][PickupID] == -1)
		{
			ARepairPickups[i][PickupID] = CreatePickup(3096, 1, x, y, z, 0);
			ARepairPickups[i][pux] = x;
			ARepairPickups[i][puy] = y;
			ARepairPickups[i][puz] = z;
			Create3DTextLabel("{FFFF00}Type {00FF00}/repair {FFFF00}to repair your vehicle!", -1, x, y, z +0.5, 50.0, 0);
			CreateDynamicMapIcon(x, y, z, 27, 0, 0, 0, -1, 300.0);
			printf("PickupID: %d, PosX: %.4f, PosY: %.4f, PosZ: %.4f",ARepairPickups[i][PickupID],x,y,z);
			break;
		}
	}
}

////and

AddARepairPickups(x, y, z);
   mysql_format(MySQL, query, 128, "INSERT INTO `repair_system` (`PickupID`, `pux`,`puy`,`puz`) VALUES (%d, %f, %f, %f)",ARepairPickups[playerid][PickupID], x, y, z); // Use %f specifier here, because we insert float for pux puy puz
   mysql_tquery(MySQL, query, "AddARepairPickups", "ffff", ARepairPickups[playerid][PickupID], x, y, z); // AddARepairPickups must be a public function
   return 1;
this is mess, I suggest to start over with clean code
Reply
#5

Quote:
Originally Posted by iorp
Посмотреть сообщение
update the code
Код:
forward OnLoadRepairPickups(playerid);
public OnLoadRepairPickups()
{
	new count;
	cache_get_row_count(count); // Get total rows
    for(new i; i < count; i++)
	{
        cache_get_value_name_int(i, "PickupID", ARepairPickups[i][PickupID]);
        cache_get_value_float(0, "pux",ARepairPickups[i][pux]);
        cache_get_value_float(0, "puy",ARepairPickups[i][puy]);
        cache_get_value_float(0, "puz",ARepairPickups[i][puz]);
	}
	return 1;
}

AddARepairPickups(Float:x, Float:y, Float:z)
{
	for (new i; i < sizeof(ARepairPickups); i++)
	{
		if (ARepairPickups[i][PickupID] == -1)
		{
			ARepairPickups[i][PickupID] = CreatePickup(3096, 1, x, y, z, 0);
			ARepairPickups[i][pux] = x;
			ARepairPickups[i][puy] = y;
			ARepairPickups[i][puz] = z;
			Create3DTextLabel("{FFFF00}Type {00FF00}/repair {FFFF00}to repair your vehicle!", -1, x, y, z +0.5, 50.0, 0);
			CreateDynamicMapIcon(x, y, z, 27, 0, 0, 0, -1, 300.0);
			printf("PickupID: %d, PosX: %.4f, PosY: %.4f, PosZ: %.4f",ARepairPickups[i][PickupID],x,y,z);
			break;
		}
	}
}

bool:IsPlayerAtRepair(playerid)
{
	for(new i; i != sizeof(ARepairPickups); i++)
	{
		if(ARepairPickups[i][PickupID] != -1)
		{
			printf("IsPlayerAtRepair: PosX: %.4f, PosY: %.4f, PosZ: %.4f",ARepairPickups[i][pux], ARepairPickups[i][puy], ARepairPickups[i][puz]);
		}

		if(ARepairPickups[i][PickupID] != -1 && IsPlayerInRangeOfPoint(playerid, 5.0, ARepairPickups[i][pux], ARepairPickups[i][puy], ARepairPickups[i][puz]))
			return true;
	}

	return false;
}

CMD:createrepair(playerid, params[])
{
   new Float:x, Float:y, Float:z;
   new query[128];
   if(PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playerid, COLOUR_RED, "Administrator status required.");
   GetPlayerPos(playerid, x, y, z);
   AddARepairPickups(x, y, z);
   for (new i; i < sizeof(ARepairPickups); i++)
   mysql_format(MySQL, query, 128, "INSERT INTO `repair_system` (`PickupID`, `pux`,`puy`,`puz`) VALUES (%d, %f, %f, %f)",ARepairPickups[i][PickupID], x, y, z); // Use %f specifier here, because we insert float for pux puy puz
   mysql_tquery(MySQL, query, "AddARepairPickups", "dfff", ARepairPickups[playerid][PickupID], x, y, z); // AddARepairPickups must be a public function
   return 1;
}
Reply
#6

Quote:
Originally Posted by DerickClark
Посмотреть сообщение
Код:
forward OnLoadRepairPickups(playerid);
public OnLoadRepairPickups()
{
	new count;
	cache_get_row_count(count); // Get total rows
    for(new i; i < count; i++)
	{
        cache_get_value_name_int(i, "PickupID", ARepairPickups[i][PickupID]);
        cache_get_value_float(0, "pux",ARepairPickups[i][pux]);
        cache_get_value_float(0, "puy",ARepairPickups[i][puy]);
        cache_get_value_float(0, "puz",ARepairPickups[i][puz]);
	}
	return 1;
}

AddARepairPickups(Float:x, Float:y, Float:z)
{
	for (new i; i < sizeof(ARepairPickups); i++)
	{
		if (ARepairPickups[i][PickupID] == -1)
		{
			ARepairPickups[i][PickupID] = CreatePickup(3096, 1, x, y, z, 0);
			ARepairPickups[i][pux] = x;
			ARepairPickups[i][puy] = y;
			ARepairPickups[i][puz] = z;
			Create3DTextLabel("{FFFF00}Type {00FF00}/repair {FFFF00}to repair your vehicle!", -1, x, y, z +0.5, 50.0, 0);
			CreateDynamicMapIcon(x, y, z, 27, 0, 0, 0, -1, 300.0);
			printf("PickupID: %d, PosX: %.4f, PosY: %.4f, PosZ: %.4f",ARepairPickups[i][PickupID],x,y,z);
			break;
		}
	}
}

bool:IsPlayerAtRepair(playerid)
{
	for(new i; i != sizeof(ARepairPickups); i++)
	{
		if(ARepairPickups[i][PickupID] != -1)
		{
			printf("IsPlayerAtRepair: PosX: %.4f, PosY: %.4f, PosZ: %.4f",ARepairPickups[i][pux], ARepairPickups[i][puy], ARepairPickups[i][puz]);
		}

		if(ARepairPickups[i][PickupID] != -1 && IsPlayerInRangeOfPoint(playerid, 5.0, ARepairPickups[i][pux], ARepairPickups[i][puy], ARepairPickups[i][puz]))
			return true;
	}

	return false;
}

CMD:createrepair(playerid, params[])
{
   new Float:x, Float:y, Float:z;
   new query[128];
   if(PlayerInfo[playerid][pAdmin] < 2) return SendClientMessage(playerid, COLOUR_RED, "Administrator status required.");
   GetPlayerPos(playerid, x, y, z);
   AddARepairPickups(x, y, z);
   for (new i; i < sizeof(ARepairPickups); i++)
   mysql_format(MySQL, query, 128, "INSERT INTO `repair_system` (`PickupID`, `pux`,`puy`,`puz`) VALUES (%d, %f, %f, %f)",ARepairPickups[i][PickupID], x, y, z); // Use %f specifier here, because we insert float for pux puy puz
   mysql_tquery(MySQL, query, "AddARepairPickups", "dfff", ARepairPickups[playerid][PickupID], x, y, z); // AddARepairPickups must be a public function
   return 1;
}
still not good code
https://sampwiki.blast.hk/wiki/MySQL/R40
Reply
#7

Does anyone know why not loading repair id?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)