HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help with Short Script

04-03-2007, 02:56 AM#1
Tastingo
This is my JASS script for a function that pauses a unit that is attacked. If you could please help me with it. There is something wrong with the code when I set Frozen. I want it to get every unit that is paused. I never did finish it, but if you could please help me making things go faster, work properly, and not leak. I'm new to JASS so go easy on me. I also heard that you could make locals that act as globals, if so could you please tell me how. I need some way to keep track of the score of each team, with an integer variable. I want to try and avoid using globals.

Collapse JASS:
function GetFrozenUnits takes nothing returns boolean
    return ( IsUnitPaused(GetFilterUnit()) == true )
endfunction

function FreezeUnit takes nothing returns nothing
//Locals
local unit UFreezing
local unit UFrozen
local force TempForce
local group Frozen
set UFreezing = GetAttacker()
set UFrozen = GetTriggerUnit()
set TempForce = GetPlayersAll()

//Heal Unit

call SetUnitState(UFrozen, UNIT_STATE_LIFE, RMaxBJ(0,100))

//Check if unit can be frozen

if( IsUnitPaused(UFrozen) == false ) then
if( GetUnitTypeId(UFrozen) != GetUnitTypeId(UFreezing)) then

//Animation

call SetUnitVertexColor(UFrozen, 0, 0, 255, 0)
call SetUnitTimeScalePercent( UFrozen, 0.00 )
call IssueImmediateOrder( UFrozen, "stop" )
set Frozen = GroupEnumUnitsInRect(Frozen, GetWorldBounds(), Condition(function GetFrozenUnits))
call PauseUnit(UFrozen, true)
call PingMinimapForForce(TempForce, GetLocationX(GetUnitLoc(UFrozen)), GetLocationY(GetUnitLoc(UFrozen)), 5.00)

//Score for players

call SetPlayerState(GetOwningPlayer(UFreezing), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(UFreezing), PLAYER_STATE_RESOURCE_GOLD) + 1)
call SetPlayerState(GetOwningPlayer(UFreezing), PLAYER_STATE_RESOURCE_FOOD_USED, GetPlayerState(GetOwningPlayer(UFreezing), PLAYER_STATE_RESOURCE_FOOD_USED) + 1)

//Check if all frozen

else
endif
else
endif

//Null Locals

set UFreezing = null
set UFrozen = null
set TempForce = null
set Frozen = null
call DestroyForce(TempForce)
call DestroyGroup(Frozen)
endfunction

//===========================================================================
function InitTrig_Freeze_Unit takes nothing returns nothing
    set gg_trg_Freeze_Unit = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Freeze_Unit, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_Freeze_Unit, function FreezeUnit )
   set gg_trg_Freeze_Unit = null
endfunction
04-03-2007, 01:52 PM#2
Vexorian
Quote:
you could make locals that act as globals

Never heard of that before.

..
GetWorldBounds() returns a new rect every time, so that is leaking.

You should not set stuff to null before "destroying it". In your code call DestroyForce(TempForce) does nothing because TempForce is null already
04-03-2007, 09:08 PM#3
Tastingo
So do you null stuff after destroying it? Also I can't figure out whats wrong with set frozen, could you help me out with that as well?
04-03-2007, 09:14 PM#4
blu_da_noob
Quote:
So do you null stuff after destroying it?

Yes. And what do you mean by 'set frozen'?
04-03-2007, 09:52 PM#5
wyrmlord
Quote:
Originally Posted by Tastingo
Collapse JASS:
else
endif

There is no need for an else with no actions in it and then an endif, just remove the 'else'. Also, I noticed this:
if( GetUnitTypeId(UFrozen) != GetUnitTypeId(UFreezing)) then Do you mean for the unit types to be different? Or should units of the same type be able to freeze each other?

Also, you're doing another GroupEnumUnitsInRect each time a unit is frozen, and then don't do anything with the group (at least that I can tell). You could just have a global variable set to frozen units and just add the currently frozen unit to the group instead of doing a new GroupEnum every time. You're also pausing the attacked unit after doing the GroupEnum.

GetPlayersAll() is a BJ function that returns the variable bj_FORCE_ALL_PLAYERS. Later in the function, you're destroying this force which I don't think you want to do.
04-03-2007, 10:42 PM#6
Tastingo
Thanks wyrm, and your tutorial is what got me this far. In the game one team is grunts the other team is footmen. Basicly instead of checking players it checks if the units are different. If the units are different then the attacking unit will freeze the attacked unit. Well how would you do this trigger then? It's not totally finished though lol. I just need the trigger to pause the attacked unit, turn it blue, stop its animation, add gold and food to the player freezing, then check if number of units that are frozen are equal to the number of players on a force. Also ping the minimap and display some text to everyone. Your help would help a lot.