Jump to content

Taxi


[MT]Tobi

Recommended Posts

  
TaxiVehicles = { 
    [420]=true, 
    [438]=true 
} 
  
--[[ Made by Morelli]]-- 
function PayPlayerOnEnter( theVehicle ) 
    local seat = getPlayerOccupiedVehicleSeat ( source ) 
    if ( (TaxiVehicles[getVehicleID(theVehicle)]) and ( not (seat == 0) ) ) then 
        local money = getPlayerMoney(source) 
        if (money > 99) then     
            local driver = getVehicleOccupant ( theVehicle, 0 ) 
            takePlayerMoney ( source, 100 ) 
            givePlayerMoney ( driver, 100 ) 
            outputChatBox( "You paid the $100 fare, to the driver, for using the taxi.", source) 
        else 
            outputChatBox( "You don't have enough money to pay the taxi driver!", source) 
            removePlayerFromVehicle ( source ) 
        end 
    end 
end 
  
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), PayPlayerOnEnter) 
  

Edited by Guest
Link to comment

You'll need this check:

  
local driverskin = getPlayerSkin ( driver ) 
if ( not driverskin == 14 ) then 
... 
else 
... 
end 
  

So, all in all, this should be the complete code:

  
TaxiVehicles = { 
    [420]=true, 
    [438]=true 
} -- Define what vehicles are taxis. In this case, it's the vehicle ID's 420 and 438. 
  
--[[ Made by Morelli]]-- 
function PayPlayerOnEnter( theVehicle ) -- Create a function which imports the 'theVehicle' from onPlayerVehicleEnter 
    local seat = getPlayerOccupiedVehicleSeat ( source ) -- Find out which seat the person who entered the vehicle is now sitting in. 
    if ( (TaxiVehicles[getVehicleID(theVehicle)]) and ( not (seat == 0) ) ) then -- Find out if the player is not in the driver seat, but in a taxi. 
        local money = getPlayerMoney(source) -- Return a variable value called 'money', which shows how much cash the passenger. 
        if (money > 99) then -- If the passenger has more than (or equal to) 100 dollars, then continue. 
            local driver = getVehicleOccupant ( theVehicle, 0 ) -- Find out the name of the driver of the taxi. 
            local driverskin = getPlayerSkin ( driver ) -- Find out the skin of the taxi driver and name it the variable 'driverskin'. 
            if ( not (driverskin == 14) ) then -- If the driver's skin does not equal to 14... 
                outputChatBox( "The person driving this taxi isn't a registered taxi driver! You haven't paid them.", source) -- Tell the passenger that they haven't paid the driver. 
            else -- Otherwise, if the driver does have skin ID 14.. 
                takePlayerMoney ( source, 100 ) -- Take $100 from the passenger 
                givePlayerMoney ( driver, 100 ) -- Give $100 to the driver 
                outputChatBox( "You paid the $100 fare, to the driver, for using the taxi.", source) -- Tell the passenger that they paid the driver. 
            end 
        else -- If the passenger has 99 or less dollars 
            outputChatBox( "You don't have enough money to pay the taxi driver!", source) -- Tell them they don't have enough money 
            removePlayerFromVehicle ( source ) -- Remove them from the vehicle 
        end 
    end 
end 
  
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), PayPlayerOnEnter) -- Define when we want this function to be triggered. 
  

I've added some comments to make it more user-friendly for those trying to learn.

Link to comment
thx, in the server window he wrotes Warning: Bad argument @ 'getplayerskin` - Line 1 and 23

is that okay or any problem?

Are you testing it with another player?

If you aren't then it's not so much a problem because the script is trying to firstly get the name of the person who is in the driver seat (when there isn't one), then they are trying to crunch this non-existant name and pull out a skin ID number to correlate to it.

Link to comment
ok, all is going right ;) i have only one question, how to make a script that a person whith the ID 50 can give other player health, when they get in car? they also must pay 100$ for these service

By ID, I assume you are reffering to skinID 50.

Well, there are multiple ways to approach this, I'd suggest structuring it in the following way

  
function FUNCTIONAME(sourcePlayer, command, target, price) 
      local targetPlayer = getPlayerFromNick ( target ) 
      if ( targetPlayer  ) then 
              if ( price ) then 
                    local sourceskin = getPlayerSkin ( sourcePlayer ) 
                    if ( not (sourceskin == 50) ) then 
                    else 
                           takePlayerMoney ( target, price ) 
                           givePlayerMoney ( sourcePlayer, price ) 
                           setElementHealth ( target, 100 ) 
                    end 
               end 
       end 
end 
  
addCommandHandler("CHANGEME", FUNCTIONAME) 
  

Using the command /changeme [targetplayername] [price] you can set the person's health to 100 and take some money off them. The person using the command must have skin ID 50.

Just read up on the wiki and adjust it to your liking.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...