View previous topic :: View next topic |
Author |
Message |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Mon Mar 15, 2021 8:00 pm Post subject: CT-VoteKick |
|
|
Just wanted to make a fun script, so i made a VoteKick script.
Still in Beta
Code: |
########################
# CT-Votekick 0.1
########################
# ComputerTech
# 16/03/21
########################
# Set flags of script usage
set ctvk(flag) "ofmn"
# Set trigger
set ctvk(trig) "!votekick"
# Set X time (in seconds) before Vote times out
set ctvk(time) "180"
# Set Votes needed to kick target
set ctvk(max) "3"
# Set Kick reason
set ctvk(reason) "VoteKick!"
bind pub $ctvk(flag) $ctvk(trig) main:proc
proc main:proc {nick host hand chan text} {
global ctvk
if {[lindex [split $text] 0] == ""} {
puthelp "PRIVMSG $chan :\0034Error\003 Syntax: $ctvk(trig) nick"
return
}
if {$ctvk(on)} {
puthelp "PRIVMSG $chan :\0034Error\003 A Vote is currently happening, please wait"
return
}
if {$ctvk(left) < $ctvk(max)} {
incr ctvk(more) -1
incr ctvk(left) 1
puthelp "PRIVMSG $chan :Another Vote to Kick $ctvk(target) / $ctvk(more) More Votes Needed!"
} else {
puthelp "PRIVMSG $chan :\0039Vote Started\003 \007Target:\0032 $ctvk(target) \003 \0038$ctvk(more) Votes needed\003"
utimer $ctvk(time) [list reset:vote $text]
if {![info exists ctvk(left)] && [info exists ctvk(target)]} {
set ctvk(target) [lindex [split $text] 0]
set ctvk(left) $ctvk(max)
}
}
if {$ctvk(left) > $ctvk(max)} {
putquick "KICK $chan $ctvk(target) :$ctvk(reason)"
unset ctvk(left)
unset ctvk(target)
}
}
proc reset:vote {text} {
unset ctvk(left)
unset ctvk(ctvk(target)
puthelp "PRIVMSG $chan :Vote Timed Out"
}
|
Suggestions are welcome  _________________ ComputerTech |
|
Back to top |
|
 |
CrazyCat Owner

Joined: 13 Jan 2002 Posts: 973 Location: France
|
Posted: Tue Mar 16, 2021 3:27 am Post subject: |
|
|
I see different small things...
- What is ctvk(more) ? You increment it, you display it, but it's never defined
- You never check if target is on the chan ?
- You use ctvk(left) but you initialize it after ?
- what happen if I do !votekick foo, !votekick foo, !votekick ComputerTech ? Three votes, but you are kicked, you don't distribute voices to the victim. The third vote is the only one which is important.
- Syntax error @ unset ctvk(ctvk(target) <-- a closing parenthesis lacking or redundant ctvk( _________________ https://www.eggdrop.fr
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1169
|
Posted: Tue Mar 16, 2021 10:08 am Post subject: Re: CT-VoteKick |
|
|
What is $ctvk(on) ?
I have not tried to run this script. But a text search of this page finds it only once. So that means it is never set.
Are you not getting an error in the partyline ?
Also (again, I haven't run it) , I curious about something.
Suppose enough votes come in quickly to kick a nick.
Then:
unset ctvk(left)
unset ctvk(target)
Now what happens when the utimer triggers?
The proc it calls also tries to unset (see the typo in that proc, already mentioned earlier by CrazyCat) those same variables.
Are you not getting errors in the partyline, because those variables no longer exist? _________________ For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia ! |
|
Back to top |
|
 |
CrazyCat Owner

Joined: 13 Jan 2002 Posts: 973 Location: France
|
Posted: Tue Mar 16, 2021 10:10 am Post subject: Re: CT-VoteKick |
|
|
willyw wrote: | What is $ctvk(on) ? |
I missed this one  _________________ https://www.eggdrop.fr
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Tue Mar 16, 2021 2:12 pm Post subject: |
|
|
Still working, but i hope this is better
Code: |
########################
# CT-Votekick 0.2
########################
# ComputerTech
# 16/03/21
########################
# Set flags of script usage
set ctvk(flag) "ofmn"
# Set trigger
set ctvk(trig) "!votekick"
# Set X time (in seconds) before Vote times out
set ctvk(time) "180"
# Set Votes needed to kick target
set ctvk(max) "3"
# Set Kick reason
set ctvk(reason) "VoteKick!"
########################
bind pub $ctvk(flag) $ctvk(trig) main:proc
proc main:proc {nick host hand chan text} {
global ctvk
if {!$ctvk(on) } {
if {[lindex [split $text] 0] == ""} {
puthelp "PRIVMSG $chan :\0034Error\003 Syntax: $ctvk(trig) nick"
return
}
}
if {![info exists ctvk(on)]} {
set ctvk(on) "1"
} elseif {![info exists ctvk(target)]} {
set ctvk(target) [lindex [split $text] 0]
} elseif {![info exists ctvk(left)]} {
set ctvk(left) $ctvk(max)
} elseif {![onchan $ctvk(target) $chan]} {
return
}
if {$ctvk(on)} {
puthelp "PRIVMSG $chan :\0034Error\003 A Vote is currently happening, please wait"
return
}
if {!$ctvk} {
if {$ctvk(on) > 1} {
incr ctvk(left) -1
if {$ctvk(on) == 1} {
puthelp "PRIVMSG $chan :\0039Vote Started\003 \007Target:\0032 $ctvk(target) \003 \0038$ctvk(left) Votes needed\003"
set ctvk($host) 1
utimer $ctvk(time) [list reset:vote $chan $text]
set ctvk(on) 2
} else {
puthelp "PRIVMSG $chan :Another Vote to Kick $ctvk(target) / $ctvk(left) More Votes Needed!"
set ctvk($host) 1
}
}
} else {
putserv "PRIVMSG $chan :$nick has already voted"
return
}
if {$ctvk(left) < 1} {
putquick "KICK $chan $ctvk(target) :$ctvk(reason)"
unset ctvk(left)
unset ctvk(target)
unset ctvk(on)
unset ctvk($host)
}
}
proc reset:vote {host chan text} {
unset ctvk(left)
unset ctvk(target)
unset ctvk(on)
unset ctvk($host)
puthelp "PRIVMSG $chan :Vote Timed Out"
}
|
Will test when i get home
EDIT
I "Think" this will restrict only one vote per user by $host will need to test after dinner  _________________ ComputerTech
Last edited by ComputerTech on Tue Mar 16, 2021 6:51 pm; edited 2 times in total |
|
Back to top |
|
 |
CrazyCat Owner

Joined: 13 Jan 2002 Posts: 973 Location: France
|
Posted: Tue Mar 16, 2021 6:39 pm Post subject: |
|
|
Quickly read, it's late...
But you seems to always have your target trouble: the first votant choose a target, others must choose a target too but only the first target is the victim.
This is not a vote. _________________ https://www.eggdrop.fr
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
Back to top |
|
 |
ComputerTech Master

Joined: 22 Feb 2020 Posts: 393
|
Posted: Tue Mar 16, 2021 6:43 pm Post subject: |
|
|
CrazyCat, thats how the VoteKick script works, only the first votant can choose the target, but i do see i need to add a way to restrict One vote per $host per Vote
Ok so i "think" the above code edit should work, will see in a bit  _________________ ComputerTech |
|
Back to top |
|
 |
|