My engine command is bugged!
#1

So, my problem here is, when you enter the car it actually just sets you uncontrollable, then you do /engine, you can move etc, but then when you do /engine and get out of the car, the player just teleports next to the car, or to the cars roof, and I really would like to make it, so the player goes into the car, the lights start, and the engine sounds comes up, and the same other way around, so the player can leave the car normally!


Код:
if(!strcmp(cmd, "/engine", true))
	{
	    if(IsPlayerConnected(playerid))
     {
			if(IsPlayerInAnyVehicle(playerid))
			{
			    if(IsADmv(idcar) || IsAHarvest(idcar) || IsADrugHarvest(idcar) || IsAPlane(idcar) || IsASweeper(idcar) || pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509)
					return 1;
	        	if(Gas[idcar] == 0)
	        	    return SendClientMessage(playerid,COLOR_RED,"   No fuel in this vehicle!");
                if(dying[playerid] == 1)
                    return SendClientMessage(playerid,COLOR_GREY,"   Do not bug abuse!");
	    		if(!engineOn[idcar])
	    		{
         		if(GetPlayerState(playerid) != PLAYER_STATE_PASSENGER)
					{
					    new playerveh = GetPlayerVehicleID(playerid);
					    engineOn[idcar] = true;
					    PutPlayerInVehicle(playerid, playerveh, 0);
					    TogglePlayerControllable(playerid,1);
					    format(string, sizeof(string), "* %s spins the key and starts vehicle's engine.", sendername);
					    ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
						return 1;
					}
					return 1;
				}
				else if(engineOn[idcar])
	    		{
	        		if(GetPlayerState(playerid) != PLAYER_STATE_PASSENGER)
					{
					    engineOn[idcar] = false;
					    TogglePlayerControllable(playerid, 0);
					    format(string, sizeof(string), "* %s spins the key and turns off the engine of the vehicle.", sendername);
					    ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
						return 1;
					}
					return 1;
				}
			}
	    }
	    return 1;
	}
Thanks!

OH and I also have this on OnPlayerStateChange



Код:
 new string[256];
	new pveh = GetVehicleModel(GetPlayerVehicleID(playerid));
	new vehicle = GetPlayerVehicleID(playerid);
	if(oldstate == PLAYER_STATE_ONFOOT && (newstate == PLAYER_STATE_PASSENGER || newstate == PLAYER_STATE_DRIVER))
	    AffectVehicleDamageToPlayer(playerid,vehicle,1);
	if((oldstate == PLAYER_STATE_PASSENGER || oldstate == PLAYER_STATE_DRIVER) && newstate == PLAYER_STATE_ONFOOT)
	    AffectVehicleDamageToPlayer(playerid,vehicle,0);
    if(newstate == PLAYER_STATE_DRIVER)
	{
		if(dying[playerid] == 1){RemovePlayerFromVehicle(playerid); TogglePlayerControllable(playerid, 0); ApplyAnimation(playerid,"PED","KO_skid_front",4.1,0,1,1,1,0); }
	}
	if(newstate == PLAYER_STATE_ONFOOT && SeatBelt[playerid]==true)
    {
    	SeatBelt[playerid]=false;
    	format(string, sizeof(string), "* %s unbuckles his/her seat belt", GetPlayerNameEx(playerid));
		ProxDetector(15.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
	}
	if(IsADmv(vehicle) || IsAHarvest(vehicle) || IsADrugHarvest(vehicle) || IsAPlane(vehicle) || IsASweeper(vehicle) || pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509)
	{	}
	else if(newstate == PLAYER_STATE_DRIVER && engineOn[vehicle] == 1)
	{
		TogglePlayerControllable(playerid,1);//allow driving - engine on
	}
	else if(newstate == PLAYER_STATE_DRIVER && engineOn[vehicle] == 0)
	{
		TogglePlayerControllable(playerid,0);//dosn't allow driving - engine off
		SendClientMessage(playerid, COLOR_WHITE,"To start the engine use '/engine' ");
Reply
#2

I think problem is with OnPlayerStateChange(not sure)

try using
pawn Код:
OnPlayerEnterVehicle
Reply
#3

What should I put? Any hints or tips?
Reply
#4

Okay so, this is what I have in OnPlayerEnterVehicle, yeah the problem is the Toggleplayercontrollable(,0)


Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(PlayerInfo[playerid][pJailed] == 2)
	{
	    new string[256];
	    SendClientMessage(playerid, COLOR_LIGHTRED, "~ Do not bug abuse! ~");
	    new Float:cx, Float:cy, Float:cz;
		GetPlayerPos(playerid, cx, cy, cz);
		SetPlayerPos(playerid, cx,  cy, cz);
		new giveplayer[MAX_PLAYER_NAME];
		GetPlayerName(playerid, giveplayer, sizeof(giveplayer));
		format(string, sizeof(string), "[SERVER]: %s has been trying to prisonbreak from admin jail!", giveplayer);
		ABroadCast(COLOR_YELLOW,string,1);
	}
    if (dying[playerid] == 1)
	{
		SendClientMessage(playerid, COLOR_GRAD2, "~ You can't drive when you are dying! ~");
		TogglePlayerControllable(playerid, 1);
		ApplyAnimation(playerid,"PED","KO_skid_front",4.1,0,1,1,1,0);
	}
	if(gTeam[playerid] >= 1||gTeam[playerid] >= 3||gTeam[playerid] >= 4)
	{
		if (IsACopCar(vehicleid) && !ispassenger)
		{
			if(IsACop(playerid) || IsASheriff(playerid)) {}
		    else {
				//WantedPoints[playerid]+=2;
				//SetPlayerCriminal(playerid,255, "Stealing A Police Vehicle");
				new Float:cx, Float:cy, Float:cz;
				GetPlayerPos(playerid, cx, cy, cz);
				SetPlayerPos(playerid, cx,  cy, cz);
			}
		}
		if(IsAGarageCar(vehicleid) && !ispassenger)
		{
		    if(IsAGarageMan(playerid)) {}
		    else {
		        new Float:cx, Float:cy, Float:cz;
				GetPlayerPos(playerid, cx, cy, cz);
				SetPlayerPos(playerid, cx,  cy, cz);
      		}
		}
		if (IsASheriffCar(vehicleid) && !ispassenger)
		{
			if(IsASheriff(playerid) || IsACop(playerid)) {}
		    else {
				new Float:cx, Float:cy, Float:cz;
				GetPlayerPos(playerid, cx, cy, cz);
				SetPlayerPos(playerid, cx,  cy, cz);
			}
		}
  		if(!ispassenger)
    	{
        for(new i=0; i<MAX_PLAYERS; i++)
        {
            if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_DRIVER)
            {
                new Float:cx, Float:cy, Float:cz;
                GetPlayerPos(playerid, cx, cy, cz);
                SetPlayerPos(playerid, cx,  cy, cz);
                SendClientMessage(playerid,COLOR_GRAD2," Someone is driving this vehicle, you must take it properly !");
            }
        }
    }
Any idea how to fix it?
Reply
#5

bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)