Engine wont turn off.
#1

When I turn the engine on using /engine, its work but when I want to turn it off using /engine too.. it's still on and display action "has turned the engine on" not even turn off..

pawn Код:
COMMAND:engine(playerid, params[])
{
    new xr = GetPlayerVehicleID(playerid);
    new car = GetPlayerNearestVehicle(playerid);
    new vehicleid = GetPlayerNearestVehicle(playerid);
    new engine,lights,alarm,doors,bonnet,boot,objective;
    new sender[MAX_STRING];
    //Vehicles[GetPlayerVehicleID(playerid)][carteam] != CIV
    if(PlayerTemp[playerid][hname]==1) myStrcpy(sender,"Stranger");
    else myStrcpy(sender,NameEx(playerid));
    if(IsPlayerInAnyVehicle(playerid) && Vehicles[xr][carmodel] == 481 && Vehicles[xr][carmodel] == 509) return SendClientError(playerid, "You are not in any vehicle, or there is no engine implented.");
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientError(playerid, "You are not in any vehicle!");
        new State;
        State = GetPlayerState(playerid);
        if(State!=PLAYER_STATE_DRIVER)  return SendClientMessage(playerid,COLOR_GREY,"You are not the driver!");
        new stringa[MAX_STRING];
        new vid = GetPlayerVehicleID(playerid);
        if(Vehicles[GetPlayerVehicleID(playerid)][carteam] == CIV && strcmp(PlayerInfo[playerid][playerteam],Vehicles[GetPlayerVehicleID(playerid)][carteam],false) && strcmp(PlayerName(playerid),Vehicles[vehicleid][carowner],false) && strcmp(PlayerName(playerid),Vehicles[vehicleid][dupekey],false))
        {
            return SendClientError(playerid, "You don't have the authority to use this vehicle or you don't have the dupe keys!");
        }
        if(engine == 0)
        {
            SetVehicleParamsEx(vid, 1, lights, alarm, doors, bonnet, boot, objective);
            format(stringa,sizeof(stringa),"%s has turns on the engine of the %s.",sender,GetVehicleName(car));
            NearMessage(playerid,stringa,COLOR_ME2);
            TogglePlayerControllable(playerid, true);
        }
        else
        {
            SetVehicleParamsEx(vid, 0, lights, alarm, doors, bonnet, boot, objective);
            format(stringa,sizeof(stringa),"%s has turns off the engine of the %s.",sender,GetVehicleName(car));
            NearMessage(playerid,stringa,COLOR_ME2);
            TogglePlayerControllable(playerid, true);
        }
    }
    return 1;
}
Reply
#2

Код:
COMMAND:engine(playerid, params[])
{
	new xr = GetPlayerVehicleID(playerid);
	new car = GetPlayerNearestVehicle(playerid);
	new vehicleid = GetPlayerNearestVehicle(playerid);
	new engine,lights,alarm,doors,bonnet,boot,objective;
	new sender[MAX_STRING];
	//Vehicles[GetPlayerVehicleID(playerid)][carteam] != CIV
	if(PlayerTemp[playerid][hname]==1) myStrcpy(sender,"Stranger");
	else myStrcpy(sender,NameEx(playerid));
	if(IsPlayerInAnyVehicle(playerid) && Vehicles[xr][carmodel] == 481 && Vehicles[xr][carmodel] == 509) return SendClientError(playerid, "You are not in any vehicle, or there is no engine implented.");
	{
	    if(!IsPlayerInAnyVehicle(playerid)) return SendClientError(playerid, "You are not in any vehicle!");
	    new State;
		State = GetPlayerState(playerid);
	    if(State!=PLAYER_STATE_DRIVER)	return SendClientMessage(playerid,COLOR_GREY,"You are not the driver!");
	    new stringa[MAX_STRING];
    	new vid = GetPlayerVehicleID(playerid);
		if(Vehicles[GetPlayerVehicleID(playerid)][carteam] == CIV && strcmp(PlayerInfo[playerid][playerteam],Vehicles[GetPlayerVehicleID(playerid)][carteam],false) && strcmp(PlayerName(playerid),Vehicles[vehicleid][carowner],false) && strcmp(PlayerName(playerid),Vehicles[vehicleid][dupekey],false))
		{
			return SendClientError(playerid, "You don't have the authority to use this vehicle or you don't have the dupe keys!");
		}
		GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
		if(engine == 0)
    	{
			SetVehicleParamsEx(vid, 1, lights, alarm, doors, bonnet, boot, objective);
			format(stringa,sizeof(stringa),"%s has turns on the engine of the %s.",sender,GetVehicleName(car));
			NearMessage(playerid,stringa,COLOR_ME2);
			TogglePlayerControllable(playerid, true);
		}
		else
    	{
			SetVehicleParamsEx(vid, 0, lights, alarm, doors, bonnet, boot, objective);
			format(stringa,sizeof(stringa),"%s has turns off the engine of the %s.",sender,GetVehicleName(car));
			NearMessage(playerid,stringa,COLOR_ME2);
			TogglePlayerControllable(playerid, true);
    	}
	}
	return 1;
}
You don't get the vehicle engine state
Reply
#3

