Jesus4Lyf
Good Idea™
- Reaction score
- 397
library Trackable2
private keyword Data
globals
private Data array Trackables
private Data TriggeringTrackable
endglobals
private struct Data
trackable array Trackers [12]
trigger ClickFire
trigger TrackFire
trigger OnClick // change to arrays or w/e to support multi-trigs
trigger OnTrack // change to arrays or w/e to support multi-trigs
real X
real Y
real Z
real Facing
string Model
player ForPlayer = null
endstruct
// Unreliable piece of junk... j/k
//private constant function H2I takes handle h returns integer
// return h
// return 0
//endfunction
// The old Key Triggers implementation. <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" />
// Fount on <a href="http://www.thehelper.net/forums/showthread.php?t=78493" class="link link--internal">http://www.thehelper.net/forums/showthread.php?t=78493</a>
// Suitable only in very controlled circumstances, so it was never approved.
private function SetTriggerData takes trigger t, integer data returns nothing
call ResetTrigger(t)
loop
exitwhen data==0
call TriggerExecute(t)
set data=data-1
endloop
endfunction
private function GetTriggerData takes trigger t returns integer
return GetTriggerExecCount(t)
endfunction
// End Key Triggers implementation.
function ClickFireCond takes nothing returns boolean
set TriggeringTrackable=GetTriggerData(GetTriggeringTrigger())
// The below can be done in a loop to support multi-trigger
if TriggerEvaluate(TriggeringTrackable.OnClick) then
call TriggerExecute(TriggeringTrackable.OnClick)
endif
return false // Must be false so attached data never changes. Do not use real actions.
endfunction
function TrackFireCond takes nothing returns boolean
set TriggeringTrackable=GetTriggerData(GetTriggeringTrigger())
// The below can be done in a loop to support multi-trigger
if TriggerEvaluate(TriggeringTrackable.OnTrack) then
call TriggerExecute(TriggeringTrackable.OnTrack)
endif
return false // Must be false so attached data never changes. Do not use real actions.
endfunction
function CreateTrackable2 takes string modelPath, real x, real y, real z, real facing returns Data
local Data d = Data.create()
local string s = "" // I honestly believe the alternative could desynch, as "" did not exist - Jesus4Lyf
local destructable platform = CreateDestructableZ(039;OTip039;,x,y,z,0.00,1,0)
local integer i = 11
loop
exitwhen i < 0
if GetLocalPlayer() == Player(i) then
set s = modelPath
else
set s = ""
endif
set d.Trackers<i> = CreateTrackable(s, x, y, facing)
//set Trackables[H2I(d.Trackers<i>) - 0x100000] = d
set i = i - 1
endloop
set d.X = x
set d.Y = y
set d.Z = z
set d.Facing = facing
set d.Model = modelPath
// Added by Jesus4Lyf
set d.ClickFire=CreateTrigger()
set d.TrackFire=CreateTrigger()
call SetTriggerData(d.ClickFire,d)
call SetTriggerData(d.TrackFire,d)
call TriggerAddCondition(d.ClickFire,Condition(function ClickFireCond))
call TriggerAddCondition(d.TrackFire,Condition(function TrackFireCond))
set i = 11
loop
exitwhen i < 0
call TriggerRegisterTrackableHitEvent(d.ClickFire, d.Trackers<i>)
call TriggerRegisterTrackableTrackEvent(d.TrackFire, d.Trackers<i>)
set i = i - 1
endloop
// End addition
call RemoveDestructable(platform)
set platform = null
return d
endfunction
function CreateTrackable2ForPlayer takes string modelPath, real x, real y, real z, real facing, player forPlayer returns Data
local Data d = Data.create()
local string s = modelPath
local destructable platform = CreateDestructableZ(039;OTip039;,x,y,z,0.00,1,0)
if GetLocalPlayer() != forPlayer then
set s = ""
endif
set d.Trackers[1] = CreateTrackable(s, x, y, facing)
//set Trackables[H2I(d.Trackers[1]) - 0x100000] = d
set d.ForPlayer = forPlayer
set d.X = x
set d.Y = y
set d.Z = z
set d.Facing = facing
set d.Model = modelPath
// Added by Jesus4Lyf
set d.ClickFire=CreateTrigger()
set d.TrackFire=CreateTrigger()
call SetTriggerData(d.ClickFire,d)
call SetTriggerData(d.TrackFire,d)
call TriggerAddCondition(d.ClickFire,Condition(function ClickFireCond))
call TriggerAddCondition(d.TrackFire,Condition(function TrackFireCond))
call TriggerRegisterTrackableHitEvent(d.ClickFire, d.Trackers[1])
call TriggerRegisterTrackableTrackEvent(d.TrackFire, d.Trackers[1])
// End addition
call RemoveDestructable(platform)
set platform = null
return d
endfunction
function TriggerRegisterTrackable2HitEvent takes trigger whichTrigger, Data d returns nothing
set d.OnClick=whichTrigger
endfunction
function TriggerRegisterTrackable2TrackEvent takes trigger whichTrigger, Data d returns nothing
set d.OnTrack=whichTrigger
endfunction
// Noooiez. H2I is naughty like that. Unstable! <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue :p" loading="lazy" data-shortname=":p" />
//function GetTriggeringTrackable2 takes nothing returns Data
// return Trackables[H2I(GetTriggeringTrackable()) - 0x100000]
//endfunction
function GetTrackedPlayer takes Data d returns player
local integer i
local trackable t
if d.ForPlayer == null then
set i = 11
set t = GetTriggeringTrackable()
loop
exitwhen i < 0
if t == d.Trackers<i> then
set t = null
return Player(i)
endif
set i = i - 1
endloop
else
return d.ForPlayer
endif
return null
endfunction
//! textmacro Trackable2_Macro takes NAME, TYPE
function GetTrackable2$NAME$ takes nothing returns $TYPE$
return TriggeringTrackable.$NAME$
endfunction
//! endtextmacro
//! runtextmacro Trackable2_Macro ("X", "real")
//! runtextmacro Trackable2_Macro ("Y", "real")
//! runtextmacro Trackable2_Macro ("Z", "real")
//! runtextmacro Trackable2_Macro ("Facing", "real")
//! runtextmacro Trackable2_Macro ("Model", "string")
//! runtextmacro Trackable2_Macro ("ForPlayer", "player")
endlibrary</i></i></i></i></i>
Makes sense. I dont know what Im writing anymore.Furthermore, "Since, I2Trackable is safe, it could be the fastest way to get attached data from trackable" doesn't make sense as all it can do is get the trackable. Not data from it.