Warcraft III resources & community, 2003–2006 · archived

Repeating Special Effects With Patterns And Cleanup

not rated
Submitted by curiFunctions0 downloads
Ever wanted special effects that repeat themselves, clean themselves up, and can automatically form useful patterns including choosing a random spot to display within range of a location? Use this.

Here is an example map that shows how to use it: http://www.wc3sear.ch/?p=Maps&ID=2056

Source


// functions to create and cleanup special effects in patterns, with the option of having them repeated

// MINIMUM WAIT IS ABOUT .25 SECONDS
// But feel free to call the function many times at once to make up for that

// sfx is just one, sfxp is in a pattern, and sfxr uses a pattern and repeats.  dur is duration.

// function sfxp takes string pattern, real distance, real dur, location mytarget, string sfxpath returns nothing

// function sfx takes real dur, location mytarget, string sfxpath returns nothing

// function sfxr takes string pattern, real distance, integer times, real delay, real dur, location mytarget, string sfxpath returns nothing

// be sure to use \\ when typing in paths.

function sfx_child takes nothing returns nothing
    local effect e = bj_lastCreatedEffect
    call PolledWait( bj_lastTransmissionDuration )
    call DestroyEffect( e )
    set e = null
endfunction

function sfx takes real dur, location mytarget, string sfxpath returns nothing

	local trigger t = CreateTrigger()
	local real temp = bj_lastTransmissionDuration
	set bj_lastTransmissionDuration = dur

    set bj_lastCreatedEffect = AddSpecialEffectLoc(sfxpath, mytarget)
	call TriggerAddAction( t, function sfx_child )
	call TriggerExecute( t )
	call DestroyTrigger( t )
	set t = null
	set bj_lastTransmissionDuration = temp

endfunction

function sfxhelper takes real x, real y, real dur, string sfxpath returns nothing

	local trigger t = CreateTrigger()
	local real temp = bj_lastTransmissionDuration
	set bj_lastTransmissionDuration = dur

    set bj_lastCreatedEffect = AddSpecialEffect(sfxpath, x, y)
	call TriggerAddAction( t, function sfx_child )
	call TriggerExecute( t )
	call DestroyTrigger( t )
	set t = null
	set bj_lastTransmissionDuration = temp

endfunction


function sfxp takes string pattern, real distance, real dur, location mytarget, string sfxpath returns nothing

local trigger t = CreateTrigger()
local real ndistance = distance * -1
local real lx = GetLocationX(mytarget)
local real ly = GetLocationY(mytarget)
local integer p = GetRandomInt(1,5)
local real angle = GetRandomReal(0, 360)

if( pattern == "random" ) then
// pick a random pattern to do

	if( p == 1 ) then
		set pattern = "one"
	elseif( p == 2 ) then
		set pattern = "diamond"
	elseif( p == 3 ) then
		set pattern = "square"
	elseif( p == 4 ) then
		set pattern = "randomsquare"
	elseif( p == 5 ) then
		set pattern = "randomcircle"
	endif

endif

if( pattern == "one" ) then
// make sfx on mytarget
    call sfxhelper( lx, ly, dur, sfxpath )

    	
elseif( pattern =="diamond" ) then
// make sfx north, south, east, west of mytarget
	call sfxhelper( lx, ly +distance, dur, sfxpath )
	call sfxhelper( lx, ly+ndistance, dur, sfxpath )
	call sfxhelper( lx +distance, ly, dur, sfxpath )
	call sfxhelper( lx+ndistance, ly, dur, sfxpath )
	

elseif( pattern == "square" ) then
// make sfx ne, se, nw, sw of mytarget

	call sfxhelper( lx+distance, ly +distance, dur, sfxpath )
	call sfxhelper( lx+distance, ly+ndistance, dur, sfxpath )
	call sfxhelper( lx +ndistance, ly+ndistance, dur, sfxpath )
	call sfxhelper( lx+ndistance, ly+distance, dur, sfxpath )


elseif( pattern == "randomsquare" ) then
// make sfx randomly in square

	call sfxhelper( lx + GetRandomReal(ndistance, distance), ly + GetRandomReal(ndistance, distance), dur, sfxpath )
	
elseif( pattern == "randomcircle" ) then
// make sfx randomly in circle

	call sfxhelper( lx + distance * Cos(angle * bj_DEGTORAD), ly + distance * Sin(angle * bj_DEGTORAD), dur, sfxpath )

endif

set t = null
endfunction




function sfxr_child takes nothing returns nothing
	local string pattern = bj_changeLevelMapName
	local real distance = bj_randomSubGroupChance
	local integer times = bj_randomSubGroupTotal
	local real delay = bj_enumDestructableRadius
	local location mytarget = bj_enumDestructableCenter
	local string sfxpath = bj_lastPlayedMusic
	local real dur = bj_lastTransmissionDuration
	
	loop
		exitwhen (times <= 0)
		set times = times - 1
		call sfxp ( pattern, distance, dur, mytarget, sfxpath )
		call PolledWait( delay )
	
	endloop
	
	set pattern = null
	set sfxpath = null
	set mytarget = null
	
endfunction




function sfxr takes string pattern, real distance, integer times, real delay, real dur, location mytarget, string sfxpath returns nothing
local trigger t = CreateTrigger()
local string bj1 = bj_changeLevelMapName
local real bj2 = bj_randomSubGroupChance
local integer bj3 = bj_randomSubGroupTotal
local real bj4 = bj_enumDestructableRadius
local location bj5 = bj_enumDestructableCenter
local string bj6 = bj_lastPlayedMusic
local real bj7 = bj_lastTransmissionDuration

set bj_changeLevelMapName = pattern
set bj_randomSubGroupChance = distance
set bj_randomSubGroupTotal = times
set bj_enumDestructableRadius = delay
set bj_enumDestructableCenter = mytarget
set bj_lastPlayedMusic = sfxpath
set bj_lastTransmissionDuration = dur

call TriggerAddAction( t, function sfxr_child )
call TriggerExecute( t )
call DestroyTrigger( t )

set bj_changeLevelMapName = bj1
set bj_randomSubGroupChance = bj2
set bj_randomSubGroupTotal = bj3
set bj_enumDestructableRadius = bj4
set bj_enumDestructableCenter = bj5
set bj_lastPlayedMusic = bj6
set bj_lastTransmissionDuration = bj7
set bj1 = null
set bj5 = null
set bj6 = null

set t = null
endfunction

Comments

2
i have no idea how to use jass, though this sounds very usefull, please help me.
hmmm