Spaces in ZCMD and Car commands
#1

Well basically I want to have it like this /car engine, /car lights, /car bonnet, /car trunk.
I cannot put spaces in ZCMD. And how would I make it start the engine and start the ligths and boonet and trunk.

This is what I have so far. I also would like a closing send client message. How do I do this?

CMD:carengine(playerid,params[])
{
return 1;
}
CMD:carbonnet(playerid,params[])
{

SendClientMessage(playerid, COLOR_GREEN, "Vehicle bonnet opened");
return 1;
}
CMD:cartrunk(playerid,params[])
{

SendClientMessage(playerid, COLOR_GREEN, "Vehicle trunk opened");
return 1;
}
CMD:carlights(playerid,params[])
{

SendClientMessage(playerid, COLOR_GREEN, "Vehicle lights enabled");
return 1;
}

Thanks
Reply
#2

You have to use SetVehicleParamsEx. Example for engine command:

pawn Код:
CMD:carengine(playerid,params[])
{
     new engine,lights,alarm,doors,bonnet,boot,objective;
     GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
     SetVehicleParamsEx(vid,1,lights,alarm,doors,bonnet,boot,objective);
     SendClientMessage(playerid, -1, "Engine turned ON");
     return 1;
}
Reply
#3

the problem with putting spaces "in zcmd":
you cannot put spaces in strcmp-designed commands either. no command processor does that.
a space is the delimeter to split parameters - but combined with that (parsing parameters), it is possible, tricky maybe, but look here:
Код:
CMD:car(playerid,params[]){
	new Action[16];
	if(!sscanf(params,"S(help)[16]",Action))
	{
		if(!sscanf(Action,"s(16)","help"))
		{
			SendClientMessage(playerid, COLOR_GREEN, "/Car Bonnet/Trunk/Lights");
			return 1;
		}
		if(!sscanf(Action,"s(16)","bonnet"))
		{
			SendClientMessage(playerid, COLOR_GREEN, "Vehicle bonnet opened");
			return 1;
		}
		if(!sscanf(Action,"s(16)","trunk"))
		{
			SendClientMessage(playerid, COLOR_GREEN, "Vehicle trunk opened");
			return 1;
		}
		if(!sscanf(Action,"s(16)","lights"))
		{
			SendClientMessage(playerid, COLOR_GREEN, "Vehicle lights enabled");
			return 1;
		}
	}
	return 1;
}
if you understand the SetVehicleParamsEx functin mentioned above, then you can copy-n-paste the Get/Set parameter lines, and insert them into my spaghetti-code. after changing the desired variable (opening/closing bonnet/trunk etc), the commands can be improved further:
by setting a (player)variable for the vehicles' parts status (0=closed/switched off, 1=opened/switched on bonnet/trunk/door(s)/light(s))... < i know, that looks horrible ^^
...then you can additionally add one more string to the parameters. if they are given as optional (uppercase "S" strings, you might want to add a default switch for lazy players, like "switch" for changing the variable from 0 to 1, and 1 to 0.
switching a binary, is simply done by doing bit=1-bit;

ok, i edited some more, and added the option (can be left out ingame, so it defaults to "switch"):
Код:
CMD:car(playerid,params[]){
	new Part[16],Action[16];
	if(!sscanf(params,"S(help)[16]S(switch)[16]",Part,Action))
	{
		if(!sscanf(Part,"s(16)","help"))
		{
			SendClientMessage(playerid, COLOR_GREEN, "/car <bonnet/trunk/lights> <switch / on/open / off/close>");
			return 1;
		}
		if(!sscanf(Part,"s(16)","bonnet"))
		{
			if(!sscanf(Action,"s(16)","switch"))
			{
				VehicleBonnet[vehicleid]=1-VehicleBonnet[vehicleid];
			}
			else if(!sscanf(Action,"s(16)","open"))
			{
				VehicleBonnet[vehicleid]=1;
			}
			else if(!sscanf(Action,"s(16)","close"))
			{
				VehicleBonnet[vehicleid]=0;
			}
			switch(VehicleBonnet[vehicleid])
			{
				case 0:
				{
					SendClientMessage(playerid, COLOR_GREEN, "Vehicle bonnet closed");
				}
				case 1:
				{
					SendClientMessage(playerid, COLOR_GREEN, "Vehicle bonnet opened");
				}
			}
			//SetVehicleParamsEx();// thats your job ^^
		}
thats only for the bonnet - try that first (not tested!), it it works, good. if not, good: fixing bugs=learning.
Reply
#4

I will just stick with /engine, seems a lot easier. Thanks for the help. Babul I am a beginner scritper, I was really confused with your post. I have done Java, so Pawn/C++ is quite new to me
Reply
#5

Mr Annoymous what is the SendClientMessage(playerid, -1, "Engine turned ON");
in your code
how do I change the the colour and what does the -1 stand for.
Also I got errors

S:\Program Files\SG-RP Custom\gamemodes\SG-RP.pwn(228) : error 017: undefined symbol "vid"
S:\Program Files\SG-RP Custom\gamemodes\SG-RP.pwn(229) : error 017: undefined symbol "vid"
S:\Program Files\SG-RP Custom\gamemodes\SG-RP.pwn(230) : error 037: invalid string (possibly non-terminated string)
S:\Program Files\SG-RP Custom\gamemodes\SG-RP.pwn(230) : error 017: undefined symbol "Engine"
S:\Program Files\SG-RP Custom\gamemodes\SG-RP.pwn(230) : error 017: undefined symbol "sucessfully"
S:\Program Files\SG-RP Custom\gamemodes\SG-RP.pwn(230) : fatal error 107: too many error messages on one line


CMD:engine(playerid,params[])
{
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vid,engine,lights,alarm,doors,b onnet,boot,objective);
SetVehicleParamsEx(vid,engine,lights,alarm,doors,1 ,boot,objective);
SendClientMessage(playerid, -1, "Engine sucessfully started);
return 1;
}
Reply
#6

lol sorry, i was editing, now the post is even "worse".
optional (multiple) strings in commands are tricky, coz strings cannot be comnpared like
if(Part="bonnet")
nor be used in switches like
switch(Part){ case "bonnet":{}}
...so the comparing parameters Part and Action in serial order is also a bad choice, but it works, as long the players are typing them in order.

edit:
the -1 represents the color White, at full brightness.
hence white is red+green+blue notation in hexadecimal, or 0x
Код:
-1 == 0xffffffff
0x44cc22 equals green like a $bill, adding 0xff opacity (non transparent for ex. 3d labels) gives
0x44cc22ff which can be used in a script, like as a #define (here its MeGsaGe-cash-color, shortened):
Код:
#define MSGCASH_COLOR 0x44cc22ff
Reply
#7

I have already defined all colours. Heres what I have now for the engine

CMD:carengine(playerid,params[])
{
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vid,engine,lights,alarm,doors,b onnet,boot,objective);
SetVehicleParamsEx(vid,1,lights,alarm,doors,bonnet ,boot,objective);
SendClientMessage(playerid, COLOR_GREEN, "Vehicle engine turned ON");
return 1;
}

The errors are
S:\Program Files\SG-RP Custom\gamemodes\SG-RP.pwn(22 : error 017: undefined symbol "vid"
S:\Program Files\SG-RP Custom\gamemodes\SG-RP.pwn(229) : error 017: undefined symbol "vid"
Reply
#8

whats the vid?
Reply
#9

new vid = GetPlayerVehicleID(playerid);
Reply
#10

suggestion:
change
Код:
SetVehicleParamsEx(vid,1,lights,alarm,doors,bonnet ,boot,objective);
to
Код:
SetVehicleParamsEx(vid,1-engine,lights,alarm,doors,bonnet ,boot,objective);
...and you got the on/off switching automatically ^^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)