Advertisement
Guest User

Untitled

a guest
Nov 13th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.08 KB | None | 0 0
  1. /**
  2. * vim: set ts=4 :
  3. * =============================================================================
  4. * NativeVotes
  5. * Copyright (C) 2011-2013 Ross Bemrose (Powerlord). All rights reserved.
  6. * =============================================================================
  7. *
  8. * This program is free software; you can redistribute it and/or modify it under
  9. * the terms of the GNU General Public License, version 3.0, as published by the
  10. * Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  14. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  15. * details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * As a special exception, AlliedModders LLC gives you permission to link the
  21. * code of this program (as well as its derivative works) to "Half-Life 2," the
  22. * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
  23. * by the Valve Corporation. You must obey the GNU General Public License in
  24. * all respects for all other code used. Additionally, AlliedModders LLC grants
  25. * this exception to all derivative works. AlliedModders LLC defines further
  26. * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
  27. * or <http://www.sourcemod.net/license.php>.
  28. *
  29. * Version: $Id$
  30. */
  31.  
  32. #include <menus>
  33. #include <sourcemod>
  34.  
  35. // NativeVotes 0.8 series
  36.  
  37. #if defined _nativevotes_included
  38. #endinput
  39. #endif
  40. #define _nativevotes_included
  41.  
  42. #define CLIENT_DISCONNECTED -1
  43.  
  44. #define NATIVEVOTES_EXTEND "Extend current Map" /** Defined in TF2, but doesn't appear to be localized */
  45.  
  46. #define NATIVEVOTES_ALL_TEAMS -1 // Defined by TF2, may be the same in L4D/L4D2
  47. #define NATIVEVOTES_TF2_ALL_TEAMS 0 // Defined by TF2, may be the same in L4D/L4D2
  48. #define NATIVEVOTES_TEAM_UNASSIGNED 0 // For completeness, do not otherwise use
  49. #define NATIVEVOTES_TEAM_SPECTATOR 1 // Spectators
  50. #define NATIVEVOTES_TEAM_1 2 // RED/Survivors/Terrorists
  51. #define NATIVEVOTES_TEAM_2 3 // BLU/Infected/Counter-Terrorists
  52.  
  53. #define NATIVEVOTES_SERVER_INDEX 99 // Defined by TF2, may be the same in L4D/L4D2
  54.  
  55. // These may seem backwards, but this is the order that the votes appear in the vote screen
  56. #define NATIVEVOTES_VOTE_INVALID -1 /**< Vote was invalid, currently only valid internally */
  57. #define NATIVEVOTES_VOTE_YES 0 /**< Vote was yes */
  58. #define NATIVEVOTES_VOTE_NO 1 /**< Vote was no */
  59.  
  60. /*
  61. The following MenuActions are supported. Arguments are also listed, as they differ slightly from the default
  62. MenuAction_Start A menu has been started (nothing passed). Only exists for compat reasons.
  63. MenuAction_Display A menu is about to be displayed (param1=client). If you choose to change the vote text,
  64. To change the text, use RedrawVoteTitle()
  65. If you do so, return 1 or _:Plugin_Changed Otherwise, return _:Plugin_Continue or 0.
  66. MenuAction_Select An item was selected (param1=client, param2=item). For subplugin support.
  67. MenuAction_End A vote has fully ended and the vote object is ready to be cleaned up
  68. param1 is MenuEnd reason, either MenuEnd_VotingCancelled or MenuEnd_VotingDone
  69. MenuAction_VoteEnd A vote sequence has succeeded (param1=chosen item)
  70. This is not called if NativeVotes_SetResultCallback has been used on the vote.
  71. You should call NativeVotes_DisplayPass or NativeVotes_DisplayPassEx after this
  72. MenuAction_VoteStart A vote sequence has started (nothing passed). Use this instead of MenuAction_Start
  73. MenuAction_VoteCancel A vote sequence has been cancelled (param1=reason)
  74. MenuAction_DisplayItem Item text is being drawn to the display (param1=client, param2=item)
  75. To change the text, use RedrawVoteItem().
  76. If you do so, return 1 or _:Plugin_Changed. Otherwise, return _:Plugin_Continue or 0.
  77. */
  78.  
  79. #define NATIVEVOTES_ACTIONS_DEFAULT MenuAction_VoteStart|MenuAction_VoteCancel|MenuAction_VoteEnd|MenuAction_End
  80.  
  81. /**
  82. * Vote types. These are mapped to translation strings and pass strings by VoteStart and VotePass handlers
  83. */
  84. enum NativeVotesType
  85. {
  86. NativeVotesType_None = 0, /** Special placeholder for callvote with no arguments for NativeVotes_OnCallVote */
  87. NativeVotesType_Custom_YesNo, /**< Yes/No, details are vote text. */
  88. NativeVotesType_Custom_Mult, /**< TF2/CS:GO: Multiple-choice, details are vote text. */
  89. NativeVotesType_ChgCampaign, /**< L4D/L4D2: Yes/No, details are campaign name */
  90. NativeVotesType_ChgDifficulty, /**< L4D/L4D2: Yes/No, details are difficulty number in L4D/L4D2 */
  91. NativeVotesType_ReturnToLobby, /**< L4D/L4D2: Yes/No, details are ignored */
  92. NativeVotesType_AlltalkOn, /**< L4D2: Yes/No, details are ignored (handled internally by extension) */
  93. NativeVotesType_AlltalkOff, /**< L4D2: Yes/No, details are ignored (handled internally by extension) */
  94. NativeVotesType_Restart, /**< Yes/No, details are ignored */
  95. NativeVotesType_Kick, /**< Yes/No, target is player userid, details are auto-set by target */
  96. NativeVotesType_KickIdle, /**< TF2/CS:GO: Yes/No, target is player userid, details are auto-set by target */
  97. NativeVotesType_KickScamming, /**< TF2/CS:GO: Yes/No, target is player userid, details are auto-set by target */
  98. NativeVotesType_KickCheating, /**< TF2/CS:GO: Yes/No, target is player userid, details are auto-set by target */
  99. NativeVotesType_ChgLevel, /**< Yes/No, details are level number in L4D/L4D2 or map name in TF2 */
  100. NativeVotesType_NextLevel, /**< TF2/CS:GO: Yes/No, details are map name */
  101. NativeVotesType_NextLevelMult, /**< TF2/CS:GO: Multiple-choice, details are ignored */
  102. NativeVotesType_ScrambleNow, /**< TF2/CS:GO: Yes/No, details are ignored */
  103. NativeVotesType_ScrambleEnd, /**< TF2: Yes/No, details are ignored */
  104. NativeVotesType_ChgMission, /**< TF2: Yes/No, details are popfile */
  105. NativeVotesType_SwapTeams, /**< CS:GO: Yes/No, details are ignored */
  106. NativeVotesType_Surrender, /**< CS:GO: Yes/No, details are ignored */
  107. NativeVotesType_Rematch, /**< CS:GO: Yes/No, details are ignored */
  108. NativeVotesType_Continue, /**< CS:GO: Yes/No, details are ignored */
  109. NativeVotesType_StartRound, /**< TF2: Yes/No, details are ignored */
  110. NativeVotesType_Eternaween, /**< TF2: Yes/No, details are ignored */
  111. NativeVotesType_AutoBalanceOn, /**< TF2: Yes/No, details are ignored */
  112. NativeVotesType_AutoBalanceOff, /**< TF2: Yes/No, details are ignored */
  113. NativeVotesType_ClassLimitsOn, /**< TF2: Yes/No, details are ignored */
  114. NativeVotesType_ClassLimitsOff, /**< TF2: Yes/No, details are ignored */
  115. };
  116.  
  117. enum NativeVotesPassType
  118. {
  119. NativeVotesPass_None = 0, /**< Special placeholder for error value */
  120. NativeVotesPass_Custom, /**< Details are custom pass message */
  121. NativeVotesPass_ChgCampaign, /**< L4D/L4D2: Details are campaign name */
  122. NativeVotesPass_ChgDifficulty, /**< L4D/L4D2/TF2: Details are difficulty number in L4D/L4D2 and mission name in TF2 */
  123. NativeVotesPass_ReturnToLobby, /**< L4D/L4D2: Details are ignored */
  124. NativeVotesPass_AlltalkOn, /**< L4D2: Details are ignored */
  125. NativeVotesPass_AlltalkOff, /**< L4D2: Details are ignored */
  126. NativeVotesPass_Restart, /**< Details are ignored */
  127. NativeVotesPass_Kick, /**< Details are player name */
  128. NativeVotesPass_ChgLevel, /**< Details are level number in L4D/L4D2 or map name in TF2/CS:GO */
  129. NativeVotesPass_NextLevel, /**< TF2/CS:GO: Details are map name */
  130. NativeVotesPass_Extend, /**< TF2/CS:GO: Details are ignored */
  131. NativeVotesPass_Scramble, /**< TF2/CS:GO: Details are ignored */
  132. NativeVotesPass_ChgMission, /**< TF2: Details are popfile */
  133. NativeVotesPass_SwapTeams, /**< CS:GO: Details are ignored */
  134. NativeVotesPass_Surrender, /**< CS:GO: Details are ignored */
  135. NativeVotesPass_Rematch, /**< CS:GO: Details are ignored */
  136. NativeVotesPass_Continue, /**< CS:GO: Details are ignored */
  137. NativeVotesPass_StartRound, /**< TF2: Details are ignored */
  138. NativeVotesPass_Eternaween, /**< TF2: Details are ignored */
  139. NativeVotesPass_AutoBalanceOn, /**< TF2: Yes/No, details are ignored */
  140. NativeVotesPass_AutoBalanceOff, /**< TF2: Yes/No, details are ignored */
  141. NativeVotesPass_ClassLimitsOn, /**< TF2: Yes/No, details are ignored */
  142. NativeVotesPass_ClassLimitsOff, /**< TF2: Yes/No, details are ignored */
  143. };
  144.  
  145. /**
  146. * Reasons a vote was canceled. Not used for L4D/L4D2, as they don't care
  147. */
  148. enum NativeVotesFailType
  149. {
  150. NativeVotesFail_Generic = 0, /**< Vote was generically cancelled. */
  151. NativeVotesFail_Loses = 3, /**< No votes outnumbered Yes votes */
  152. NativeVotesFail_NotEnoughVotes = 4, /**< Vote did not receive enough votes. */
  153. };
  154.  
  155. /**
  156. * Reasons a callvote command failed.
  157. * This is provided as a convenience to plugin authors as it's not strictly part of the vote system
  158. */
  159. enum NativeVotesCallFailType
  160. {
  161. NativeVotesCallFail_Generic = 0, /**< Generic fail. */
  162. NativeVotesCallFail_Loading = 1, /**< L4D/L4D2: Players are still loading. */
  163. NativeVotesCallFail_Recent = 2, /**< TF2/CS:GO: You can't call another vote yet: Argument is seconds until you can call another vote. */
  164. NativeVotesCallFail_Disabled = 5, /**< TF2/CS:GO: Server has disabled that issue. */
  165. NativeVotesCallFail_MapNotFound = 6, /**< TF2/CS:GO: Server does not have that map. */
  166. NativeVotesCallFail_SpecifyMap = 7, /**< TF2/CS:GO: You must specify a map. */
  167. NativeVotesCallFail_Failed = 8, /**< TF2/CS:GO: This vote failed recently. */
  168. NativeVotesCallFail_WrongTeam = 9, /**< TF2/CS:GO: Team can't call this vote. */
  169. NativeVotesCallFail_Waiting = 10, /**< TF2/CS:GO: Vote can't be called during Waiting For Players. */
  170. NativeVotesCallFail_PlayerNotFound = 11, /**< TF2/CS:GO: Player to kick can't be found. Buggy in TF2. */
  171. NativeVotesCallFail_Unknown = 11,
  172. NativeVotesCallFail_CantKickAdmin = 12, /**< TF2/CS:GO: Can't kick server admin. */
  173. NativeVotesCallFail_ScramblePending = 13, /**< TF2/CS:GO: Team Scramble is pending.. */
  174. NativeVotesCallFail_Spectators = 14, /**< TF2/CS:GO: Spectators aren't allowed to call votes. */
  175. NativeVotesCallFail_LevelSet = 15, /**< TF2/CS:GO: Next level already set. */
  176. NativeVotesCallFail_MapNotValid = 16, /**< ???: Map is invalid. */
  177. NativeVotesCallFail_KickTime = 17, /**< ???: Cannot kick for time. */
  178. NativeVotesCallFail_KickDuringRound = 18, /**< ???: Cannot kick during a round. */
  179. NativeVotesCallFail_AlreadyActive = 19 /**< TF2: Cannot call vote because modification (Eternaween) is already active (may not work) */
  180. };
  181.  
  182. /*
  183. * Is a specific vote type supported by this game?
  184. *
  185. * @param voteType Vote type
  186. */
  187. native bool:NativeVotes_IsVoteTypeSupported(NativeVotesType:voteType);
  188.  
  189. /**
  190. * Creates a new, empty vote.
  191. *
  192. * @param handler Function which will receive vote actions.
  193. * @param voteType Vote type, cannot be changed after set
  194. * @param actions Optionally set which actions to receive. Start,
  195. * Cancel, and End will always be received regardless
  196. * of whether they are set or not. They are also
  197. * the only default actions.
  198. * @return A new vote Handle on INVALID_HANDLE if a vote type is unsupported by this game.
  199. */
  200. native Handle:NativeVotes_Create(MenuHandler:handler, NativeVotesType:voteType,
  201. MenuAction:actions=NATIVEVOTES_ACTIONS_DEFAULT);
  202.  
  203. /**
  204. * Frees all handles related to a vote.
  205. *
  206. * THIS MUST BE CALLED TO AVOID HANDLE LEAKS
  207. *
  208. * @param vote Vote handle
  209. * @noreturn
  210. */
  211. native Handle:NativeVotes_Close(Handle:vote);
  212.  
  213. /**
  214. * Appends a new item to the end of a vote. Only valid for Multiple Choice votes
  215. *
  216. * @param vote NativeVotes Handle.
  217. * @param info Item information string.
  218. * @return True on success, false on failure.
  219. * @error Invalid Handle, item limit reached, or if the vote is not multiple choice.
  220. */
  221. native bool:NativeVotes_AddItem(Handle:vote, const String:info[], const String:display[]);
  222.  
  223. /**
  224. * Inserts an item into the menu before a certain position; the new item will
  225. * be at the given position and all next items pushed forward.
  226. *
  227. * @param vote Vote Handle.
  228. * @param position Position, starting from 0.
  229. * @param info Item information string.
  230. * @return True on success, false on failure.
  231. * @error Invalid Handle or vote position, or if the vote is not multiple choice.
  232. */
  233. native bool:NativeVotes_InsertItem(Handle:vote, position, const String:info[], const String:display[]);
  234.  
  235. /**
  236. * Removes an item from the menu.
  237. *
  238. * @param vote Vote Handle.
  239. * @param position Position, starting from 0.
  240. * @return True on success, false on failure.
  241. * @error Invalid Handle or vote position, or if the vote is not multiple choice.
  242. */
  243. native bool:NativeVotes_RemoveItem(Handle:vote, position);
  244.  
  245. /**
  246. * Removes all items from a vote.
  247. *
  248. * @param vote Vote Handle.
  249. * @noreturn
  250. * @error Invalid Handle or vote position, or if the vote is not multiple choice.
  251. */
  252. native NativeVotes_RemoveAllItems(Handle:vote);
  253.  
  254. /**
  255. * Retrieves information about a vote item.
  256. *
  257. * @param vote Vote Handle.
  258. * @param position Position, starting from 0.
  259. * @param infoBuf Info buffer.
  260. * @param infoBufLen Maximum length of the info buffer.
  261. * @return True on success, false if position is invalid.
  262. * @error Invalid Handlem
  263. */
  264. native bool:NativeVotes_GetItem(Handle:vote,
  265. position,
  266. String:infoBuf[],
  267. infoBufLen,
  268. String:dispBuf[]="",
  269. dispBufLen=0);
  270.  
  271. /**
  272. * Returns the number of items in a vote.
  273. *
  274. * @param vote Vote Handle.
  275. * @return Number of items in the vote.
  276. * @error Invalid Handle.
  277. */
  278. native NativeVotes_GetItemCount(Handle:vote);
  279.  
  280. /**
  281. * Sets the vote's details for votes that support details
  282. * If this is a custom vote, use NativeVotes_SetTitle to set the vote's title.
  283. *
  284. * @param vote Vote Handle.
  285. * @param argument Details string. See vote types for what details stands for.
  286. * @noreturn
  287. * @error Invalid Handle.
  288. */
  289. native NativeVotes_SetDetails(Handle:vote, const String:argument[]);
  290.  
  291. /**
  292. * Returns the text of a vote's details if set.
  293. *
  294. * @param vote Vote Handle.
  295. * @param buffer Buffer to store details.
  296. * @param maxlength Maximum length of the buffer.
  297. * @noreturn
  298. * @error Invalid Handle.
  299. */
  300. native NativeVotes_GetDetails(Handle:vote, String:buffer[], maxlength);
  301.  
  302. /**
  303. * Sets a custom vote's title
  304. *
  305. * @param vote Vote Handle.
  306. * @param title Vote title string.
  307. * @noreturn
  308. * @error Invalid Handle.
  309. */
  310. native NativeVotes_SetTitle(Handle:vote, const String:argument[]);
  311.  
  312. /**
  313. * Return the vote's Title.
  314. * If not set, returns Details instead.
  315. * This behavior is for compatibility with NativeVotes 0.8.0 and below.
  316. *
  317. * @param vote Vote Handle.
  318. * @param buffer Buffer to store title.
  319. * @param maxlength Maximum length of the buffer.
  320. * @noreturn
  321. * @error Invalid Handle.
  322. */
  323. native NativeVotes_GetTitle(Handle:vote, String:buffer[], maxlength);
  324.  
  325. /**
  326. * Sets the target userid for vote
  327. * This should be used instead of SetArgument for votes that target players
  328. *
  329. * Also sets target SteamID
  330. *
  331. * @param vote Vote Handle.
  332. * @param userid Client index of target player
  333. * @param setDetails If true, also sets vote details to client's name
  334. * @noreturn
  335. * @error Invalid Handle.
  336. */
  337. native NativeVotes_SetTarget(Handle:vote, client, bool:setDetails=true);
  338.  
  339. /**
  340. * Returns the userid of a vote's target
  341. *
  342. * @param vote Vote Handle.
  343. * @return Client index of target player or 0 for no target or target disconnected since vote started
  344. * @error Invalid Handle.
  345. */
  346. native NativeVotes_GetTarget(Handle:vote);
  347.  
  348. /**
  349. * Get the Steam ID of a vote's target
  350. * Useful if the target has disconnect from the server during a vote.
  351. * This was added in specifically for Kick/Ban votes
  352. *
  353. * @param vote Vote Handle.
  354. * @param buffer Buffer to store steamId. Should be 19 characters or more..
  355. * @param maxlength Maximum length of the buffer.
  356. * @noreturn
  357. * @error Invalid Handle.
  358. */
  359. native NativeVotes_GetTargetSteam(Handle:vote, String:buffer[], maxlength);
  360.  
  361. /**
  362. * Returns whether a vote is in progress.
  363. *
  364. * @return True if a NativeVotes vote is in progress, false otherwise.
  365. */
  366. native bool:NativeVotes_IsVoteInProgress();
  367.  
  368. /**
  369. * Returns a style's maximum items
  370. *
  371. * @return Maximum items
  372. */
  373. native NativeVotes_GetMaxItems();
  374.  
  375. /**
  376. * Sets a vote's option flags.
  377. *
  378. * If a certain bit is not supported, it will be stripped before being set.
  379. *
  380. * NOTE: This is currently unused, but reserved for future use.
  381. *
  382. * @param menu Builtin Vote Handle.
  383. * @param flags A new bitstring of VOTEFLAG bits.
  384. * @noreturn
  385. * @error Invalid Handle.
  386. */
  387. native NativeVotes_SetOptionFlags(Handle:vote, flags);
  388.  
  389. /**
  390. * Retrieves a menu's option flags.
  391. *
  392. * NOTE: This is currently unused, but reserved for future use.
  393. *
  394. * @param vote Builtin Vote Handle.
  395. * @return A bitstring of VOTEFLAG bits.
  396. * @error Invalid Handle.
  397. */
  398. native NativeVotes_GetOptionFlags(Handle:vote);
  399.  
  400. /**
  401. * Cancels the vote in progress.
  402. *
  403. * @noreturn
  404. * @error If no vote is in progress.
  405. */
  406. native NativeVotes_Cancel();
  407.  
  408. /**
  409. * Callback for when a vote has ended and results are available.
  410. *
  411. * Due to SourceMod Forward limitations in plugins, multi-dimension arrays can't be passed
  412. * to forwards. This means we have to split the client_info and item_info arrays into
  413. * their components.
  414. *
  415. * @param vote The vote being voted on.
  416. * @param num_votes Number of votes tallied in total.
  417. * @param num_clients Number of clients who could vote.
  418. * @param client_indexes Array of client indexes. Parallel with client_votes.
  419. * @param client_votes Array of client votes. Parallel with client_indexes.
  420. * @param num_items Number of unique items that were selected.
  421. * @param item_indexes Array of vote item indexes. Parallel with item_votes..
  422. * @param item_votes Array of vote vote counts. Parallel with item_indexes.
  423. * @noreturn
  424. */
  425. functag public NativeVotes_VoteHandler(Handle:vote,
  426. num_votes,
  427. num_clients,
  428. const client_indexes[],
  429. const client_votes[],
  430. num_items,
  431. const item_indexes[],
  432. const item_votes[]);
  433. /**
  434. * Function to convert client/vote arrays into their two-dimensional versions,
  435. * which can then be passed to a standard vote handler.
  436. *
  437. * client_info and item_info are the resulting arrays.
  438. *
  439. * Note: When declaring client_info and item_info, you'll probably want to declare them like this:
  440. * new client_info[num_clients][2];
  441. * new item_info[num_items][2];
  442. *
  443. * @param num_clients Number of clients who could vote.
  444. * @param client_indexes Array of client indexes. Parallel with client_votes.
  445. * @param client_votes Array of client votes. Parallel with client_indexes.
  446. * @param num_items Number of unique items that were selected.
  447. * @param item_indexes Array of vote item indexes. Parallel with item_votes..
  448. * @param item_votes Array of vote vote counts. Parallel with item_indexes.
  449. * @param client_info Array of clients. Use VOTEINFO_CLIENT_ defines.
  450. * @param item_info Array of items, sorted by count. Use VOTEINFO_ITEM
  451. * defines.
  452. * @noreturn
  453. */
  454. stock NativeVotes_FixResults(num_clients,
  455. const client_indexes[],
  456. const client_votes[],
  457. num_items,
  458. const item_indexes[],
  459. const item_votes[],
  460. client_info[][2],
  461. item_info[][2])
  462. {
  463. for (new i = 0; i < num_clients; ++i)
  464. {
  465. client_info[i][VOTEINFO_CLIENT_INDEX] = client_indexes[i];
  466. client_info[i][VOTEINFO_CLIENT_ITEM] = client_votes[i];
  467. }
  468.  
  469. for (new i = 0; i < num_items; ++i)
  470. {
  471. item_info[i][VOTEINFO_ITEM_INDEX] = item_indexes[i];
  472. item_info[i][VOTEINFO_ITEM_VOTES] = item_votes[i];
  473. }
  474. }
  475.  
  476. /**
  477. * Sets an advanced vote handling callback. If this callback is set,
  478. * MenuAction_VoteEnd will not be called.
  479. *
  480. * @param vote NativeVotes Handle.
  481. * @param callback Callback function.
  482. * @noreturn
  483. * @error Invalid Handle or callback.
  484. */
  485. native NativeVotes_SetResultCallback(Handle:vote, NativeVotes_VoteHandler:callback);
  486.  
  487. /**
  488. * Returns the number of seconds you should "wait" before displaying
  489. * a public vote. This number is the time remaining until
  490. * (last_vote + sm_vote_delay).
  491. *
  492. * @return Number of seconds to wait, or 0 for none.
  493. */
  494. native NativeVotes_CheckVoteDelay();
  495.  
  496. /**
  497. * Returns whether a client is in the pool of clients allowed
  498. * to participate in the current vote. This is determined by
  499. * the client list passed to NativeVotes_Display().
  500. *
  501. * @param client Client index.
  502. * @return True if client is allowed to vote, false otherwise.
  503. * @error If no vote is in progress or client index is invalid.
  504. */
  505. native bool:NativeVotes_IsClientInVotePool(client);
  506.  
  507. /**
  508. * Redraws the current vote to a client in the voting pool.
  509. *
  510. * @param client Client index.
  511. * @param revotes True to allow revotes, false otherwise.
  512. * @return True on success, false if the client is in the vote pool
  513. * but cannot vote again.
  514. * @error No vote in progress, client is not in the voting pool,
  515. * or client index is invalid.
  516. */
  517. native bool:NativeVotes_RedrawClientVote(client, bool:revotes=true);
  518.  
  519. /**
  520. * Retrieve the vote type
  521. *
  522. * @param vote NativeVotes Handle.
  523. * @return The built in vote type
  524. * @error Invalid Handle
  525. */
  526. native NativeVotesType:NativeVotes_GetType(Handle:vote);
  527.  
  528. /**
  529. * Set the team this vote is for, or NATIVEVOTES_ALL_TEAMS for all teams.
  530. *
  531. * Defaults to NATIVEVOTES_ALL_TEAMS if not explicitly set.
  532. *
  533. * @param vote NativeVotes Handle.
  534. * @param team Team number this vote is for
  535. * @noreturn
  536. * @error Invalid Handle
  537. */
  538. native NativeVotes_SetTeam(Handle:vote, team);
  539.  
  540. /**
  541. * Retrieve the team this vote is for
  542. *
  543. * @param vote NativeVotes Handle.
  544. * @return Team index or NATIVEVOTES_ALL_TEAMS for all teams.
  545. * @error Invalid Handle
  546. */
  547. native NativeVotes_GetTeam(Handle:vote);
  548.  
  549. /**
  550. * Set the client index of the player who initiated the vote.
  551. * Use NATIVEVOTES_SERVER_INDEX if initiated by the server itself.
  552. *
  553. * Defaults to NATIVEVOTES_SERVER_INDEX if not explicitly set.
  554. *
  555. * @param vote NativeVotes Handle.
  556. * @param client Client who initiated the vote or NATIVEVOTES_SERVER_INDEX
  557. * @noreturn
  558. * @error Invalid Handle
  559. */
  560. native NativeVotes_SetInitiator(Handle:vote, client);
  561.  
  562. /**
  563. * Retrieve the client index of the player who initiated the vote or NATIVEVOTES_SERVER_INDEX if
  564. * initiated by the server itself.
  565. *
  566. * @param Vote handle
  567. * @return Client index or NATIVEVOTES_SERVER_INDEX
  568. * @error Invalid Handle
  569. */
  570. native NativeVotes_GetInitiator(Handle:vote);
  571.  
  572. /**
  573. * Broadcasts a vote to a list of clients. The most selected item will be
  574. * returned through MenuAction_VoteEnd. On a tie, a random item will be returned
  575. * from a list of the tied items.
  576. *
  577. * Note that MenuAction_VoteStart, MenuAction_VoteCancel, MenuAction_VoteEnd, and MenuAction_End are all
  578. * default callbacks and do not need to be enabled.
  579. *
  580. * @param vote Vote Handle.
  581. * @param clients Array of clients to broadcast to.
  582. * @param numClients Number of clients in the array.
  583. * @param time Maximum time to leave menu on the screen.
  584. * @return True on success, false if a vote is already in progress.
  585. * @error Invalid Handle, or a vote is already in progress.
  586. */
  587. native bool:NativeVotes_Display(Handle:vote, clients[], numClients, time);
  588.  
  589. /**
  590. * Sends a vote menu to all clients. See NativeVotes_Display() for more information.
  591. *
  592. * @param vote Vote Handle.
  593. * @param time Maximum time to leave menu on the screen.
  594. * @return True on success, false if this menu already has a vote session
  595. * in progress.
  596. * @error Invalid Handle, or a vote is already in progress.
  597. */
  598. stock bool:NativeVotes_DisplayToAll(Handle:vote, time)
  599. {
  600. new total = 0;
  601. decl players[MaxClients];
  602.  
  603. for (new i=1; i<=MaxClients; i++)
  604. {
  605. if (!IsClientInGame(i) || IsFakeClient(i))
  606. {
  607. continue;
  608. }
  609. players[total++] = i;
  610. }
  611.  
  612. return NativeVotes_Display(vote, players, total, time);
  613. }
  614.  
  615. /**
  616. * Sends a vote menu to a single team. See NativeVotes_Display() for more information.
  617. *
  618. * @param vote Vote Handle.
  619. * @param team Team to send vote to. 1 = spectators, 2 = RED/Survivors/Terrorists, 3 = BLU/Infected/Counter-Terrorists
  620. * @param time Maximum time to leave menu on the screen.
  621. * @return True on success, false if this menu already has a vote session
  622. * in progress.
  623. * @error Invalid Handle, or a vote is already in progress.
  624. */
  625. stock bool:NativeVotes_DisplayToTeam(Handle:vote, team, time)
  626. {
  627. NativeVotes_SetTeam(vote, team);
  628.  
  629. new total;
  630. decl players[MaxClients];
  631.  
  632. for (new i=1; i<=MaxClients; i++)
  633. {
  634. if (!IsClientInGame(i) || IsFakeClient(i) || (GetClientTeam(i) != team))
  635. {
  636. continue;
  637. }
  638. players[total++] = i;
  639. }
  640.  
  641. return NativeVotes_Display(vote, players, total, time);
  642. }
  643.  
  644. /**
  645. * Sends a vote menu to all clients who are not spectators or waiting to choose a team. See NativeVotes_Display() for more information.
  646. *
  647. * @param vote Vote Handle.
  648. * @param time Maximum time to leave menu on the screen.
  649. * @return True on success, false if this menu already has a vote session
  650. * in progress.
  651. * @error Invalid Handle, or a vote is already in progress.
  652. */
  653. stock bool:NativeVotes_DisplayToAllNonSpectators(Handle:vote, time)
  654. {
  655. new total;
  656. decl players[MaxClients];
  657.  
  658. for (new i=1; i<=MaxClients; i++)
  659. {
  660. if (!IsClientInGame(i) || IsFakeClient(i) || (GetClientTeam(i) < 2))
  661. {
  662. continue;
  663. }
  664. players[total++] = i;
  665. }
  666.  
  667. return NativeVotes_Display(vote, players, total, time);
  668. }
  669.  
  670. /**
  671. * Display vote passed screen
  672. *
  673. * You MUST call one of the NativeVotesDisplayPass* or NativeVotes_DisplayFail functions
  674. * to hide the vote screen for users who didn't vote, and to clear out their selection
  675. * for the next vote.
  676. *
  677. * @param vote Vote handle
  678. * @param details Normally the item that won the vote or format string. Also used for custom vote winners
  679. * @param ... Variable number of format parameters.
  680. * @noreturn
  681. */
  682. native NativeVotes_DisplayPass(Handle:vote, const String:details[]="");
  683.  
  684. /**
  685. * Display vote passed screen with custom text to a single user
  686. *
  687. * You MUST call one of the NativeVotesDisplayPass* or NativeVotes_DisplayFail functions
  688. * to hide the vote screen for users who didn't vote, and to clear out their selection
  689. * for the next vote.
  690. *
  691. * @param vote Vote handle
  692. * @param client client to display to
  693. * @param format A format string.
  694. * @param any Variable number of format parameters
  695. * @noreturn
  696. */
  697. native NativeVotes_DisplayPassCustomToOne(Handle:vote, client, const String:format[], any:...);
  698.  
  699. /**
  700. * Display vote passed screen with custom text
  701. *
  702. * You MUST call one of the NativeVotesDisplayPass* or NativeVotes_DisplayFail functions
  703. * to hide the vote screen for users who didn't vote, and to clear out their selection
  704. * for the next vote.
  705. *
  706. * @param vote Vote handle
  707. * @param format A format string.
  708. * @param any Variable number of format parameters
  709. * @noreturn
  710. */
  711. stock NativeVotes_DisplayPassCustom(Handle:vote, const String:format[], any:...)
  712. {
  713. decl String:buffer[192];
  714.  
  715. for (new i = 1; i <= MaxClients; ++i)
  716. {
  717. if (IsClientInGame(i))
  718. {
  719. SetGlobalTransTarget(i);
  720. VFormat(buffer, sizeof(buffer), format, 3);
  721. NativeVotes_DisplayPassCustomToOne(vote, i, "%s", buffer);
  722. }
  723. }
  724. }
  725.  
  726. /**
  727. * Display vote passed screen with a custom type.
  728. *
  729. * A sample usage of this would be if Extend won an RTV vote: NativeVotes_DisplayPassEx(vote, NativeVotesPass_Extend, map);
  730. *
  731. * You MUST call one of NativeVotes_DisplayPass, NativeVotes_DisplayPassEx,
  732. * or NativeVotes_DisplayFail to hide the vote screen for users who didn't vote
  733. * and to clear out their selection for the next vote.
  734. *
  735. * #param vote Vote handle
  736. * @param passType The pass screen to display
  737. * @param details Normally the item that won the vote. Also used for custom vote winners
  738. * @noreturn
  739. */
  740. native NativeVotes_DisplayPassEx(Handle:vote, NativeVotesPassType:passType, const String:details[]="");
  741.  
  742. /**
  743. * Display failure screen.
  744. *
  745. * You MUST call one of NativeVotes_DisplayPass, NativeVotes_DisplayPassEx,
  746. * or NativeVotes_DisplayFail to hide the vote screen for users who didn't vote,
  747. * and to clear out their selection for the next vote.
  748. *
  749. * @param reason Vote failure reason from NativeVotesFailType enum
  750. * @noreturn
  751. */
  752. native NativeVotes_DisplayFail(Handle:vote, NativeVotesFailType:reason=NativeVotesFail_Generic);
  753.  
  754. /**
  755. * Quick stock to determine whether voting is allowed. This doesn't let you
  756. * fine-tune a reason for not voting, so it's not recommended for lazily
  757. * telling clients that voting isn't allowed.
  758. *
  759. * @return True if voting is allowed, false if voting is in progress
  760. * or the cooldown is active.
  761. */
  762. stock bool:NativeVotes_IsNewVoteAllowed()
  763. {
  764. if (NativeVotes_IsVoteInProgress() || NativeVotes_CheckVoteDelay() != 0)
  765. {
  766. return false;
  767. }
  768.  
  769. return true;
  770. }
  771.  
  772. /**
  773. * Used when callvote is called with no arguments.
  774. *
  775. * This is used to configure the VoteSetup usermessage on TF2 and CS:GO
  776. *
  777. * @param client Client, in case the votes are restricted by client
  778. * @param voteTypes Populate this array with the vote types this server supports
  779. * Custom and multiple choice votes are not supported from
  780. * the GUI and are thus ignored.
  781. * @return Plugin_Continue to allow the server itself (or another plugin) to process the callvote
  782. * Plugin_Changed if you're changing the voteTypes,
  783. * Plugin_Handled to return a blank VoteSetup usermessage
  784. * Plugin_Stop to prevent VoteSetup usermessage (not recommended)
  785. */
  786. //functag public Action:NativeVotes_CallVoteSetupHandler(client, NativeVotesType:voteTypes[]);
  787.  
  788. /**
  789. * Forward for "callvote" handling
  790. *
  791. * You should respond to this by starting a vote or by calling NativeVotes_DisplayCallVoteFail
  792. *
  793. * @param client Client
  794. * @param voteType Type of vote being called. This will NEVER be a multiple-choice or custom vote.
  795. * @param voteArgument Vote argument or blank if the vote type has no argument.
  796. * @param target target userid for kick votes or 0 for all other votes
  797. * @return Plugin_Continue to allow the server itself (or another plugin) to process the callvote
  798. * Plugin_Handled if you processed this vote type
  799. * Plugin_Stop to block the vote type (not recommended)
  800. */
  801. //functag public Action:NativeVotes_CallVoteHandler(client, NativeVotesType:voteType, const String:voteArgument[], target);
  802.  
  803. /**
  804. * Register a plugin as a vote manager.
  805. * This is used to abstract away the details of the callvote command.
  806. *
  807. * @param callHandler Handler for callvote commands.
  808. * @param setupHandler Handler to override the which vote types your server supports. Only useful on TF2 and CS:GO.
  809. * @noreturn
  810. */
  811. //native NativeVotes_RegisterVoteManager(NativeVotes_CallVoteHandler:callHandler, NativeVotes_CallVoteSetupHandler:setupHandler=INVALID_FUNCTION);
  812.  
  813. /**
  814. * Send a call vote fail screen to a user
  815. * Used to respond to a callvote with invalid arguments or for other reasons
  816. * (such as trying to target an admin for a kick/ban vote)
  817. *
  818. * @param client The client to display the fail screen to
  819. * @param reason A vote call fail reason
  820. * @param time For NativeVotesCallFail_Recent, the number of seconds until the vote
  821. * can be called again
  822. */
  823. native NativeVotes_DisplayCallVoteFail(client, NativeVotesCallFailType:reason, time);
  824.  
  825. /**
  826. * Redraws the vote title from inside a MenuAction_Display callback
  827. * Not supported on L4D
  828. *
  829. * @param text Vote title to draw
  830. * @error If called from outside MenuAction_Display
  831. * @return Plugin_Changed if the change is allowed, Plugin_Continue if it isn't.
  832. */
  833. native Action:NativeVotes_RedrawVoteTitle(const String:text[]);
  834.  
  835. /**
  836. * Redraws the vote text from inside a MenuAction_DisplayItem callback.
  837. * Only supported on multiple-choice votes
  838. *
  839. * @param text Vote text to draw.
  840. * @error If called from outside MenuAction_DisplayItem
  841. * @return Plugin_Changed if the change is allowed, Plugin_Continue if it isn't.
  842. */
  843. native Action:NativeVotes_RedrawVoteItem(const String:text[]);
  844.  
  845. /**
  846. * Retrieves voting information from MenuAction_VoteEnd.
  847. *
  848. * @param param2 Second parameter of MenuAction_VoteEnd.
  849. * @param winningVotes Number of votes received by the winning option.
  850. * @param totalVotes Number of total votes received.
  851. * @noreturn
  852. */
  853. stock NativeVotes_GetInfo(param2, &winningVotes, &totalVotes)
  854. {
  855. winningVotes = param2 & 0xFFFF;
  856. totalVotes = param2 >> 16;
  857. }
  858.  
  859. /**
  860. * Do not edit below this line!
  861. */
  862. public SharedPlugin:__pl_nativevotes =
  863. {
  864. name = "nativevotes",
  865. file = "nativevotes.smx",
  866. #if defined REQUIRE_PLUGINS
  867. required = 1,
  868. #else
  869. required = 0,
  870. #endif
  871. };
  872.  
  873. public __pl_nativevotes_SetNTVOptional()
  874. {
  875. MarkNativeAsOptional("NativeVotes_IsVoteTypeSupported");
  876. MarkNativeAsOptional("NativeVotes_Create");
  877. MarkNativeAsOptional("NativeVotes_Close");
  878. MarkNativeAsOptional("NativeVotes_AddItem");
  879. MarkNativeAsOptional("NativeVotes_InsertItem");
  880. MarkNativeAsOptional("NativeVotes_RemoveItem");
  881. MarkNativeAsOptional("NativeVotes_RemoveAllItems");
  882. MarkNativeAsOptional("NativeVotes_GetItem");
  883. MarkNativeAsOptional("NativeVotes_GetItemCount");
  884. MarkNativeAsOptional("NativeVotes_SetDetails");
  885. MarkNativeAsOptional("NativeVotes_GetDetails");
  886. MarkNativeAsOptional("NativeVotes_SetTitle");
  887. MarkNativeAsOptional("NativeVotes_GetTitle");
  888. MarkNativeAsOptional("NativeVotes_SetTarget");
  889. MarkNativeAsOptional("NativeVotes_GetTarget");
  890. MarkNativeAsOptional("NativeVotes_GetTargetSteam");
  891. MarkNativeAsOptional("NativeVotes_IsVoteInProgress");
  892. MarkNativeAsOptional("NativeVotes_GetMaxItems");
  893. MarkNativeAsOptional("NativeVotes_SetOptionFlags");
  894. MarkNativeAsOptional("NativeVotes_GetOptionFlags");
  895. MarkNativeAsOptional("NativeVotes_Cancel");
  896. MarkNativeAsOptional("NativeVotes_SetResultCallback");
  897. MarkNativeAsOptional("NativeVotes_CheckVoteDelay");
  898. MarkNativeAsOptional("NativeVotes_IsClientInVotePool");
  899. MarkNativeAsOptional("NativeVotes_RedrawClientVote");
  900. MarkNativeAsOptional("NativeVotes_RedrawClientVote");
  901. MarkNativeAsOptional("NativeVotes_GetType");
  902. MarkNativeAsOptional("NativeVotes_SetTeam");
  903. MarkNativeAsOptional("NativeVotes_GetTeam");
  904. MarkNativeAsOptional("NativeVotes_SetInitiator");
  905. MarkNativeAsOptional("NativeVotes_GetInitiator");
  906. MarkNativeAsOptional("NativeVotes_Display");
  907. MarkNativeAsOptional("NativeVotes_DisplayPass");
  908. MarkNativeAsOptional("NativeVotes_DisplayPassCustomToOne");
  909. MarkNativeAsOptional("NativeVotes_DisplayPassEx");
  910. MarkNativeAsOptional("NativeVotes_DisplayFail");
  911. MarkNativeAsOptional("NativeVotes_RegisterVoteManager");
  912. MarkNativeAsOptional("NativeVotes_DisplayCallVoteFail");
  913. MarkNativeAsOptional("NativeVotes_RedrawVoteTitle");
  914. MarkNativeAsOptional("NativeVotes_RedrawVoteItem");
  915. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement