Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 21/07/23 in all areas

  1. in Lua, the operator != is ~= if type(inv) ~= "table" then -- Something end
    1 point
  2. Usp, I meant the first (return) type mistake ?
    1 point
  3. Definitely first one. I would format it like this though, with the start of the function on the same line. It's the common way of writing it because you'll have less indentation. addEventHandler("onClientGUIClick", window, function(button, state) if button ~= "left" then return end if source == btnClose then return closeMenu() end if source == btnChange then local AmountKey = guiGetText(EditKey) if AmountKey == "" then return outputChatBox("error", 255, 25, 25, true) end if string.len(AmountKey) ~= 16 then return outputChatBox("error", 255, 25, 25, true) end outputChatBox("successful", 255,126,0, true) closeMenu() end end) Good luck!
    1 point
  4. A different technique: Guard Clauses You might want to read this, to get a better understanding of the technique. The result is more or less the same, except there are some differences with the returned values. In your function it doesn't matter, but there are functions where it does matter a lot.
    1 point
  5. Hello I would say it depends on preference, I personnaly like the second way (using return). It makes not too many scopes and looks to me a good way to dissociate clearly validation of received arguments before executing the function. Some tips / observations about your code : 1 _ To check string length you can directly use # ( instead of string.len() ) for example : if (not #string > 0) then 2 _ Looks like a tool to give money. If you try to check money range, why don't you convert the string to a int/number ( using tonumber() ) and then doing necessary checks (if you need to check minimum / maximum range). 3 _ I don't understand string.len(AmountKey) ~= 16 which means if your string has not 16 char it return the error.
    1 point
  6. function updateBtnColor () for i, v in ipairs (ButtonRegister) do v.borderColor = tocolor(255, 167, 0, Alpha) end end function pressRegisterBut() Alpha = 0 updateBtnColor () addEventHandler("onClientRender", getRootElement(), movePanelOut) end function pressBack() Alpha = 0 updateBtnColor () addEventHandler("onClientRender", getRootElement(), movePanelIn) end function movePanelOut() Alpha = math.min(Alpha + 5, 255) updateBtnColor () PageId = 2 if tonumber(Alpha) == 255 then removeEventHandler("onClientRender", getRootElement(), movePanelOut) end end function movePanelIn() Alpha = math.min(Alpha + 5, 255) updateBtnColor () PageId = 1 if tonumber(Alpha) == 255 then removeEventHandler("onClientRender", getRootElement(), movePanelIn) end end
    1 point
  7. Hi, I've moved your thread into the main Scripting section as this is the right place to request scripting-related help.
    1 point
  8. Hey, The problem is that the events onVehicleStartExit and onPlayerQuit have different parameters and your function is made to handle the arguments only from onVehicleStartExit. You can check out the documentations (the links above) of the two events and see what parameters they have. Simple example: when a player leaves (onPlayerQuit) the first argument is quitType and in your function it's thePlayer. This is why you get "Quit" as player and it can't get the occupied vehicle of "Quit" as it's expecting a ped not string. This should do the trick: function ExitCar (playerORquitType, seat) local thePlayer = playerORquitType local seat = seat if(type(thePlayer) ~= "player") then -- if the function is triggered by onPlayerQuit thePlayer = source -- in onPlayerQuit the player who left is "source" end if(type(seat) ~= "number") then -- if the function is triggered by onPlayerQuit; there is no argument for seat seat = getPedOccupiedVehicleSeat(thePlayer) -- so we get the seat of the player end local theVehicle = getPedOccupiedVehicle (thePlayer) local vehid = getElementID (theVehicle) if vehid == "1" or vehid == "2" or vehid == "3" or vehid == "4" or vehid == "5" or vehid == "6" then local onMark = getElementData(thePlayer, "onMark") or false -- we put this in a variable so we don't make unnecessary calls if onMark then if seat and seat == 0 then destroyElement(onMark) end end end end addEventHandler("onVehicleStartExit", getRootElement(), ExitCar) addEventHandler("onPlayerQuit", getRootElement(), ExitCar) *PS: Please, don't just copy and paste it but try to understand how it works. It might help you in future similar situations.
    1 point
×
×
  • Create New...