SUPPORT ACCOUNT CLANS
Welcome, Unregistered.
 

Thread: Custom Game Settings

Results 1 to 7 of 7
  1. #1

    Question Custom Game Settings

    I guess a lot of us know the old method to let players
    vote for different game settings in custom maps in
    warcraft 3.

    For example how much kills are required to win the game
    or how long the game will go.

    I am trying to create such a method into my map.

    What I want:

    People are selecting their favorite option by sending their
    hero next to the according area (represented by a gadget).
    After all players did vote or the time to vote expire the game
    will evaluate and set up the settings. Game starts...

    What I did:
    I have created a gadget for game option A, this gadget has
    one passive ability, which is a aura that counts how much
    players decided to move next to this gadget (vote). So
    it stores the votes for itself.

    Used: 1 x gadget, 1 x ability, 1 x state

    The same for game option B and C.

    Now I made a main game setting gadget. It's task is to
    wait until the voting time expires or all players have voted.
    After that it compares the number of votes for each option
    and set the option with the most votes as the used. Now
    the heroes will be ported into the "gaming zone".

    So thats the idea behind. Thats the code for it.

    CODE

    Game Option A

    Gadget_Game_Setting_A
    PHP Code:
    <gadget
        name
    ="Game_Setting_A"
        
        
    icon="/items/powerups/damage/icon.tga"
        
    portrait="/items/powerups/damage/icon.tga"
        
    model="/items/powerups/damage/model.mdf"
        
    skin=""
        
        
    passiveeffect="/items/powerups/damage/effects/passive.effect"
        
    spawneffect="/items/powerups/damage/effects/spawn.effect"
        
    respawneffect=""
        
    selectsound=""
        
    orderconfirmedsound=""
        
        
    preglobalscale="1.7"
        
    modelscale="1"
        
    effectscale="0.9"
        
    boundsheight="32"
        
    boundsradius="16"
        
    selectionradius="64"
        
    targetoffset="0 0 64"

        
    maxhealth="75"

        
    immunity="DefuseKitImmunity"

        
    attacktype="none"
        
    combattype="Ranged"
        
    corpsetime="300"
        
    corpsefadetime="0"
        
    deathtime="0"
        
        
    prefertouch="true"
        
    unitwalking="true"
        
    drawonmap="false"

        
    invulnerable="true"

        
    inventory0="Ability_Game_Setting_A"
    >

    </
    gadget
    Ability_Game_Setting_A
    PHP Code:
    <ability
        name
    ="Ability_Game_Setting_A" 
        
    statuseffecttooltip=""
        
    icon=""

        
    maxlevel="1"
        
    baselevel="1"

        
    actiontype="passive"
        
    passiveeffect=""
        
        
    maxcharges="10"
        
    initialcharges="0"
    >

        <
    aura name="State_Game_Setting_A" radius="300" continuous="true" targetscheme="all_heroes" ignoreinvulnerable="true" />
        
    </
    ability
    State_Game_Setting_A
    PHP Code:
    <state
        name
    ="State_Game_Setting_A"
        
    duration="3000"
        
    stunned="true"
    >
        <
    oninflict>
            <
    addcharges entity="source_entity" count="1"/>
        </
    oninflict>
    </
    state


    Game Settings

    Gadget_Game_Settings
    PHP Code:
    <gadget
        name
    ="Gadget_Game_Settings"
        
    model=""
        
    canattack="false"
        
    canrotate="false"
        
    drawonmap="false"
        
    hoveronmap="false"
        
    icon=""
        
    immunity="DefuseKitImmunity"
        
    invisible="true"
        
    invulnerable="true"
        
    isselectable="false"
        
        
    inventory0="Ability_Game_Settings"
    >

    </
    gadget
    Ability_Game_Settings
    PHP Code:
    <ability
        name
    ="Ability_Game_Settings" 
        
    statuseffecttooltip=""
        
    icon=""

        
    maxlevel="1"
        
    baselevel="1"

        
    actiontype="passive"
        
    passiveeffect=""
        
        
    maxcharges="30"
        
    invulnerable="true"

    >
        <
    onlearn>
            <
    setaccumulator entity="this_entity" value="-1" />
            <
    activatemodifierkey entity="this_entity" name="start_vote" />
        </
    onlearn>
        
        <
    modifier key="start_vote" modpriority="100">
            <
    aura name="State_Ability_Game_Settings_Timer" radius="300" targetscheme="self" ignoreinvulnerable="true" />
            <
    aura name="State_Ability_Game_Settings_Counter" radius="3000" targetscheme="all_heroes" ignoreinvulnerable="true" />
            
            <
    onframe>
                <
    pushentitybyname name="Game_Setting_A" />
                <
    pushability source="stack_entity" name="Ability_Game_Setting_A" />
                <
    addcharges entity="stack_entity" count="0" />
                <
    setvar0 a="var0" b="result" op="add" />
                
                <
    pushentitybyname name="Game_Setting_B" />
                <
    pushability source="stack_entity" name="Ability_Game_Setting_B" />
                <
    addcharges entity="stack_entity" count="0" />
                <
    setvar1 a="var1" b="result" op="add" />
                
                <
    pushentitybyname name="Game_Setting_C" />
                <
    pushability source="stack_entity" name="Ability_Game_Setting_C" />
                <
    addcharges entity="stack_entity" count="0" />
                <
    setvar2 a="var2" b="result" op="add" />
                
                <
    setvar3 a="var3" b="0" op="mul" />
                <
    setvar3 a="var0" b="var1" op="add" />
                <
    setvar3 a="var3" b="var2" op="add" />
                
                <
    compare a="var3" b="accumulator" op="eq" >
                    <
    activatemodifierkey entity="this_entity" name="all_voted" />
                    <
    applystate name="State_Ability_Game_Settings_All_Voted" target="source_entity" continuous="true" />
                </
    compare>
                
                <
    compare a="charges" b="30" op="eq" >
                    <
    activatemodifierkey entity="this_entity" name="all_voted" />
                    <
    applystate name="State_Ability_Game_Settings_All_Voted" target="source_entity" continuous="true" />
                </
    compare>
                
            </
    onframe>
        </
    modifier>
            
        <
    modifier key="all_voted" modpriority="100">
            <
    onframe/>
        </
    modifier>
        
    </
    ability
    State_Ability_Game_Settings_Counter
    PHP Code:
    <state
        name
    ="State_Ability_Game_Settings_Counter"
        
    duration="1000"
    >
        <
    oninflict>
            <
    changeaccumulator entity="source_entity" b="1" op="add"/>
        </
    oninflict>
    </
    state
    State_Ability_Game_Settings_Timer
    PHP Code:
    <state
        name
    ="State_Ability_Game_Settings_Timer"
        
        
    impactinterval="1000"
        
    maxtotalimpacts="30"
        
    maximpactspertarget="30"
    >
        <
    onimpact>
            <
    addcharges entity="source_entity" count="1"/>
        </
    onimpact>
    </
    state
    State_Ability_Game_Settings_All_Voted
    PHP Code:
    <state
        name
    ="State_Ability_Game_Settings_All_Voted"
        

    >
        <
    oninflict>
            <
    setaccumulator entity="this_entity" value="0" />
            <
    testnearby radius="3000" targetscheme="all_heroes" ignoreinvulnerable="true" />
            <
    setvar3 a="result" b="var3" op="add" />
            
            <
    pushentitybyname name="Game_Setting_A" />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_A" />
            <
    addcharges entity="stack_entity" count="0" />
            <
    setvar0 a="var0" b="result" op="add" />
            
            <
    pushentitybyname name="Game_Setting_B" />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_B" />
            <
    addcharges entity="stack_entity" count="0" />
            <
    setvar1 a="var1" b="result" op="add" />
            
            <
    pushentitybyname name="Game_Setting_C" />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_C" />
            <
    addcharges entity="stack_entity" count="0" />
            <
    setvar2 a="var2" b="result" op="add" />
            
            <
    compare a="var0" b="var1" op="gt" >
                <
    changeaccumulator b="var0" op="add" />
            </
    compare>
            <else>
                <
    changeaccumulator b="var1" op="add" />
            </else>
            <
    compare a="var2" b="accumulator" op="gt" >
                <
    setaccumulator value="var0" />
            </
    compare>
            
            <
    pushentitybyname name="Hellbourne_Base" />
            <
    pushability source="stack_entity" name="Ability_Lives_Left" />
            <
    setcharges entity="stack_entity" a="accumulator" b="charges" op="add" />
            
            <
    pushentitybyname name="Legion_Base" />
            <
    pushability source="stack_entity" name="Ability_Lives_Left" />
            <
    setcharges entity="stack_entity" a="accumulator" b="charges" op="add" />
            
            <
    areaofeffect
                radius
    ="3000"
                
    effecttype=""
                
    targetscheme="all_heroes"
                
    targetselection="all"
                
    global="true"
                
    ignoreinvulnerable="true"
            
    >
                    <
    compare a="target_team" b="1" op="eq">
                        <
    setent0 name="Rune_1" /> 
                        <
    teleport target="ent0" source="target_entity" />
                    </
    compare
                    <else> 
                        <
    setent0 name="Rune_2" />
                        <
    teleport target="ent0" source="target_entity" />
                    </else> 
            </
    areaofeffect>
        </
    oninflict>
    </
    state



    Now, at the moment it does not work. Even the States of the Auras do
    apply to the heroes. I am confused so I decided to ask the forums if this
    is good way to implement such things, if it should/could be done in another
    even better way and to ask what am I doing wrong =)

    I hope it is not to much code and that I did not fail hard ;D

    [Custom Map]
    Valkyrie Wars [Dream]
    [Guide] How to create a neutral creep spot | [Map] Borderland [Dream]
    [MineCraft Server] CraftCraft 20Slot 24/7 [84.200.47.30]

  2. #2
    I think this is a good way to do it, but you might want to improve some of it.

    First off, your accumulator that count the number of player start at '-1', if this really set it to '-1' (never tried negative number), then when you have 1 player in the game, the aura will set the accumulator to '0'. Then when you test if all the player have voted you do: if number_of_votes == accumulator.
    So if you have 1 player that votes once, it will be: if 1 == 0.
    I guess it would make more sense to start your accumulator at 0.

    Counting the number of player could be done with a
    <foreachplayer>
    <changeaccumulator b="1" op="add" />
    </forachplayer>
    Right at the start of the vote.

    Rather doing an <onframe> event to test if every player voted, you can simply test the condition each time you apply a state on a player. So if a player vote, when you do the <addcharges /> to add a vote to the gadget, you will received the total number of vote on the gadget. So you could test right under that <addcharges /> if the number of charges returned is the same value as the accumulator that has the total number of player.
    This would probably make the script a lot easier since you already know that either this gadget has every vote, or that there are no gadget that has every vote (since you have at least one vote on this one).

    As for the vote timeout, if your gadget spawns at the same time the vote starts, you can simply put a lifetime="30000" on the gadget and then the <onexpired /> event will trigger when the vote runs out. So you could do a <delete /> on the gadget in the case every player voted, so the <onexpired /> doesn't trigger.

    Here are some tip too:

    If you want to set the value of a variable you can do it like this:
    <setvar0 a="result" />
    <setvar0 a="0" />
    <setvar0 a="var1" />
    So this will set the value of 'var0' to 'result'. This way it might be a bit less confusing when reading because you can have things like:
    <setvar0 a="var0" b="result" op="add" />
    This kind of line is tricky when reading, because you have to go look at all the script above to make sure that 'var0' has not value set to it. Otherwise you could also do:
    <setvar0 a="result" b="0" op="add" />

    I think that will all this you will be able to fix most issue and have something that is easier to "debug".


  3. #3
    Thanks Oloko, that will help me a lot to clean up my code and debug. I
    will try it when I come home tommorrow.

    Okay now I have done some changes.

    @Oloko:
    I had set the accumulator to -1 because I didn't know if there is a moment
    when the game world is loaded (so the <onframe> tag is triggered ) and there
    is no player, so the player number is 0. If this would happen the <onframe> tag
    would compare the player number with the number of player already voted, both
    0, so it would return true and initiate the next phase. I did know remove all the
    <onframe> part so the <compare> only happens when a hero does vote.

    I am using now the <foreachplayer> method to count player number but I am
    afraid, what happens if you have observer or referees, do they count as players
    or do they not count? If they count I could avoid them by doing a <compare>
    for each player which team they belong but which team does observer and referees have?

    I could use a lifetime on the gadget and use the <onexpired> tag if the lifetime
    is started at the moment the game starts (being in the world). If not I have
    to use the aura with the state to force the vote to start on game start and
    not while in lobby.

    I did forget how variables are initiate thats why I did it that way, I have changed it now. Thanks.

    After debugging it seems that some things do not work as I want them to.
    After the vote time runs out everyone get ported out as intended, but the
    settings (charges of main buildings live ability ) are not changed.
    Furthermore after I have voted ( I am alone so player number 1 and
    number of player voted 1 so) it should trigger the part that all players voted
    but it does not.

    The State compare the charges on its source_entity (the vote option, example A) and the accumulator of the source_entity. But the accumulator
    is set to 0, at least after saving the accumulator into var1 , var1 is 0.

    That leads me to the point that the accumulator is not set up as intended.
    So checking the State_Count_Max_Players, which should do it. Debugging it
    tells me that it does add a charge for each player on itself and after that it
    changes the accumulator of the possible voting options to the player number.
    So nothing wrong...

    Maybe I am using the accumulator the wrong way? I don't know :/

    There is the new code, added some comments for better understanding.
    Hope you can help me again.


    Game Option A (B and C equal to A)


    Ability_Game_Option_A
    PHP Code:
        name="Ability_Game_Setting_A" 
        
    statuseffecttooltip=""
        
    icon=""

        
    maxlevel="1"
        
    baselevel="1"

        
    actiontype="passive"
        
    passiveeffect=""
        
        
    maxcharges="10"
        
    initialcharges="0"
    >

        <
    aura state="State_Game_Setting_A" radius="300" targetscheme="all_heroes" ignoreinvulnerable="true" />
        
    </
    ability
    State_Game_Option_A
    PHP Code:
    <state
        name
    ="State_Game_Setting_A"
        
    stunned="true"
    >
        <
    oninflict>
            <
    addcharges entity="source_entity" count="1"/>    <!-- Adds 1 Charge to this Voting Option -->
            <
    setvar0 a="result" />
            
            <!-- 
    Getting all current votes -->
            <
    changeaccumulator entity="source_entity" b="1" op="mul" />            
            <
    setvar1 a="result" />
            <
    printdebuginfo />
            
            <
    pushentitybyname name="Game_Setting_B" />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_B" />
            <
    addcharges entity="stack_entiy" count="0" />
            <
    setvar0 a="result" b="var0" op="add" />
            
            <
    pushentitybyname name="Game_Setting_C" />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_C" />
            <
    addcharges entity="stack_entiy" count="0" />
            <
    setvar0 a="result" b="var0" op="add"/>
            
            <!-- 
    Comparing number of votes with player number -->
            <
    compare a="var0" b="var1" op="eq" >
                <
    pushentitybyname name="Game_Settings" />
                <
    setent0 entity="stack_entity" />
                <!-- 
    Starts next phase if all voted -->
                <
    applystate name="State_Ability_Game_Settings_All_Voted" target="ent0" />
                <
    printdebuginfo />
            </
    compare>    

        </
    oninflict>
    </
    state


    Game_Settings

    Ability_Game_Settings
    PHP Code:
    <ability
        name
    ="Ability_Game_Settings" 
        
    statuseffecttooltip=""
        
    icon=""

        
    maxlevel="1"
        
    baselevel="1"

        
    actiontype="passive"
        
    passiveeffect=""
        

    >
        <
    aura state="State_Count_Max_Players" radius="300" targetscheme="self" ignoreinvulnerable="true" /> <!-- Used to count max player number at game start -->
        <
    aura state="State_Ability_Game_Settings_Timer" radius="300" targetscheme="self" ignoreinvulnerable="true" /> <!-- Used to start a timer (30 sec to vote ) -->
        
    </
    ability
    State_Count_Max_Players
    PHP Code:
    <state
        name
    ="State_Count_Max_Players"
        
    initialcharges="0"
        
    maxcharges="10"
    >
        <
    oninflict>
            <!-- 
    Adds 1 Charge for each player to this state -->
            <
    foreachplayer>
                <
    addcharges entity="this_entity" count="1" />
            </
    foreachplayer>
            
            
            <!-- 
    Set the accumulator for each game option to the  player number -->
            <
    pushentitybyname name="Game_Setting_A" />
            <
    printdebuginfo />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_A" />
            <
    printdebuginfo />
            <
    setaccumulator entity="stack_entity" value="charges" />
            <
    printdebuginfo />
            
            <
    pushentitybyname name="Game_Setting_B" />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_B" />
            <
    setaccumulator entity="stack_entity" value="charges" />
            
            <
    pushentitybyname name="Game_Setting_C" />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_C" />
            <
    setaccumulator entity="stack_entity" value="charges" />
            
        </
    oninflict>
    </
    state
    State_Ability_Game_Settings_Timer
    PHP Code:
    <state
        name
    ="State_Ability_Game_Settings_Timer"
        
        
    impactinterval="1000"
        
    maxtotalimpacts="30"
        
    maximpactspertarget="30"
        
    initialcharges="0"
        
    maxcharges="30"
    >
        <
    onimpact>
            <
    addcharges />
            <
    compare a="charges" b="30" op="eq" >
                <
    applystate name="State_Ability_Game_Settings_All_Voted" target="source_entity" />
            </
    compare>
        </
    onimpact>
    </
    state
    State_Ability_Game_Settings_All_Voted
    PHP Code:
    <state
        name
    ="State_Ability_Game_Settings_All_Voted"
        

    >
        <
    oninflict>
            <!-- 
    This State does need to know how much Player exist -->
            <
    setaccumulator entity="this_entity" value="0" />
            <
    testnearby radius="1000" targetscheme="all_heroes" ignoreinvulnerable="true" />
            <
    setvar3 a="result" b="var3" op="add" />
            <!-- 
    Player number saved in var3 -->
        
            <!-- 
    This State does need to know how much player voted for the game options -->
            <!-- 
    Number of votes for A saved in var0 -->
            <
    pushentitybyname name="Game_Setting_A" />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_A" />
            <
    addcharges entity="stack_entity" count="0" />
            <
    setvar0 a="var0" b="result" op="add" />
            
            <!-- 
    Number of votes for B saved in var1 -->
            <
    pushentitybyname name="Game_Setting_B" />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_B" />
            <
    addcharges entity="stack_entity" count="0" />
            <
    setvar1 a="var1" b="result" op="add" />
            
            <!-- 
    Number of votes for C saved in var2 -->
            <
    pushentitybyname name="Game_Setting_C" />
            <
    pushability source="stack_entity" name="Ability_Game_Setting_C" />
            <
    addcharges entity="stack_entity" count="0" />
            <
    setvar2 a="var2" b="result" op="add" />
            <
    printdebuginfo />
            
            <!-- 
    Compares the votes with each other -->
            <!-- 
    Using the accumlator for calculation storage -->
            <!-- 
    Game SettingLives is stored in var3 -->
            <
    compare a="var0" b="var1" op="gt" >
                <
    changeaccumulator b="var0" op="add" />
                <
    setvar3 a="30" />
            </
    compare>
            <else>
                <
    changeaccumulator b="var1" op="add" />
                <
    setvar3 a="60" />
            </else>
            <
    compare a="var2" b="accumulator" op="gt" >
                <
    setaccumulator value="var0" />
                <
    setvar3 a="90" />
            </
    compare>
            
            <!-- 
    Applying settings to main buildings (lives) for each team -->
            <
    pushentitybyname name="Hellbourne_Base" />
            <
    pushability source="stack_entity" name="Ability_Lives_Left" />
            <
    setcharges entity="stack_entity" a="var3" />
            
            <
    pushentitybyname name="Legion_Base" />
            <
    pushability source="stack_entity" name="Ability_Lives_Left" />
            <
    setcharges entity="stack_entity" a="var3" />
            
            <!-- 
    All heroes are ported to their bases -->
            <
    areaofeffect
                radius
    ="3000"
                
    effecttype=""
                
    targetscheme="all_heroes"
                
    targetselection="all"
                
    global="true"
                
    ignoreinvulnerable="true"
            
    >
                    <
    compare a="target_team" b="1" op="eq">
                        <
    setent0 name="Rune_1" /> 
                        <
    teleport target="ent0" source="target_entity" />
                    </
    compare
                    <else> 
                        <
    setent0 name="Rune_2" />
                        <
    teleport target="ent0" source="target_entity" />
                    </else> 
            </
    areaofeffect>
            <
    pushentitybyname name="Game_Settings" />
            <
    kill target="stack_entity" />
        </
    oninflict>
    </
    state

    Last edited by Schm0ftie; 06-11-2011 at 10:29 PM.

    [Custom Map]
    Valkyrie Wars [Dream]
    [Guide] How to create a neutral creep spot | [Map] Borderland [Dream]
    [MineCraft Server] CraftCraft 20Slot 24/7 [84.200.47.30]

  4. #4
    Edited posting above.

    [Custom Map]
    Valkyrie Wars [Dream]
    [Guide] How to create a neutral creep spot | [Map] Borderland [Dream]
    [MineCraft Server] CraftCraft 20Slot 24/7 [84.200.47.30]

  5. #5
    can you pm the map?

    Some tips :
    for debugging i suggest you use <printvalue value="result" label="Votecount"/>
    and <printvalue value="accumulator" label="Accum"/>

    in State_Count_Max_Players you want to print several entities, i suggest you put them in ent0-3 , copy the charges/accum in var0-3 and then use printdebuginfo only once.

    Also i found 2x this typo in State_Game_Option_A :
    Code:
    <addcharges entity="stack_entiy" count="0" />
            <setvar0 a="result" b="var0" op="add" />
    
    Last edited by an7hraxjax; 06-12-2011 at 05:02 AM.

  6. #6
    Changed the typos, still don't know why accumulator seems not to work.
    Will using the printvalue method, looks way better then simple <print...>
    Download Me =)

    [Custom Map]
    Valkyrie Wars [Dream]
    [Guide] How to create a neutral creep spot | [Map] Borderland [Dream]
    [MineCraft Server] CraftCraft 20Slot 24/7 [84.200.47.30]

  7. #7
    feel free to join me at IRC : honscience

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •