SA-MP Forums Archive
Where to add code :/ - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Where to add code :/ (/showthread.php?tid=480106)



Where to add code :/ - Lajko1 - 08.12.2013

Maybe this question is bit stupid, but I can't decide where should I add 1 part of code..

So I have fuel system, and for sure bikes don't need fuel and so on.. so I don't know where to put "if(vehicleid == ...)"
Should I add it somewhere here, if I will add it here, I don't know between what lines and where :/ hah

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) // If he entered in vehicle and if he is driver
    {
        if(oldstate-1 && newstate)
        {
            TextDrawHideForPlayer(playerid, vName[playerid]);
            TextDrawHideForPlayer(playerid, vSpeed[playerid]);
            TextDrawHideForPlayer(playerid, vGear[playerid]);
            TextDrawHideForPlayer(playerid, vHP[playerid]);
            TextDrawHideForPlayer(playerid, vFuel[playerid]);
            TextDrawHideForPlayer(playerid, HP[playerid]);
            TextDrawHideForPlayer(playerid, Speed[playerid]);
            TextDrawHideForPlayer(playerid, Gear[playerid]);
            TextDrawHideForPlayer(playerid, Veh[playerid]);
            TextDrawHideForPlayer(playerid, Fuel[playerid]);
        }
        if(Carinfo[vehicleid][F] < 1)
        {
            TextDrawHideForPlayer(playerid, vName[playerid]);
            TextDrawHideForPlayer(playerid, vSpeed[playerid]);
            TextDrawHideForPlayer(playerid, vGear[playerid]);
            TextDrawHideForPlayer(playerid, vHP[playerid]);
            TextDrawHideForPlayer(playerid, vFuel[playerid]);
            TextDrawHideForPlayer(playerid, HP[playerid]);
            TextDrawHideForPlayer(playerid, Speed[playerid]);
            TextDrawHideForPlayer(playerid, Gear[playerid]);
            TextDrawHideForPlayer(playerid, Veh[playerid]);
            TextDrawHideForPlayer(playerid, Fuel[playerid]);
            SendClientMessage(playerid, COLOR_YELLOW,"{FF0000}INFO: {FFFFFF}This vehicle is out of fuel, buy gas can at any gas station and refuel it.");
            SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
            return 1;
        }
        else if(Carinfo[vehicleid][F] > 1)
        {
            SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}Write {FF6A22}/engine {FFFFFF}to turn on engine.");
            return 1;
        }
    }
    return 1;
}
or here?

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
    return 1;
}
and as always, thanks in advance


Re: Where to add code :/ - EmilLykke - 08.12.2013

You can place it under
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid)
{
    return 1;
}
That should work out.


Re: Where to add code :/ - Padevex - 08.12.2013

Put it under OnPlayerStateChange and then under the newstate=driver
That way, the text draws will only show once he is the driver.

If you do it under OnPlayerEnterVehicle, they will show once your character is opening the door.
So, if he opens the door and presses a button to STOP entering, the textdraw will still show.
So he won't be in a car, and the textdraw will show.


Re: Where to add code :/ - Lajko1 - 09.12.2013

I just need to detect if player is driving BMX, there won't be needed to write /engine and so on but I don't know where to place code


Re: Where to add code :/ - newbie scripter - 09.12.2013

Inside OnPlayerChangeState
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
        if(GetPlayerVehicleID(playerid) != 481)
        {
            // ure code
        }
    }
    return 1;
}



Re: Where to add code :/ - Lajko1 - 09.12.2013

Is that correct?

