Jobs ID's aren't loading successfully.
#1

I'm working on a dynamic job system. Everything works fine and loads fine, but somehow my /gotojob command fails me. Let's say I do /gotojob 1, which should teleport me to the job with the id 1. It doesn't. It teleports me to the job with the id 2 instead. I don't know why or what I did wrong.
But there is the command and the load function for the jobs from the database.

Код:
CMD:gotojob(playerid, params[])
{
	if(pInfo[playerid][pAdminLevel] > 0)
	{
		new aName[MAX_PLAYER_NAME], id;
		GetPlayerName(playerid, aName, sizeof(aName));
		if(sscanf(params, "d", id)) return SendClientMessage(playerid, COLOR_GREY, "Usage: {FFFFFF}/gotojob [jobid]");
		new string[256], string2[256];
		format(string2, sizeof(string2), "Admin %s has teleported to the job %d.", aName, id);
		AdminChat(string2, COLOR_CHATADMIN);
		format(string, sizeof(string), "You have teleported to the job ID: %d.", id);
		SendClientMessage(playerid, COLOR_GREY, string);
		SetPlayerPos(playerid, jInfo[id][jPosX], jInfo[id][jPosY], jInfo[id][jPosZ]);
	}
	else return SendClientMessage(playerid, COLOR_GREY, NotAdmin);
	return 1;
}
Код:
public OnJobsLoad(jobid)
{
	new string5[256], string3[256];
	for(new i = 0; i < cache_num_rows(); i++)
	{
		jInfo[i][jID] = cache_get_field_content_int(i, "jobID");
		cache_get_field_content(i,"jobName",jInfo[i][jName],mysql,256);
		jInfo[i][jPickup] = cache_get_field_content_int(i, "jobPickup");
		jInfo[i][jPosX] = cache_get_field_content_float(i, "jobPosX");
		jInfo[i][jPosY] = cache_get_field_content_float(i, "jobPosY");
		jInfo[i][jPosZ] = cache_get_field_content_float(i, "jobPosZ");
		jInfo[i][jType] = cache_get_field_content_int(i, "jobType");
		jCount++;
		CreatePickup(jInfo[i][jPickup], 1, jInfo[i][jPosX],jInfo[i][jPosY],jInfo[i][jPosZ], 0);
		format(string3, sizeof(string3), "{0095E6}Job ID: {FFFFFF}%d\n{0095E6}Job Name: {FFFFFF}%s\n{0095E6}Use /getjob", jInfo[i][jID], jInfo[i][jName]);
		Create3DTextLabel(string3, 0x008080FF, jInfo[i][jPosX],jInfo[i][jPosY],jInfo[i][jPosZ], 8.0, 0, 0);
	}
	format(string5, sizeof(string5), " %d jobs loaded from database.", jCount);
	print(string5);
	return 1;
}
Код:
	mysql_format(mysql, query2, sizeof(query2), "SELECT * FROM `jobs`");
	mysql_tquery(mysql, query2, "OnJobsLoad");
How can I fix this and what can I do better?
Reply
#2

Try this:

Код:
SetPlayerPos(playerid, jInfo[id-1][jPosX], jInfo[id-1][jPosY], jInfo[id-1][jPosZ]);
First Job ID might be 0. And second it's 1, and so on.
Reply
#3

Quote:
Originally Posted by Lucky13
Посмотреть сообщение
Try this:

Код:
SetPlayerPos(playerid, jInfo[id-1][jPosX], jInfo[id-1][jPosY], jInfo[id-1][jPosZ]);
First Job ID might be 0. And second it's 1, and so on.
But the thing is, whenever I save a job in the database, it saves the id 1 instead of 0. Idk why tho. Is that normal?
Reply
#4

Can I see the Callback where you save them?
Reply
#5

Quote:
Originally Posted by Lucky13
Посмотреть сообщение
Can I see the Callback where you save them?
I don't save them through a callback, but through a command.

Код:
CMD:createjob(playerid, params[])
{
	if(pInfo[playerid][pAdminLevel] >= 5)
	{
		new aName[MAX_PLAYER_NAME], jobid, string3[256], jobname[256], string[1024], query[1024],Float:x, Float:y, Float:z;
		if(GetPlayerVirtualWorld(playerid) > 0) return SendClientMessage(playerid, COLOR_GREY, "You can't create a job in a virtual world.");
		if(sscanf(params, "d", jobid)) 
		{
			SendClientMessage(playerid, COLOR_GREY, "Usage: {FFFFFF}/createjob [type]");
			SendClientMessage(playerid, COLOR_GREY, "Job ID's: Drugs Dealer (1), Arms Dealer (2), Trucker (3), Farmer (4), Garbage Man (5), Detective (6), Car Jacker (7), Street Sweeper (8)");
		}
		else 
		{
			GetPlayerName(playerid, aName, sizeof(aName));
			GetPlayerPos(playerid, x, y, z);
			if(jobid == 1)
			{
				jobname = "Drugs Dealer";
			}
			if(jobid == 2)
			{
				jobname = "Arms Dealer";
			}
			if(jobid == 3)
			{
				jobname = "Trucker";
			}
			if(jobid == 4)
			{
				jobname = "Farmer";
			}
			if(jobid == 5)
			{
				jobname = "Garbage Man";
			}
			if(jobid == 6)
			{
				jobname = "Detective";
			}
			if(jobid == 7)
			{
				jobname = "Car Jacker";
			}
			if(jobid == 8)
			{
				jobname = "Street Sweeper";
			}
			
			mysql_format(mysql, query, sizeof(query), "INSERT INTO `jobs` (`jobName`, `jobPickup`, `jobPosX`, `jobPosY`, `jobPosZ`, `jobType`) VALUES ('%s', 1275, '%f', '%f', '%f', '%d')",  jobname, x, y, z, jobid);
			mysql_tquery(mysql, query, "GetJobID", "i", jobid);
			format(string, sizeof(string), "AdmWarn: {FFFFFF}Admin %s has created a new job %s (%d).", aName, jobname, jobid);
			AdminChat(string, COLOR_RED);
			CreatePickup(1275, 1, x,y,z, 0);
			format(string3, sizeof(string3), "{0095E6}Job ID: {FFFFFF}%d\n{0095E6}Job Name: {FFFFFF}%s\n{0095E6}Use /getjob", jInfo[jobid][jID], jobname);
			Create3DTextLabel(string3, 0x008080FF, x,y,z, 8.0, 0, 0);		
		}
	}
	else return SendClientMessage(playerid, -1, NotAdmin);
	return 1;
}
Btw, I'm romanian too :3
Reply
#6

Maybe if you change it to:

Код:
                        if(jobid == 0)
			{
				jobname = "Drugs Dealer";
			}
			if(jobid == 1)
			{
				jobname = "Arms Dealer";
			}
			if(jobid == 2)
			{
				jobname = "Trucker";
			}
			if(jobid == 3)
			{
				jobname = "Farmer";
			}
			if(jobid == 4)
			{
				jobname = "Garbage Man";
			}
			if(jobid == 5)
			{
				jobname = "Detective";
			}
			if(jobid == 6)
			{
				jobname = "Car Jacker";
			}
			if(jobid == 7)
			{
				jobname = "Street Sweeper";
			}
Would work :3

Nice to hear you are Romanian too :3 If you want, add me on Skype: leather_face_1 and we can fix it there if it's still not good.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)