-
Posts
6,058 -
Joined
-
Last visited
-
Days Won
208
Everything posted by IIYAMA
-
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)
-
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:
Spoilerlocal 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.
SpoileraddEventHandler("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)
Spoilerdo -- 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