I guess a lot of us know the old method to let players
vote for different game settings in custom maps in
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.
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
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
<changeaccumulator b="1" op="add" />
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".
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.
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.
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 06:02 AM.
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 =)
feel free to join me at IRC : honscience