| 06-20-2006, 02:53 AM | #1 |
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 |
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:41 AM | #5 |
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) 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 |
Why not loop? (ok, technically since things may be weird (gaps or renumbering) this may be inappropriate) 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 |
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: 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: 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: 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: 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: 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: 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 |
| 06-20-2006, 04:21 PM | #8 |
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 | |
Quote:
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 | |
Quote:
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. |
