Jump to content

IIYAMA

Moderators
  • Posts

    6,058
  • Joined

  • Last visited

  • Days Won

    208

Everything posted by IIYAMA

  1. Another approach would be checking if there is something between the camera and the text position.https://wiki.multitheftauto.com/wiki/IsLineOfSightClear But it does have some flaws, like for example being blocked by transparent collisions Or the camera center is blocked by collision, but the sides are not when peaking around a corner. (Can be fixed by using more lines or using this function https://wiki.multitheftauto.com/wiki/GetScreenFromWorldPosition)
  2. Nope, it does not. Maybe you used too much of the example code? local messageNodes = xmlNodeGetChildren(xml) local outputText = "" for i,node in ipairs(messageNodes) do outputText = outputText .. tostring(xmlNodeGetValue(node)) .. "\n" end outputChatBox(outputText)
  3. IIYAMA

    table with svg

    Remove the sub table. This is a table: {}. And in your code you have 2 of those. 1 main table and 1 sub table. In here is the sub table you have to remove: {svgCreate(400, 200, "assets/media/roundedRectangle.svg")} You only want the value of svgCreate in your main table.
  4. Locked for unclear ownership of (multiple) resource(s) which code is used on multiple topics. TR_mysql <or/and> nl_mysql
  5. Locked for unclear ownership of (multiple) resource(s) which code is used on multiple topics. TR_mysql <or/and> nl_mysql
  6. If it is that sketchy (the ownership that is), locking the topic wouldn't be a bad idea.
  7. Creating a Roleplay/RPG server?

    Today I have added a utility function to the wiki, which you might want to use.

    https://wiki.multitheftauto.com/wiki/GetPedGender

    --[[
    
    The command /gender will display the gender of your player/ped element.
    
    ]]
    addCommandHandler("gender", 
    function () 
    	outputChatBox("My gender: " .. tostring(getPedGender(localPlayer)))
    end)

     

  8. IIYAMA

    Help Needed

    Whoops, it seems like I forgot to invert the second part. ?
  9. IIYAMA

    Help Needed

    You might want to add some debug lines to figure out the issue. function postAnn(msg, r1, b1, g1, playsound) iprint("postAnn arguments", msg, r1, b1, g1, playsound) if msg and (string.len(msg) > 0) then iprint("postAnn message is OK") if playsound and tonumber(playsound) and (tonumber(playsound) > 0) then iprint("postAnn play audio") playSound(playsound .. ".mp3") end alphaBG = 0 textString = msg stringLegth = string.len(textString) * 11 posX = sx if r1 and b1 and g1 then r, b, g = r1, b1, g1 end show = true addEventHandler("onClientRender", getRootElement(), drawAnnText) end end addEvent("rl:post", true) addEventHandler("rl:post", getRootElement(), postAnn) If none of the debug lines are displayed, the issue is probably on serverside (or less likely but possible somewhere else clientside). You will be looking for: triggerClientEvent( [optional,] "rl:post" You should search for: rl:post Keep in mind that doing it this way, the effect speed is based on FPS and not time. Which means that the effect speed is reduced depending on the user his FPS. So better to use 1 of the 2 methods above.
  10. Make sure that clientside and serverside are separate files Make sure that serverside is defined as a serverside file in the meta.xml Make sure that the serverside file does actually run. (Add outputChatbox/iprint/print/outputDebugString on the first line of the file and see if it is displaying something, the text output doesn't matter as long as you recognize it)
  11. IIYAMA

    Help Needed

    Most of the dx effects have color arguments. --[[ Constants ]] local animationDuration = 1000 --[[ Get the current machine time ]] local timeNow = getTickCount() --[[ Progress: timeNow % 1000 = 0 t/m 999.99 (0 t/m 999.99) / 1000 = 0 t/m 1 ]] local progress = (timeNow % animationDuration) / animationDuration --[[ local opacityProgress = progress * 2 | progress: 0.4 = opacityProgress: 0.8 ------------------------------------ if progress > 0.5 then ------------------------------------ opacityProgress = progress * 2 - 1 | progress: 0.6 = opacityProgress: 0.2 ]] local opacityProgress = progress * 2 if progress > 0.5 then opacityProgress = progress * 2 - 1 end local bleepColor = tocolor(255, 255, 255, 255 * opacityProgress)
  12. This is probably because of a text on raster optimisation. It is probably trying to place parts of the character on top of full pixels instead of 2 (half) pixels with opacity at 50%. This optimisation will probably be skipped when you enable the subPixelPositioning parameter. But this might make the readability harder (for low res) and more blurry. The solution The_GTA gives you would probably be the best fix. Or if you want to stay in control: https://wiki.multitheftauto.com/wiki/WordWrap
  13. That is because of screen ratio difference. This is how it works: 1920px | 1080px = 16:9 ratio 1920 / 16 = 120 120 * 9 = 1080! 2560px | 1080px = 21:9 ratio 2560 / 21 = 121,9047619047619‬.... 121,9047619047619‬.... * 9 = 1080 So if you apply your ratio to to a 1920x1080 resolution: 2560 / 16 = 160‬ 160‬ * 9 = 1440!!!!! You will be stretching the thing you want to scale. So in order to fix that problem. You want to go for the smallest dimensions which is the Y axis! 1920 x 1080 2560 x 1080 1080 x 1080 is a square which fits in both screens. The scale will be 1 for both resolutions. Squares have the ratio 1, which is a good normalizer. If the resolution was: 1280 × 720 720 / 1080 = 0,666666 scale The scale will go down because there are less pixels needed to cover up the same area. How does that looks like in the code: local sx_, sy_ = guiGetScreenSize() local sx, sy = sx_/2560, sy_/1080 local scale = sy -- I have defined this variable with the value of sy, so you do not confuse them later on. function teszt() dxDrawRectangle(140*sx, 200*sy, 700 * scale, 700 * scale,tocolor(0,0,0,165)) end addEventHandler("onClientRender",root,teszt) Golden rules (for keeping things in proportion? Position: X position = sx Y position = sy Scaling: X scaling = sy Y scaling = sy Offset from position: X offset = sy Y offset = sy Note: Sometimes for responsive layout you do not want to keep things in proportion. Like making the UI bigger for wider screens and show more elements, which you otherwise had to scroll to.
  14. There are multiple topics out there which explain the basics of scaling and positioning. You probably have seen those in the tutorial section, so I am not going to refer to those. Anyway, how about you give this utility/helper function a try? https://wiki.multitheftauto.com/wiki/GetScreenStartPositionFromBox The second example shows you how to combine scaling with position. If I create something with dx function I most of the time make use of that helper to speed things up. @Turbesz
  15. Hi there, interested in scripting and debugging?

    Read the story below! ?

     


     

    Today I was testing a resource that I have been working on for the last 2 days. It is a resource for creating 'fires' as element. Used for fixing a lot of issues with 'fire' in general, good for zombie/coop, pvp and roleplay gamemodes. (will be public...)

    Anyway, this post is not about the resource. It is about a way you could check your resource for unwanted function calls.

     

    Back to the story.

    So I opened the network stats window. (/shownetstat)

    I noticed that the data rate going out was incredible high. (This is how much data my MTA client is sending to the server) The zombie resource was also using a lot of the network, but I could notice the difference.

    Unfortunately I wasn't sure which part was causing it. ?

     

    So I started writing a function wrapper. There is also the https://wiki.multitheftauto.com/wiki/AddDebugHook but I was a bit too lazy to test it out. So I went for the simple wrapper. The function that I had to check was 'triggerServerEvent'. Because this one is most likely the one responsible for the high out going network usage.

    do
    	-- Save the original triggerServerEvent reference
    	local triggerServerEvent_ = triggerServerEvent
    	
    	function triggerServerEvent (...)
    		return triggerServerEvent_(...)
    	end
    end

     

    Now I had to collect some of the results. First step was to define some of the variables that are used to store the results.

    Spoiler
    -- Define all required variables
    local triggerServerEventCount = 0 -- How many times the function is called
    local triggerServerEventByEvent = {} -- Which event and from where + how many times
    local debugInfo = ""

     

     

    Grouping and counting the results is also very important:

    Spoiler
    local arg = {...}
    
    --[[
    
    Group by the function calls by 'event' and call location
    
    ]]
    local groupByKey = arg[1] .. " > Line: " ..  debug.getinfo(2).currentline  .. " "
    triggerServerEventByEvent[groupByKey] = (triggerServerEventByEvent[groupByKey]  or 0) + 1
    
    --[[
    
    Increase the function execution counter
    
    ]]
    triggerServerEventCount = triggerServerEventCount + 1

     

     

    And the last step was to display, update and reset the collected results every 1 second.

    Spoiler
    addEventHandler("onClientRender", root, 
      function () 
        --[[
    
        Display information
    
        ]]
        dxDrawText(debugInfo, 30, 300)
      end)
    
    setTimer(function () 
        --[[
    
        Update the display information
    
        ]]
        debugInfo = "triggerServerEventCount: " .. triggerServerEventCount .. " > " .. inspect(triggerServerEventByEvent) .. "\n\n"
        triggerServerEventCount = 0
        triggerServerEventByEvent = {}
      end, 1000, 0)

     

     

    And here is more or less the result (screenshot & code). Could be improved by also adding the filename, but this is was good enough for this resource.

    (In the screenshot the issue is already fixed, just displaying debug information ingame)mta-screen_2021-10-16_21-01-20.thumb.png.8e7b9a484631211c4b02fbc8e4adf557.png

    Spoiler
    
    do
    	-- Save the original triggerServerEvent reference
    	local triggerServerEvent_ = triggerServerEvent
    
    
    	-- Define all required variables
    	local triggerServerEventCount = 0 -- How many times the function is called
    	local triggerServerEventByEvent = {} -- Which event and from where
    	local debugInfo = ""
    
    	addEventHandler("onClientRender", root, 
    	function () 
    		--[[
    
    			Display information
    
    		]]
    		dxDrawText(debugInfo, 30, 300)
    	end)
    
    	setTimer(function () 
    		--[[
    
    			Update the display information
    
    		]]
    		debugInfo = "triggerServerEventCount: " .. triggerServerEventCount .. " > " .. inspect(triggerServerEventByEvent) .. "\n\n"
    		triggerServerEventCount = 0
    		triggerServerEventByEvent = {}
    	end, 1000, 0)
    
    	function triggerServerEvent (...)
    		local arg = {...}
    
    		--[[
    
    			Group by the function calls by 'event' and call location
    
    		]]
    		local groupByKey = arg[1] .. " > Line: " ..  debug.getinfo(2).currentline  .. " "
    		triggerServerEventByEvent[groupByKey] = (triggerServerEventByEvent[groupByKey]  or 0) + 1
    
    		--[[
    
    			Increase the function execution counter
    
    		]]
    		triggerServerEventCount = triggerServerEventCount + 1
    
    		--[[
    
    			Resume the normal behaviour of the function:
    
    		]]
    		return triggerServerEvent_(...)
    	end
    end

     

     

  16. You will have to add both utility functions: callServerFunction, callClientFunction Syntax: callServerFunction("openWindowServer", <vehicle>, <window>, <window open status>) Client: if seatWindows[0] and setVehicleWindowOpen( playerVehicle, 4, not isVehicleWindowOpen( playerVehicle, 4 ) ) then callServerFunction("openWindowServer", playerVehicle, 4, isVehicleWindowOpen( playerVehicle, 4 )) Server: function openWindowServer (vehicle, window, openStatus) if isElement(vehicle) then callClientFunction(root, "openWindowClient", vehicle, window, openStatus) end end Client: function openWindowClient (vehicle, window, openStatus) if isElement(vehicle) then setVehicleWindowOpen(vehicle, window, openStatus) end end
  17. You mean if you click on the gui button, clientside stuff happens for all other players? You will have to go through the serverside either way unfortunately. Peer to peer is not allowed. The code: When you write /yo. You will be execute the helloClient function on all loaded players. Client -- Sending addCommandHandler("yo", function () callServerFunction("helloServer") end, false, false) -------- -- Receiving function helloClient (playerName) outputChatBox(playerName .. ": YO!") end https://wiki.multitheftauto.com/wiki/CallClientFunction Server function helloServer () callClientFunction(root, "helloClient", getPlayerName(client)) end https://wiki.multitheftauto.com/wiki/CallServerFunction client = a predefined variable. All predefined variables that are available in the helloServer function: https://wiki.multitheftauto.com/wiki/AddEventHandler source, this, sourceResource, sourceResourceRoot, client, eventName btw. I wrote this library to make this kind of stuff a lot easier. Which does more or less the same, only with a lot more features, like return values to callBack functions and security options. Which I recommend for GUI's, for example you only want to give players access to specific actions within a GUI. Syntax: https://gitlab.com/IIYAMA12/mta-communication-enchantment/-/tree/master/documentation/syntax Client: -- Sending addCommandHandler("yo", function () callServer("helloServer") end, false, false) -------- -- Receiving function helloClient (playerName) outputChatBox(playerName .. ": YO!") end Server: function helloServer () callClient(root, "helloClient", getPlayerName(client)) end
  18. Step 1 You have to make sure that you have 1 clientside file and 1 serverside file. The (client/server)side is defined by the meta.xml: <script src="server.lua" /> <!-- serverside --> <script src="client.lua" type="client"/> <!-- clientside--> Step 2 Copy the code for the function: https://wiki.multitheftauto.com/wiki/CallClientFunction Add to server file. Add to client file. Step 3 The example code: Add to server file. addCommandHandler("callFunction", function (player, cmd, functionName) callClientFunction(player, functionName) end, false, false) Add to client file. function test1 () outputChatBox("You called function test1 ") end function test2 () outputChatBox("You called function test2 ") end function test3 () outputChatBox("You called function test3 ") end Step 4 Now when use the /callFunction command in combination with a function name of your choice, it will call that client function on YOUR pc. You can use the commands: /callFunction test1 /callFunction test2 /callFunction test3 Or default functions created by MTA. The only problem is that most of those require some arguments. Which are currently not defined and passed to your client functions.
  19. The quality of the map file looks very good, no noise effects. How about you try an AI upscale site? Some of them will give very good results. See attached file for an example result (which is 3000x3000 ?). But yea native would be a bit better.
  20. I had a similar issue on my local machine in the past. For some unknown reason the server wasn't ready yet to receive the event, when the client triggered a server event immediately. Not sure if that is going on with this script but clientside looks kinda empty. So I wouldn't consider it to be impossible.
  21. In that case you still have to use createProjectile. If you check all parameters and put velocity and force to 0. Set the creation position. The teargas shouldn't fly away when you create it.
  22. You can create the teargas effect with the createEffect function. https://wiki.multitheftauto.com/wiki/CreateEffect All: https://wiki.multitheftauto.com/wiki/Client_Scripting_Functions#Effects_functions It is only the visualisation of the effect. And sound can be enabled/disabled. Enjoy.
  23. It captures there as a scissor. (as The_GTA explains) But what problems are you referring to? (Re-writing your script is not one of them ?)
  24. You capture it in the left-top-corner of your screen and use dxDrawImage to draw it at the correct location. Everything you capture will not be drawn (immediately). That is how it is suppose to work.
×
×
  • Create New...