Check playername - 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: Check playername (
/showthread.php?tid=554924)
Check playername -
cyberlord - 05.01.2015
Hello need help , i want to do like if player gets into train as passenger pay 10euro to driver so , i need to get driver name or id somehow and then give him those money that i take from passenger , need some exmaples how to do this
Re: Check playername -
Larceny - 05.01.2015
You have to check if the player entered in the train and if the train has a driver.
Here's an example:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
switch(newstate)
{
case PLAYER_STATE_PASSENGER:
{// Check if player has entered as passenger
if(GetPlayerVehicleID(playerid) == TRAIN_ID)
{// Check if the vehicle is the train, CHANGE TO TRAIN VEHICLE ID
new driverid = GetVehicleDriverID(GetPlayerVehicleID(playerid));
// Get the driverid
if(driverid != INVALID_PLAYER_ID)
{// Check if the train has a driver
// Do stuff
}
}
}
}
return 1;
}
stock GetVehicleDriverID(vehicleid)
{
for(new i; i < MAX_PLAYERS; i++)
{
if(IsPlayerInVehicle(i, vehicleid))
{
if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
{
return i;
}
}
}
return INVALID_PLAYER_ID;
}