HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

I Require assistance with one of my dynamic arenas

12-07-2006, 10:21 AM#1
CoDRaZieL
I am in the process of creating a dynamic arena for a map im busy with, basically the room is a grid made up of 106 doors, and this trigger opens and closes those doors, however sometimes there is a slight jerk which could effect a player targetting an important spell, can someone please examine this code and suggest ways to optimise it
Collapse JASS:
function Trig_Wall_Shuffle_Conditions takes nothing returns boolean
    if ( not ( udg_DynamicArenaIsOn == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Wall_Shuffle_Func001Func001001 takes nothing returns boolean
    return ( IsDestructableAliveBJ(GetEnumDestructable()) == true )
endfunction

function Trig_Wall_Shuffle_Func002Func001Func001002002 takes nothing returns boolean
    return ( IsDestructableDeadBJ(GetLastCreatedDestructable()) == true )
endfunction


function Trig_Wall_Shuffle_Timer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer steps = GetHandleInt(t,"steps")
    local destructable Destwall = RandomDestructableInRectBJ(gg_rct_Wall_Arena, Condition(function Trig_Wall_Shuffle_Func001Func001001))
    local destructable Tempwall = RandomDestructableInRectBJ(gg_rct_Wall_Arena, Condition(function Trig_Wall_Shuffle_Func002Func001Func001002002))
    call KillDestructable(Destwall)
    call DestructableRestoreLife( Tempwall, GetDestructableMaxLife(Tempwall), false )
    set steps = steps -1
    call SetHandleInt(t,"steps",steps)
    if steps <=0 then
        call DestroyTimer(t)
    endif
    set Tempwall = null
    set Destwall = null
endfunction

function Trig_Wall_Shuffle_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local real duration = 0.10
    local integer steps = 150
    call SetHandleInt(t,"steps",steps)
    call TimerStart(t,duration,true,function Trig_Wall_Shuffle_Timer)
endfunction

//===========================================================================
function InitTrig_Wall_Shuffle takes nothing returns nothing
    set gg_trg_Wall_Shuffle = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Wall_Shuffle,3 )
    call TriggerAddCondition( gg_trg_Wall_Shuffle, Condition( function Trig_Wall_Shuffle_Conditions ) )
    call TriggerAddAction( gg_trg_Wall_Shuffle, function Trig_Wall_Shuffle_Actions )
endfunction

any help is greatly appreciated
12-07-2006, 01:17 PM#2
Vexorian
This belongs to the triggers and scripts forum, moved.
12-07-2006, 03:26 PM#3
Captain Griffen
Stop using BJs; use natives instead.
Stop using handle variables; use direct GC, or, even better, some dynamic array system.
12-08-2006, 09:21 AM#4
aquilla
hiho, I felt nice so I optimized it :D
Collapse JASS:
globals                                                                // the global variables used in the following functions
    boolean udg_DynamicArenaIsOn                                       // added like this to allow JassCraft to run a syntax check
    destructable array udg_des
    destructable array udg_res
    integer udg_randi
    integer udg_wallnum = 5 // number of doors to be opened each interval
    
    rect gg_rct_Wall_Arena                                             // blizzard global
endglobals

function RandomWallInRect takes nothing returns nothing                // this function is basicly what the BJ one does,
    local destructable d = GetEnumDestructable()                       // they ran interval*2*150/3 = 10 times/interval, this runs 1 time/interval
    local integer i = 1
    set udg_randi = udg_randi + 1                                      // iteration
    if GetDestructableLife(d) > 0 then                                 // if it's alive, add it to possibly be destroyed
        loop
            exitwhen i > udg_wallnum
            set udg_des[i] = d
            set i = i+1
        endloop
    else                                                               // else add it to possibly be ressurrected
        loop
            exitwhen i > udg_wallnum
            set udg_res[i] = d
            set i = i+1
        endloop
    endif
    set d=null
endfunction

function ShuffleWalls takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer i = 1
    if udg_DynamicArenaIsOn then
        set udg_randi = 0
        call EnumDestructablesInRect(gg_rct_Wall_Arena, null, function RandomWallInRect)
        loop                                                          // loop and kill/restore the selected destructables
            exitwhen i > udg_wallnum
            call KillDestructable(udg_des[i])
            call DestructableRestoreLife(udg_res[i], GetDestructableMaxLife(udg_res[i]), false)
            set i = i+1
        endloop
    endif
    set t=null
endfunction

function ShuffleWallsInit takes nothing returns nothing
    call TimerStart(GetExpiredTimer(), 0.1, true, function ShuffleWalls)         // 0.1 being interval
endfunction

//===========================================================================
function InitTrig_Wall_Shuffle takes nothing returns nothing
    call TimerStart(CreateTimer(), 3, false, function ShuffleWallsInit)          // 3 being start delay
endfunction
If you don't use JassCraft yet I suggest you get in from the tools section now, it really makes things easier to read :)
I added comments to explain things, if there's something you don't understand - just ask

(Oh, I haven't actually tested the code but I can't find anything wrong with it)

12-08-2006, 10:37 AM#5
CoDRaZieL
Thank you for your help, i am trying to fix this now, because only the 2 doors in the top right are opening and closing, and they are doing it rapidly . i do use jasscraft, since i started learning jass. do you perhaps know why only those 2 doors are being opened and closed, iv created all of the globals, and i have tried to set the arrays to both 53 and 106, 106 is the number of doors in the arena, and well, 53 is half that. but for some reason, no matter what i try, only the top 2 doors are affected, i even tried making half of the doors destroyed
12-09-2006, 02:44 PM#6
CoDRaZieL
Sorry for the mistake, i gave you the incorrect trigger, but i applied the same logic to my proper trigger and it works 100% now, with no lag , even when i run both dynamic arenas at the same time, thanks for your help
12-10-2006, 04:23 PM#7
CoDRaZieL
These are my two finished dynamic arena triggers, there are initialization functions where needed, i would love to get some feedback ,come on guys, tell me what you think

This First one is called The Enchanted Hallway and is comprised of a grid created by doors which randomly open and close
Collapse JASS:
function Trig_Wall_Shuffle_Timer takes nothing returns nothing
    local integer randomD = GetRandomInt(1,53)
    local integer randomA = GetRandomInt(1,53)
    local destructable Destwall = udg_LiveDestructables[randomA]
    local destructable Reviwall = udg_DeadDestructables[randomD]
    call KillDestructable(Destwall)
    call DestructableRestoreLife( Reviwall, GetDestructableMaxLife(Reviwall), false )
    set udg_DeadDestructables[randomD] = Destwall
    set udg_LiveDestructables[randomA] = Reviwall
    set Reviwall = null
    set Destwall = null
endfunction

function Trig_Wall_Shuffle_Init takes nothing returns nothing
    if udg_DynamicArenaIsOn then
    call TimerStart(GetExpiredTimer(),0.1,true,function Trig_Wall_Shuffle_Timer)
    endif
endfunction
//===========================================================================
function InitTrig_Wall_Shuffle takes nothing returns nothing
    call TimerStart(CreateTimer(),3,false,function Trig_Wall_Shuffle_Init)
endfunction

it has an initialization trigger that looks like this
Trigger:
Wall Shuffle Init
Collapse Events
Map initialization
Conditions
Collapse Actions
Collapse Player Group - Pick every player in (All players) and do (Actions)
Collapse Loop - Actions
Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Visibility across Wall Arena <gen>
Collapse Destructible - Pick every destructible in Wall Arena <gen> and do (Actions)
Collapse Loop - Actions
Destructible - Make (Picked destructible) Invulnerable
Custom script: call SetDestructableAnimationSpeed(GetEnumDestructable(),500)
Collapse For each (Integer A) from 1 to 53, do (Actions)
Collapse Loop - Actions
Set DeadDestructables[(Integer A)] = (Random destructible in Wall Arena <gen> matching ((((Matching destructible) is dead) Equal to True) and (((Matching destructible) is invulnerable) Equal to True)))
Destructible - Make DeadDestructables[(Integer A)] Vulnerable
Set LiveDestructables[(Integer A)] = (Random destructible in Wall Arena <gen> matching ((((Matching destructible) is alive) Equal to True) and (((Matching destructible) is invulnerable) Equal to True)))
Destructible - Make LiveDestructables[(Integer A)] Vulnerable



And then there is the Living Forest which basically is an ever-changing forest where one moment you may be hiding behind a tree ready to ambush your opponent and the next thing you know, POOF, no more cover:
Collapse JASS:
function Trig_Living_Forest_Create takes nothing returns nothing
local location L = GetRandomLocInRect(gg_rct_Tree_Arena)
call CreateDestructableZ('LTlt', GetLocationX(L), GetLocationY(L), 0, 0, 1, 0)
set L = null
endfunction

function Trig_Living_Forest_Destroy takes nothing returns nothing
call RemoveDestructable(RandomDestructableInRectBJ(gg_rct_Tree_Arena,null))
endfunction

function Trig_Living_Forest_Create_Init takes nothing returns nothing
if udg_DynamicArenaIsOn then
    call TimerStart(GetExpiredTimer(),0.1,true,function Trig_Living_Forest_Create)
endif
endfunction

function Trig_Living_Forest_Destroy_Init takes nothing returns nothing
if udg_DynamicArenaIsOn then
    call TimerStart(GetExpiredTimer(),0.1,true,function Trig_Living_Forest_Destroy)
endif
endfunction

//===========================================================================
function InitTrig_Living_Forest takes nothing returns nothing
    call TimerStart(CreateTimer(),3,false,function Trig_Living_Forest_Create_Init)
    call TimerStart(CreateTimer(),48,false,function Trig_Living_Forest_Destroy_Init)
endfunction

I know about the BJ, i will eventually rewrite it when i have the time to no longer use the BJ but use natives as i have now been taught to do

Thank you for all the help you guys have given me in creating these wonderful arenas, i have tested them and they are lag free and fun. I even tried leaving it on the whole night, and when i woke up there was still no lag, the tree count was a stable 446 and the doors were still just as good as when they started, then i quit and it took 2 seconds to get past the game summary screen back to the main menu