VoteManager API (votekick/ban/map/burn/gravity/etc)
1 Attachment(s)
VoteManager
By: ferret! Description VoteManager provides a series of natives and forwards that other plugins can use to create votes and respond to the results. VoteManager handles creating the vote menus, and forwards the winning answer out to the client plugins. Includes vote plugins that do the votes from my Basic Votes and Extended Votes plugins:
Please use my project area on the Allied Modders Bug Tracker to report any issues or make requests. Your login for the bug tracker is the same as your forum login. Set the category to this plugin's name. Please read the next post for detail usage information |
Re: VoteManager API
VoteManager Basics
You should read includes/vmgr.inc as well as this post. I will detail each natives and forward here though, and provide examples. The first thing you should do if you are going to use VMgr is detail a global variable, or if multiple votes, an array. Something like g_MyVote would work. You'll use this to store the index or "handle" for your vote. 0 is a valid index, so you should set it to -1 to start. Code:
new g_MyVote = -1; Code:
new g_MyVotes[5] = {-1, ...} VM_OnCoreReady() will be issued when VMGR_CORE.SMX has completed loading and can actually accept vote registrations. You should have this in your plugin and use it to register the votes. Don't worry about the parameters of VM_RegisterVote, we'll get there soon. Code:
public VM_OnCoreReady() VM_OnVoteStart(vote) will be issued whenever a vote begins. You can compare vote to your vote indexes to find out if it's your vote. This is provided in case you wish to take some other action when your vote is ran. An example might be to PrintToChatAll some message. Code:
public VM_OnVoteStart(vote) This is probably the most important forward. This is called when a vote ends. Lots of parameters, right? They're documented in vmgr.inc but I'll go over them here too. The first parameter, vote, is the index that just ended. The second is true if successful, false if not. (Note: A vote for multiple actions is always successful). Item[] is the name of the item that won. Client, userid, name, and authid are all target related. If your vote doesn't have a target, they will be 0. Otherwise, they will have the target's data. VMgr provides all of this in case the target disconnected. We wouldn't want something to run away from a voteban, would we? Code:
public VM_OnVoteEnd(vote, bool:result, String:item[], client, userid, String:name[], String:authid[]) This native is a bit of a problem right now. Please be sure to read my next post concerning "To-Do's". The purpose of this native is to allow a plugin to check if VMgr_Core is ready. You would use this in OnPluginStart, and register your votes with it. Why? If your plugin reloads, it won't know about it's votes anymore. But since VMgr_Core didn't reload, VM_OnCoreReady won't ever occur. So this provides you a second method of finding out if the Core is there and ready. Use with care. Until "Non-required Natives" are a part of Sourcemod, doing this makes VMgr a required plugin for your's to load. Code:
public OnPluginStart() |
Re: VoteManager API
native bool:VM_UnregisterVote(index) If you register a vote, you should unregister it. Use this in OnPluginUnload(). Unfortunately, this once again causes VMgr to become a required plugin, until "Non-required Natives" are a reality. This will return false if the index is invalid. Code:
public OnPluginUnload() Now we're down to the most important part of all this. Registering your vote. Code:
stock VM_RegisterVote(const String:name[], VM_RegisterVote does several things. It gives your vote's information to the Core, and registers a command and a convar. The first parameter, name, should be a no-spaces single word for the vote, such as "kick". Title should be the title of the vote, such as "Kick Player". admflag is the admin flag you want the command to be restricted to. It defaults to ADMFLAG_VOTE. vType and tType control how the vote works. I will detail both below. The last parameter, 'say', controls whether or not this vote will work from chat. It defaults to true. If you change this to false, your vote will be console command only, regardless of the value of vm_sayvotes. Code:
g_MyVote = VM_RegisterVote("kick", "Kick", _, _, TargetType:Client, true); Here's the enums: Code:
enum VoteType VoteType currently has 5 options. I will probably be adding a sixth soon. The first is the default, YesNo. In this case your vote will take a single argument, and the options displayed to the player will be Yes and No. For a vote of this type, item[] will be "Yes" or "No" when VM_OnVoteEnd is called. The next are all MultiVotes. It should be noted that a MultiVote is ALWAYS successful. There is no failure. Each MultiVote has a type associated with it, such as Int, Float, String and Map. VMgr_Core checks the arguments supplied with the vote command against this. For example, all arguments sent with a MultiMap vote are ran through IsMapValid(). Int and Float votes are tested as well. MultiString's receive no validation. When only a single argument is provided to a MultiVote, the vote will display like a YesNo vote. The difference is that when VM_OnVoteEnd is called, item[] will be set to that argument's value, rather than Yes or No. That's just about everything. So as an example, here is the complete vmgr_kick plugin: Code:
#pragma semicolon 1 |
Re: VoteManager API
Known Issues
|
Re: VoteManager API
P.S. requires SM build 1084 or higher.
|
Re: VoteManager API
Wow, I love it. :]
|
Re: VoteManager API (votekick/ban/map/burn/gravity/etc)
I plan to change VM_OnVoteStart to include target information like VM_OnVoteEnd.
|
Re: VoteManager API (votekick/ban/map/burn/gravity/etc)
Please reupload without subversion.
|
Re: VoteManager API (votekick/ban/map/burn/gravity/etc)
Reuploaded. Also moved the votes to vmgr_votes folder as original post stated.
|
Re: VoteManager API (votekick/ban/map/burn/gravity/etc)
Version 1.0 is almost ready.
Notable changes:
|
All times are GMT -4. The time now is 12:27. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.