random hero and repick help :(

  • Thread starter Thread starter pure.b
  • Start date Start date
P

pure.b

Guest
okay i already have a topic going and i dont know if its against the rules to post another so if this is in a bad spot plz dont remove them straight away.

anyway i have a few codes which i try to use to make a random system to work

set udg_randomhero[1] = 'H002'
set udg_randomhero[2] = 'H000'
set udg_randomhero[3] = 'O000'
set udg_randomhero[4] = 'N000'
set udg_randomhero[5] = 'Hpal'
set udg_randomhero[6] = 'Hamg'
set udg_randomhero[7] = 'Hmkg'
set udg_randomhero[8] = 'Hblm'

that defines my players then i have

function Trig_random_Conditions takes nothing returns boolean
if ( not ( udg_usedrandom[GetConvertedPlayerId(GetTriggerPlayer())] == 0 ) ) then
return false
endif
return true
endfunction

function Trig_random_Func011C takes nothing returns boolean
if ( not ( GetOwningPlayer(GetLastCreatedUnit()) == ForcePickRandomPlayer(GetPlayersAllies(Player(0))) ) ) then
return false
endif
return true
endfunction

function Trig_random_Func012C takes nothing returns boolean
if ( not ( GetOwningPlayer(GetLastCreatedUnit()) == ForcePickRandomPlayer(GetPlayersAllies(Player(5))) ) ) then
return false
endif
return true
endfunction

function Trig_random_Func013002 takes nothing returns nothing
call SetPlayerUnitAvailableBJ( GetUnitTypeId(GetLastCreatedUnit()), false, GetEnumPlayer() )
endfunction

function Trig_random_Actions takes nothing returns nothing
call CreateNUnitsAtLoc( 1, udg_randomhero[GetRandomInt(1, 9)], GetTriggerPlayer(), GetRectCenter(gg_rct_South_hero_start), 90.00 )
if ( Trig_random_Func011C() ) then
call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(gg_rct_South_hero_start) )
else
call DoNothing( )
endif
if ( Trig_random_Func012C() ) then
call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(gg_rct_North_hero_start) )
else
call DoNothing( )
endif
call ForForce( GetPlayersAll(), function Trig_random_Func013002 )
call SetPlayerStateBJ( GetOwningPlayer(GetSoldUnit()), PLAYER_STATE_RESOURCE_FOOD_CAP, 0 )
call PanCameraToTimedLocForPlayer( GetEnumPlayer(), GetUnitLoc(GetLastCreatedUnit()), 0.00 )
set udg_usedrandom[GetConvertedPlayerId(GetTriggerPlayer())] = 1
set udg_haveunit[GetConvertedPlayerId(GetTriggerPlayer())] = 1
endfunction

//===========================================================================
function InitTrig_random takes nothing returns nothing
set gg_trg_random = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_random, Player(0), "-random", true )
call TriggerRegisterPlayerChatEvent( gg_trg_random, Player(1), "-random", true )
call TriggerRegisterPlayerChatEvent( gg_trg_random, Player(2), "-random", true )
call TriggerRegisterPlayerChatEvent( gg_trg_random, Player(3), "-random", true )
call TriggerRegisterPlayerChatEvent( gg_trg_random, Player(5), "-random", true )
call TriggerRegisterPlayerChatEvent( gg_trg_random, Player(6), "-random", true )
call TriggerRegisterPlayerChatEvent( gg_trg_random, Player(7), "-random", true )
call TriggerRegisterPlayerChatEvent( gg_trg_random, Player(8), "-random", true )
call TriggerAddCondition( gg_trg_random, Condition( function Trig_random_Conditions ) )
call TriggerAddAction( gg_trg_random, function Trig_random_Actions )
endfunction





thats my random system (if code isnt good tell me and ill post images)

anyway thing code works okay but problems that i encounter are that it dosent look to see if the unit is already used, i want it to buy a unit from the tavern instead of just creating it. So what i need it to do is like use a random number between 1 & 10 to make the unit, but then to like cancel out say number 6 cause it was already used... how do i do all this? should i post my triggers if it makes more sense???
 
This is always a tough one.

