callvote kick

substance

New Member
Reaction score
34
I'm finishing up a simple callvote system to kick people (and hopefully do other things later). Just wanted to make sure things were optimized before i moved on:

JASS:
globals
boolean Voting = false
timer VotingTimer
integer VotingValue
timerdialog VotingTimerDialog
trigger VoteTrigger
integer VoteYes = 0
integer VoteNo = 0
boolean array Voted
endglobals

function EndKickVoting takes nothing returns nothing
 local sound endkicksound = CreateSound("Sound\\Interface\\QuestFailed.wav", false, false, false, 10, 10, "")
 local integer i = 0

 if VoteYes > VoteNo  then
    call DisplayTextToForce( GetPlayersAll(), "Vote passed!")
    call RemovePlayer(Player(VotingValue),PLAYER_GAME_RESULT_DEFEAT)
 else
    call DisplayTextToForce( GetPlayersAll(), "Vote failed!")
    call SetSoundVolume(endkicksound, PercentToInt(75, 127))
    call StartSound(endkicksound)
 endif

 call StartSound(endkicksound)

 loop
    exitwhen i == 12
    set Voted<i> = false
    set i = i+1
 endloop 
  
 set VoteYes = 0
 set Voting = false
 set VoteNo = 0
 set VotingValue = 0
 call PauseTimer(VotingTimer)
 call DestroyTimer(VotingTimer)
 call TimerDialogDisplay(VotingTimerDialog, false)
 call DestroyTimerDialog(VotingTimerDialog)
 call DisableTrigger(VoteTrigger)
 call DestroyTrigger(VoteTrigger)
endfunction

