Engine wont turn off.
#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


Messages In This Thread
Engine wont turn off. - by jimdo - 14.08.2016, 03:19
Re: Engine wont turn off. - by X337 - 14.08.2016, 03:44
Re: Engine wont turn off. - by jimdo - 14.08.2016, 03:46
Re: Engine wont turn off. - by X337 - 14.08.2016, 03:51
Re: Engine wont turn off. - by jimdo - 14.08.2016, 04:26
Re: Engine wont turn off. - by Sew_Sumi - 14.08.2016, 04:29
Re: Engine wont turn off. - by jimdo - 14.08.2016, 04:35
Re: Engine wont turn off. - by WhiteGhost - 14.08.2016, 04:40
Re: Engine wont turn off. - by Sew_Sumi - 14.08.2016, 04:43

Forum Jump:


Users browsing this thread: 1 Guest(s)