Dynamic job script - actors and saving?
#6

Ah god. This is a mess, don't really understand this loop thing, nor how to load things properly.
Also uploaded the code to pastebin so it's easier to read: http://pastebin.com/YJth3Heh
Код:
#define MAX_JOBS 1
enum JobData
{
	jobid,
	jobtype,
	jobname[MAX_PLAYER_NAME],
	Float:jobposx,
	Float:jobposy,
	Float:jobposz,
	Float:jobposr,
	jobworld,
	actorskin

};
new jobData[MAX_JOBS][JobData];

CMD:createjob(playerid, params[])
{
	if(charData[playerid][characteradmin] > 1) return ErrorMSG(playerid, "You are not authorized to use this command");
	new createjobtype, createjobname[24], createactorskin;
	if(sscanf(params, "is[24]", createjobtype, createjobname, createactorskin)) return UsageMSG(playerid, "/createjob [jobtype] [jobname] [actorskin]");
	if(createjobtype > 6 || createjobtype == 0) return ErrorMSG(playerid, "The job type has to be between 1 and 6");
	new Float:x, Float:y, Float:z, Float:r, createjobworld;
	GetPlayerPos(playerid, x, y, z);
	GetPlayerFacingAngle(playerid, r);
	createjobworld = GetPlayerVirtualWorld(playerid);

	format(jobData[createjobtype][jobname], 24, "%s", createjobname);
	jobData[createjobtype][jobposx] = x;
	jobData[createjobtype][jobposy] = y;
	jobData[createjobtype][jobposz] = z;
	jobData[createjobtype][jobworld] = createjobworld;
	CreateActor(createactorskin, x, y, z, r);

	mysql_format(connection, query, sizeof(query), "INSERT INTO `jobs` (jobtype, jobname, jobposx, jobposy, jobposz, actorskin) VALUES(%d, '%s', %f, %f, %f, %d)", createjobtype, createjobname, x, y, z, createactorskin);
	mysql_tquery(connection, query, "", "");
	return CMD_SUCCESS;
}

CMD:editjob(playerid, params[])
{
	new editjobid, editoption, editjobtext[24];
	if(charData[playerid][characteradmin] > 1) return ErrorMSG(playerid, "You are not authorized to use this command");
	if(sscanf(params, "is[24]", editjobid, editoption, editjobtext)) return UsageMSG(playerid, "/editjob [option(1-name, 2-pos)] [text]");
	if(editoption == 1)
	{
		for(new i = 0, j = cache_get_row_count(); i < MAX_JOBS && i < j; i++) 
		{ 
			if(IsPlayerInRangeOfPoint(playerid, 3, jobData[i][jobposx], jobData[i][jobposy], jobData[i][jobposz]))	
			{	
				new Float:x, Float:y, Float:z;
				GetPlayerPos(playerid, x, y, z);
				mysql_format(connection, query, sizeof(query), "UPDATE `jobs` SET `jobname` = '%s' WHERE `jobid` = %d", editjobtext, i);
				mysql_tquery(connection, query, "", "");
			}
		}
	}
	return CMD_SUCCESS;
}

forward OnLoadJobs();
public OnLoadJobs()
{
	new rows, fields;
	cache_get_data(rows, fields, connection);
	if(rows)
	{
		jobid = cache_get_row_int(rows, 0, connection);
		jobData[jobid][jobtype] = cache_get_field_content_int(1, "jobtype");
		cache_get_row(rows, 2, jobData[jobid][jobname], connection, 24);
		jobData[jobid][jobname] = cache_get_field_content_int(3, "jobname");
		jobData[jobid][jobposx] = cache_get_field_content_float(4, "jobposx");
		jobData[jobid][jobposy] = cache_get_field_content_float(5, "jobposy");
		jobData[jobid][jobposz] = cache_get_field_content_float(6, "jobposz");
		jobData[jobid][jobposr] = cache_get_field_content_float(7, "jobposr");
		jobData[jobid][jobworld] = cache_get_field_content_int(8, "jobworld");
		jobData[jobid][actorskin] = cache_get_field_content_float(6, "actorskin");
		format(msg, sizeof(msg), "%s\n/takejob", jobData[jobid][jobname]);
		CreateActor(jobData[jobid][actorskin], jobData[jobid][jobposx], jobData[jobid][jobposy], jobData[jobid][jobposz], jobData[jobid][jobposr]);
	}
	return true;	
}
Reply


Messages In This Thread
Dynamic job script - actors and saving? - by TheBigFive - 05.08.2016, 20:10
Re: Dynamic job script - actors and saving? - by TheBigFive - 05.08.2016, 23:20
Re: Dynamic job script - actors and saving? - by AndySedeyn - 05.08.2016, 23:26
Re: Dynamic job script - actors and saving? - by TheBigFive - 05.08.2016, 23:56
Re: Dynamic job script - actors and saving? - by AndySedeyn - 06.08.2016, 00:41
Re: Dynamic job script - actors and saving? - by TheBigFive - 06.08.2016, 11:43
Re: Dynamic job script - actors and saving? - by TheBigFive - 06.08.2016, 15:57
Re: Dynamic job script - actors and saving? - by TheBigFive - 12.08.2016, 16:18

Forum Jump:


Users browsing this thread: 2 Guest(s)