Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maxed out skills resets while testing map #131

Closed
sh4z4n opened this issue Oct 3, 2018 · 8 comments
Closed

Maxed out skills resets while testing map #131

sh4z4n opened this issue Oct 3, 2018 · 8 comments

Comments

@sh4z4n
Copy link

sh4z4n commented Oct 3, 2018

Which resource(s) have this problem?
defaultstats

To Reproduce
Steps to reproduce the behaviour:

  1. Start Freeroam, then defaultstats.
  2. Spawn any bicycle, hold jump button and release to make high jump.
  3. 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.

@sh4z4n sh4z4n changed the title defaultstats: doesn't work correctly while testing mP defaultstats: doesn't work correctly while testing map Oct 3, 2018
@sh4z4n
Copy link
Author

sh4z4n commented Oct 21, 2018

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?

@qaisjp qaisjp changed the title defaultstats: doesn't work correctly while testing map doesn't work correctly while testing map Jan 8, 2019
@sh4z4n sh4z4n closed this as completed Jan 18, 2019
@sh4z4n sh4z4n reopened this Jan 18, 2019
@sh4z4n sh4z4n changed the title doesn't work correctly while testing map Maxed out skills resets while testing map Jan 18, 2019
@ghost
Copy link

ghost commented May 22, 2020

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?

@PlatinMTA
Copy link
Contributor

PlatinMTA commented May 22, 2020

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?

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.

@ghost
Copy link

ghost commented May 22, 2020

yeah, just noticed that, i guess i just miss-read the initial problem. gonna check again.

@Dutchman101
Copy link
Member

Dutchman101 commented May 23, 2020

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:
image

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:

  1. Start Freeroam, then defaultstats.
  2. Spawn any bicycle, hold jump button and release to make high jump.
  3. 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.

@Dutchman101
Copy link
Member

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.

@jlillis jlillis added this to the Backlog milestone Mar 19, 2021
@MittellBuurman
Copy link
Contributor

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 onGamemodeMapStart to onGamemodeStartin defaultstats. This does work, but there's a caveat; on first server startup, when you restart play, onGamemodeStart does trigger, but defaultstats doesn't pick it up. When restarting the defaultstats and then restarting play fixes 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" />

@jlillis
Copy link
Contributor

jlillis commented Mar 3, 2024

Fixed via #471

@jlillis jlillis closed this as completed Mar 3, 2024
jlillis pushed a commit that referenced this issue Mar 3, 2024
…#131) (#471)

fix issue where defaultstats did not set player stats correctly

- changed resourceRoot to root in defaultstats.lua
- added conditions in applyStatsForEveryone to only apply stats when resource `type` is `gamemode` or `map`; or the resource itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants