Jump to content

HELP Script Gas script


Recommended Posts



local screenW,screenH = guiGetScreenSize()
local resW,resH = 1366,768
local x,y =  (screenW/resW), (screenH/resH)

local font = dxCreateFont("fonts/font.ttf", 10)
local MaxFuel = 100

function getVehicleFuel(v)
	local fuel = getElementData(v, "fuel")	
	if (fuel) then
		return fuel
	end
	return 0
end

addCommandHandler("fueladm",fuel) 

Hello! You can insert code blocks with the <> sign. Use it next time.

 

Your problem is that this code does not set any value. In order to set the "amount of fuel" you have to use setElementData to set the value for fuel. Also functions can get parameters/arguments from command calls. You can catch those arguments in the paramter list after the function's name.

-- Catch parameters of command call

-- On server-side
function funcName(player, command, value1, value2)
  
end
addCommandHandler("testCall", funcName)

-- When you type /testCall it will call the funcName function, providing the calling player, the command that has been used for the call, and additional values typed in alongside the command. In command calls, additional values are seperated with spaces. For example: /testCall value1 value2

-- On client-side

function funcName(command, value1, value2)
  
end
addCommandHandler("testCall", funcName)

-- The same playbook here, except that client-side calls do not provide the calling player, because it is obvious that the calling player is the client itself. The localPlayer.

 

Now your function should look somehow like this:

-- Client-side
function setVehFuel(cmd, fuel)
  local veh = getPedOccupiedVehicle(localPlayer); -- Gets the currently occupied vehicle of the player, returns false if the player is not in a vehicle.
  if (veh) then -- Translates to if (veh ~= false/nil) then
    setElementData(veh, "fuel", tonumber(fuel)); -- Sets the fuel element data of the vehicle to the value that the caller provided converted into a number from string.
  end
end
addCommandHandler("setFuel", setVehFuel);

 

  • Like 1
Link to comment
  • 3 months later...

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