What is the different?
Reply
#4

I added
Код:
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
Before you check the engine state
Reply
#5

Oh thanks.. worked.
Reply
#6

Why do you get the nearest vehicle, and then check if they are in the vehicle, and then deny if they aren't in a vehicle

You've got to have SO many errors from that code....
Reply
#7

I dont know, thats how my code works. No errors were showing.
Reply
#8

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Why do you get the nearest vehicle, and then check if they are in the vehicle, and then deny if they aren't in a vehicle

You've got to have SO many errors from that code....
I Strongly argree with Sew,this has alot of unnecessary code.
Reply
#9

Quote:
Originally Posted by jimdo
Посмотреть сообщение
I dont know, thats how my code works. No errors were showing.
You're getting the nearest vehicle twice, into 2 different values.

You're then using 2 different values to display the engine turning on, and off (For the GetVehicleName portion).


Not to mention, you could just use the players vehicle to define all of it.

Then when you're dealing with names, you've done that 3 different ways getting toward 6 times.

-Edit-

I've been working a bit on this, try this. I've re-arranged a lot of the code, so be sure to hold your current "working" command somewhere, and give this a go.

Just be sure to backup your current work if you do check this out. (This is untested but it's in better structure and logic than what yours was. Logic being testing first, then making variables. Structure being that we're not making random variables all over the place for the same things.

PHP код:
COMMAND:engine(playeridparams[])
{
    if(!
IsPlayerInAnyVehicle(playerid)) return SendClientError(playerid"You are not in any vehicle!"); //Checking for if we even need to do anything at all in the first instance.
    
new vehicleid GetPlayerVehicleID(playerid); //Getting VehicleID once
    
if(Vehicles[vehicleid][carmodel] == 481 || Vehicles[vehicleid][carmodel] == 509) return SendClientError(playerid"There is no engine in this vehicle."); //Checking for the engine now that we know they are in a car
    
    
new sender[MAX_PLAYER_NAME]; //This only actually needs to be 24 or so long, it's not needing to be MAX_STRING, which if that is 255, then that is SOOOO old, MAX_STRING should be around 144. (That's all a line of text can display in the client chat)
    
    
if(PlayerTemp[playerid][hname]==1myStrcpy(sender,"Stranger"); // Assigning the name to the player.
    
else myStrcpy(sender,NameEx(playerid)); // If you use this a lot, you could look at making a global variable for this to use throughout your script. (pAlias for instance and make that do it on the command that selects what they have, and OnPlayerConnect.
    
    
new engine,lights,alarm,doors,bonnet,boot,objective;
    
    
//Vehicles[GetPlayerVehicleID(playerid)][carteam] != CIV
    
    
if(GetPlayerState(playerid)!=PLAYER_STATE_DRIVER)    return SendClientMessage(playerid,COLOR_GREY,"You are not the driver!"); // Checking they are the driver
    
    
new stringa[MAX_STRING];
    
    if(
Vehicles[vehicleid][carteam] == CIV && strcmp(PlayerInfo[playerid][playerteam],Vehicles[vehicleid][carteam],false) && strcmp(PlayerName(playerid),Vehicles[vehicleid][carowner],false) && strcmp(PlayerName(playerid),Vehicles[vehicleid][dupekey],false))
    {
        return 
SendClientError(playerid"You don't have the authority to use this vehicle or you don't have the dupe keys!");
    }
    
GetVehicleParamsEx(vehicleidenginelightsalarmdoorsbonnetbootobjective);
    if(
engine == 0)
    {
        
SetVehicleParamsEx(vehicleid1lightsalarmdoorsbonnetbootobjective);
        
format(stringa,sizeof(stringa),"%s has turns on the engine of the %s.",sender,GetVehicleName(car));
        
NearMessage(playerid,stringa,COLOR_ME2);
    }
    else
    {
        
SetVehicleParamsEx(vehicleid0lightsalarmdoorsbonnetbootobjective);
        
format(stringa,sizeof(stringa),"%s has turns off the engine of the %s.",sender,GetVehicleName(car));
        
NearMessage(playerid,stringa,COLOR_ME2);
    }
    return 
1;

There will be more to do, so anyone who spots a fault, or anything that could be improved, would be welcome to show it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)