pawn Код:
stock NoFuel(playerid)
{
    new V = GetPlayerVehicleID(playerid);
    if(V != 481 || V != 509 || V != 510 || V != 441 || V != 464 || V != 465 || V != 501 || V != 564 || V != 594)
    {
        return 1;
    }
    return 0;
}
and

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) // If he entered in vehicle and if he is driver
    {
        if(GetPlayerVehicleID(playerid) != NoFuel(vehicleid))
        {
            SetVehicleParamsEx(vehicleid,1,lights,alarm,doors,bonnet,boot,objective);
            return 1;
        }
        if(oldstate-1 && newstate)
        {
            TextDrawHideForPlayer(playerid, vName[playerid]);
            TextDrawHideForPlayer(playerid, vSpeed[playerid]);
            TextDrawHideForPlayer(playerid, vGear[playerid]);
            TextDrawHideForPlayer(playerid, vHP[playerid]);
            TextDrawHideForPlayer(playerid, vFuel[playerid]);
            TextDrawHideForPlayer(playerid, HP[playerid]);
            TextDrawHideForPlayer(playerid, Speed[playerid]);
            TextDrawHideForPlayer(playerid, Gear[playerid]);
            TextDrawHideForPlayer(playerid, Veh[playerid]);
            TextDrawHideForPlayer(playerid, Fuel[playerid]);
        }
        if(Carinfo[vehicleid][F] < 1)
        {
            TextDrawHideForPlayer(playerid, vName[playerid]);
            TextDrawHideForPlayer(playerid, vSpeed[playerid]);
            TextDrawHideForPlayer(playerid, vGear[playerid]);
            TextDrawHideForPlayer(playerid, vHP[playerid]);
            TextDrawHideForPlayer(playerid, vFuel[playerid]);
            TextDrawHideForPlayer(playerid, HP[playerid]);
            TextDrawHideForPlayer(playerid, Speed[playerid]);
            TextDrawHideForPlayer(playerid, Gear[playerid]);
            TextDrawHideForPlayer(playerid, Veh[playerid]);
            TextDrawHideForPlayer(playerid, Fuel[playerid]);
            SendClientMessage(playerid, COLOR_YELLOW,"{FF0000}INFO: {FFFFFF}This vehicle is out of fuel, buy gas can at any gas station and refuel it.");
            SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
            return 1;
        }
        else if(Carinfo[vehicleid][F] > 1)
        {
            SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}Write {FF6A22}/engine {FFFFFF}to turn on engine.");
            return 1;
        }
    }
    return 1;
}



Re: Where to add code :/ - newbie scripter - 09.12.2013

idk about that stock just do

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
        if(GetPlayerVehicleID(playerid) != 481)
        {
    new vehicleid = GetPlayerVehicleID(playerid);
    new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER) // If he entered in vehicle and if he is driver
    {
        if(oldstate-1 && newstate)
        {
            TextDrawHideForPlayer(playerid, vName[playerid]);
            TextDrawHideForPlayer(playerid, vSpeed[playerid]);
            TextDrawHideForPlayer(playerid, vGear[playerid]);
            TextDrawHideForPlayer(playerid, vHP[playerid]);
            TextDrawHideForPlayer(playerid, vFuel[playerid]);
            TextDrawHideForPlayer(playerid, HP[playerid]);
            TextDrawHideForPlayer(playerid, Speed[playerid]);
            TextDrawHideForPlayer(playerid, Gear[playerid]);
            TextDrawHideForPlayer(playerid, Veh[playerid]);
            TextDrawHideForPlayer(playerid, Fuel[playerid]);
        }
        if(Carinfo[vehicleid][F] < 1)
        {
            TextDrawHideForPlayer(playerid, vName[playerid]);
            TextDrawHideForPlayer(playerid, vSpeed[playerid]);
            TextDrawHideForPlayer(playerid, vGear[playerid]);
            TextDrawHideForPlayer(playerid, vHP[playerid]);
            TextDrawHideForPlayer(playerid, vFuel[playerid]);
            TextDrawHideForPlayer(playerid, HP[playerid]);
            TextDrawHideForPlayer(playerid, Speed[playerid]);
            TextDrawHideForPlayer(playerid, Gear[playerid]);
            TextDrawHideForPlayer(playerid, Veh[playerid]);
            TextDrawHideForPlayer(playerid, Fuel[playerid]);
            SendClientMessage(playerid, COLOR_YELLOW,"{FF0000}INFO: {FFFFFF}This vehicle is out of fuel, buy gas can at any gas station and refuel it.");
            SetVehicleParamsEx(vehicleid,0,lights,alarm,doors,bonnet,boot,objective);
            return 1;
        }
        else if(Carinfo[vehicleid][F] > 1)
        {
            SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}Write {FF6A22}/engine {FFFFFF}to turn on engine.");
            return 1;
        }
    }
}
}
    return 1;
}