Maxed out skills resets while testing map
Which resource(s) have this problem? defaultstats
To Reproduce Steps to reproduce the behaviour:
- Start Freeroam, then defaultstats.
- Spawn any bicycle, hold jump button and release to make high jump.
- Start Map Editor and press F5.
Now repeat the same steps of number 2.
Expected behaviour Everytime Freeroam starts after press Full Test your maxed out skills resets because defaultstats automatically stop so you can't do bicycle high jump or shoot while walking, for example.
As far I know this only happens with Freeroam but I didn't test another gamemodes. Anyway, set race gamemode on map settings and then leave test mode, stats does not reset. Very weird, huh?
Here's the line actually causing that issue: click me
I guess that onGamemodeMapStart is being triggered here, removing that line might work. Question here is: Would it make sense to remove that line?
Here's the line actually causing that issue: click me I guess that
onGamemodeMapStartis being triggered here, removing that line might work. Question here is: Would it make sense to remove that line?
That doesn't look like the problem. Check out that defaultstats will give you the max ammount of biking ability, but when using the editor sh4z4n said that the maxed out skills resets, probably because defaultstats just stops.
Even if it was reseting your stats at every freeroam start, you will have 999 biking skill anyway, and you should be able to make really high jumps with that.
For your question, it seems that onGamemodeMapStart is kinda pointless, even if the stats reset after a gamemode change, the players would eventually spawn ig. Also i don't think that any gamemode resets your stats ever.
yeah, just noticed that, i guess i just miss-read the initial problem. gonna check again.
Something weird is going on.. facts:
that the maxed out skills resets, probably because defaultstats just stops.
if defaultstats stops, then it will stop applying the defined stats when it's supposed to, but not set all stats to zero. This is what currently (per this bug) happens, and the reset stats apply to more than just bikes: everything, including that in map editor you'll be aiming down the sights like this:

