HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

repeasting the same trigger 2-8 times but w/ different players

06-20-2006, 02:53 AM#1
darkwulfv
EDIT: sry for title typo... :p

Is it bad to do this:
A trigger that sets a random race for a player who types -random
But, I have to repeat the trigger 7 other times for each player, becuase there is no way to set it so that any player who types -random kicks the trigger into action. so what i have is like this:

RandomP1(these are the triggers themselves, not the contents)
RandomP2
etc. to
RandomP8

Is there a way, maybe in Jass, to make it so i need to only use one trigger that uses something like

A player types a chat message containing -random as exact match
call whatever, set whatever, null whatever, blah blah (<-- actions)

rather than
Player 1(red) types....
then another trigger
Player 2(blue) types....

Any help available?
06-20-2006, 03:04 AM#2
harshateja
If anything, it will be even less effective (even in Jass) because if I remember correctly, 1 trigger with 8 events carries less implications than 8 triggers with 1 event. WHy don't you just make 1 triggr with 8 events and use GetTriggerPlayer() incase you want player specific attributes.
06-20-2006, 03:14 AM#3
darkwulfv
here let me post my trigger see if that helps any. I'm a bit confused at the moment.
Trigger:
RandomP1
Collapse Events
Player - Player 1 (Red) types a chat message containing -random as An exact match
Conditions
Collapse Actions
Set random = (Random integer number between 1 and 4)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
random Equal to 1
Collapse Then - Actions
Unit - Create 1 Peasant for (Triggering player) at ((Triggering player) start location) facing Default building facing (270.0) degrees
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
random Equal to 2
Collapse Then - Actions
Unit - Create 1 Footman for (Triggering player) at ((Triggering player) start location) facing Default building facing (270.0) degrees
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
random Equal to 3
Collapse Then - Actions
Unit - Create 1 Knight for (Triggering player) at ((Triggering player) start location) facing Default building facing (270.0) degrees
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
random Equal to 4
Collapse Then - Actions
Unit - Create 1 Rifleman for (Triggering player) at ((Triggering player) start location) facing Default building facing (270.0) degrees
Else - Actions
Custom script: set random = null