function VoteTriggerFunction takes nothing returns nothing
local string value = SubString(GetEventPlayerChatString(),6,StringLength(GetEventPlayerChatString()))
local integer pid = GetPlayerId(GetTriggerPlayer())

   if Voted[pid] != true then
      if value == &quot;yes&quot; then
         set VoteYes = VoteYes + 1
      elseif value ==  &quot;no&quot; then
         set VoteNo = VoteNo + 1
      else
         call DisplayTextToPlayer(GetTriggerPlayer(),0,0,&quot;You&#039;re a fucking idiot. Use &#039;-vote yes&#039; or &#039;-vote no&#039;.&quot;)
      endif
         call TimerDialogSetTitle(VotingTimerDialog, &quot;Kick &quot;+GetPlayerNameColored(Player(VotingValue))+&quot;? Yes(|cFFFFFFFF&quot;+I2S(VoteYes)+&quot;|r) No(|cFFFFFFFF&quot;+I2S(VoteNo)+&quot;|r)&quot;)
      set Voted[pid] = true
   else
      call DisplayTextToPlayer(GetTriggerPlayer(),0,0,&quot;You have already casted your vote&quot;)
   endif
endfunction

function CallvoteActions takes nothing returns nothing
 local string command = SubString(GetEventPlayerChatString(),10,14)
 local string value = SubString(GetEventPlayerChatString(),15,StringLength(GetEventPlayerChatString()))
 local player tp = GetTriggerPlayer()
 local integer i = 1 
 local sound votesound = CreateSound(&quot;Sound\\Interface\\SecretFound.wav&quot;, false, false, false, 10, 10, &quot;&quot;)
 local string array color
 
if Voting == false then
 if command == &quot;kick&quot; then
    set color[1] = &quot;red&quot;
    set color[2] = &quot;blue&quot;
    set color[3] = &quot;teal&quot;
    set color[4] = &quot;purple&quot;
    set color[5] = &quot;yellow&quot;
    set color[6] = &quot;orange&quot;
    set color[7] = &quot;green&quot;
    set color[8] = &quot;pink&quot;
    set color[9] = &quot;gray&quot;
    set color[10] = &quot;light blue&quot;
    set color[11] = &quot;dark green&quot;
    set color[12] = &quot;brown&quot;
    
    loop
       exitwhen i == 13
       if (S2I(value) == i) or (value == GetPlayerName(Player(i-1))) or (value == color<i>) then
          set Voting = true
          set VotingValue = i - 1
          set VotingTimer = CreateTimer()
          call TimerStart(VotingTimer ,15.00, false, function EndKickVoting)
          set VotingTimerDialog = CreateTimerDialog(VotingTimer)
          call TimerDialogSetTitle(VotingTimerDialog, &quot;Kick &quot;+GetPlayerNameColored(Player(VotingValue))+&quot;? Yes(|cFFFFFFFF&quot;+I2S(VoteYes)+&quot;|r) No(|cFFFFFFFF&quot;+I2S(VoteNo)+&quot;|r)&quot;)
          call TimerDialogDisplay(VotingTimerDialog, true)
          call SetSoundVolume(votesound, PercentToInt(75, 127))
          call StartSound(votesound)
          call DisplayTextToForce( GetPlayersAll(), GetPlayerNameColored(tp)+&quot; has called a vote to kick &quot;+GetPlayerNameColored(Player(VotingValue ))+&quot;.&quot;)
          call DisplayTextToForce( GetPlayersAll(), &quot;Use &#039;-vote yes&#039; or &#039;-vote no&#039; to cast your vote.&quot;)
          set i = 0
          set VoteTrigger = CreateTrigger()
          loop
             exitwhen i == 11
             call TriggerRegisterPlayerChatEvent( VoteTrigger, Player(i), &quot;-vote&quot;, false )
             set i = i+1
          endloop          
          call TriggerAddAction(VoteTrigger ,function VoteTriggerFunction)
       endif
       set i = i+1
    endloop
    
    if Voting == false then
       call DisplayTextToPlayer(tp,0,0,&quot;You&#039;ve entered a incorrect value for the &#039;kick&#039; command. You can kick a player by using their playerID (1-12), their color, or their name.&quot;)
       call DisplayTextToPlayer(tp,0,0,&quot;ie. &#039;-callvote kick orange&#039;&quot;)
    endif    
 endif
else
   call DisplayTextToPlayer(tp,0,0,&quot;There can only be one vote at a time.&quot;)
endif
endfunction

//===========================================================================
function InitTrig_callvote takes nothing returns nothing
    set gg_trg_callvote = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_callvote, Player(0), &quot;-callvote&quot;, false )
    call TriggerAddAction( gg_trg_callvote, function CallvoteActions )
endfunction</i></i>


The idea behind it was to make it easy and fairly intuitive for players to call a vote. So a player can declare who he wants to kick in mulitiple ways.

  • '-callvote kick 1' - Use the player's (converted) id.
  • '-callvote kick red' - Use the player's color.
  • '-callvote kick WorldEdit' - Use the player's name.

I'm also posting this incase anyone wants to use it, or make a system based off of it(I couldnt find anything when I search a while ago). I made it for my upcoming map TEAM CTF **edit** btw havent nulled and cleaned up yet.
 
geteventplaychatstring could be set to a variable and used

you run the same check if voting==false after you have already checked, so there is no way it is possible

setting all your colors once instead of everytime would be better

there are a few on-nulled variables

You're a fucking idiot
some may not care for that...

lastly, and biggest concern, is that you loop through all 13 players.....and create a trigger for each, and add the event that each player does -vote

is this really needed? could you not just have 1 trigger to always use that u do not need to create(and let leak) and just check if its time for a vote and whether that player has voted yet?

other then that not bad
 
geteventplaychatstring could be set to a variable and used

didnt think of that. fixed.

you run the same check if voting==false after you have already checked, so there is no way it is possible

hmm, if you are reffering to :
JASS:
if Voting == false then
       call DisplayTextToPlayer(tp,0,0,&quot;You&#039;ve entered a incorrect value for the &#039;kick&#039; command. You can kick a player by using their playerID (1-12), their color, or their name.&quot;)
       call DisplayTextToPlayer(tp,0,0,&quot;ie. &#039;-callvote kick orange&#039;&quot;)
    endif

The loop sets Voting = true, so if Voting is still true after the loop is ran then none of the values matched, meaning the player misspelled the value. Unless you're talkign about something else?

setting all your colors once instead of everytime would be better

as in a global? I guess I could do that.

there are a few on-nulled variables
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"You're a fucking idiot.

some may not care for that...

Hah, yeh I guess I forgot to change that to something more friendly =p. And I haven't null anything yet. (I usually do that last).

lastly, and biggest concern, is that you loop through all 13 players.....and create a trigger for each, and add the event that each player does -vote

is this really needed? could you not just have 1 trigger to always use that u do not need to create(and let leak) and just check if its time for a vote and whether that player has voted yet?

You might have mis-read, I only create 1 trigger. The loop is for adding the chatevent for each player :

JASS:
          set VoteTrigger = CreateTrigger()
          loop
             exitwhen i == 11
             call TriggerRegisterPlayerChatEvent( VoteTrigger, Player(i), &quot;-vote&quot;, false )
             set i = i+1
          endloop          
          call TriggerAddAction(VoteTrigger ,function VoteTriggerFunction)


And then I destroy the created trigger after the voting timer is done. However, if there's a leak in my method I'll change it.

other then that not bad

Thank you, that means alot coming from you.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good
  • The Helper The Helper:
    I would like to see it again like Ghan had it the first time with pagination though - without the pagination that view will not work but with pagination it just might...
  • The Helper The Helper:
    This drink recipe I have had more than a few times back in the day! Mind Eraser https://www.thehelper.net/threads/cocktail-mind-eraser.194720/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top