| 01-18-2007, 04:14 AM | #1 | |
Quote:
Here's the thread that was posted in. |
| 01-18-2007, 05:19 AM | #2 |
The way I would do it would be to make a trigger for each event possible, and then attach the trigger (using a GC and the return handle bug) to whatever the event is for. Basically you create triggers on the fly and then you can delete them when you need to, to free up space. The cloning, I'm guessing, is just using the same actions on a trigger, but changing the events. This is simply done by making the actions of the different triggers, the same functions. Looking at the trigger you posted in the other thread, I would "attach" the trigger to the unit that is attacked, and if it isn't damage by your hero within 2 seconds, destroy the trigger. If the trigger does fire, get it to destroy itself when it's done. |
| 01-18-2007, 06:13 AM | #3 |
Code:
function TriggerAddActionX takes trigger T, code C returns nothing
call SetCore(H2Sx(T),"TriggerAction",H2Ix(TriggerAddAction(T,C)))
endfunction
function TriggerReSet takes trigger T returns trigger
local triggeraction TA = I2TAx(GetCore(H2Sx(T),"TriggerAction"))
local trigger TR = CreateTrigger()
// trigger action is bounded to local
call TriggerDestroy(T)
// events cleared
call TriggerAddAction(TR,TA)
return TR
endfunctionNever used this BUT it must work 1) Every Trigger Action must be bounded to its base trigger 2) Trigger must have single trigger action 3) If Trigger Have mass trigger actions use CS cache tables for storage 4) Save trigger handle 5) Destroy trigger 6) Create trigger 7) Add stored trigger action function returns trigger, soo you will be able to add events |
| 01-18-2007, 10:18 AM | #4 |
Ever Thought about using Vexorians special events? The pawn the solutions here posted easily. Btw. it's part of the castersystem 14.2 EDIT: I guess I missunderstood you. To clone atrigger on the fly, you must simply attach the triggers triggeraction to the trigger Here is a possible solution: JASS:function Code2Int takes code c returns integer return c return 0 endfunction function Int2Code takes integer c returns code return c return null endfunction function Int2TAction takes integer i returns triggeraction return i return null endfunction function TAction2Int takes triggeraction ac returns integer return ac return 0 endfunction function CreateTriggerWithAction takes code c returns trigger local trigger T=CreateTrigger() call SetCSData(T,NewPair(TAction2Int(TriggerAddAction(T,c)),Code2Int(c))) set bj_destInRegionDiesTrig=T set T=null return bj_destInRegionDiesTrig endfunction function DestroyTriggerWithAction takes trigger t returns nothing local trigger T=t local integer data=GetCSData(T) local triggeraction AC=Int2TAction(GetPayirX(data)) call DisableTrigger(T) //this is one of many unproofed ways to stop triggers corrupting handle inices call TriggerRemoveAction(T,AC) set AC=null call DestroyTrigger(T) set T=null call DestroyPair(data) endfunction function CloneTrigger takes trigger t,boolean killold returns trigger local trigger T=CreateTrigger() local integer data=GetCSData(t) local code c=Int2Code(GetPairY(data)) //must be stored to a local for bug preventing local DATA=NewPair(TAction2Int(TriggerAddAction(T,c)),GetPairY(data)) call SetCSData(T,DATA) if (killold) then call DestroyTriggerWithAction(t) endif set bj_destInRegionDiesTrig=T set T=null //I am not sure if we use t as return if it hostages the handle index (pipedream mentioned something) return bj_destInRegionDiesTrig endfunction |
| 01-18-2007, 11:29 AM | #5 |
as i know code type is immune to return bug |
| 01-18-2007, 11:38 AM | #6 |
It isn't. --- You could make a data structure to describe events, and use it to add events to triggers at the same time as you keep an array of the events for the trigger. Then you could have a remove event thing that created the trigger and readded the remaining triggers... ...but: - Some events will fire when added to the trigger - Doing it this way doesn't really serve any purpose does it? It doesn't prevent DestroyTrigger , it doesn't save memory since you need more memory to use it. If anything it would increase the calls and risks of using DestroyTrigger |
| 01-18-2007, 11:15 PM | #7 |
That thread has nothing to do with what I wanted to do with "cloning" a trigger. I have a trigger with the event "Unit - Unit takes damage" dynamically added for each unit on the map (part of an attack detection engine), but the map is a hero-defence type map, meaining that there are a LOT of events that will eventually be added to the trigger. I was hoping to be able to flush the events from the trigger to get rid of the lag. That's all; I'm going to look into DioD and BertTheJasser's ideas soon. |
