Difference between revisions of "NDGIA"
Line 7: | Line 7: | ||
|} | |} | ||
</center> | </center> | ||
− | <p style="width: 60%;margin: 0 auto">Example of adding a | + | <p style="width: 60%;margin: 0 auto">Example of adding a view to a object</p> |
<div style="width:60%;margin: 0 auto"> | <div style="width:60%;margin: 0 auto"> | ||
− | + | --this will add a view that will interact with players within 30 units | |
− | + | --It will check and update every 0.5 seconds | |
− | + | AddView("ViewHandler",SearchPlayerInRange(30,true),0.5) | |
</div> | </div> | ||
− | <p style="width: 60%;margin: 0 auto">Example of | + | <p style="width: 60%;margin: 0 auto">Example of handling a object entering a view</p> |
<div style="width:60%;margin: 0 auto"> | <div style="width:60%;margin: 0 auto"> | ||
− | + | --- OnEnterView - this function is triggered by the EventHandler EnterView | |
− | + | --@ param: enteringObject - this is the object in the world that moves within the 30 unit view | |
− | + | function OnEnterView(enteringObject) | |
+ | If(enteringObject:IsPlayer()) then | ||
+ | enteringObject:SystemMessage("you have entered " .. this:GetName() .. " view.") | ||
+ | end | ||
+ | end | ||
+ | |||
+ | --Register the event handler for the "ViewHandler" when a player enters the view | ||
+ | RegisterEventHandler(EventType.EnterView, "ViewHandler", OnEnterView) | ||
</div> | </div> | ||
− | <p style="width: 60%;margin: 0 auto">Example of | + | <p style="width: 60%;margin: 0 auto">Example of handling a object leaving a view</p> |
<div style="width:60%;margin: 0 auto"> | <div style="width:60%;margin: 0 auto"> | ||
− | + | --- OnLeaveView - this function is triggered by the EventHandler LeaveView | |
− | + | --@ param: enteringObject - this is the object in the world that moves within the 30 unit view | |
− | + | function OnLeaveView (leavingObject) | |
+ | If(leavingObject:IsPlayer()) then | ||
+ | leavingObject:SystemMessage("you have left " .. this:GetName() .. " view.") | ||
+ | end | ||
+ | end | ||
+ | |||
+ | --Register the event handler for the "ViewHandler" when a player leavesthe view | ||
+ | RegisterEventHandler(EventType.EnterView, "ViewHandler", OnLeaveView) | ||
</div> | </div> |
Revision as of 13:59, 9 November 2019
Global Functions & Examples
AddView(eventid,searcher,frequency) eventid - Event identifier for eventssearcher - Object searcher that defines the view frequency - Update frequency check in seconds. |
The frequency argument may be omitted, the View will default to 0.25 seconds for the frequency. The minimum value of frequency is 0.1 seconds. |
Example of adding a view to a object
--this will add a view that will interact with players within 30 units --It will check and update every 0.5 seconds AddView("ViewHandler",SearchPlayerInRange(30,true),0.5)
Example of handling a object entering a view
--- OnEnterView - this function is triggered by the EventHandler EnterView --@ param: enteringObject - this is the object in the world that moves within the 30 unit view function OnEnterView(enteringObject) If(enteringObject:IsPlayer()) then enteringObject:SystemMessage("you have entered " .. this:GetName() .. " view.") end end --Register the event handler for the "ViewHandler" when a player enters the view RegisterEventHandler(EventType.EnterView, "ViewHandler", OnEnterView)
Example of handling a object leaving a view
--- OnLeaveView - this function is triggered by the EventHandler LeaveView --@ param: enteringObject - this is the object in the world that moves within the 30 unit view function OnLeaveView (leavingObject) If(leavingObject:IsPlayer()) then leavingObject:SystemMessage("you have left " .. this:GetName() .. " view.") end end --Register the event handler for the "ViewHandler" when a player leavesthe view RegisterEventHandler(EventType.EnterView, "ViewHandler", OnLeaveView)