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:
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.
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.
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 == "yes" then
set VoteYes = VoteYes + 1
elseif value == "no" then
set VoteNo = VoteNo + 1
else
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"You039;re a fucking idiot. Use 039;-vote yes039; or 039;-vote no039;.")
endif
call TimerDialogSetTitle(VotingTimerDialog, "Kick "+GetPlayerNameColored(Player(VotingValue))+"? Yes(|cFFFFFFFF"+I2S(VoteYes)+"|r) No(|cFFFFFFFF"+I2S(VoteNo)+"|r)")
set Voted[pid] = true
else
call DisplayTextToPlayer(GetTriggerPlayer(),0,0,"You have already casted your vote")
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("Sound\\Interface\\SecretFound.wav", false, false, false, 10, 10, "")
local string array color
if Voting == false then
if command == "kick" then
set color[1] = "red"
set color[2] = "blue"
set color[3] = "teal"
set color[4] = "purple"
set color[5] = "yellow"
set color[6] = "orange"
set color[7] = "green"
set color[8] = "pink"
set color[9] = "gray"
set color[10] = "light blue"
set color[11] = "dark green"
set color[12] = "brown"
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, "Kick "+GetPlayerNameColored(Player(VotingValue))+"? Yes(|cFFFFFFFF"+I2S(VoteYes)+"|r) No(|cFFFFFFFF"+I2S(VoteNo)+"|r)")
call TimerDialogDisplay(VotingTimerDialog, true)
call SetSoundVolume(votesound, PercentToInt(75, 127))
call StartSound(votesound)
call DisplayTextToForce( GetPlayersAll(), GetPlayerNameColored(tp)+" has called a vote to kick "+GetPlayerNameColored(Player(VotingValue ))+".")
call DisplayTextToForce( GetPlayersAll(), "Use 039;-vote yes039; or 039;-vote no039; to cast your vote.")
set i = 0
set VoteTrigger = CreateTrigger()
loop
exitwhen i == 11
call TriggerRegisterPlayerChatEvent( VoteTrigger, Player(i), "-vote", 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,"You039;ve entered a incorrect value for the 039;kick039; command. You can kick a player by using their playerID (1-12), their color, or their name.")
call DisplayTextToPlayer(tp,0,0,"ie. 039;-callvote kick orange039;")
endif
endif
else
call DisplayTextToPlayer(tp,0,0,"There can only be one vote at a time.")
endif
endfunction
//===========================================================================
function InitTrig_callvote takes nothing returns nothing
set gg_trg_callvote = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_callvote, Player(0), "-callvote", 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.