Jump to content

Skully

Members
  • Posts

    123
  • Joined

  • Days Won

    3

Posts posted by Skully

  1. You are converting a string to a number, the value of code_descriptions is a string value and when a string is passed as a parameter to tonumber() it will attempt to convert it to a numerical value, for instance turning the string "2.1" into an integer. When a string cannot be converted, you get nil.

    If you want to show the description, you do not need to run tonumber() on result["table"]["code_descriptions"].

    fetchRemote("[...]",
        function(data)
            local result = fromJSON(data)
            local code = tonumber(result["table"]["code_one"])
            local descriptions = result["table"]["code_descriptions"]
            print(code) -- Outputs 113
            print(descriptions) -- Should output "hello world"
        end,
    nil, true)

     

  2. You can use the onTrailerAttach event and detach the trailer as soon as this event is triggered. The only downside is you cannot simply cancel the event or detach the trailer immediately, instead you must use a timer that triggers after 50ms for it to be effective.

    function detachTrailer(theVehicle)
        local theTrailer = source
        setTimer(function()
            if isElement(theVehicle) and isElement(theTrailer) then
                detachTrailerFromVehicle(theVehicle, theTrailer)
            end
        end, 50, 1)
    end
    addEventHandler("onTrailerAttach", root, detachTrailer)

     

  3. 49 minutes ago, Arshin said:

    In general for the best experience and FPS for low PC how much distance for this function ?

    Leave it at the default value, or you can implement a setting that can be toggled for players to reduce it just a little below the default (400).

    If I'm not mistaken, this setting takes into consideration what the player's client has set their draw distance too in MTA settings as well, so you shouldn't rely on this for the sole purpose of increasing FPS; if a player wants to increase framerate by draw distance, they can reduce it in their own MTA settings.

  4. This is not possible with just simple webhooks. You will have to create a Discord Bot and integrate it into MTA, you can use Discord.js to create the bot (or use an existing oneand implement the functionality to fetch the total number of members in a guild, with this you can connect your server to the bot or create an API endpoint to retrieve the total members.

     

  5. If you are asking whether it impacts framerate - yes; you are increasing the maximum distance of area to be rendered in. As such, reducing the distance will increase framerate.

  6. 9 hours ago, Heshan_Shalinda_eUnlock said:

    I have used this script and create a resource but the doorstate does not working but when we are not in a vehicle the message will we displayed.

    How to fix this?

    The code I provided was a rough example on how to handle client-server sync.

    If you want to use the code for handling opening and closing a vehicle trunk, you can simply adjust the code below to be called from your GUI rather than from a /trunk command, additionally use getVehicleDoorOpenRatio/setVehicleDoorOpenRatio instead and execute it on the server so it automatically syncs it to every client.

    Client

    addCommandHandler("trunk", function()
    	local theVehicle = getPedOccupiedVehicle(localPlayer)
    	if not theVehicle then -- If the player is not in a vehicle.
    		outputChatBox("You must be in a vehicle to toggle the trunk!", 255, 0, 0)
    		return
    	end
    
    	local newState = (getVehicleDoorOpenRatio(theVehicle, 1) == 0) and 1 or 0 -- If the trunk ratio is 0, it is closed so we need to open it (value of 1), otherwise we need to close it (value of 0)
    	triggerServerEvent("syncVehicleTrunkChange", theVehicle, newState) -- Notify the server to set the new door ratio.
    end)

    Server

    function handleVehicleDoorSync(newState) setVehicleDoorOpenRatio(source, 1, newState) end
    addEvent("syncVehicleTrunkChange", true)
    addEventHandler("syncVehicleTrunkChange", root, handleVehicleDoorSync)
  7. What you are requesting is known as synchronization, when a client executes a client-side function and you want to share that state across every other player, you must notify the server of the action so that it can tell all players of the change too.

    This can be achieved with events using triggerServerEvent and triggerClientEvent.

    For instance, the example below displays how a client executing /trunk will run the function setVehicleDoorState and then share it across to to the server which in turn makes it visible for all other players.

    Client

    addCommandHandler("trunk", function()
        local theVehicle = getPedOccupiedVehicle(localPlayer)
        if not theVehicle then -- If the player is not in a vehicle.
          outputChatBox("You must be in a vehicle to toggle the trunk!", 255, 0, 0)
          return
        end
        
        local newState = (getVehicleDoorState(theVehicle, 1) == 0) and 1 or 0 -- If the trunk is closed, set it to 1 (open) otherwise it must be open, so close it. (state 1)
        setVehicleDoorState(theVehicle, 1, newState) -- Set the trunk state for this client.
        triggerServerEvent("syncVehicleTrunkChange", theVehicle, newState) -- Notify the server to set the newState for every player.
    end)
    
    -- This function is called whenever another player toggles a vehicle trunk, it executes the function on this client to update the trunk state
    -- to the same as what the source player set it to.
    function updateDoorStateFromOtherPlayer(newState)
    	setVehicleDoorState(source, 1, newState)
    end
    addEvent("updateVehicleDoorState", true)
    addEventHandler("updateVehicleDoorState", root, updateDoorStateFromOtherPlayer)

     

    Server

    function handleVehicleDoorSync(newState)
    	for i, thePlayer in ipairs(getElementsByType("player") do -- For every online player.
    		triggerClientEvent(thePlayer, "updateVehicleDoorState", thePlayer, source, newState) -- Trigger the event to set the vehicle door state to the newState provided.
    	end
    end
    addEvent("syncVehicleTrunkChange", true)
    addEventHandler("syncVehicleTrunkChange", root, handleVehicleDoorSync)

     

    Alternatively to save yourself this hassle, if the function is shared as such is the case with setVehicleDoorState, then you can just execute it on the server-side in which case it will automatically be synced to every client.

    • Thanks 1
    • Confused 1
  8. Hi there!

    This is a brief showcase of an advanced medical system I created as a part of my personal project roleplay gamemode; after completing this resource I took a short break and wanted to work on a small video project, I took that opportunity to create a showcase of the system and its functionalities.

     

    Feedback or any questions are always appreciated, thanks for checking it out!

    • Like 2
  9. You can use the event onResourceStop to capture the moment a resource script is stopped, and onResourceStart for when it is started.

    As for saving your variable data into an XML file, there are a variety of XML functions you can use to create a XML file structure with nodes and save your data there, see the following example taken from the xmlSaveFile page:

    -- Creates a file named "new.xml" with root node "newroot" and childnode "newchild".
    function createFileHandler()
    	local RootNode = xmlCreateFile("new.xml"," newroot")
    	local NewNode = xmlCreateChild(RootNode, "newchild")
    	xmlSaveFile(RootNode)
    	xmlUnloadFile(RootNode)
    end
    addCommandHandler("createfile", createFileHandler)

     

  10. Why are you trying to run a .html file through Lua?

    To do this correctly, you need to have two seperate files; one for the web page and your client side Lua code which loads the web page itself, from your error it looks like everything is in one file as you have displayed it? You cannot run HTML code and Lua within the same file.

  11. You could created a dummy ped and use GetPedAnimation on it after you shoot it with a sniper to fetch the animation that plays, it should give you both the block and animation.

    From the wiki:

    addEventHandler("onClientPreRender", root, function()
        local block, animation = getPedAnimation(localPlayer)
        dxDrawText ("CURRENT ANIMATION INFO...", 100, 300)
        if not block then block = "N/A" end
        if not animation then animation = "N/A" end
        dxDrawText("Block = "..block.." Animation = "..animation, 100, 315)
    end)

     

  12. On 03/10/2018 at 06:41, Fist said:

    You can't compare programming to being Administrator or Moderator or any kind of that stuff from gaming community. That's literally whole new category of work. That literally takes almost 0 effort and time comparing to programming. That's why people do it for free, not asking anything else in return than other that status. By judging off of these requirements what you've put on. I can say with ease, that you trying to milk someone without anything in return. You basically ask someone to make a project for you without giving anything in return. As people said above, don't expect to find anyone.

     

    See my previous response:

    On 08/09/2018 at 22:22, Skully said:

    Yes, developers who code for the satisfaction and enjoyment of programming still exist. If you're not interested and are only in it for the money then feel free to move on.

    If you don't see it that way I do, then I respect your perspective - this topic is to catch the eye of those who are looking to get their hands on a new project - there is no harm or fault in trying.

×
×
  • Create New...