Difference between revisions of "Events Reference"
imported>Scrivener07 |
(Unprofessional writing) |
||
(One intermediate revision by one other user not shown) | |||
Line 33: | Line 33: | ||
Events are not like the old block types. When you make an event in your script that extends ObjectReference or ReferenceAlias you are essentially creating a new version of that event, and you need to declare it with the same number of parameters. Those parameters are then used inside the script. | Events are not like the old block types. When you make an event in your script that extends ObjectReference or ReferenceAlias you are essentially creating a new version of that event, and you need to declare it with the same number of parameters. Those parameters are then used inside the script. | ||
You should pretty much just copy and paste the events straight from the wiki, unless you desire to change the name of the parameters for some reason | You should pretty much just copy and paste the events straight from the wiki, unless you desire to change the name of the parameters for some reason. | ||
For example: | For example: | ||
Line 45: | Line 45: | ||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Event OnHit(Game.GetPlayer()) | Event OnHit(Game.GetPlayer()) | ||
;do something | |||
EndEvent | EndEvent | ||
</source> | </source> | ||
''' | '''However, that does NOT work.''' | ||
Instead what you need to do is something like this: | Instead what you need to do is something like this: | ||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Event OnHit(ObjectReference akAggressor, Form akWeapon, Projectile akProjectile) | Event OnHit(ObjectReference akAggressor, Form akWeapon, Projectile akProjectile) | ||
if akAggressor | if akAggressor != game.getPlayer() | ||
return | |||
endif | endif | ||
;do something | |||
EndEvent | EndEvent | ||
</source> | </source> |
Latest revision as of 15:06, 18 August 2024
Events are special functions that the game will call when something happens. Note that simply defining an event won't make the game call it, you must follow the name and argument list of an event that the game already sends you.
Event Definition[edit | edit source]
<event> ::= <event header> [<function block> 'endEvent']
Function headers must always be followed by a standard function block and "EndEvent", unless they are native (which are handled by the game).
Event Header[edit | edit source]
<event header> ::= 'Event' <identifier> '(' [<parameters>] ')' ['Native'] <flags>*
The event header is identical to the function header, but does not allow for return types or allow for the "Global" flag.
Parameters[edit | edit source]
The parameters are identical to the function parameter list, but should match the data that the game will send to the event.
Examples[edit | edit source]
; A simple activate event handler
Event OnActivate(ObjectReference akActivator)
PlayAnimation("CoolStuff")
endEvent
Special Variables[edit | edit source]
Event special variables are identical to a non-global function's.
Calling Events[edit | edit source]
Calling events is identical to calling a function.
A note about events[edit | edit source]
Events are not like the old block types. When you make an event in your script that extends ObjectReference or ReferenceAlias you are essentially creating a new version of that event, and you need to declare it with the same number of parameters. Those parameters are then used inside the script.
You should pretty much just copy and paste the events straight from the wiki, unless you desire to change the name of the parameters for some reason.
For example:
Event OnHit(ObjectReference akAggressor, Form akWeapon, Projectile akProjectile)
EndEvent
You might be tempted to try something like this:
Event OnHit(Game.GetPlayer())
;do something
EndEvent
However, that does NOT work.
Instead what you need to do is something like this:
Event OnHit(ObjectReference akAggressor, Form akWeapon, Projectile akProjectile)
if akAggressor != game.getPlayer()
return
endif
;do something
EndEvent
See Also[edit | edit source]
Language: | English • 日本語 |
---|