Lets start with a boolean array, and I'll call it Hero_Taken[].

Whenever a hero is picked, set Hero_Taken[whatever #] to true.

Now for the repick, remove the hero and set Hero_Taken[whatever #] to false.

For random, you need to check the array. This is tough because it doesn't always pick a non-taken number, and can cause infinite loops.

(I'm not at my pc, so the exact code may very a little, k?)
Code:
function Trig_random_Actions takes nothing returns nothing
[b]local integer OURNUM

loop
  set OURNUM = GetRandomInt(1,9)
  exitwhen  ( Hero_Taken[OURNUM] ==  false)
endloop
[/b]
[b]set Hero_Taken[OURNUM] = true[/b]
call CreateNUnitsAtLoc( 1, udg_randomhero[[b]OURNUM[/b]], GetTriggerPlayer(), GetRectCenter(gg_rct_South_hero_start), 90.00 )
if ( Trig_random_Func011C() ) then
call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(gg_rct_South_hero_start) )
else
call DoNothing( )
endif
if ( Trig_random_Func012C() ) then
call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(gg_rct_North_hero_start) )
else
call DoNothing( )
endif
call ForForce( GetPlayersAll(), function Trig_random_Func013002 )
call SetPlayerStateBJ( GetOwningPlayer(GetSoldUnit()), PLAYER_STATE_RESOURCE_FOOD_CAP, 0 )
call PanCameraToTimedLocForPlayer( GetEnumPlayer(), GetUnitLoc(GetLastCreatedUnit()), 0.00 )
set udg_usedrandom[GetConvertedPlayerId(GetTriggerPlayer())] = 1
set udg_haveunit[GetConvertedPlayerId(GetTriggerPlayer())] = 1
endfunction
 
sorry im not really the best with that code i just posted it like that cause it was easier.

if it makes it easier for you here is my acctual triggers, i used the website help for some of that code so it helped me out.

if you please could just have a look or tamper with it i'd be VERy gratefull, if i am being to asking please just tell me.
 

Attachments

hmmm u might not get that fixed for a while cuz not many people know JASS :banghead: luckily ryoko does :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Real users can't really disable Javascript anymore these days.
  • Ghan Ghan:
    The internet is broken without it.
  • Ghan Ghan:
    Bot readable, not human usable.
  • The Helper The Helper:
    got it
  • The Helper The Helper:
    Happy Thursday!
  • The Helper The Helper:
    Check out the new Featured Content feature we apparently got with the forum software upgrade! https://www.thehelper.net/featured/
  • The Helper The Helper:
    Also on the bottom right side bar we now have a Trending Content Box!
    +1
  • The Helper The Helper:
    Not on the Headline News page just on the Forums page can we get that Featured and Trending on the home page?
  • Ghan Ghan:
    Since the home page is technically a forum, it now shows on all forum views. Still in the sidebar.
    +1
  • The Helper The Helper:
    Happy Friday! Hope everyone has a fantastic day and an even better weekend!
  • The Helper The Helper:
    Happy Sunday!
  • The Helper The Helper:
    I lovc that I can post webp and X links now! :)
  • The Helper The Helper:
    Happy Thursday!
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    we were down for a minute - think a log file or something got too big
    +1
  • Ghan Ghan:
    The alerts say it was down for a while unfortunately.
  • Ghan Ghan:
    Didn't know what was going on while I was at work.
  • Ghan Ghan:
    Disk filled up with logs. Fixed now.
    +1
  • The Helper The Helper:
    not a problem at all thanks for getting us back up
  • The Helper The Helper:
    I think the bots are finding a way to get through the anubis
  • The Helper The Helper:
    Happy Wednesday Everyone! Hope everyone has a Fantastic Day!
    +1
  • The Helper The Helper:
    Yeah, stats are showing big bot influx like 12k page views.
  • Wizard Wizard:
    :wave:
    +1
  • Ghan Ghan:
    TH changed his avatar again. 6 more weeks of summer.
    +3
  • Wizard Wizard:
    lol
    +1

The Helper Discord

Members online

No members online now.

Affiliates

Hive Workshop NUON Dome World Editor Tutorials
Back
Top