SA-MP Forums Archive
[HELP] Simple Object Editor - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] Simple Object Editor (/showthread.php?tid=638021)



[HELP] Simple Object Editor Problem [HELP] - ThomasEvil - 25.07.2017

Hello, i use this simple object editor. But i have little problem. When i use /addobject the new object number is 390 instead of 1. 390 becasue i have 390 objects under OnGameModeInIt. How can i do that object made by this editor start at 1 please?

So /addobject creates object number 1. next time /addobject creates object number 2. ect ...

This is the editor:

Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#define culoare 0xFFFFFFAA
new objects;
new objectmodel[500];
forward WriteLog(string[]);
public OnFilterScriptInit()
{
	printf("|------OBJECTS EDITOR--------|");
	printf("|                            |");
	printf("|                            |");
	printf("|                            |");
	printf("|                            |");
	printf("|----------------------------|");
	return 1;
}
COMMAND:addobject(playerid, params[])
{
    new oid,myobject;
	if (!sscanf(params, "i",oid ))
	{
		new string[128];
  		new Float:x, Float:y, Float:z;
    	GetPlayerPos(playerid, x, y, z);
	    myobject = CreateObject(oid, x+2, y+2, z+2, 0.0, 0.0, 90.0);
	    format(string, sizeof(string), "CREATED:%d||CreateObject(%d,%f,%f,%f,0.0,0.0,90.0)",myobject,oid,x,y,z);
	    SendClientMessage(playerid,culoare,string);
	    objectmodel[myobject]=oid;
		objects++;
	    return 1;
	}
	else
	{
	    SendClientMessage(playerid,culoare,"USE : /addobject [objectid]");
	    SendClientMessage(playerid,culoare,"WARNING : Using an wrong id may crash your server");
	    return 1;
	}
}
COMMAND:editobject(playerid, params[])
{
    new oid;
	if (!sscanf(params, "i",oid ))
	{
	    EditObject(playerid, oid);
	    return 1;
	}else{SendClientMessage(playerid,culoare,"USE : /editobject [objectid]");SendClientMessage(playerid,culoare,"INFO :Type /objects for a list of created objects"); return 1;}
	
}
COMMAND:gotoobject(playerid, params[])
{
    new oid;
	if (!sscanf(params, "i",oid ))
	{
	    new Float:xo, Float:yo, Float:zo;
		GetObjectPos(oid, xo, yo, zo);
		SetPlayerPos(playerid,xo+1,yo+1,zo+1);
		return 1;
	}else{SendClientMessage(playerid,culoare,"Use :/gotoobject[objectid]"); return 1;}
}
COMMAND:ohelp(playerid,params[])
{
    SendClientMessage(playerid,culoare,"/addobject || /editobject ||/gotoobject || /objects || /savemap");
    SendClientMessage(playerid,culoare,"/oprew");
	return 1;
}
COMMAND:savemap(playerid, params[])
{
    for(new i = 0; i <=500; i++)
    {
        new stringg[128];
        new Float:RotX,Float:RotY,Float:RotZ;
		GetObjectRot(i, RotX, RotY, RotZ);
		new Float:xo, Float:yo, Float:zo;
		GetObjectPos(i, xo, yo, zo);
		if(xo!=0 && yo!=0 && zo!=0)
		{
	        format(stringg, sizeof(stringg), "CreateObject(%d,%f,%f,%f,%f,%f,%f);",objectmodel[i],xo,yo,zo,RotX,RotY,RotZ,90);
	        WriteLog(stringg);
        }
        
    }
    new stringg[128];
    format(stringg, sizeof(stringg), "________________//\\_______________");
    WriteLog(stringg);
    SendClientMessage(playerid,culoare,"All Objects have been saved to mapa.txt");
    return 1;
}
COMMAND:objects(playerid, params[])
{
	SendClientMessage(playerid,culoare,"___________L I S T______________");
    for(new i = 1; i <=500; i++)
    {
        new stringg[128];
        new Float:RotX,Float:RotY,Float:RotZ;
		GetObjectRot(i, RotX, RotY, RotZ);
		new Float:xo, Float:yo, Float:zo;
		GetObjectPos(i, xo, yo, zo);
		if(xo!=0 && yo!=0 && zo!=0)
		{
        	format(stringg, sizeof(stringg), "ID:%dCreateObject(%d,%f,%f,%f,%f,%f,%f);",i,objectmodel[i],xo,yo,zo,RotX,RotY,RotZ);
        	SendClientMessage(playerid,culoare,stringg);
		}

    }
    SendClientMessage(playerid,culoare,"________________________________");
    return 1;
}
public WriteLog(string[])
{
	new entry[192];
	format(entry, sizeof(entry), "%s\n",string);
	new File:hFile;
	hFile = fopen("mapa.txt", io_append);
	fwrite(hFile, entry);
	fclose(hFile);
	return 1;
}
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
    if(response == EDIT_RESPONSE_FINAL)
	{
    	SetObjectPos(objectid,fX,fY,fZ);
    	SetObjectRot(objectid,fRotX,fRotY,fRotZ);
    	SendClientMessage(playerid,culoare,"Object Saved");
    	return 1;
	}
	return 1;
}
I would love if someone add /attachobject (i mean attach to player) and /attachsave (save position of attached object on player) commands to this code :P


Re: [HELP] Simple Object Editor - BrianFaria - 25.07.2017

what?


Re: [HELP] Simple Object Editor - ThomasEvil - 25.07.2017

When i use /addobject the new object is 391th becasue i have 390x CreateObject under OnGameModeInIt. But i want them in-game made objects to start from 1. not from 390. So i want that /addobject ignore objects made by OnGameModeInIt.


Re: [HELP] Simple Object Editor - ThomasEvil - 26.07.2017

BUMP

I just need that the code ignore previous objects from OnGameModeInIt...
When i add new object with /addobject the new objets is not ID 1, but ID 390 becasue i have 389 objets in my server .. I need to ignore objets from OnGameModeInIt and just create 1-500 objets with this code, to save it later.


Re: [HELP] Simple Object Editor - ThomasEvil - 27.07.2017

BUMP

Anyone?


Re: [HELP] Simple Object Editor - Pottus - 27.07.2017

The problem is here you are not even saving object ids instead relying on the array index of the created object which can work for some systems like vehicles but a bad idea with objects. You should save the objectid on a open array slot then reference that.

Код:
	    myobject = CreateObject(oid, x+2, y+2, z+2, 0.0, 0.0, 90.0);
	    format(string, sizeof(string), "CREATED:%d||CreateObject(%d,%f,%f,%f,0.0,0.0,90.0)",myobject,oid,x,y,z);
	    SendClientMessage(playerid,culoare,string);
	    objectmodel[myobject]=oid;



Re: [HELP] Simple Object Editor - ThomasEvil - 28.07.2017

I'am stuck at this I store it as objectmodel but how is possible that it know there is another objects ?


Re: [HELP] Simple Object Editor - ThomasEvil - 29.07.2017

BUMP

Anyone?


Re: [HELP] Simple Object Editor - Antenastyle - 29.07.2017

I recommend you to save every object you create into the database/ini/whatever, that will solve your problem and allow you storage the id from 1, also will help you saving the coordinates, id... everything


Re: [HELP] Simple Object Editor - ThomasEvil - 29.07.2017

I do save objects into txt file. I alsoe have loading system which works fine.. But i still have problem with that numbers.. I mean i must do it bad in /addobject idk..