Jump to content

IIYAMA

Moderators
  • Posts

    6,097
  • Joined

  • Last visited

  • Days Won

    218

Everything posted by IIYAMA

  1. 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)
  2. 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
  3. 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.
  4. 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
  5. 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

     

     

  6. 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
  7. 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
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. 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 ?)
  14. 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.
  15. The following function can change the scale over the x, y and z axis: https://wiki.multitheftauto.com/wiki/SetObjectScale Which would have the same outcome. (requires a relative value instead of an absolute value.)
  16. It does have some benefits. Some very good ones. But I could also find a few cons, how would you address the following? 1. You have to write more code. (More than double in some cases) 2. You need to know the exact table keys. For some functions those are obvious, for other that might become complicated based on the context and requires more wiki info: x, x1, x2, text, message, speed, velocity, time, duration. This is a language as well as a logic issue. It needs some clear rules in order to function. 3. Somebody has to update the wiki with a 3e syntax. 4. A lot of object instance creation and disposal on onClientRender is a combination I rather not recommend.
  17. It doesn't appear to be making use of GTA objects. Atleast I base that on the previews. A Serverside implementation could be interesting, when you add the collisions yourself.
  18. Looks very cool CrosRoad. Will there also be a Serverside implementation? (Would be nice to have a {backwards compatible} module) And will it be possible to create separate environments on multiple threads?
  19. Indeed, my bad. According to the docs, you need to use ORDER BY, before you can use LIMIT in an UPDATE query.
  20. The database should to be considered the truth of what the balance actually is, not your elementdata. See here how to update the balance: dbExec(conexiune,"UPDATE afacere SET balance = balance + ? WHERE NR=? LIMIT 1", payout, ID) You need a second 'SELECT' query for updating the elementdata.
  21. You can use https://wiki.multitheftauto.com/wiki/BindKey as replacement. You can bind it on specific keys like 'mouse1' (left click) or control names like 'fire', to achieve your goal.
  22. There was literally nothing? No need to play the fool. To be precise, your previous topic's were locked for the following reason: Since people already replied to this topic, I will wait an amount of time before I may or may not come to the conclusion that you are doing the following:
  23. Locked for the same reason as this topic:
  24. If you are not interested in scripting and here for recruiting, then this is not the section for you. See section guidelines: You should recruit people only there: https://forum.multitheftauto.com/forum/149-looking-for-staff/ Locked
  25. You should only combine them when for example they contain utility functions, like: https://wiki.multitheftauto.com/wiki/CheckPassiveTimer When setting the file to shared, it will make a file copy for the server and a copy for every player/client. <script src="test.lua" type="shared" /> Serverside code runs on the server. > MTA Server.exe Clientside code runs on every player individuality. > MTA San Andreas.exe (There are as much clientsides as there are players > variables are not shared) Running code on the wrong application, doesn't sounds like a good idea to me. Serverside shouldn't draw UI. Clientside shouldn't kick/ban players. > With other words: A player client(MTA San Andreas.exe) shouldn't be able to ban another player, because the server(MTA Server.exe) is the only application that is able to ban a player.
×
×
  • Create New...