- Joined
- Feb 15, 2005
- Messages
- 183
ok, I am jsut learning JASS and I have been working on my first truly ALL Jass script, but as many of you have probably guessed by now, I am running into some trouble. The point of my script is to get a very accurate read out of how much damage a unit does to another unit, and get gold equal to that damage. This is the script I have right now.
The trigger works and gives me the first value when the unit starts the attack, but as soon as the other unit takes damage, the game crashes. I think it probably has to do something with my condition function and the local trigger i created. If anyone can tell me how to fix this I would really appreciate it alot.
JASS:
function Calc takes real Life, unit Attacked, unit Attacker returns nothing
local integer Damage
set Damage = ( R2I(Life) - R2I(GetUnitStateSwap(UNIT_STATE_LIFE, Attacker)) )
call DisplayTextToForce( GetPlayersAll(), R2S(Damage) )
call AdjustPlayerStateBJ( Damage, GetOwningPlayer(Attacker), PLAYER_STATE_RESOURCE_GOLD )
endfunction
function DamageSource takes unit Attacker returns boolean
if ( not ( Attacker == GetEventDamageSource() ) ) then
return false
endif
return true
endfunction
function InitCalc takes real Life, unit Attacked, unit Attacker returns nothing
local trigger Calcstart
set Calcstart = CreateTrigger()
call TriggerAddCondition(Calcstart, Condition(function DamageSource))
call TriggerRegisterUnitEvent(Calcstart, Attacked, EVENT_UNIT_DAMAGED)
call TriggerAddAction( Calcstart, function Calc )
endfunction
function InitialLife takes nothing returns nothing
local real Life = GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit())
call DisplayTextToForce( GetPlayersAll(), R2S(Life) )
call InitCalc(Life, GetTriggerUnit(), GetEventDamageSource())
endfunction
function InitTrig_DamageToGold takes nothing returns nothing
set gg_trg_DamageToGold = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_DamageToGold, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddAction( gg_trg_DamageToGold, function InitialLife )
endfunction
The trigger works and gives me the first value when the unit starts the attack, but as soon as the other unit takes damage, the game crashes. I think it probably has to do something with my condition function and the local trigger i created. If anyone can tell me how to fix this I would really appreciate it alot.