Make this command toggle?
#1

Hello again! So I would like to make this command "toggable", like if I input "/siren" a siren will appear, but if I input "/siren" again, the siren would disappear with it's message.
PHP код:
new glob4;
new 
glob3
PHP код:
CMD:siren(playeridparams[])
{
    if(
fInfo[playerid][fPolice] != 1) return SCM(playeridCOR_CINZA"You are not a Police Officer.");
    
glob4 GetPlayerVehicleID(playerid);
    
glob3 CreateObject(18646, -0.70.150.850.00.096.00);
    
AttachObjectToVehicle(glob3glob40.014999, -0.3799990.9149990.0000000.0000000.000000);
        
SendClientMessage(playeridCOLOR_GREY"You turned your siren on.");
    return 
1;

Thank you!!!!!
Reply
#2

I would just create a variable 'SirenStatus' and use that to store and determine the siren status.

Код:
new SirenStatus[MAX_PLAYERS] = false;

CMD:siren(playerid, params[]) 
{ 
    if(fInfo[playerid][fPolice] != 1) return SCM(playerid, COR_CINZA, "You are not a Police Officer."); 
    if(SirenStatus[playerid] == true) // Siren is already on
    {
    	SirenStatus[playerid] = false; // The siren is on, so we turn it off.
    	// Place code here to turn off the siren
        return SendClientMessage(playerid, COLOR_GREY, "You turned your siren off."); 
    }
    SirenStatus[playerid] = true; // The siren is off, so we turn it on.
    glob4 = GetPlayerVehicleID(playerid); 
    glob3 = CreateObject(18646, -0.7, 0.15, 0.85, 0.0, 0.0, 96.0, 0); 
    AttachObjectToVehicle(glob3, glob4, 0.014999, -0.379999, 0.914999, 0.000000, 0.000000, 0.000000); 
    SendClientMessage(playerid, COLOR_GREY, "You turned your siren on."); 
    return 1; 
}
Reply
#3

Quote:
Originally Posted by MEW273
Посмотреть сообщение
I would just create a variable 'SirenStatus' and use that to store and determine the siren status.

Код:
new SirenStatus[MAX_PLAYERS] = false;

CMD:siren(playerid, params[]) 
{ 
    if(fInfo[playerid][fPolice] != 1) return SCM(playerid, COR_CINZA, "You are not a Police Officer."); 
    if(SirenStatus[playerid] == true) // Siren is already on
    {
    	SirenStatus[playerid] = false; // The siren is on, so we turn it off.
    	// Place code here to turn off the siren
        return SendClientMessage(playerid, COLOR_GREY, "You turned your siren off."); 
    }
    SirenStatus[playerid] = true; // The siren is off, so we turn it on.
    glob4 = GetPlayerVehicleID(playerid); 
    glob3 = CreateObject(18646, -0.7, 0.15, 0.85, 0.0, 0.0, 96.0, 0); 
    AttachObjectToVehicle(glob3, glob4, 0.014999, -0.379999, 0.914999, 0.000000, 0.000000, 0.000000); 
    SendClientMessage(playerid, COLOR_GREY, "You turned your siren on."); 
    return 1; 
}
only 1 warning:

(2749) : warning 213: tag mismatch
Reply
#4

Which line?
Reply
#5

I feel like this CMD works better overall and it uses streamer's objects.

Код:
new VehSirenState[MAX_VEHICLES] = 0; //put this somewhere in the global variables, to check the state
new VehSirenObject[MAX_VEHICLES] = 0; //put this somewhere in the global variables to save the ojbect id to destroy.
CMD:siren(playerid, params[])
{
	if(fInfo[playerid][fPolice] == 1)
	{
		if(IsPlayerInAnyVehicle(playerid))
		{
			new vehicleid = GetPlayerVehicleID(playerid);
			if(VehSirenState[vehicleid] == 1)
			{
				VehSirenState[vehicleid] = 0;
    			        DestroyDynamicObject(VehSirenObject[vehicleid]);
   				SendClientMessage(playerid, COLOR_GREY, "You have turned your siren OFF.");
				return 1;
			}
		 	new type;
			if(sscanf(params, "i", type))
			{
				SendClientMessage(playerid, COLOR_GRAY, "USAGE: /siren [Type]");
				SendClientMessage(playerid, COLOR_WHITE, "Type: 1 = Dashboard, 2 = Outside");
				return 1;
			}
			switch(type)
			{
				case 1:
				{
				    VehSirenState[vehicleid] = 1;
				    VehSirenObject[vehicleid] = CreateDynamicObject(18646, 10.0, 10.0, 10.0, 0, 0, 0);
				    AttachDynamicObjectToVehicle(VehSirenObject[vehicleid], vehicleid, 0.0, 0.75, 0.275, 0.0, 0.1, 0.0);
				    SendClientMessage(playerid, COLOR_GREY, "You have turned on your dashboard siren.");
				}
				case 2:
				{
				    VehSirenState[vehicleid] = 1;
				    new Float:properz;
				    switch(GetVehicleModel(vehicleid))
	   				{
					    case 415: properz = 0.640;
					    case 541: properz = 0.660;
					    case 560: properz = 0.835;
					    case 598: properz = 0.835;
					    case 596 .. 597: properz = 0.880;
					    case 490: properz = 1.135;
					    case 599: properz = 1.035;
					    case 407: properz = 1.100;
					    case 427: properz = 1.100;
					    case 544: properz = 1.100;
					    default: properz = 0.780;
					}
					new Float:propery;
					switch(GetVehicleModel(facvehicleid))
					{
					    case 407: propery = 0.9;
					    case 427: propery = 0.8;
					    case 544: propery = 0.9;
					    default: propery = 0.0;
					}
    				        VehSirenObject[vehicleid] = CreateDynamicObject(18646, 10.0, 10.0, 10.0, 0, 0, 0);
    				        AttachDynamicObjectToVehicle(VehSirenObject[vehicleid], vehicleid, -0.43, propery, properz, 0.0, 0.1, 0.0);
					SendClientMessage(playerid, COLOR_GREY, "You have turned out the siren outside.");
				}
				default:
				{
					SendClientMessage(playerid, COLOR_GRAY, "Unknown type! /siren [Type]");
					SendClientMessage(playerid, COLOR_WHITE, "Type: 1 = Dashboard, 2 = Outside");
				}
			}
		}
		else return SCM(playerid, COLOR_GRAY, "You are not driving a car.");
	}
	else return SendClientMessage(playerid, COLOR_GRAY, "You're not a law enforcement officer.");
	return 1;
}
I took this right out of my personal gamemode, converted a few vars in the post so it might have some typos or lost indentation
Reply
#6

Quote:
Originally Posted by MEW273
Посмотреть сообщение
Which line?
if(SirenStatus[playerid] == true) // Siren is already on
Reply
#7

This is because it must be new bool:SirenStatus[MAX_PLAYERS] = false; either way the command he provided won't really do the job.
Reply
#8

Ok thanks to everybody +rep to all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)