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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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