| 03-06-2009, 03:38 AM | #1 |
Well I'm a little confused at something I made just a moment ago. It started out fine and dandy sure; but I feel it came out a bit... pointless? All it does it set up a way to allow you avoid making any triggers for when the spell fires; and instead handles that itself. (1 trigger for every spellcast.) It also makes constructing a spells initializer faster, too. Anyways; any comments reguarding it? JASS:library CastLearnLib initializer init uses Callbacks globals CASTING_EVENT array CASTING_EVENTS CASTING_EVENT array LEARNING_EVENTS private constant integer EVENT_ANY_VAL = 94680 constant playerunitevent EVENT_ANY = ConvertPlayerUnitEvent(EVENT_ANY_VAL) constant playerunitevent EVENT_EFFECT = EVENT_PLAYER_UNIT_SPELL_EFFECT constant playerunitevent EVENT_END = EVENT_PLAYER_UNIT_SPELL_ENDCAST constant playerunitevent EVENT_FINISH = EVENT_PLAYER_UNIT_SPELL_FINISH constant playerunitevent EVENT_CAST = EVENT_PLAYER_UNIT_SPELL_CAST constant playerunitevent EVENT_CHANNEL = EVENT_PLAYER_UNIT_SPELL_CHANNEL constant playerunitevent EVENT_LEARN = EVENT_PLAYER_HERO_SKILL private constant integer MinSpellHandleId = 'A000' private trigger Cast private trigger Learn endglobals function interface CLB takes nothing returns nothing private function H2I takes handle h returns integer return h return 0 endfunction struct CASTING_EVENT integer sid CLB use integer pue endstruct function GetRegisteredSpellEvent takes integer sid returns CASTING_EVENT return CASTING_EVENTS[sid - MinSpellHandleId] endfunction function GetRegisteredLearningEvent takes integer sid returns CASTING_EVENT return LEARNING_EVENTS[sid - MinSpellHandleId] endfunction //if cast otherwise learn function RegisterSpellEvent takes integer sid, boolean cast, playerunitevent pt, CLB use returns nothing local CASTING_EVENT cs = CASTING_EVENT.create() set cs.sid = sid set cs.use = use set cs.pue = H2I(pt) if(cast)then set CASTING_EVENTS[sid - MinSpellHandleId] = cs else set LEARNING_EVENTS[sid - MinSpellHandleId] = cs endif endfunction function CastActions takes nothing returns nothing local unit cast = GetTriggerUnit() local integer sid = GetSpellAbilityId() local CASTING_EVENT t = GetRegisteredSpellEvent(sid) local integer evnt = H2I(GetTriggerEventId()) if(t == 0)then return endif if(evnt != t.pue and t.pue != EVENT_ANY_VAL)then return endif set CALLBACK_STRUCT = t call t.use.execute() endfunction function LearnActions takes nothing returns nothing local unit cast = GetTriggerUnit() local integer sid = GetSpellAbilityId() local CASTING_EVENT t = GetRegisteredLearningEvent(sid) local integer evnt = H2I(GetTriggerEventId()) if(t == 0)then return endif if(evnt != t.pue and t.pue != EVENT_ANY_VAL)then return endif set CALLBACK_STRUCT = t call t.use.execute() endfunction private function init takes nothing returns nothing set Cast = CreateTrigger() set Learn = CreateTrigger() call TriggerRegisterAnyUnitEventBJ(Cast, EVENT_PLAYER_UNIT_SPELL_EFFECT) call TriggerRegisterAnyUnitEventBJ(Cast, EVENT_PLAYER_UNIT_SPELL_CHANNEL) call TriggerRegisterAnyUnitEventBJ(Cast, EVENT_PLAYER_UNIT_SPELL_FINISH) call TriggerRegisterAnyUnitEventBJ(Cast, EVENT_PLAYER_UNIT_SPELL_ENDCAST) call TriggerRegisterAnyUnitEventBJ(Cast, EVENT_PLAYER_UNIT_SPELL_CAST) call TriggerRegisterAnyUnitEventBJ(Learn, EVENT_PLAYER_HERO_SKILL) call TriggerAddAction(Cast, function CastActions) call TriggerAddAction(Learn, function LearnActions) endfunction endlibrary |
| 03-06-2009, 04:12 AM | #2 | |
Hm, first comment. Quote:
To be honest this is just a waste of allocated memory, just use the blizzard constants for the system. Who cares if they take a little bit longer to type lol. |
| 03-06-2009, 04:31 AM | #3 | |
Quote:
Remember that constants are inlined by vjass; it saves some time, no? |
| 03-06-2009, 04:52 AM | #4 |
So you made BJ's... for constants? ![]() |
| 03-06-2009, 04:59 AM | #5 |
Inline is lame... Use common.j data |
| 03-06-2009, 06:51 AM | #6 |
Isn't there already something like this in xe/caster system? |
| 03-06-2009, 09:24 AM | #7 |
yes ofc, but this system use "other" methods |
| 03-06-2009, 09:40 AM | #8 |
JASS:call TriggerAddAction(Cast, function CastActions) call TriggerAddAction(Learn, function LearnActions) I would use Conditions here ...since they are faster... Sure you cant have no waits in Conditionfuncs ...but that doesnt matter ..since you are using .execute ..which runs the "real" Actions func in a new thread. |
