• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Two issues with a custom spell based on channel

Status
Not open for further replies.
Level 15
Joined
Aug 7, 2013
Messages
1,338
Hi,

So I made a custom spell based off of channel and triggered it.

The spell works fine, except there are two problems:


1. if a hero levels up while using the spell, it will not pick up its Attack Tome
the tome will be left on the ground for anyone to pick up

2. if a ranged hero kills another unit while using spell, the cooldown will not reset
this means the hero can immediately use the spell again!

The spell is based off of Channel (ANcl) and has two versions: a melee based one and a ranged based one. How can I fix the two problems above with minimal changes to the code, and hopefully no dummy units.

JASS:
scope AttackTrig initializer init

globals
	constant integer ATTACK_MELEE = 'ATT0'
	constant integer ATTACK_RANGED = 'ATT1'
	constant integer BASE_DAMAGE = 5
	constant integer MELEE_MULTIPLIER = 6
	constant integer RANGED_MULTIPLIER = 5
endglobals

private function main takes nothing returns boolean
	local integer spellId = GetSpellAbilityId()
	local unit target
	local unit caster
    local player p
    local integer pid
	local real damage
    local Monster m
    if spellId == ATTACK_MELEE or spellId == ATTACK_RANGED then
		set target = GetSpellTargetUnit()
		if target == null then
			call printl("thinks the target is null")
		endif
		set caster = GetTriggerUnit()
		set p = GetOwningPlayer(caster)
		set pid = GetPlayerId(p)
		set m = playerDatum[pid].party.getMonsterByUnit(caster)
		if spellId == ATTACK_MELEE then
			set damage = BASE_DAMAGE + (m.attrPts[ATT] * MELEE_MULTIPLIER)
		else
			set damage = BASE_DAMAGE + (m.attrPts[ATT] * RANGED_MULTIPLIER)
		endif
		call UnitDamageTarget(caster, target, damage, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL, null)
		//call KillUnit(target)
		call printl("did : " + R2S(damage) + " damage.")	
    endif
    return false
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t, Condition(function main))
endfunction

endscope
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
Sorry I left that detail out.

Basically I use Attack tomes to modify a unit's damage, since it doesn't show a plus.

When a unit levels up, it is given an attack tome that increases its damage permanently.

So when a unit kills with the custom spell in the OP AND levels up, the tome doesn't get used by the unit but is left on the ground.

What I think is, is that the unit is still in the channel period, and while channeling units can't pick up items. So the tome doesn't get used.
 
Set the follow-through/casting time to 0 (and all the stuff that actually cause the spell to "channel").

If that doesn't work, the tome thing can be resolved by periodically issuing the order until the unit has finished. All the IssueBlahOrder... natives return a boolean (whether the order can actually be carried out). So simply check if the order was carried out. If not, then start a timer, hide the item, and then in the callback: show the item, attempt to issue -> pause if success -> keep looping if failed. Kind of a weird method, but it would be the cleanest way of getting it to go through.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
I've done all those things before with follow through time, etc. They've been at 0.

In regards to the tome problem, I don't actually issue any orders, this is the call:

JASS:
UnitAddItemById(u, damageTomes[gain])

In any case, how do I resolve the kill problem--if a ranged hero kills a unit with this custom ability, the ability doesn't go under cooldown.

For reference here's the ranged version of the ability, exactly identical to the melee version except the casting range and the names.

10q9qbq.png
 
Oops. I realized that you use the event "EVENT_PLAYER_UNIT_SPELL_CAST". That event fires before a unit actually uses the mana and before the cooldown is spent. Changing that to EVENT_PLAYER_UNIT_SPELL_EFFECT will likely fix your issues with that (in general, use that event unless you really need to do something before the actual spell takes effect).
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
That fixes the issue with the ranged hero, thank you!

But the tome issue still isn't resolved.

You had mentioned using the boolean returned by IssueOrder... but I do not use IssueOrder for adding the tome. What order would I issue?
 
Status
Not open for further replies.
Top