• 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.

[JASS] Trying to include allies with mass teleport

Status
Not open for further replies.
Level 4
Joined
Jun 8, 2004
Messages
66
I've been trying to create one of two spells with no success - either a "summon allies" skill that brings all allied units (minus a few types that are special) to a unit's location, or a variation of mass teleport that brings allies with you. Has anyone created a spell like this before?

The code can be found below. It has a tendency to work only some of the time - more often it works in smaller games or in games I host solo and throw a few computer players into.

The below code is supposed to bring allies with you when you do a regular mass teleport (I have events declared elsewhere which call the skill).

Basically it seems to always at least do the effects, but it doesn't always move the allied units.


By the way, what's leaking?

JASS:
function jrp_spell_mass_tele takes unit trigunit, unit targunit, integer spell_id returns nothing

	local unit tempunit
	local group tempgroup
	local location tpoint1
	local location tpoint2

	local player trigplayer = GetOwningPlayer(trigunit)
	local player tempplayer
	call TriggerSleepAction( 4 )
	set tpoint2 = GetUnitLoc(trigunit)
	
	set tpoint1 = GetUnitLoc(trigunit)
	set tempgroup = GetUnitsInRangeOfLocAll(600, tpoint1)
	call RemoveLocation( tpoint1 )
	
	loop
		exitwhen(FirstOfGroup(tempgroup) == null)
		set tempunit = FirstOfGroup(tempgroup)
		set tempplayer = GetOwningPlayer(tempunit)
		if ( (GetOwningPlayer(tempunit) != trigplayer) and (IsPlayerAlly(trigplayer, tempplayer) == true) and (IsUnitType(tempunit, UNIT_TYPE_STRUCTURE) == false) and (GetUnitTypeId(tempunit) != 'earc') ) then
			set tpoint1 = GetUnitLoc(tempunit)
			call AddSpecialEffectLocBJ( tpoint1, "Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl" )
			call DestroyEffectBJ( GetLastCreatedEffectBJ() )
			call RemoveLocation( tpoint1 )
			call SetUnitPositionLoc( tempunit, tpoint2 )
			set tpoint1 = GetUnitLoc(tempunit)
			call AddSpecialEffectLocBJ( tpoint1, "Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl" )
			call DestroyEffectBJ( GetLastCreatedEffectBJ() )
			call RemoveLocation( tpoint1 )
		endif
		call GroupRemoveUnit(tempgroup, tempunit)
		
	endloop
	
	call DestroyGroup( tempgroup )
	call RemoveLocation( tpoint2 )

endfunction

The spell_id argument is actually a holdover from a previous version of the map, and isn't used in the function. I'll probably get around to removing it soon.
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
Can you post the code where you're using that function? Maybe you did something wrong there. This way I can't know for sure which action happens first.

Can you explain the rest of the parameters?

Isn't targunit the unit which trigunit (with allies) has to teleport to? If so, you move the allies to trigunit, not targunit.

Btw, the code has a leak and it is full of BJs :).
 
Level 4
Joined
Jun 8, 2004
Messages
66
Yea I ended up changing it to try to follow trigunit after it teleports in case targunit somehow wasn't being saved (the way the stupid thing wasn't working, I was thinking maybe mass teleport was acting as a spell that you cast on an area rather than a unit).

trigunit was supposed to be the casting unit and targunit was meant to be the target unit (aka destination).

It wasn't working any better when I had it try to go to targunit's location.

By the way, where are the leaks? If it's in the BJ's, I'll start cleaning those up sometime soon. Maybe by chance I'll also fix the desync I was having.

[edit]Well, I've determined one probable problem
nope, turns out I commented out the other event registration line. Only one event at a time fires the trigger


JASS:
// **************************************************************************************
// Main Controller for the spells
// **************************************************************************************
function Trig_Unit_casts_spell_Actions takes nothing returns nothing

