SA-MP Forums Archive
Taxi's - 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: Taxi's (/showthread.php?tid=412284)



Taxi's - Da_Noob - 01.02.2013

So, I've made a Taxi Driver job. Now, I tried to create a /fare system, but it kinda fails. I've tried numerous things, but they just fail. Here's what I have so far.

pawn Код:
forward IsVehicleDriver(vehicleid)
pawn Код:
public IsVehicleDriver(vehicleid)
{
     for(new i=0;i<=MAX_PLAYERS;i++)
     {
           if(IsPlayerInAnyVehicle(i))
           {
                if(GetPlayerVehicleID(i)==vehicleid)
                {
                       if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
                       {
                             return 1;
                        }
                 }
           }
     }
     return 0;
}
My OnPlayerExitVehicle

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsATaxi(vehicleid))
    {
        new s[180];
        GivePlayerMoney(IsVehicleDriver(vehicleid), PlayerFare[IsVehicleDriver(vehicleid)]);
        GivePlayerMoney(playerid, -PlayerFare[IsVehicleDriver(vehicleid)]);
        format(s,sizeof(s),"You've exited the taxi and paid $%d.", PlayerFare[IsVehicleDriver(vehicleid)]);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, s);
        format(s,sizeof(s),"%s has exited your taxi. You've received $%d.", GetName(playerid), PlayerFare[IsVehicleDriver(vehicleid)]);
        SendClientMessage(IsVehicleDriver(vehicleid), COLOR_LIGHTBLUE, s);
    }
    return 1;
}
Anybody knows how to fix this problem? I've tried a lot of things, but they just fail. The client won't send any message and nobodoy receives money.


Re: Taxi's - Misiur - 01.02.2013

pawn Код:
//Find
if(IsATaxi(vehicleid))
{
(...)
}
//Add this
else {
    SendClientMessage(playerid, COLOR_LIGHTBLUE, "This wasn't considered a taxi");
}
Run server, get in a taxi, get out of it. Is this message visible? If yes - debug your IsATaxi function


Re: Taxi's - Da_Noob - 01.02.2013

The message isn't visible when I go out of a taxi, it's vissible when I exit any other vehicle.

I also noticed a bug, whenever I'm the driver of the taxi and I go out of it, it says: "You've exited the taxi and paid 0$." But when I'm a passenger and I exit I get:"Da Noob has exited your taxi. You've recieved 0$."

Any fix?


Re: Taxi's - Da_Noob - 02.02.2013

Bump


Re: Taxi's - Misiur - 02.02.2013

Your IsVehicleDriver needs fix - it should return player id:
I renamed it for clarity
pawn Код:
forward GetVehicleDriverId(vehicleid);
(...)
public GetVehicleDriverId(vehicleid)
{
    for(new pid=0;pid<=MAX_PLAYERS;pid++)
    {
        if(IsPlayerInVehicle(pid, vehicleid) && GetPlayerState(pid) == PLAYER_STATE_DRIVER) return pid;
    }
    return INVALID_PLAYER_ID;
}
now for the main part of code:

pawn Код:
public OnPlayerExitVehicle(playerid, vehicleid)
{
    if(IsATaxi(vehicleid))
    {
        new s[180], taxiDriverId = GetVehicleDriverId(vehicleid);
        //Do not trigger action for driver
        if(playerid == taxiDriverId) return 1;
       
        GivePlayerMoney(taxiDriverId , PlayerFare[taxiDriverId]);
        GivePlayerMoney(playerid, -PlayerFare[taxiDriverId]);
        format(s,sizeof(s),"You've exited the taxi and paid $%d.", PlayerFare[taxiDriverId]);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, s);
        format(s,sizeof(s),"%s has exited your taxi. You've received $%d.", GetName(playerid), PlayerFare[taxiDriverId]);
        SendClientMessage(taxiDriverId, COLOR_LIGHTBLUE, s);
    }
    return 1;
}
Try this


Re: Taxi's - Da_Noob - 02.02.2013

Works! Thank you!