Adding a job - error index out of bounds.. how?
#1

I have recently tried to add a job to my script, but apparently it won't let me. I don't get what's wrong, because all the other jobs works perfectly fine. And I can't find anything different that this job doesn't include, but I am still getting this error. So when I do /makejob 6 Farmer it gives me "Unknown command". Farmer job has been defined as jobid 6. However if I do /makejob 5 Something it works perfectly fine, but is of course not the farmer job though. Do you guys see why it wouldn't let me make that job? It has been defined as number 6 at the top of the script (code shown below).

Adding a farmer job, which will get "slot" 6 as 0-5 is already used by other jobs.
Код:
#DEFINE FARMER 6 (added at the top of the script)
Код:
CMD:makejob(playerid, params[])
{
	if(!CheckAdmin(playerid, HIGH_ADMIN_LEVEL)) return NotAuthMSG(playerid);
	new jobid, name[64], Float:x, Float:y, Float:z;
	if(sscanf(params,"ds[64]ddd", jobid, name)) return SyntaxMSG(playerid, "/makejob [jobid] [name]");
	x = PlayerPosX(playerid); y = PlayerPosY(playerid); z = PlayerPosZ(playerid);
	format(JobsInfo[jobid][jobName], 128, "%s", name);  // GETTING ERROR HERE (Array index out of bounds - acceing elemnt at index 6 past array upper bound 5)
	JobsInfo[jobid][jobX] = x;
	JobsInfo[jobid][jobY] = y;
	JobsInfo[jobid][jobZ] = z;
	JobsInfo[jobid][jobOn] = 1;
	format(msg, sizeof(msg), "A new job was added, [JobID: %d, Name: %s]", jobid, name);
	SCM(playerid, COLOR_RED, msg);
	AddJobToFile(jobid, name, x, y, z);
	return 1;
}
Код:
public LoadDynamicJobs()
{
    new rows, fields;
	new total = 0, jobid = 0;
    cache_get_data(rows, fields);
    if(rows)
    {
		while(total < rows)
		{
			jobid = cache_get_row_int(total, 1);
			JobsInfo[jobid][jobID] = cache_get_row_int(total, 0); // GETTING ERROR HERE (Array index out of bounds - acceing elemnt at index 6 past array upper bound 5)
			cache_get_row(total, 2, JobsInfo[jobid][jobName], dbHandle, 128);
			JobsInfo[jobid][jobX] = cache_get_row_float(total, 3);
			JobsInfo[jobid][jobY] = cache_get_row_float(total, 4);
			JobsInfo[jobid][jobZ] = cache_get_row_float(total, 5);
			JobsInfo[jobid][jobSideJob] = cache_get_row_int(total, 18);
			JobsInfo[jobid][jobOn] = 1;
		}
    }
    return 1;
}
AddJobToFile:
Код:
stock AddJobToFile(jobid, name[], Float:x, Float:y, Float:z)
{
	format(query, sizeof(query), "INSERT INTO `jobs` (jobid, name, posx, posy, posz) VALUES(%d, '%s', %f, %f, %f)", jobid, name, x, y, z);
	mysql_function_query(dbHandle, query, true, "OnJobInsert", "d", jobid);
	return 1;
}
OnJobInsert:
Код:
public OnJobInsert(JobID)
{
	JobsInfo[JobID][jobID] = cache_insert_id(dbHandle);
	return 1;
}
JobsInfo:
Код:
enum JOBS_INFO
{
	jobID,
	jobPickUp,
	Text3D:jobLabel,
	jobName[64],
	Float:jobX,
	Float:jobY,
	Float:jobZ,
	jobOn
}
new JobsInfo[MAX_JOBS][JOBS_INFO];
Reply
#2

If FARMER is jobid 6, then MAX_JOBS should be 7. It is currently 6 according to crashdetect.

Just to point out a mistake I noticed:
pawn Код:
if(sscanf(params,"ds[64]ddd", jobid, name)) return SyntaxMSG(playerid, "/makejob [jobid] [name]");
5 specifiers and 2 arguments given. Remove the last 3 "ddd" specifiers.

strcpy would be better than format for copying strings.
Reply
#3

PHP код:
CMD:makejob(playeridparams[])
{
    if(!
CheckAdmin(playeridHIGH_ADMIN_LEVEL)) return NotAuthMSG(playerid);
    new 
jobidname[64], Float:xFloat:yFloat:z;
    
/*if(sscanf(params,"ds[64]ddd", jobid, name)) return SyntaxMSG(playerid, "/makejob [jobid] [name]");
    its wrong change it to*/
if(sscanf(params,"ds[64]"jobidname)) return SyntaxMSG(playerid"/makejob [jobid] [name]");
PlayerPosX(playerid); PlayerPosY(playerid); PlayerPosZ(playerid);
    
format(JobsInfo[jobid][jobName], 128"%s"name);  // GETTING ERROR HERE (Array index out of bounds - acceing elemnt at index 6 past array upper bound 5)
    
JobsInfo[jobid][jobX] = x;
    
JobsInfo[jobid][jobY] = y;
    
JobsInfo[jobid][jobZ] = z;
    
JobsInfo[jobid][jobOn] = 1;
    
format(msgsizeof(msg), "A new job was added, [JobID: %d, Name: %s]"jobidname);
    
SCM(playeridCOLOR_REDmsg);
    
AddJobToFile(jobidnamexyz);
    return 
1;

and as about the concept of indices its should be 7 not 6
(the MAX_JOBS)
Reply
#4

Alright, will try that out. It was set to 5, so when I added the new job I simply thought it'd work out when I increased it to 6 but apparently not. Hopefully it works, thanks.

Worked, thanks.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)