Jump to content

[Solved] isPedInVehicle problem


Shuubaru

Recommended Posts

Hi, I did a gui with a button to buy a full repair in-game, but i have a problem with this. When i press on the button i get this error on the debug:

guibuyer_s.lua:2: Bad argument @ 'isPedInVehicle' [Expected ped at argument 1, got nil]

and the vehicle do not fix.

--clientside (not full code)

function buyFRepair () 
triggerServerEvent ( "buyFRepair", getLocalPlayer()) 
end 
addEventHandler ( "onClientGUIClick", GUIEditor_Button[1], buyFRepair ) 

--serverside

function buyFRepair(player) 
     if isPedInVehicle(player) then 
    local vehicle = getPedOccupiedVehicle(player) 
    if onTakeMoney( player, infos.frepairPrice) then 
        if vehicle then 
            setElementHealth( vehicle,1000 ) 
            outputChatBox("[FULL REPAIR] #FFFFFF"..getPlayerName(player).." #FFFFFFhas bought full repair. #B72A00-1600",root,_r,_g,_b,true) 
        end 
    else 
        outputChatBox("[ERROR] #ffffffYou dont have enough cash!",player,255,0,0,true) 
    end 
     else 
        outputConsole ( "You must be in a vehicle!",player,255,0,0,true) 
     end 
end 
addEvent("buyFRepair",true) 
addEventHandler("buyFRepair",root,buyFRepair) 

what can I do to fix it?

Sorry for my english.

Edited by Guest
Link to comment

Try that,

client side:

function buyFRepair () 
triggerServerEvent ( "buyFRepair", getLocalPlayer(), getLocalPlayer()) 
end 
addEventHandler ( "onClientGUIClick", GUIEditor_Button[1], buyFRepair ) 

server side:

function buyFRepair(player) 
     if not player  then  
          return 
     end 
     if isPedInVehicle(player) then 
    local vehicle = getPedOccupiedVehicle(player) 
    if onTakeMoney( player, infos.frepairPrice) then 
        if vehicle then 
            setElementHealth( vehicle,1000 ) 
            outputChatBox("[FULL REPAIR] #FFFFFF"..getPlayerName(player).." #FFFFFFhas bought full repair. #B72A00-1600",root,_r,_g,_b,true) 
        end 
    else 
        outputChatBox("[ERROR] #ffffffYou dont have enough cash!",player,255,0,0,true) 
    end 
     else 
        outputConsole ( "You must be in a vehicle!",player,255,0,0,true) 
     end 
end 
addEvent("buyFRepair",true) 
addEventHandler("buyFRepair",root,buyFRepair) 

Link to comment
Try that,

client side:

function buyFRepair () 
triggerServerEvent ( "buyFRepair", getLocalPlayer(), getLocalPlayer()) 
end 
addEventHandler ( "onClientGUIClick", GUIEditor_Button[1], buyFRepair ) 

server side:

function buyFRepair(player) 
     if not player  then  
          return 
     end 
     if isPedInVehicle(player) then 
    local vehicle = getPedOccupiedVehicle(player) 
    if onTakeMoney( player, infos.frepairPrice) then 
        if vehicle then 
            setElementHealth( vehicle,1000 ) 
            outputChatBox("[FULL REPAIR] #FFFFFF"..getPlayerName(player).." #FFFFFFhas bought full repair. #B72A00-1600",root,_r,_g,_b,true) 
        end 
    else 
        outputChatBox("[ERROR] #ffffffYou dont have enough cash!",player,255,0,0,true) 
    end 
     else 
        outputConsole ( "You must be in a vehicle!",player,255,0,0,true) 
     end 
end 
addEvent("buyFRepair",true) 
addEventHandler("buyFRepair",root,buyFRepair) 

works, i love you <3 :oops:

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...