PDA

View Full Version : Where to add code :/


Lajko1
08/12/2013, 11:38 PM
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

public OnPlayerStateChange(playerid, newstate, oldstate)
{
new vehicleid = GetPlayerVehicleID(playerid);
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vehicleid,engine,lights,alarm,d oors,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?

public OnPlayerEnterVehicle(playerid, vehicleid)
{
return 1;
}

and as always, thanks in advance

EmilLykke
09/12/2013, 12:02 AM
You can place it under public OnPlayerEnterVehicle(playerid, vehicleid)
{
return 1;
}

That should work out.

Padevex
09/12/2013, 12:54 AM
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.

Lajko1
09/12/2013, 11:30 AM
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 :D

newbie scripter
09/12/2013, 11:51 AM
Inside OnPlayerChangeState

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
if(GetPlayerVehicleID(playerid) != 481)
{
// ure code
}
}
return 1;
}

Lajko1
09/12/2013, 02:14 PM
Is that correct?

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

public OnPlayerStateChange(playerid, newstate, oldstate)
{
new vehicleid = GetPlayerVehicleID(playerid);
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vehicleid,engine,lights,alarm,d oors,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;
}

newbie scripter
09/12/2013, 02:19 PM
idk about that stock just do


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,d oors,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;
}