SA-MP Forums Archive
How to Fix This?? - 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: How to Fix This?? (/showthread.php?tid=622101)



How to Fix This?? - RedRex - 18.11.2016

Hi everyone.. i have problem when a player Type /delobject - To Delet the object
its not deleting and for edit object and stopedit Can you help me to Fix??

Code For /Delobject
Код:
CMD:delobject(playerid,params[])
{
    if(pInfo[playerid][pLevel] >= 4)
	{
		new id;
	    if(sscanf(params, "i",id)) return SendClientMessage(playerid,yellow,"Usage: /delobject <Object ID>");
	    DestroyObject(id);
	    CommandToAdmins(playerid,"delobject");
		format(Jstring, sizeof(Jstring), "You have deteled the Object ID: '%d'", id);
		if(!IsValidObject(id)) return SendClientMessage(playerid,red, "Error: Invalid object!");
		return SendClientMessage(playerid,yellow, Jstring);
	}
	else return ShowMessage(playerid, red, 1);
}
Code for Edit Object
Код:
CMD:editobject(playerid,params[])
{
    if(pInfo[playerid][pLevel] >= 4)
	{
		new id, Float:X, Float:Y, Float:Z;
	    if(sscanf(params, "i",id)) return SendClientMessage(playerid,yellow,"Usage: /Editobject <Object ID>");
	    if(!IsValidObject(id)) return SendClientMessage(playerid,red, "Error: Invalid object!");
	    GetObjectPos(id,X,Y,Z);
	    if(!IsPlayerInRangeOfPoint(playerid, 20.0,X,Y,Z)) return SendClientMessage(playerid,red, "Error: You must go close of the object. try /gotoobject");
	    CommandToAdmins(playerid,"editobject");
		EditObject(playerid, id);
		format(Jstring, sizeof(Jstring), "You are editing the Object: %d, /Stopedit to stop editing.", id);
		return SendClientMessage(playerid,yellow, Jstring);
	}
	else return ShowMessage(playerid, red, 1);
}
Stop edit Objects
Код:
CMD:stopedit(playerid,params[])
{
    if(pInfo[playerid][pLevel] >= 4)
	{
		CancelEdit(playerid);
        CommandToAdmins(playerid,"stopedit");
		return SendClientMessage(playerid, yellow, "You stopped editing the object!");
	}
	else return ShowMessage(playerid, red, 1);
}
And This...

Код:
CMD:gotoobject(playerid,params[])
{
    if(pInfo[playerid][pLevel] >= 4)
	{
		new id, Float:X, Float:Y, Float:Z;
	    if(sscanf(params, "i",id)) return SendClientMessage(playerid,yellow,"Usage: /Gotoobject <Object ID>");
	    if(!IsValidObject(id)) return SendClientMessage(playerid,red, "Error: Invalid object!");
	    GetObjectPos(id,X,Y,Z);
	    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
		SetVehiclePos(GetPlayerVehicleID(playerid),X+3,Y,Z);
        else SetPlayerPos(playerid,X+3,Y,Z);
        CommandToAdmins(playerid,"gotoobject");
		format(Jstring, sizeof(Jstring), "You have been teleported to Object ID: '%d' | Position - X: %0.2f, Y: %0.2f, Z: %0.2f ", id, X, Y, Z);
		return SendClientMessage(playerid,yellow, Jstring);
	}
	else return ShowMessage(playerid, red, 1);
}
I Make it but when i type /delobject or this commands its give me ERORR: INVAILD OBJECT Help me plesae



Re: How to Fix This?? - BroZeus - 19.11.2016

You are deleting the object before you check if its valid or not so obviously it won't be valid as the object has already been deleted!!
Use this :
PHP код:
if(sscanf(params"i",id)) return SendClientMessage(playerid,yellow,"Usage: /delobject <Object ID>");
if(!
IsValidObject(id)) return SendClientMessage(playerid,red"Error: Invalid object!");// PLACE THIS LINE HERE NOT AFTER FORMAT
DestroyObject(id);
CommandToAdmins(playerid,"delobject");
format(Jstringsizeof(Jstring), "You have deteled the Object ID: '%d'"id);
return 
SendClientMessage(playerid,yellowJstring); 



Re: How to Fix This?? - Micko123 - 19.11.2016

This one just for future..

When you are createing command first thing is to do all the if checks.. So you firstly check is valid obj, is he inputed all parameters, is he allowed to use it.. After all check do things that command need to do.. There is some hierarchy while creating cmds


Re: How to Fix This?? - RedRex - 19.11.2016

Hello again when i type what you mean i got 4 ERRORS

Код:
error 017: undefined symbol "id"
error 017: undefined symbol "id"
error 017: undefined symbol "id"
error 017: undefined symbol "id"
PHP код:
CMD:delobject(playerid,params[])
{
    if(
pInfo[playerid][pLevel] >= 4)
    {
       if(
sscanf(params"i",id)) return SendClientMessage(playerid,yellow,"Usage: /delobject <Object ID>");
       if(!
IsValidObject(id)) return SendClientMessage(playerid,red"Error: Invalid object!");// PLACE THIS LINE HERE NOT AFTER FORMAT
       
DestroyObject(id);
       
CommandToAdmins(playerid,"delobject");
       
format(Jstringsizeof(Jstring), "You have deteled the Object ID: '%d'"id);
       return 
SendClientMessage(playerid,yellowJstring);
    }
    else return 
ShowMessage(playeridred1);

its say ID Is taken ...


Re: How to Fix This?? - RedRex - 19.11.2016

Please help me.


Re: How to Fix This?? - jlalt - 19.11.2016

you did not make new var to handle id.
PHP код:
CMD:delobject(playerid,params[])
{
    
    if(
pInfo[playerid][pLevel] >= 4)
    {
       new 
id = -1;
       if(
sscanf(params"i",id)) return SendClientMessage(playerid,yellow,"Usage: /delobject <Object ID>");
       if(!
IsValidObject(id)) return SendClientMessage(playerid,red"Error: Invalid object!");// PLACE THIS LINE HERE NOT AFTER FORMAT
       
DestroyObject(id);
       
CommandToAdmins(playerid,"delobject");
       
format(Jstringsizeof(Jstring), "You have deteled the Object ID: '%d'"id);
       return 
SendClientMessage(playerid,yellowJstring);
    }
    else return 
ShowMessage(playeridred1);




Re: How to Fix This?? - RedRex - 19.11.2016

Oh thanks +rep