// GetSpellAbilityUnit()
local unit spell_trigger
// GetSpellTargetUnit()
local unit spell_target
// GetSpellTargetLoc()
local location spell_targloc

local integer ability_id = GetSpellAbilityId()

// -----------------------------------

// Mass Teleport (Scout)
if (ability_id == 'AHmt') then
	// Only set these if necessary
	set spell_trigger = GetSpellAbilityUnit()
	set spell_target = GetSpellTargetUnit()
	// Call abil
	call jrp_spell_mass_tele(spell_trigger,spell_target,ability_id)
	// Important so it stops checking
	return
endif
// -----------------------------------

endfunction

//===========================================================================
function InitTrig_Unit_casts_spell takes nothing returns nothing
    set gg_trg_Unit_casts_spell = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Unit_casts_spell, function Trig_Unit_casts_spell_Actions )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Unit_casts_spell, EVENT_PLAYER_UNIT_SPELL_CAST )
endfunction
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
JASS:
function Trig_Unit_casts_spell_Actions takes nothing returns nothing
    local unit spell_trigger
    local unit spell_target
    local location spell_targloc
    local integer ability_id = GetSpellAbilityId()
    if ability_id == 'AHmt' then
        set spell_trigger = GetSpellAbilityUnit()
        set spell_target = GetSpellTargetUnit()
        call jrp_spell_mass_tele(spell_trigger,spell_target,ability_id)
    endif
    set spell_trigger = null
    set spell_target = null
    set spell_targloc = null
endfunction

function InitTrig_Unit_casts_spell takes nothing returns nothing
    set gg_trg_Unit_casts_spell = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Unit_casts_spell, function Trig_Unit_casts_spell_Actions )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Unit_casts_spell, EVENT_PLAYER_UNIT_SPELL_CAST )
endfunction

Remember to null all handle variables at the end of the function and I see no reason for that return
 
Level 4
Joined
Jun 8, 2004
Messages
66
I ended up using this one to get it to work. It could be cleaned up a slight bit by using player locals.

JASS:
function jrp_spell_mass_tele takes unit trigunit, location targloc, integer spell_id returns nothing

	local unit tempunit
	local group tempgroup
	local location tpoint1 = GetUnitLoc(trigunit)
	local location tpoint2
	
	local effect tele01 = jrp_create_effect(tpoint1, "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl" )
	local effect tele02 = jrp_create_effect(targloc, "Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl" )
	
	call PolledWait( 1.75 )
	
	set tempgroup = GetUnitsInRangeOfLocAll(600, targloc)
	
	loop
	exitwhen(FirstOfGroup(tempgroup) == null)
		set tempunit = FirstOfGroup(tempgroup)

		if ( (GetOwningPlayer(tempunit) != GetOwningPlayer(trigunit)) and (IsPlayerAlly(GetOwningPlayer(trigunit), GetOwningPlayer(tempunit)) == true) and (IsUnitType(tempunit, UNIT_TYPE_STRUCTURE) == false) and (GetUnitTypeId(tempunit) != 'earc') ) then
			set tpoint2 = GetUnitLoc(tempunit)
			call jrp_create_and_destroy_effect( tpoint2, "Abilities\\Spells\\Items\\AIre\\AIreTarget.mdl" )
			call RemoveLocation( tpoint2 )
			
			call SetUnitPositionLoc( tempunit, tpoint1 )

			set tpoint2 = GetUnitLoc(tempunit)
			call jrp_create_and_destroy_effect( tpoint2, "Abilities\\Spells\\Items\\AIre\\AIreTarget.mdl" )
			call RemoveLocation( tpoint2 )
		endif
		
	call GroupRemoveUnit(tempgroup, tempunit)
	endloop
	
	call DestroyGroup( tempgroup )
	call RemoveLocation( tpoint1 )
	call RemoveLocation( targloc )

	call DestroyEffect( tele01 )
	call DestroyEffect( tele02 )
	
endfunction
 
Status
Not open for further replies.
Top