| 02-27-2004, 10:50 PM | #1 |
this would be easy without limits, but there are limits for what im doing. I want 20 random units to be spawned in a region, they have to be a unit from a group of three units. so far the way i have it is a spawns a random number from 1-20 nftr than sets that number to a variable, then I do 20 - how many nftr are in the region (so like if i had 15 in the region, that means theres room for 5 for random units) then i do a random number from 1 - N for nftb and repeat everything. the prob is like, when i test it enters WC3, and when i manually test from WC3, theres like no box to pick which player you want to be, its really weird. but heres the chunk of MY script :D Code:
function Trolls_spawn_Actions takes nothing returns nothing
// local variable
local integer n
// conditions for units in region matching
function Trolls_spawn_conditions0001 takes nothing returns boolean
return ( IsUnitType( GetFilterUnit(), 'nftr') == true )
endfunction
function Trolls_spawn_conditions0001 takes nothing returns boolean
return ( IsUnitType( GetFilterUnit(), 'nftb') == true )
endfunction
// main chunk for Troll Spawn 3
call CreateNUnitsAtLoc ( GetRandomInt(0, 20), 'nftr', PLAYER_NEUTRAL_AGGRESSIVE, GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_3), bj_UNIT_FACING)
set n = (20 - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_3, Condition(function Trolls_spawn_conditions0001 ))))
call CreateNunitsAtLoc ( GetRandomInt(0, n), 'nftb', PLAYER_NEUTRAL_AGGRESSIVE, GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_3), bj_UNIT_FACING)
set n = (n - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_3, Condition(function Trolls_spawn_conditions0002 ))))
call CreateNunitsAtLoc ( GetRandomInt(0, n), 'nftt', PLAYER_NEUTRAL_AGGRESSIVE, GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_3), bj_UNIT_FACING)
// main chunk for Troll Spawn 2
call CreateNUnitsAtLoc ( GetRandomInt(0, 15), 'nftr', PLAYER_NEUTRAL_AGGRESSIVE, GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_2), bj_UNIT_FACING)
set n = (15 - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_3, Condition(function Trolls_spawn_conditions0001 ))))
call CreateNunitsAtLoc ( GetRandomInt(0, n), 'nftb', PLAYER_NEUTRAL_AGGRESSIVE, GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_2), bj_UNIT_FACING)
set n = (n - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_3, Condition(function Trolls_spawn_conditions0002 ))))
call CreateNunitsAtLoc ( GetRandomInt(0, n), 'nftt', PLAYER_NEUTRAL_AGGRESSIVE, GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_2), bj_UNIT_FACING)
// main chunk for Troll Spawn 1
call CreateNUnitsAtLoc ( GetRandomInt(0, 15), 'nftr', PLAYER_NEUTRAL_AGGRESSIVE, GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_1), bj_UNIT_FACING)
set n = (15 - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_3, Condition(function Trolls_spawn_conditions0001 ))))
call CreateNunitsAtLoc ( GetRandomInt(0, n), 'nftb', PLAYER_NEUTRAL_AGGRESSIVE, GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_1), bj_UNIT_FACING)
set n = (n - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_3, Condition(function Trolls_spawn_conditions0002 ))))
call CreateNunitsAtLoc ( GetRandomInt(0, n), 'nftt', PLAYER_NEUTRAL_AGGRESSIVE, GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_1), bj_UNIT_FACING)
endfunctionEDITED by Cubasis: Changed the tag to use [code] instead |
| 02-28-2004, 11:59 AM | #2 |
You can't declare functions within other functions. |
| 02-28-2004, 03:19 PM | #3 |
OOOOOH DUH!!!! I KNEW THAT! ok, well im kind of new to the whole UNIT MATCHING thing, but I did know that :bangH: :bangH: :bangH: |
| 02-28-2004, 04:50 PM | #4 |
ok, well as i suspected something else would pop up. I noticed i forgot the conditions!!! well as it turns out my condition is like and or(or, or) so its like so messed up so im gonna have to work on that :( |
| 02-28-2004, 04:51 PM | #5 |
crap, sorry for triple post but man, i do not want to edit this. ill give like 50 points or something to edit this and make it work |
| 02-28-2004, 06:56 PM | #6 |
Eh, it is kinda a mess. You are still nesting functions, and there is a condition-function empty and stuff. I reccomend recreating the whole trigger in GUI, using some temporary Global instead of your local... Then converting it to Jass, and replacing all references of the global, with your local variable. Cubasis |
| 02-28-2004, 07:33 PM | #7 |
Code:
// conditions for units in region matching
function Trig_Trolls_spawn_conditions0003 takes nothing returns boolean
return GetUnitTypeId( GetFilterUnit()) == 'nftr'
endfunction
function Trig_Trolls_spawn_conditions takes nothing returns boolean
local player pl = GetOwningPlayer(GetEnteringUnit())
return pl == Player(1) or pl == Player(0) or pl == Player(8) or pl == Player(7)
endfunction
function Trig_Trolls_spawn_conditions0004 takes nothing returns boolean
local integer id = GetUnitTypeId( GetFilterUnit())
return id == 'nftr' or id == 'nftb'
endfunction
function Trig_Trolls_spawn_Actions takes nothing returns nothing
// local variable
local integer n
// main chunk for Troll Spawn 2
call CreateNUnitsAtLoc( GetRandomInt(0, 15), 'hftr', Player(PLAYER_NEUTRAL_AGGRESSIVE), GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_2), bj_UNIT_FACING )
set n = 15 - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_2, Condition(function Trig_Trolls_spawn_conditions0003 )))
call CreateNUnitsAtLoc ( GetRandomInt(0, n), 'nftb', Player(PLAYER_NEUTRAL_AGGRESSIVE), GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_2), bj_UNIT_FACING)
set n = (n - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_2, Condition(function Trig_Trolls_spawn_conditions0004 ))))
call CreateNUnitsAtLoc ( GetRandomInt(0, n), 'nftt', Player(PLAYER_NEUTRAL_AGGRESSIVE), GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_2), bj_UNIT_FACING)
// main chunk for Troll Spawn 3
call CreateNUnitsAtLoc ( GetRandomInt(0, 20), 'nftr', Player(PLAYER_NEUTRAL_AGGRESSIVE), GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_3), bj_UNIT_FACING)
set n = (20 - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_3, Condition(function Trig_Trolls_spawn_conditions0003 ))))
call CreateNUnitsAtLoc ( GetRandomInt(0, n), 'nftb', Player(PLAYER_NEUTRAL_AGGRESSIVE), GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_3), bj_UNIT_FACING)
set n = (n - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_3, Condition(function Trig_Trolls_spawn_conditions0004 ))))
call CreateNUnitsAtLoc ( GetRandomInt(0, n), 'nftt', Player(PLAYER_NEUTRAL_AGGRESSIVE), GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_3), bj_UNIT_FACING)
// main chunk for Troll Spawn 1
call CreateNUnitsAtLoc ( GetRandomInt(0, 15), 'nftr', Player(PLAYER_NEUTRAL_AGGRESSIVE), GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_1), bj_UNIT_FACING)
set n = (15 - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_1, Condition(function Trig_Trolls_spawn_conditions0003 ))))
call CreateNUnitsAtLoc ( GetRandomInt(0, n), 'nftb', Player(PLAYER_NEUTRAL_AGGRESSIVE), GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_1), bj_UNIT_FACING)
set n = (n - CountUnitsInGroup (GetUnitsInRectMatching(gg_rct_Troll_Quest_Spawn_1, Condition(function Trig_Trolls_spawn_conditions0004 ))))
call CreateNUnitsAtLoc ( GetRandomInt(0, n), 'nftt', Player(PLAYER_NEUTRAL_AGGRESSIVE), GetRandomLocInRect(gg_rct_Troll_Quest_Spawn_1), bj_UNIT_FACING)
endfunction
//===========================================================================
function InitTrig_Trolls_spawn takes nothing returns nothing
set gg_trg_Trolls_spawn = CreateTrigger( )
call TriggerRegisterEnterRectSimple ( gg_trg_Trolls_spawn, gg_rct_Trolls_Quest_Kill_50 )
call TriggerAddCondition(gg_trg_Trolls_spawn, Condition(function Trig_Trolls_spawn_conditions) )
call TriggerAddAction( gg_trg_Trolls_spawn, function Trig_Trolls_spawn_Actions )
endfunctionThey will kill you, but feel free to test it. Next time, start with one spawn first, and test the code every other secund so you don't write a lot of code that doesn't even compile... ;) |
| 02-28-2004, 07:45 PM | #8 |
still doesnt work... did you test it? and if not, could you? it looks better than mine though. cause i was basing my Or(or, or) off of what the GUI triggers convert to and what i hate about GUI triggers, is theyre always like If (not ( ) ) WTF IS WITH THE NOT I HATE IT! sorry off topic there :D |
| 02-29-2004, 05:14 AM | #9 |
Well, I am not sure exactly how it is supposed to work... But you can check what happens on my test map. |
| 02-29-2004, 04:07 PM | #10 |
well, havent checked yet on ur map, but on mine it didnt even load, wait i have 1 more thing to check, brb. edit:hmm, ya urs works fine except u forgot the most important thing :ggani: call Disable trigger lol so a lot of guys spawned every time i entered the region. so im gonna fix that on my version thing and i prolly copied wrong or something, then see how it works edit2: Ill send u ur points now cause i know it works :D edit3: now i feel silly i didnt even copy it or something went wrong ://// |
