- Joined
- Nov 4, 2006
- Messages
- 153
So um...I'm just trying to learn JASS and I can't seem to do anything correctly! First attempt at JASS. Anyways, I am trying to make a sort of damage system type thing. It will go like this (it is similar to some of my maps if you have seen any of them):
- when unit tries to attack a unit, it will create a trigger called "Damage Trigger"
- the "Damage Trigger" will remain in play so that I may use it for special passive effects or something
- when the unit that was attacked is killed, the "Damage Trigger" is destroyed for that unit so there's not a whole bunch at once
I am probably doing everything incorrectly, so any feedback is welcome, except comments like "freaking dumba$$" . Hope to learn a lot...or at least retain some knowledge. Btw, using NewGen but trying to do regular JASS first (I don't know the difference yet).
- when unit tries to attack a unit, it will create a trigger called "Damage Trigger"
- the "Damage Trigger" will remain in play so that I may use it for special passive effects or something
- when the unit that was attacked is killed, the "Damage Trigger" is destroyed for that unit so there's not a whole bunch at once
I am probably doing everything incorrectly, so any feedback is welcome, except comments like "freaking dumba$$" . Hope to learn a lot...or at least retain some knowledge. Btw, using NewGen but trying to do regular JASS first (I don't know the difference yet).
JASS:
globals
group Ug_DamageSys //This will be used to hold units that "have" the DamageTrigger. They are removed from it once they die.
endglobals
function AttackTrigger_Conditions takes nothing returns boolean
return (IsUnitInGroup(GetTriggerUnit(), Ug_DamageSys) == false) and (GetUnitAbilityLevel(GetAttacker(), 'A002') > 0) //Checks that the unit does not already have the DamageTrigger AND at least has the ability "Roots Passive"
endfunction
function DamageTrigger_Conditions takes nothing returns boolean
return true //Just returns true...Do I need to put this function at all? - I will try removing it later
endfunction
function DeathTrigger_Conditions takes nothing returns boolean
return true //Same as above
endfunction
function DeathTrigger_Actions takes nothing returns nothing
local unit AttackedUnit = GetTriggerUnit()
// local string message = "The Death Trigger is Working"
// local force players = GetPlayersAll()
call GroupRemoveUnit(Ug_DamageSys, AttackedUnit) //Unit died, so it no longer has the DamageTrigger
// call DisplayTextToForce( players, message )
// set players = null
// set message = null
set AttackedUnit = null
endfunction
function DamageTrigger_Actions takes nothing returns nothing
local unit AttackedUnit = GetTriggerUnit()
local unit AttackingUnit = GetEventDamageSource()
local trigger DamageTrigger = GetTriggeringTrigger()
local string message = "The Damage Trigger is Working"
local force players = GetPlayersAll()
call DisplayTextToForce( players, message )
call UnitDamageTarget(AttackingUnit, AttackedUnit, GetEventDamage(), true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, null)
set DamageTrigger = null
set AttackingUnit = null
set AttackedUnit = null
set players = null
set message = null
endfunction
function AttackTrigger_Actions takes nothing returns nothing
local unit AttackingUnit = GetAttacker() //We store the attacking unit
local unit AttackedUnit = GetTriggerUnit() //We store the attacked unit - this one will take the damage
local trigger DamageTrigger = CreateTrigger() //We create the damage trigger
local trigger DeathTrigger = CreateTrigger()
call TriggerRegisterUnitEvent(DamageTrigger, AttackedUnit, EVENT_UNIT_DAMAGED)
call TriggerAddCondition(DamageTrigger, Condition(function DamageTrigger_Conditions))
call TriggerAddAction(DamageTrigger, function DamageTrigger_Actions)
call GroupAddUnit(Ug_DamageSys, AttackedUnit)
set DamageTrigger = null
call TriggerRegisterDeathEvent(DeathTrigger, AttackedUnit)
call TriggerAddCondition(DeathTrigger, Condition( function DeathTrigger_Conditions))
call TriggerAddAction( DeathTrigger, function DeathTrigger_Actions)
set DeathTrigger = null
set AttackingUnit = null
set AttackedUnit = null
endfunction
function InitTrig_AttackDamageDetection takes nothing returns nothing
local trigger AttackTrigger = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(AttackTrigger, EVENT_PLAYER_UNIT_ATTACKED)
call TriggerAddCondition(AttackTrigger, Condition( function AttackTrigger_Conditions))
call TriggerAddAction(AttackTrigger, function AttackTrigger_Actions)
set AttackTrigger = null
endfunction