EVENT EGS

From EDukeWiki
Revision as of 13:20, 4 February 2022 by Doom64hunter (talk | contribs)
Jump to navigation Jump to search
Event ID player# THISACTOR RETURN
EVENT_EGS closest player to sprite spawned sprite 0 values

EVENT_EGS is a Game Event.

This event is triggered when a new sprite is spawned on the map.

This event run for all actors, thus the gamevar THISACTOR refers to the ID of the sprite that is executing the code.

The playernum is set to the closest player in range. vm.playerDist is set to the distance of the spawned sprite to the closest player, hence commands such as ifpdistl will work as expected.

Internally, this is the moment the sprite structures and gamevars are reset for the sprite ID.

In comparison, EVENT_SPAWN runs for all sprites that pre-exist when the map is loaded and newly spawned sprites, and internally is used for changing the properties of specific sprites (such as enemies, etc).

Note that EVENT_EGS and EVENT_SPAWN are triggered the moment the sprite is spawned.

For example:

useractor notenemy ACTOR
    espawn PIGCOP
    setactor[RETURN].pal 1
enda

onevent EVENT_EGS
    ifactor PIGCOP
        spritepal 2
endevent

In this case, the PIGCOP palette will be 1, because EVENT_EGS takes place before the lines below the espawn command.

Deleting sprites during EVENT_EGS may cause problems, since some hard-coded functions may try to change their properties after they were spawned (similar to the espawn example above).

EVENT_EGS can be used to save the original sprite owner before it's changed.