Jump to content

Need help


arris

Recommended Posts

local money = getPlayerMoney( player ) 
if money >= 200 then 
  fixVehicle( vehicle ) 
else 
  outputChatBox( "You need 200$ to repair your car", player, 255, 0, 0 ) 
end 

something like this...

ahh dont he need takePlayerMoney too :b ?

Link to comment
ahh, ye, thats my usual mistake xD i always forget to add this line :lol:

ye i saw yersterday :D

  
local money = getPlayerMoney( player ) 
if money >= 200 then 
  fixVehicle( vehicle ) 
  takePlayerMoney( player, 200 ) 
else 
  outputChatBox( "You need 200$ to repair your car", player, 255, 0, 0 ) 
end 

Link to comment

This is how i have it and it doesn't work

function fix(button,state) --- BUTTON 1 
local money = getPlayerMoney( player ) 
if money >= 200 then 
  fixVehicle( vehicle ) 
  takePlayerMoney( player, 200 ) 
else 
  outputChatBox( "You need 200$ to repair your car", player, 255, 0, 0 ) 
end 
if button == "left" and state == "down" then 
        local clientPlayer = getLocalPlayer() 
        if isPlayerInVehicle(clientPlayer) == true then 
            local Vehicle = getPlayerOccupiedVehicle ( clientPlayer) 
            fixVehicle(Vehicle) 
            outputChatBox("Vehicle Successfully Fixed/Repaired",255,255,0,true) 
        else  
            outputChatBox("You are not in a vehicle",255,0,0,true) 
        end 
    end 
end 
--- --- --- --- -- 

Also can someone help me with this code

addEventHandler( "onPlayerWasted", getRootElement( ), 
function() 
                setTimer( spawnPlayer, 5000, 1, source, 2001.6312255859, 1544.2255859375, 13.5859375 ) 
        end 
) 

i have that code but i want to create another code that if the player has a house he spawn there if he doesn't he spawns at 2001.6312255859, 1544.2255859375, 13.5859375 can someone help

Link to comment

hmm what about if ( money >= 200) then ?

  
function whatever ( button, player, state ) 
         local vehicle = getPlayerOccupiedVehicle( player )  -- or getPedOccupiedVehicle if its for nightly... 
         if vehicle  then  
                  local money = getPlayerMoney ( player ) 
                  if ( money >= 200) then 
                              fixVehicle( vehicle ) 
                              takePlayerMoney( player, 200 ) 
                  else 
                        outputChatBox( "You need 200$ to repair your car", player, 255, 0, 0 ) 
                  end 
         else 
               outputChatBox(" you need a vehicle for this ", player, 255, 0, 0 ) 
         end 
end 
  
  

and the other question.. i dont know how to do it :b but what about spawn player where he died ? ;)

Link to comment

dorf, idk what you have done in your code, but i think it should be like next:

client side:

addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), 
  function () 
    --your code with your button-- 
  
   addEventHandler( "onClientGUIClick", yourButton, 
     function () 
       triggerServerEvent( "fixMyVehicle", getLocalPlayer() ) 
     end 
   ) 
  end 
) 

server-side:

addEvent( "fixMyVehicle", true ) 
  
function fix() 
  local vehicle = getPlayerOccupiedVehicle( source ) 
  if vehicle then 
    local money = getPlayerMoney( source ) 
    if money >= 200 then 
      fixVehicle( vehicle ) 
    else 
      outputChatBox( "You dont have enough money!", source, 255, 0, 0 ) 
    end 
  end 
end 
addEventHandler( "fixMyVehicle", getRootElement(), fix ) 

Link to comment

DaK, 2 things:

- where is takePlayerMoney?

- don't forget about false as the last parameter in addEventHandler call if you use gui elements as attachedTo (2nd parameter)

Also, I don't see a point in making a variable which is only used once (the money var is used in the if statement only).

Link to comment
Arris about that spawn in house... You can't just ask for code here. You have to learn both - code and search and in you can't find anything - then come here and ask for something.

I did look and i found somethings but i didn't need those and so thats why i asked.

Link to comment
DaK, 2 things:

- where is takePlayerMoney?

- don't forget about false as the last parameter in addEventHandler call if you use gui elements as attachedTo (2nd parameter)

Also, I don't see a point in making a variable which is only used once (the money var is used in the if statement only).

1) lol i forgot again to add this line >.<

2) so, it should be

addEventHandler( "onClientGUIClick", yourButton, 
  function () 
    triggerServerEvent( "fixMyVehicle", getLocalPlayer() ) 
  end 
, false ) 

and.. can you explain in details, why i should use 'false' if event is attached? cse i cant understand what wiki says about it :\

(its an offtopic i think..)

Link to comment

If you attach a function to a button without the false then that function will be triggered even if you click other GUI (windows, buttons, images, etc.) but if you use false, then this function will be called only if source == this (In other words, if "attachedTo" element (the button in this case) is equal to source (clicked gui element)).

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