This is the same for the other 7 triggers, except in the event it's player 2 or 3 or 4 etc.
06-20-2006, 03:24 AM#4
harshateja
Trigger:
Collapse Events
Player - Player 1 (Red) types a chat message containing -random as An exact match
Player - Player 2 (Blue) types a chat message containing -random as An exact match
Player - Player 3 (I dunno) types a chat message containing -random as An exact match
Player - Player 4 (I dunno) types a chat message containing -random as An exact match
Player - Player 5 (I dunno) types a chat message containing -random as An exact match
Player - Player 6 (I dunno) types a chat message containing -random as An exact match
Player - Player 7 (I dunno) types a chat message containing -random as An exact match
Player - Player 8 (I dunno) types a chat message containing -random as An exact match
Conditions
Collapse Actions
Set random = (Random integer number between 1 and 4)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
random Equal to 1
Collapse Then - Actions
Unit - Create 1 Peasant for (Triggering player) at ((Triggering player) start location) facing Default building facing (270.0) degrees
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
random Equal to 2
Collapse Then - Actions
Unit - Create 1 Footman for (Triggering player) at ((Triggering player) start location) facing Default building facing (270.0) degrees
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
random Equal to 3
Collapse Then - Actions
Unit - Create 1 Knight for (Triggering player) at ((Triggering player) start location) facing Default building facing (270.0) degrees
Collapse Else - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
random Equal to 4
Collapse Then - Actions
Unit - Create 1 Rifleman for (Triggering player) at ((Triggering player) start location) facing Default building facing (270.0) degrees
Else - Actions
Custom script: set random = null
06-20-2006, 03:41 AM#5
darkwulfv
o... doi *wacks self in head* I always thought that doing that would mean that all of those have to happen. Thx dude! +rep (if I can) <-- nope sry : (

Thx Harsha, here it is in JASS (so I can copy it to the master map)
Collapse JASS:
set udg_random = GetRandomInt(1, 4)
function Trig_RandomP1_Func001Func001Func001Func001C takes nothing returns boolean
    if ( not ( udg_random == 4 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RandomP1_Func001Func001Func001C takes nothing returns boolean
    if ( not ( udg_random == 3 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RandomP1_Func001Func001C takes nothing returns boolean
    if ( not ( udg_random == 2 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RandomP1_Func001C takes nothing returns boolean
    if ( not ( udg_random == 1 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RandomP1_Actions takes nothing returns nothing
    if ( Trig_RandomP1_Func001C() ) then
        call CreateNUnitsAtLoc( 1, 'hpea', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
    else
        if ( Trig_RandomP1_Func001Func001C() ) then
            call CreateNUnitsAtLoc( 1, 'hfoo', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
        else
            if ( Trig_RandomP1_Func001Func001Func001C() ) then
                call CreateNUnitsAtLoc( 1, 'hkni', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
            else
                if ( Trig_RandomP1_Func001Func001Func001Func001C() ) then
                    call CreateNUnitsAtLoc( 1, 'hrif', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
                else
                endif
            endif
        endif
    endif
set udg_random = null
endfunction

//===========================================================================
function InitTrig_RandomP1 takes nothing returns nothing
    set gg_trg_RandomP1 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(0), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(1), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(2), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(3), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(4), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(5), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(6), "-random", true )
    call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(7), "-random", true )
    call TriggerAddAction( gg_trg_RandomP1, function Trig_RandomP1_Actions )
endfunction

Does this look right? (mainly the top line and bottom line before the endfunction)
06-20-2006, 04:04 AM#6
PipeDream
Why not loop? (ok, technically since things may be weird (gaps or renumbering) this may be inappropriate)
Collapse JASS:
function InitTrig_RandomP1 takes nothing returns nothing
    local integer i = 0
    set gg_trg_RandomP1 = CreateTrigger(  )
    loop
        exitwhen i >= 8 //Better to make this nplay or similar
        call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(i), "-random", true )
        set i = i + 1
    endloop
    call TriggerAddAction( gg_trg_RandomP1, function Trig_RandomP1_Actions )
endfunction
06-20-2006, 03:54 PM#7
The)TideHunter(
Theres no need to set a integer to 0 or null at the end of a function darkwulfv.
Booleans, strings, reals, integers and code dont leak.

You have the set udg_random = GetRandomInt(1, 4) outside the function, that will cause a error.

Also, change:

Collapse JASS:
function Trig_RandomP1_Func001Func001Func001Func001C takes nothing returns boolean
    if ( not ( udg_random == 4 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RandomP1_Func001Func001Func001C takes nothing returns boolean
    if ( not ( udg_random == 3 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RandomP1_Func001Func001C takes nothing returns boolean
    if ( not ( udg_random == 2 ) ) then
        return false
    endif
    return true
endfunction

function Trig_RandomP1_Func001C takes nothing returns boolean
    if ( not ( udg_random == 1 ) ) then
        return false
    endif
    return true
endfunction

To:

Collapse JASS:
function Trig_RandomP1_Func001Func001Func001Func001C takes nothing returns boolean
    return (udg_random == 1)
endfunction

function Trig_RandomP1_Func001Func001Func001C takes nothing returns boolean
    return (udg_random == 2)
endfunction

function Trig_RandomP1_Func001Func001C takes nothing returns boolean
    return (udg_random == 3)
endfunction

function Trig_RandomP1_Func001C takes nothing returns boolean
    return (udg_random == 4)
endfunction

and:

Collapse JASS:
function Trig_RandomP1_Actions takes nothing returns nothing
    if ( Trig_RandomP1_Func001C() ) then
        call CreateNUnitsAtLoc( 1, 'hpea', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
    else
        if ( Trig_RandomP1_Func001Func001C() ) then
            call CreateNUnitsAtLoc( 1, 'hfoo', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
        else
            if ( Trig_RandomP1_Func001Func001Func001C() ) then
                call CreateNUnitsAtLoc( 1, 'hkni', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
            else
                if ( Trig_RandomP1_Func001Func001Func001Func001C() ) then
                    call CreateNUnitsAtLoc( 1, 'hrif', GetTriggerPlayer(), GetPlayerStartLocationLoc(GetTriggerPlayer()), bj_UNIT_FACING )
                else
                endif
            endif
        endif
    endif
set udg_random = null
endfunction

To:

Collapse JASS:
function Trig_RandomP1_Actions takes nothing returns nothing
    local location StartPoint = GetPlayerStartLocationLoc(GetTriggerPlayer())
    set udg_random = GetRandomInt(1, 4)
    if (Trig_RandomP1_Func001C()) then
        call CreateNUnitsAtLoc(1, 'hpea', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    elseif(Trig_RandomP1_Func001Func001C()) then
        call CreateNUnitsAtLoc(1, 'hfoo', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    elseif(Trig_RandomP1_Func001Func001Func001C()) then
        call CreateNUnitsAtLoc(1, 'hkni', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    elseif(Trig_RandomP1_Func001Func001Func001Func001C()) then
        call CreateNUnitsAtLoc(1, 'hrif', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    endif
    call RemoveLocation(StartPoint)
    set StartPoint = null
endfunction

Final trigger:

Collapse Random Trigger:
function Trig_RandomP1_Func001Func001Func001Func001C takes nothing returns boolean
    return (udg_random == 1)
endfunction

function Trig_RandomP1_Func001Func001Func001C takes nothing returns boolean
    return (udg_random == 2)
endfunction

function Trig_RandomP1_Func001Func001C takes nothing returns boolean
    return (udg_random == 3)
endfunction

function Trig_RandomP1_Func001C takes nothing returns boolean
    return (udg_random == 4)
endfunction

function Trig_RandomP1_Actions takes nothing returns nothing
    local location StartPoint = GetPlayerStartLocationLoc(GetTriggerPlayer())
    set udg_random = GetRandomInt(1, 4)
    if (Trig_RandomP1_Func001C()) then
        call CreateNUnitsAtLoc(1, 'hpea', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    elseif(Trig_RandomP1_Func001Func001C()) then
        call CreateNUnitsAtLoc(1, 'hfoo', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    elseif(Trig_RandomP1_Func001Func001Func001C()) then
        call CreateNUnitsAtLoc(1, 'hkni', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    elseif(Trig_RandomP1_Func001Func001Func001Func001C()) then
        call CreateNUnitsAtLoc(1, 'hrif', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    endif
    call RemoveLocation(StartPoint)
    set StartPoint = null
endfunction

//====================
function InitTrig_RandomP1 takes nothing returns nothing
    local integer i = 0
    set gg_trg_RandomP1 = CreateTrigger(  )
    loop
        exitwhen i >= 8 //Better to make this nplay or similar
        call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(i), "-random", true )
        set i = i + 1
    endloop
    call TriggerAddAction( gg_trg_RandomP1, function Trig_RandomP1_Actions )
endfunction

EDIT: Or even better, you dont have to have the condition functions, you could use If's directly like:

Collapse Improved Random Trigger:
function Trig_RandomP1_Actions takes nothing returns nothing
    local location StartPoint = GetPlayerStartLocationLoc(GetTriggerPlayer())
    set udg_random = GetRandomInt(1, 4)
    if(udg_random == 1) then
        call CreateNUnitsAtLoc(1, 'hpea', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    elseif(udg_random == 2) then
        call CreateNUnitsAtLoc(1, 'hfoo', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    elseif(udg_random == 3) then
        call CreateNUnitsAtLoc(1, 'hkni', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    elseif(udg_random == 4) then
        call CreateNUnitsAtLoc(1, 'hrif', GetTriggerPlayer(), StartPoint), bj_UNIT_FACING)
    endif
    call RemoveLocation(StartPoint)
    set StartPoint = null
endfunction

//====================
function InitTrig_RandomP1 takes nothing returns nothing
    local integer i = 0
    set gg_trg_RandomP1 = CreateTrigger(  )
    loop
        exitwhen i >= 8 //Better to make this nplay or similar
        call TriggerRegisterPlayerChatEvent( gg_trg_RandomP1, Player(i), "-random", true )
        set i = i + 1
    endloop
    call TriggerAddAction( gg_trg_RandomP1, function Trig_RandomP1_Actions )
endfunction
Edited because: Improved Trigger.
06-20-2006, 04:21 PM#8
blu_da_noob
You have a rogue bracket there after StartPoint in the create unit function call. That should also be change to native CreateUnit.
06-20-2006, 04:21 PM#9
Captain Griffen
Quote:
Booleans, strings, reals, integers and code dont leak.

Strings leak (each string leaks only once though, but it cannot be dealt with except by not using the string in the first place), but string variables do not have to be nullified.
06-20-2006, 04:23 PM#10
The)TideHunter(
Quote:
Originally Posted by Captain Griffen
Strings leak (each string leaks only once though, but it cannot be dealt with except by not using the string in the first place), but string variables do not have to be nullified.

I know they 'leak' once, but i wouldent call it a leak.
Im sure this debate has been said quite a few times, everybody has their own opinion.