HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

my vars arent being set

10-15-2004, 12:52 AM#1
-={tWiStÄr}=-
I have a spell, it is basicly bear form, but it transforms the hero into a unit so theres some differences and it has to be completely triggered. so the way i do it, is when the hero cast an ability off of warstomp, it is instantly moved to a corner, then a new unit is created. the units stats are set, items etc. then the unit has an ability called revert. he presses this and it puts the hero back, adds appropiate exp, stats etc. the problem is there is a variable PlayerHero[n] that dictates special things that happen to the hero, like the name that follows it, and revival etc. well the PlayerHero isnt set back to the normal unit like it says.
Note: there is no conflict in other triggers and i have another spell EXACTLY like it but i is set to 3 or 4 and of course functions are renamed
Code:
function Trig_Mount_HorseON_Conditions takes nothing returns boolean
	return GetSpellAbilityId() == 'A01O'
endfunction
function Trig_Mount_HorseON_Func0002 takes nothing returns nothing
	if ( GetUnitCurrentOrder(GetEnumUnit()) == String2OrderIdBJ("stop") ) then
		call IssueImmediateOrderBJ( GetEnumUnit(), "stop" )
	else
		call DoNothing( )
	endif
endfunction
function Trig_Mount_HorseON_Actions takes nothing returns nothing
	local real life
	local integer skilllevel
	local integer i = 0
	local integer p = GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))
	local integer attribloop
	local integer attribadd = 1
	local location heroloc = GetUnitLoc(GetSpellAbilityUnit())
	if (IsPlayerInForce(GetOwningPlayer(GetSpellAbilityUnit()), udg_Teams[1]) == true) then
		set i = 1
	else
		set i = 2
	endif
	set skilllevel = GetUnitAbilityLevelSwapped('A01O', GetSpellAbilityUnit())
	set udg_transformhero[i] = GetSpellAbilityUnit()
	set life = GetUnitLifePercent(udg_transformhero[i])
	call CreateNUnitsAtLoc( 1, udg_Transformunittype[skilllevel], GetOwningPlayer(GetSpellAbilityUnit()), heroloc, bj_UNIT_FACING )
	set udg_TransformGameUnit[i] = GetLastCreatedUnit()
	set udg_PlayerHero[p] = udg_TransformGameUnit[i]
	call SetUnitLifePercentBJ(udg_TransformGameUnit[i], life)
	set heroloc = GetUnitLoc(udg_TransformGameUnit[i]) 
	if ( i == 1) then
		call CreateNUnitsAtLoc( 1, 'H00B', Player(10), heroloc, bj_UNIT_FACING )
	else
		call CreateNUnitsAtLoc( 1, 'H00B', Player(11), heroloc, bj_UNIT_FACING )
	endif
	set udg_transformunitfollow[i] = GetLastCreatedUnit()
	call IssueTargetOrderBJ( udg_transformunitfollow[i], "move", udg_TransformGameUnit[i] )
	if ( i == 1 ) then
		call SetUnitOwner( udg_transformhero[i], Player(10), true )
	else
		call SetUnitOwner( udg_transformhero[i], Player(11), true )
	endif
	call SetUnitPositionLoc( udg_transformhero[i], GetRectCenter(gg_rct_Heromove) )
	call UnitTransferAllItemsToUnit(udg_transformhero[i], udg_TransformGameUnit[i])
	call SelectUnitAddForPlayer( udg_TransformGameUnit[i], GetOwningPlayer(udg_TransformGameUnit[i]) )
	call IssueImmediateOrderBJ( udg_TransformGameUnit[i], "stop" )
	call ForGroupBJ( GetUnitsInRangeOfLocAll(100000.00, heroloc), function Trig_Mount_HorseON_Func0002 )
	set attribloop = GetUnitAbilityLevelSwapped('A00A', GetSpellAbilityUnit())
	loop
		exitwhen attribadd > attribloop
		call UnitAddAbilityBJ( udg_attribbonus[attribadd], udg_TransformGameUnit[i] )
		set attribadd = attribadd + 1
	endloop
	if attribloop >= 4 then
		call UnitAddAbilityBJ( 'A00D', udg_TransformGameUnit[i] )
	else
		call DoNothing()
	endif
	call RemoveLocation(heroloc)
endfunction
//===========================================================================
function InitTrig_Mount_HorseON takes nothing returns nothing
	set gg_trg_Mount_HorseON = CreateTrigger( )
	call TriggerRegisterAnyUnitEventBJ( gg_trg_Mount_HorseON, EVENT_PLAYER_UNIT_SPELL_CAST )
	call TriggerAddCondition( gg_trg_Mount_HorseON, Condition( function Trig_Mount_HorseON_Conditions ) )
	call TriggerAddAction( gg_trg_Mount_HorseON, function Trig_Mount_HorseON_Actions )