Theory 1: The problem is triggered by gamemodestopper.lua:18, because that function calls mapmanager_exports.lua#L193 and these utility functions are malfunctioning:
function isGamemode(resource)
if type(resource) ~= "userdata" then
return false
end
return (getResourceInfo(resource,"type") == "gamemode")
end
function isMap(resource)
if type(resource) ~= "userdata" then --!w
return false
end
return (getResourceInfo(resource,"type") == "map")
end
I believe they are malfunctioning as "defaultstats" doesn't currently have any "type" defined in its meta.xml which means it shouldn't return true, but under the circumstances of this issue (when called by editor), return true which leads to the resource mistakenly stopping. The reason for this isn't immediately clear to me.
But most of all, while I was reproducing i found that this is only the case when you do this:
- Start Freeroam, then defaultstats.
- Spawn any bicycle, hold jump button and release to make high jump.
- Start Map Editor and press F5.
in "Host game" mode (main menu), and the problem isn't there (stats won't be nulled) when you run MTA Server.exe and perform the same steps. The reason these utility functions or something else fails only with "Host game" is yet to be investigated
The reason for stats being nulled (which like I said, normally doesn't happen when "defaultstats" stops).. my guess: applyStatsForEveryone() (from onGamemodeMapStart) is called before map editor performs the check and stops the resource, but in the midst of 'writing' stats to the game and therefore not getting the chance to complete (resulting in GTA/MTA nulling it instead, for some reason). But nowhere in the code of editor (or anywhere else) is there something that would cause all stats to be nulled (as if "defaultstats" never ran to set new values), so something is funky.
Update 1: while writing this post, I suddenly stopped being able to reproduce the issue at all (even after restoring all resources to default).. both in "Host game" and MTA Server. So all of this can happen randomly.. what I noticed though, is that in my case it only happened when this: WARNING: 'FREEROAM' resource is currently running. The resource has been shut off as a precaution! was being output even though freeroam resource was still running (it failed to stop it). So when it didn't fail to stop it, the stats issue could no longer be reproduced.
Not done debugging yet, but this all means the problem might be deeper (or perhaps in MTA)
Update 2 (and Theory 2): the script that outputs above message: editor_main/server/freeroam.lua has been updated in b53f42b and with this update, my reproduction rate seems to be zero. The moment i reverted it to the old revision which had a serious syntax mistake in it:
if getResourceState(getResourceFromName"freeroam") == "running" then .. missing a (
stopResource(getResourceFromName"freeroam") .. missing a (
.. i reproduced it a few times instantly. But then it started being random again, not always reproducing. So, i wonder if it's possible if this incorrect usage of getResourceFromName (missing parentheses) could result in undefined behavior due to scripting function implementation, of which the undefined behavior can result in a chance it will grab another resource, in this case stopping "defaultstats" and maybe even corrupting things like zero'ing what it set (the stats). This would mean people that haven't got the latest version of resources can run into this issue.
I edited the above comment significantly, and i want to re-iterate that I am looking for the root cause this deep because of the following:
Nowhere in the code of editor (or anywhere else) is there something that would cause all stats to be nulled (as if "defaultstats" never ran to set new values), stopping "defaultstats" normally doesn't null the stats (literally to 0 value, even worse than GTA defaults). This would only happen if "defaultstats" hasn't run at least once while the player was connected.. so yeah, something is funky, probably within MTA itself and not the resources.
I edited the above comment significantly, and i want to re-iterate that I am looking for the root cause this deep because of the following:
Nowhere in the code of editor (or anywhere else) is there something that would cause all stats to be nulled (as if "defaultstats" never ran to set new values), stopping "defaultstats" normally doesn't null the stats (literally to 0 value, even worse than GTA defaults). This would only happen if "defaultstats" hasn't run at least once while the player was connected.. so yeah, something is funky, probably within MTA itself and not the resources.
There are 2 issues I found in both defaultstats and play resource.
- defaultstats uses
onGamemodeMapStart, which I assume looks specifically for map elements. Play does not have a map defined(?). I tried using the event to trigger the call, but did not work. - I then changed the event from
onGamemodeMapStarttoonGamemodeStartindefaultstats. This does work, but there's a caveat; on first server startup, when you restartplay,onGamemodeStartdoes trigger, butdefaultstatsdoesn't pick it up. When restarting thedefaultstatsand then restartingplayfixes the issue.
default mtaserver.conf and the importance of resource load order
When using a lot of resources that talk to eachother, I have found a lot of interesting things. Sometimes your function works, and sometimes it doesn't. the phrase have you tried turning it off and on again somehow does the trick.. but why?
The answer: resource load order.
in the default mtaserver.conf file, all resources are loaded in the following order:
<resource src="admin" startup="1" protected="0" />
<resource src="defaultstats" startup="1" protected="0" />
<resource src="helpmanager" startup="1" protected="0" />
<resource src="joinquit" startup="1" protected="0" />
<resource src="mapcycler" startup="1" protected="0" />
<resource src="mapmanager" startup="1" protected="0" />
<resource src="parachute" startup="1" protected="0" />
<resource src="resourcebrowser" startup="1" protected="1" default="true" />
<resource src="resourcemanager" startup="1" protected="1" />
<resource src="scoreboard" startup="1" protected="0" />
<resource src="spawnmanager" startup="1" protected="0" />
<resource src="voice" startup="1" protected="0" />
<resource src="votemanager" startup="1" protected="0" />
<resource src="webadmin" startup="1" protected="0" />
<resource src="play" startup="1" protected="0" />
Neatly packed in alphabetical order, this list is out of order. defaultstats will load, but not function 100%
But why?!
Resource load order is important. Since some resources are depending on other resources.
In this case, the defaultstats resource is loaded before mapmanager (actually mapcycler, but that's out of this scope).
mapmanager_main.lua
currentGamemode = nil
currentGamemodeMap = nil
nextGamemode = nil
nextGamemodeMap = nil
setGameType(false)
setMapName("None")
addEvent("onGamemodeStart") --> now it is registered, any resources that has an eventHandler already defined before the resource started, they are nothing but sad empty stubs.
addEvent("onGamemodeStop")
addEvent("onGamemodeMapStart") --> This is the current event used
addEvent("onGamemodeMapStop")
defaultstats.lua
local function applyStatsForEveryone()
local playersTable = getElementsByType("player")
for playerID = 1, #playersTable do
applyStatsForPlayer(playersTable[playerID])
end
end
addEventHandler("onResourceStart", resourceRoot, applyStatsForEveryone)
addEventHandler("onGamemodeStart", root, applyStatsForEveryone)
-- > adds event before mapmanager loads, throws an exception to root (we cannot see)
Since the addEventHandler is triggered before the resource that adds the event is running. It actually throws an error. However, we cannot capture it (unless we explicitly log it) and therefore we're left with our ears scratching.
PR will follow soon
I got the changes ready, just got to make a PR.
I'll leave this here, and tell you where you should put the defaultstats resource in the .conf file.
Putting it under mapmanager is recommended.
<resource src="admin" startup="1" protected="0" />
<!-- <resource src="defaultstats" startup="1" protected="0" /> --> <!-- default -->
<resource src="helpmanager" startup="1" protected="0" />
<resource src="joinquit" startup="1" protected="0" />
<resource src="mapcycler" startup="1" protected="0" /> <!-- mapmanager is included here -->
<resource src="defaultstats" startup="1" protected="0" /> <!-- where it should be (at least) -->
<resource src="mapmanager" startup="1" protected="0" /> <!-- where the events are added -->
<resource src="parachute" startup="1" protected="0" />
<resource src="resourcebrowser" startup="1" protected="1" default="true" />
<resource src="resourcemanager" startup="1" protected="1" />
<resource src="scoreboard" startup="1" protected="0" />
<resource src="spawnmanager" startup="1" protected="0" />
<resource src="voice" startup="1" protected="0" />
<resource src="votemanager" startup="1" protected="0" />
<resource src="webadmin" startup="1" protected="0" />
<resource src="play" startup="1" protected="0" />
Fixed via #471