Post by AttackerCat33 on Dec 15, 2022 17:35:29 GMT
Hello guys i am going to show you how to create a simple vote system with yes or no so let's start
First Sorry guys for my bad english let's start
1- If you want to create yes no vote just 2 variables done like this:
new g_Yes, g_No
2- Add a Variable For The Menu like this:
new iMenu
3- In plugin_init() add like this for vote menu:
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("vote_test", "VoteMenu") <------------- Add This
}
4- Now let's create how vote system work:
A- We need to create task to end the vote in a x time and show the vote menu like this:
public VoteMenu(id)
{
test_vote(id)
set_task(6.0, "endvote")
}
B- test_vote(id) is the vote menu if someone doesn't know, let's create the vote menu like this example code:
public test_vote(id)
{
iMenu = menu_create("Test Vote", "test")
menu_additem(iMenu, "Yes")
menu_additem(iMenu, "No")
menu_display(id, iMenu)
}
C- We need now create the vote menu hander commands:
As you can see here if you are choose yes the yes count will be increase and same in no vote
If yes count increase the no count will be decreased
Note: i Add This Check if the no vote go to in a negative number
if(g_No <= 0) return
g_No--
public test(id, menu, item)
{
switch(item)
{
case 0:
{
g_Yes++
test_vote(id)
if(g_No <= 0) return
g_No--
test_vote(id)
}
case 1:
{
g_No++
test_vote(id)
if(g_Yes <= 0) return
g_Yes--
test_vote(id)
}
}
}
5- Now let's go to how to create the vote results
A- The Result of the vote should like this, as you can see we need to stop the menu because we don't need it, and you can see the voting odds as you can see
public endvote()
{
menu_destroy(iMenu)
if(g_Yes > g_No)
{
client_print(0, print_chat, "All Votes With %d Yes", g_Yes)
}
else if(g_Yes == g_No)
{
client_print(0, print_chat, "Draw", g_No)
}
else if(g_Yes < g_No)
{
client_print(0, print_chat, "All Votes With %d No", g_No)
}
g_Yes = 0
g_No = 0
}
You Can Try The Full Test Plugin with this code
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "ShaunCraft"
new g_Yes, g_No, iMenu
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("vote_test", "VoteMenu")
}
public VoteMenu(id)
{
test_vote(id)
set_task(6.0, "endvote")
}
public endvote()
{
menu_destroy(iMenu)
if(g_Yes > g_No)
{
client_print(0, print_chat, "All Votes With %d Yes", g_Yes)
}
else if(g_Yes == g_No)
{
client_print(0, print_chat, "Draw", g_No)
}
else if(g_Yes < g_No)
{
client_print(0, print_chat, "All Votes With %d No", g_No)
}
g_Yes = 0
g_No = 0
}
public test_vote(id)
{
iMenu = menu_create("Test Vote", "test")
menu_additem(iMenu, "Yes")
menu_additem(iMenu, "No")
menu_display(id, iMenu)
}
public test(id, menu, item)
{
switch(item)
{
case 0:
{
g_Yes++
test_vote(id)
if(g_No <= 0) return
g_No--
test_vote(id)
}
case 1:
{
g_No++
test_vote(id)
if(g_Yes <= 0) return
g_Yes--
test_vote(id)
}
}
}