forgottenserver icon indicating copy to clipboard operation
forgottenserver copied to clipboard

fix #4077 (monster id 0 in onSpawn event)

Open Zbizu opened this issue 2 years ago • 5 comments

Changes Proposed

set monster ID before calling the script Issues addressed: #4077

Zbizu avatar Apr 11 '22 18:04 Zbizu

This event is called too early, with that fix you are setting id twice, It will work cause setId has id == 0 check, but anyway that's workaround and is probably problematic

nekiro avatar Apr 11 '22 19:04 nekiro

Can't we just call setId on each creature class consctructor?

conde2 avatar Apr 12 '22 19:04 conde2

Can't we just call setId on each creature class consctructor?

I believe it sets the id after creature is placed to avoid waste of ids for unplaced creatures, this is though very rare, when creature is created but not placed, so your suggestion might be actually quite good, unless I missed something

nekiro avatar Apr 12 '22 22:04 nekiro

I believe it sets the id after creature is placed to avoid waste of ids for unplaced creatures, this is though very rare, when creature is created but not placed, so your suggestion might be actually quite good, unless I missed something

the id pool is big enough to run the server for several months without restarting, even on high exp ue spam server the pool will never get exhausted if you restart server daily

Zbizu avatar Apr 12 '22 23:04 Zbizu

Would it not be best, for the end user, if "onSpawn" was a void, with the whole created monster passed after creation, and then there be another event in first SpawnMonster call, so earlier in execution, before deciding to spawn or not, to serve as the bool, which could have more information such as, onPrepareSpawn(monsterType, spawnId, spawnBlock, centerPos, radius, #aliveInSpawn, startup)

would work in a similar manner to onDeath, and onPrepareDeath

We could actually even keep onSpawn as a bool and have it remove the monster if false to keep from breaking backwards compatibility, as was suggested by forgee, and it still be called in same place for Game.CreateMonster().

Codinablack avatar Apr 17 '22 22:04 Codinablack

Simplest solution. Good!

@Zbizu the id pool is big enough to run the server for several months without restarting, even on high exp ue spam server the pool will never get exhausted if you restart server daily

I agree.

Any reason not to merge?

ramon-bernardo avatar Nov 20 '22 11:11 ramon-bernardo

@ramon-bernardo

Any reason not to merge?

Divided opinions on the solution.

I have this code in my engine and it does the job so I won't be working on this pr anymore. If you guys are not interested in merging it in its current state, you can close it.

For anyone interested in continuing this pr: --MonsterAutoId could be called on failing to place monster to free the unused slot, though I'm not sure if that doesn't introduce a data race.

Zbizu avatar Dec 13 '22 10:12 Zbizu

If no one is willing to dedicate time, I'd rather have the bug fixed.

ranisalt avatar Dec 13 '22 18:12 ranisalt