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.
 

emjlr3

Change can be a good thing
Reaction score
395
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
 

substance

New Member
Reaction score
34
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 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