This component runs custom Lua script code, implementing the behaviour of the entity in the game world. More...
Public Member Functions | |
InitEventTypes (number n) | |
This functions sets the number of event types that can be used with PostEvent(). More... | |
PostEvent (number EventType) | |
This function is used for posting an event of the given type. More... | |
DamageAll (number Damage, number InnerRadius, number OuterRadius) | |
Inflicts damage to nearby entities. More... | |
Public Member Functions inherited from ComponentBaseT | |
any | get (string var_name) |
Returns the value of an attribute (a member variable) of this class. More... | |
set (string var_name, any new_value) | |
Sets an attribute (a member variable) of this class to a new value. More... | |
string | GetExtraMessage (string var_name) |
Returns the result of VarBaseT::GetExtraMessage() for the given member variable. More... | |
interpolate (string var_name, number start_value, number end_value, number time) | |
Schedules a value for interpolation between a start and end value over a given period of time. More... | |
EntityT | GetEntity () |
Returns the entity that this component is a part of (or nil if the component is currently "stand-alone", not a part of any entity). More... | |
InitClientApprox (string VarName) | |
Registers the given attribute (a member variable) of this class for interpolation over client frames in order to bridge the larger intervals between server frames. More... | |
OnInit () | |
This method is called for each component of each entity as the last step of initializing a newly loaded map. More... | |
OnClientFrame (number t) | |
This method is called for each component of each entity before the client renders the next frame. More... | |
Public Attributes | |
string | Name |
The file to load the Lua script code from. More... | |
string | ScriptCode |
Immediate Lua script code to use with this entity. More... | |
Event Handlers (Callbacks) | |
See the Event Handlers (Callbacks) overview page for additional information about the methods in this group. | |
OnActivate (EntityT Other) | |
This method is called when another entity wants to prompt us to become active. More... | |
OnTrigger (EntityT Other) | |
This method is called when another entity moves into this entity's trigger volume. More... | |
ProcessEvent (int EventType, int EventCount) | |
This method is called on the client in order to process and react to events. More... | |
Think (number FrameTime) | |
The server calls this method on each server clock tick, in order to advance the world to the next server frame. More... | |
tuple | GetMove (int PartNr, number FrameTime) |
This method is called when there also is a ComponentMoverT component in the entity. More... | |
ChangeWeapon (int GroupNr) | |
This method is called when the player has pressed a button to change the weapon. More... | |
TakeDamage (EntityT Other, number Amount, number DirX, number DirY, number DirZ) | |
This method is called when another entity caused damage to this entity. More... | |
This component runs custom Lua script code, implementing the behaviour of the entity in the game world.
The script code can be loaded from a separate file, or it can be entered and kept directly in the component.
Keeping the script code in a separate file is useful when it is re-used with several entity instances or in several maps. Keeping the script code directly in the component is useful for short scripts that are unique to a single map and entity instance. Note that both options can also be combined: The script code from a file is loaded first, and immediate code can be used to augment it (for example to "configure" it).
Note that the variables of this class (also referred to as "Public Attributes" or "Member Data") must be used with the get() and set() methods at this time – see get() and set() for details.
If you would like to create a new component of this type explicitly (those defined in the CaWE Map Editor are instantiated automatically), use WorldT::new():
ChangeWeapon | ( | int | GroupNr | ) |
This method is called when the player has pressed a button to change the weapon.
GroupNr | The number of the weapon group from which the next weapon is to be drawn. |
DamageAll | ( | number | Damage, |
number | InnerRadius, | ||
number | OuterRadius | ||
) |
Inflicts damage to nearby entities.
This function finds all entities that are close to this (within a distance of OuterRadius
, excluding this entity itself) and have a ComponentScriptT component. It then calls that script component's TakeDamage() method in order to apply the damage accordingly.
Damage | The maximum damage to apply to nearby entities. |
InnerRadius | Entities that are closer than InnerRaduis are damaged by the full amount of Damage . |
OuterRadius | Entities that are farther than OuterRadius are not damaged at all. |
The damage that is inflicted to entities that are between InnerRaduis
and OuterRadius
is linearly scaled from Damage
to 0. Entities must implement the TakeDamage() script callback method in order to actually process the inflicted damage.
tuple GetMove | ( | int | PartNr, |
number | FrameTime | ||
) |
This method is called when there also is a ComponentMoverT component in the entity.
The mover calls this method in order to learn which of its part to move where over the given frame time.
InitEventTypes | ( | number | n | ) |
This functions sets the number of event types that can be used with PostEvent().
OnActivate | ( | EntityT | Other | ) |
This method is called when another entity wants to prompt us to become active.
Note that this method is usually not called directly from Cafu's C++ code, but rather from other script code, e.g. from GUIs whose button has been pressed.
OnTrigger | ( | EntityT | Other | ) |
This method is called when another entity moves into this entity's trigger volume.
PostEvent | ( | number | EventType | ) |
This function is used for posting an event of the given type.
The event is automatically sent from the entity instance on the server to the entity instances on the clients, and causes a matching call to the ProcessEvent() callback there. The meaning of the event type is up to the script code that implements ProcessEvent(). Note that events are fully predictable: they work well even in the presence of client prediction.
ProcessEvent | ( | int | EventType, |
int | EventCount | ||
) |
This method is called on the client in order to process and react to events.
TakeDamage | ( | EntityT | Other, |
number | Amount, | ||
number | DirX, | ||
number | DirY, | ||
number | DirZ | ||
) |
This method is called when another entity caused damage to this entity.
Think | ( | number | FrameTime | ) |
The server calls this method on each server clock tick, in order to advance the world to the next server frame.
string Name |
The file to load the Lua script code from.
std::string
string ScriptCode |
Immediate Lua script code to use with this entity.
std::string