endfunction

Revert trigger:
Code:
function Trig_Mount_HorseOFF_Conditions takes nothing returns boolean
	local integer t = GetUnitTypeId(GetSpellAbilityUnit())
	return GetSpellAbilityId() == 'A007'
	return t == 'h00H' or t == 'h00I' or t == 'h00G' or t == 'h00L' or t == 'h00E' 
endfunction
function Trig_Mount_HorseOFF_Actions takes nothing returns nothing
	local real life
	local integer i = 0
	local integer p = GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))
	local location heroloc = GetUnitLoc(GetSpellAbilityUnit())
	if (IsPlayerInForce(GetOwningPlayer(GetSpellAbilityUnit()), udg_Teams[1]) == true) then
		set i = 1
	else
		set i = 2
	endif
	set life = GetUnitLifePercent(udg_TransformGameUnit[i])
	call SetUnitLifePercentBJ(udg_transformhero[i], life)
	set heroloc = GetUnitLoc(udg_TransformGameUnit[i]) 
	call SetUnitOwner( udg_transformhero[i], GetOwningPlayer(GetSpellAbilityUnit()), true )
	call SetUnitPositionLoc( udg_transformhero[i], heroloc )
	set udg_PlayerHero[p] = udg_transformhero[i]
	call RemoveUnit(GetSpellAbilityUnit())
	call SetHeroXP(udg_transformhero[i], (GetHeroXP(udg_transformhero[i]) + GetHeroXP(udg_transformunitfollow[i])), true)
	call RemoveUnit(udg_transformunitfollow[i])
	call SelectUnitAddForPlayer( udg_transformhero[i], GetOwningPlayer(udg_transformhero[i]) )
	call RemoveLocation(heroloc)
	set udg_transformhero[i] = null
endfunction
//===========================================================================
function InitTrig_Mount_HorseOFF takes nothing returns nothing
	set gg_trg_Mount_HorseOFF = CreateTrigger( )
	call TriggerRegisterAnyUnitEventBJ( gg_trg_Mount_HorseOFF, EVENT_PLAYER_UNIT_SPELL_CAST )
	call TriggerAddCondition( gg_trg_Mount_HorseOFF, Condition( function Trig_Mount_HorseOFF_Conditions ) )
	call TriggerAddAction( gg_trg_Mount_HorseOFF, function Trig_Mount_HorseOFF_Actions )
endfunction
I've tried practicly everything, even storing the units integer in a gamecache and trying to recover it.
edit: typo in trigger
10-15-2004, 08:58 AM#2
PitzerMike
Why not use the chaos ability to do the shape shifting?

Remember: it will remain the same unit but be a different unit-type
afaik this also works for hero-unit conversion
10-15-2004, 02:14 PM#3
-={tWiStÄr}=-
i dunno i think ive heard probs with that, and does it revert back? it would really be easier just to tell me whats wrong. i have the exact same thing for another spell on the same hero (of course its based off another spell).
10-18-2004, 06:16 AM#4
-={tWiStÄr}=-
I hate to bump this, but ive had this problem practicly since ive started my map, can someone please help.
10-24-2004, 02:17 AM#5
Guest
I am assuming you haven't fixed it yet...?

Make some debug functions that print the name of udg_transformhero and udg_transform unit, or that create speech indicators for them (the white flashy circles), or something, so you can isolate where the problem occurs. Make it so you can trigger them before, during, and after each of these functions... i.e., you could display the unittype of udg_PlayerHero, and of udg_transformhero, just before the `set udg_PlayerHero[p] = udg_transformhero[i]' line, then right after, to make sure that's what's going wrong...
10-24-2004, 03:08 AM#6
-={tWiStÄr}=-
i've already tried that. the wierd part is, i know that in each function it knows which vars are what. in the second function (where the problem is) I change udg_transformhero[i]'s team, and it works. but then when i try to set PlayerHero[p] to it something screws up.
10-24-2004, 04:41 AM#7
Guest
o.0 How can you tell that it's not being set properly? The stored hero does shows up properly, right?

What about a debug trigger that runs that specific line of code that sets udg_PlayerHero? if you run it before the mounthorseOFF trigger, does it work properly?

You should also make sure the trigger isn't running twice somehow... -shrug-

because if it was, PlayerHero would be set wrong....