* add vote.inc (wip)

* rename boxing
This commit is contained in:
Lorenc 2018-03-26 00:02:19 +11:00
parent 7a87da3873
commit d446a98d07
2 changed files with 382 additions and 69 deletions

View File

@ -22,7 +22,6 @@
/* ENUMS */ /* ENUMS */
enum E_BOXER_DATA { enum E_BOXER_DATA {
E_ACCOUNT_ID,
E_WINS, E_WINS,
E_LOSSES, E_LOSSES,
E_TOTAL_FIGHTS, E_TOTAL_FIGHTS,
@ -51,15 +50,27 @@ new g_boxingArenaData[ E_ARENA_DATA ];
new g_boxingArenaObjects[ 9 ]; new g_boxingArenaObjects[ 9 ];
public OnPlayerConnect( playerid ) { public OnPlayerConnect( playerid ) {
g_boxingMatchData[ playerid ][ E_FIGHTING ] = false;
Boxing_SetValues( playerid ); g_boxingMatchData[ playerid ][ E_OPPONENT ] = -1;
g_boxingMatchData[ playerid ][ E_INVITED ] = false;
g_boxingMatchData[ playerid ][ E_ROUNDS_SET ] = 1;
g_boxingMatchData[ playerid ][ E_BET_AMOUNT_SET ] = 0;
g_boxingMatchData[ playerid ][ E_IS_HOST ] = false;
g_boxingMatchData[ playerid ][ E_SCORE ] = 0;
} }
public OnPlayerDisconnect( playerid, reason ) { public OnPlayerDisconnect( playerid, reason ) {
g_boxingMatchData[ playerid ][ E_WINS ] = 0;
Boxing_ResetValues( playerid ); g_boxingMatchData[ playerid ][ E_LOSSES ] = 0;
g_boxingMatchData[ playerid ][ E_TOTAL_FIGHTS ] = 0;
g_boxingMatchData[ playerid ][ E_FIGHTING ] = false;
g_boxingMatchData[ playerid ][ E_OPPONENT ] = -1;
g_boxingMatchData[ playerid ][ E_INVITED ] = false;
g_boxingMatchData[ playerid ][ E_INVITE_TIMER ] = 0;
g_boxingMatchData[ playerid ][ E_ROUNDS_SET ] = 1;
g_boxingMatchData[ playerid ][ E_BET_AMOUNT_SET ] = 0;
g_boxingMatchData[ playerid ][ E_IS_HOST ] = false;
g_boxingMatchData[ playerid ][ E_SCORE ] = 0;
} }
/* BOXING COMMANDS */ /* BOXING COMMANDS */
@ -279,7 +290,6 @@ stock ResetBoxingPlayerVariables( playerid, targetID ) {
g_boxingMatchData[ targetID ][ E_FIGHTING ] = false; g_boxingMatchData[ targetID ][ E_FIGHTING ] = false;
g_boxingMatchData[ targetID ][ E_SCORE ] = 0; g_boxingMatchData[ targetID ][ E_SCORE ] = 0;
TogglePlayerControllable( targetID, 1 ); TogglePlayerControllable( targetID, 1 );
return true; return true;
} }
@ -294,8 +304,7 @@ stock ResetBoxingArenaVariables() {
} }
forward KillInviteTimer( playerid ); function KillInviteTimer( playerid ) {
public KillInviteTimer( playerid ) {
new opponent = g_boxingMatchData[ playerid ][ E_OPPONENT ]; new opponent = g_boxingMatchData[ playerid ][ E_OPPONENT ];
@ -311,10 +320,8 @@ public KillInviteTimer( playerid ) {
} }
/* MATCH FUNCTIONS */ /* ** Functions ** */
function StartMatch( playerid, targetID ) {
forward StartMatch( playerid, targetID );
public StartMatch( playerid, targetID ) {
if ( g_boxingMatchData[ playerid ][ E_FIGHTING ] == true && g_boxingMatchData[ playerid ][ E_FIGHTING ] ) { if ( g_boxingMatchData[ playerid ][ E_FIGHTING ] == true && g_boxingMatchData[ playerid ][ E_FIGHTING ] ) {
@ -356,20 +363,16 @@ public StartMatch( playerid, targetID ) {
} }
forward NextRound( playerid, targetID ); function NextRound( playerid, targetID ) {
public NextRound( playerid, targetID ) {
SetBoxingPlayerConfig( playerid, targetID ); SetBoxingPlayerConfig( playerid, targetID );
KillTimer( g_boxingArenaData[ E_CD_TIMER ] ); KillTimer( g_boxingArenaData[ E_CD_TIMER ] );
g_boxingArenaData[ E_CD_TIMER ] = SetTimerEx( "boxingCountDown", 960, false, "d", 8 ); g_boxingArenaData[ E_CD_TIMER ] = SetTimerEx( "boxingCountDown", 960, false, "d", 8 );
return true; return true;
} }
forward EndMatch( playerid, targetID ); function EndMatch( playerid, targetID ) {
public EndMatch( playerid, targetID ) {
if ( g_boxingArenaData[ E_BET ] == 0 ) { if ( g_boxingArenaData[ E_BET ] == 0 ) {
@ -411,8 +414,7 @@ public EndMatch( playerid, targetID ) {
} }
forward ForfeitMatch( playerid, targetID ); function ForfeitMatch( playerid, targetID ) {
public ForfeitMatch( playerid, targetID ) {
if ( g_boxingArenaData[ E_BET ] == 0 ) { if ( g_boxingArenaData[ E_BET ] == 0 ) {
@ -444,8 +446,7 @@ public ForfeitMatch( playerid, targetID ) {
} }
forward SetBoxingPlayerConfig( playerid, targetID ); function SetBoxingPlayerConfig( playerid, targetID ) {
public SetBoxingPlayerConfig( playerid, targetID ) {
SetPlayerPos( playerid, 2238.29, 1679.2426, 1009.188 ); SetPlayerPos( playerid, 2238.29, 1679.2426, 1009.188 );
SetPlayerPos( targetID, 2234.3279, 1675.3125, 1009.188 ); SetPlayerPos( targetID, 2234.3279, 1675.3125, 1009.188 );
@ -472,8 +473,7 @@ public SetBoxingPlayerConfig( playerid, targetID ) {
} }
forward boxingCountDown( time ); function boxingCountDown( time ) {
public boxingCountDown( time ) {
if ( !time ) { if ( !time ) {
@ -517,7 +517,7 @@ public boxingCountDown( time ) {
/* ONPLAYER GIVE/TAKE DAMAGE HANDLING */ /* ONPLAYER GIVE/TAKE DAMAGE HANDLING */
public OnPlayerTakeDamage( playerid, issuerid, Float:amount, weaponid, bodypart ) { hook OnPlayerTakeDamage( playerid, issuerid, Float:amount, weaponid, bodypart ) {
if ( g_boxingMatchData[ playerid ][ E_FIGHTING ] == true ) { if ( g_boxingMatchData[ playerid ][ E_FIGHTING ] == true ) {
@ -670,48 +670,6 @@ stock DestroyBoxingArena() {
} }
/* MYSQL PLAYER RELATED */
stock Boxing_SetValues( playerid ) {
// TODO: player variable setting
g_boxingMatchData[ playerid ][ E_ACCOUNT_ID ] = playerid;
// ^ so it doesn't spit a warning
g_boxingMatchData[ playerid ][ E_FIGHTING ] = false;
g_boxingMatchData[ playerid ][ E_OPPONENT ] = -1;
g_boxingMatchData[ playerid ][ E_INVITED ] = false;
g_boxingMatchData[ playerid ][ E_ROUNDS_SET ] = 1;
g_boxingMatchData[ playerid ][ E_BET_AMOUNT_SET ] = 0;
g_boxingMatchData[ playerid ][ E_IS_HOST ] = false;
g_boxingMatchData[ playerid ][ E_SCORE ] = 0;
}
stock Boxing_SaveValues( playerid ) {
// TODO: player variable saving
g_boxingMatchData[ playerid ][ E_ACCOUNT_ID ] = playerid;
// ^ so it doesn't spit a warning
}
stock Boxing_ResetValues( playerid ) {
g_boxingMatchData[ playerid ][ E_ACCOUNT_ID ] = -1;
g_boxingMatchData[ playerid ][ E_WINS ] = 0;
g_boxingMatchData[ playerid ][ E_LOSSES ] = 0;
g_boxingMatchData[ playerid ][ E_TOTAL_FIGHTS ] = 0;
g_boxingMatchData[ playerid ][ E_FIGHTING ] = false;
g_boxingMatchData[ playerid ][ E_OPPONENT ] = -1;
g_boxingMatchData[ playerid ][ E_INVITED ] = false;
g_boxingMatchData[ playerid ][ E_INVITE_TIMER ] = 0;
g_boxingMatchData[ playerid ][ E_ROUNDS_SET ] = 1;
g_boxingMatchData[ playerid ][ E_BET_AMOUNT_SET ] = 0;
g_boxingMatchData[ playerid ][ E_IS_HOST ] = false;
g_boxingMatchData[ playerid ][ E_SCORE ] = 0;
return 1;
}
/* MESSAGE FUNCTIONS */ /* MESSAGE FUNCTIONS */
stock SendBoxingGlobal( string[] ) { stock SendBoxingGlobal( string[] ) {

View File

@ -0,0 +1,355 @@
/*
* Irresistible Gaming (c) 2018
* Developed by Cloudy
* Module: vote.inc
* Purpose: vote system for individuals
*/
/* ** Includes ** */
#include < YSI\y_hooks >
/* ** Definitions ** */
#define DIALOG_VOTE_CONFIG 5671
#define DIALOG_VOTE_QUESTION 5672
#define DIALOG_VOTE_ADDOPTION 5673
#define DIALOG_VOTE_EDITOPTION 5674
/* ** Variables ** */
new bool: v_started;
new v_question [ 80 ]; //// the vote question content
new v_option [ 5 ] [ 50 ]; //// five options max
new v_option_votes [ 5 ]; //// Stores the votes of each option.
new v_voted [ MAX_PLAYERS ]; //// This will have the accounts ID's of the voters, to prevent voting more than once.
new Text: v_TD_Question;
new Text: v_TD_Option [ 5 ];
/* ** Hooks ** */
hook OnGameModeInit( )
{
ResetVoteAll( );
LoadVotingTextdraws( );
return 1;
}
hook OnPlayerText( playerid, text[ ] )
{
if( !v_started || GetPlayerAccountID( playerid ) <= 0 ) return 1; /// no poll or player isn't logged in.
new option;
if( !sscanf( text, "i", option ) ) {
if( ( 1 <= option <= 5 ) && strcmp( v_option[ option-1 ], "n/a", true ) ) {
if( !didPlayerVote( playerid ) ) {
new string[ 128 ];
AddPlayerVote( playerid, option-1 );
format( string, sizeof( string ), "{C0C0C0}[SERVER]{FFFFFF} Your vote has been added: {C0C0C0}%d", option );
SendClientMessage( playerid, -1, string );
return 0;
}
}
}
return 1;
}
#if defined AC_INCLUDED
hook OnPlayerDeathEx( playerid, killerid, reason, Float: damage, bodypart )
#else
hook OnPlayerDeath( playerid, killerid, reason )
#endif
{
HideVoteTextdrawsForPlayer( playerid );
return 1;
}
hook OnPlayerSpawn( playerid )
{
ShowVoteTextdrawsForPlayer( playerid );
return 1;
}
hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[ ] )
{
if( dialogid == DIALOG_VOTE_CONFIG && response ) {
if( GetPlayerAdminLevel( playerid ) >= 4 ) {
if( listitem == 0 )
ShowPlayerDialog( playerid, DIALOG_VOTE_QUESTION, DIALOG_STYLE_INPUT, "{FFFFFF}Vote Settings - Set Question", "{FFFFFF}Write the question you want to vote for:", "Set", "Back" );
else if( !strcmp( inputtext, "Add a new option", true, 16 ) )
ShowPlayerDialog( playerid, DIALOG_VOTE_ADDOPTION, DIALOG_STYLE_INPUT, "{FFFFFF}Vote Settings - Add Option", "{FFFFFF}Write the option you want to add:", "Add", "Back" );
else {
new optionid = strval( inputtext[ 0 ] ) - 1;
SetPVarInt( playerid, "p_VoteEditOption", optionid );
ShowPlayerDialog( playerid, DIALOG_VOTE_EDITOPTION, DIALOG_STYLE_INPUT, "{FFFFFF}Vote Settings - Edit Option", "{FFFFFF}Enter the text you want to set the option to:", "Update", "Back" );
}
}
}
else if( dialogid == DIALOG_VOTE_QUESTION ) {
if( GetPlayerAdminLevel( playerid ) >= 4 )
return SendError( playerid, "You don't have an appropriate administration level to use this feature." );
if( response ) {
if( !strlen( inputtext ) )
ShowPlayerDialog( playerid, DIALOG_VOTE_QUESTION, DIALOG_STYLE_INPUT, "{FFFFFF}Vote Settings - Set Question", "{FFFFFF}Write the question you want to vote for:\n\n{FF0000}Invalid question", "Set", "Back" );
else {
format( v_question, sizeof( v_question ), inputtext );
if( v_started ) updateQuestionTD( );
ShowVoteConfig( playerid );
}
}
}
else if( dialogid == DIALOG_VOTE_ADDOPTION ) {
if( GetPlayerAdminLevel( playerid ) >= 4 )
if( response ) {
if( v_started ) {
SendClientMessage( playerid, -1, "{FF0000}[ERROR]{FFFFFF} You cannot edit options while poll is on." );
ShowVoteConfig( playerid );
return 1;
}
if( !strlen( inputtext ) )
ShowPlayerDialog( playerid, DIALOG_VOTE_ADDOPTION, DIALOG_STYLE_INPUT, "{FFFFFF}Vote Settings - Add Option", "{FFFFFF}Write the option you want to add:\n\n{FF0000}Invalid text", "Add", "Back" );
else {
if( getNextOptionID( ) != -1 ) {
format( v_option[ getNextOptionID( ) ], 50, inputtext );
SendClientMessage(playerid, -1, "{C0C0C0}[VOTE]{FFFFFF} You've added a new option." );
}
else
SendClientMessage(playerid, -1, "{FF0000}[ERROR]{FFFFFF} You can have a maximum of 5 options." );
ShowVoteConfig( playerid );
}
}
else if( !response )
ShowVoteConfig( playerid );
}
else if( dialogid == DIALOG_VOTE_EDITOPTION ) {
if( GetPlayerAdminLevel( playerid ) >= 4 )
if( response ) {
if( v_started ) {
SendClientMessage( playerid, -1, "{FF0000}[ERROR]{FFFFFF} You cannot edit options while poll is on." );
ShowVoteConfig( playerid );
return 1;
}
if( !strlen( inputtext ) )
ShowPlayerDialog( playerid, DIALOG_VOTE_EDITOPTION, DIALOG_STYLE_INPUT, "{FFFFFF}Vote Settings - Edit Option", "{FFFFFF}Enter the text you want to set the option to:\n\n{FF0000}Invalid text", "Update", "Back" );
else {
new optionid = GetPVarInt( playerid, "p_VoteEditOption" );
format( v_option[ optionid ], 50, inputtext );
SendClientMessage(playerid, -1, "{C0C0C0}[VOTE]{FFFFFF} You've updated an option." );
ShowVoteConfig( playerid );
}
}
else if( !response )
ShowVoteConfig( playerid );
}
return 1;
}
stock ResetVoteAll( )
{
v_question = "n/a";
for( new i = 0; i < 5; i++ ) v_option[ i ] = "n/a";
ResetVotes( );
endVote( );
}
stock ResetVotes( )
{
for( new i = 0; i < MAX_PLAYERS; i++ ) v_voted[ i ] = -1;
for( new i = 0; i < 5; i++ ) v_option_votes[ i ] = 0;
}
stock startVote( )
{
v_started = true;
ResetVotes( );
updateAllVote( );
ShowVoteTextdrawsForAll( );
}
stock endVote( )
{
HideVoteTextdrawsForAll( );
v_started = false;
ResetVotes( );
}
stock updateOptionTD( option )
{
if( strcmp( v_option[ option ], "n/a" ) ) {
new string[128];
format(string, sizeof(string), "%i. (%d) %s", option+1, v_option_votes[ option ], v_option[ option ] );
TextDrawSetString( v_TD_Option[ option ], string );
}
else TextDrawSetString( v_TD_Option[ option ], " " );
}
stock updateQuestionTD( )
{
new question[ 80 ];
format( question, sizeof( question ), "~y~POLL: ~w~~h~%s", v_question );
TextDrawSetString( v_TD_Question, question );
}
stock updateAllVote( )
{
updateQuestionTD( );
for( new i = 0; i < 5; i++ )
updateOptionTD( i );
}
stock ShowVoteConfig( playerid )
{
reorderOptions( );
new finalstring[ 600 ];
format( finalstring, sizeof( finalstring ), "{C0C0C0}QUESTION: {FFFFFF}%s\n", v_question);
new c_options = 0;
for( new i = 0; i < 5; i++ ) if( strcmp( v_option[ i ], "n/a", true ) ) {
format( finalstring, sizeof( finalstring ), "%s{C0C0C0}%i. {FFFFFF}%s\n", finalstring, i+1, v_option[ i ] );
c_options++;
}
if(c_options < 5)
format( finalstring, sizeof( finalstring ), "%s{FFFFFF}Add a new option..", finalstring );
ShowPlayerDialog( playerid, DIALOG_VOTE_CONFIG, DIALOG_STYLE_LIST, "{FFFFFF}Vote Settings", finalstring, "Select", "Close" );
}
stock reorderOptions( ) /// This thing, is to re-order options, like if there is option 1, 2 and 3, and I remove option 2, then option 3 will come in place of option 2.
{
for( new i = 0; i < 5; i++ ) {
if( i + 1 < 5 )
if( !strcmp( v_option[ i ], "n/a" ) && strcmp( v_option[ i+1 ], "n/a" ) ) {
v_option[ i ] = v_option[ i+1 ];
v_option_votes[ i ] = v_option_votes[ i+1 ];
v_option[ i+1 ] = "n/a";
v_option_votes[ i+1 ] = 0;
}
}
}
stock getNextOptionID( )
{
for( new i = 0; i < 5; i++ ) if( !strcmp( v_option[ i ], "n/a" ) ) {
return i;
}
return -1;
}
stock didPlayerVote( playerid )
{
for( new i = 0; i < MAX_PLAYERS; i++ ) if( v_voted[ i ] == GetPlayerAccountID( playerid ) ) {
return true;
}
return false;
}
stock AddPlayerVote( playerid, option )
{
for( new i = 0; i < MAX_PLAYERS; i++ ) {
if( v_voted[ i ] == -1 ) {
v_voted[ i ] = GetPlayerAccountID( playerid );
v_option_votes[ option ]++;
updateOptionTD( option );
break;
}
}
}
stock LoadVotingTextdraws( )
{
v_TD_Question = TextDrawCreate( 16.000000, 168.000000, "POLL: Who's the best player here?" );
TextDrawBackgroundColor( v_TD_Question, 255 );
TextDrawFont( v_TD_Question, 1 );
TextDrawLetterSize( v_TD_Question, 0.200000, 1.100000 );
TextDrawColor( v_TD_Question, -1 );
TextDrawSetOutline( v_TD_Question, 1 );
TextDrawSetProportional( v_TD_Question, 1 );
TextDrawSetSelectable( v_TD_Question, 0 );
new Float: td_y_temp = 182.000000;
for( new i = 0; i < 5; i++ ) {
v_TD_Option[ i ] = TextDrawCreate( 16.000000, td_y_temp, "1. (35) Cloudy" );
TextDrawBackgroundColor( v_TD_Option[ i ], 255 );
TextDrawFont( v_TD_Option[ i ], 1);
TextDrawLetterSize( v_TD_Option[ i ], 0.200000, 1.100000 );
TextDrawColor( v_TD_Option[ i ], -1 );
TextDrawSetOutline( v_TD_Option[ i ], 1 );
TextDrawSetProportional( v_TD_Option[ i ], 1 );
TextDrawSetSelectable( v_TD_Option[ i ], 0 );
td_y_temp += 11.0;
}
}
stock ShowVoteTextdrawsForPlayer( playerid )
{
if( v_started ) {
TextDrawShowForPlayer( playerid, v_TD_Question );
for( new i = 0; i < 5; i++ ) {
if( strcmp( v_option[ i ], "n/a" ) ) TextDrawShowForPlayer( playerid, v_TD_Option[ i ] );
else TextDrawHideForPlayer( playerid, v_TD_Option[ i ] );
}
}
}
stock HideVoteTextdrawsForPlayer( playerid )
{
if( v_started ) {
TextDrawHideForPlayer( playerid, v_TD_Question );
for( new i = 0; i < 5; i++ ) {
TextDrawHideForPlayer( playerid, v_TD_Option[ i ] );
}
}
}
stock ShowVoteTextdrawsForAll( ) {
if( v_started ) {
TextDrawShowForAll( v_TD_Question );
for( new i = 0; i < 5; i++ ) {
if( strcmp( v_option[ i ], "n/a" ) ) TextDrawShowForAll( v_TD_Option[ i ] );
else TextDrawHideForAll( v_TD_Option[ i ] );
}
}
}
stock HideVoteTextdrawsForAll( ) {
if( v_started ) {
TextDrawHideForAll( v_TD_Question );
for( new i = 0; i < 5; i++ ) TextDrawHideForAll( v_TD_Option[ i ] );
}
}
/* ** Commands **/
CMD:vote( playerid, params[ ] )
{
if( GetPlayerAdminLevel( playerid ) < 4 )
return SendClientMessage( playerid, -1, "{FF0000}[ERROR]{FFFFFF} You don't have an appropriate administration level to use this command." );
if( !strcmp( params, "start", true, 5 ) ) {
if( !strcmp( v_question, "n/a" ) )
return SendClientMessage( playerid, -1, "{FF0000}[ERROR]{FFFFFF} You have not set a question for the vote." );
startVote( );
new string[ 128 ];
format( string, sizeof( string ), "{FF0770}[ADMIN]{FFFFFF} %s(%d) has started a new poll.", ReturnPlayerName( playerid ), playerid );
SendClientMessageToAll( -1, string );
}
else if( !strcmp( params, "end", true, 3 ) ) {
if( !v_started )
return SendClientMessage( playerid, -1, "{FF0000}[ERROR]{FFFFFF} There are no poll to end." );
endVote( );
new string[ 128 ];
format( string, sizeof( string ), "{FF0770}[ADMIN]{FFFFFF} %s(%d) has ended the poll.", ReturnPlayerName( playerid ), playerid );
SendClientMessageToAll( -1, string );
}
else if( !strcmp( params, "reset", true, 5 ) ) {
if( v_started ) SendClientMessageToAll( -1, sprintf( "{FF0770}[ADMIN]{FFFFFF} %s(%d) has ended the poll.", ReturnPlayerName( playerid ), playerid ) );
ResetVoteAll();
SendClientMessage( playerid, -1, "{C0C0C0}[VOTE]{FFFFFF} You have reset vote parameters." );
}
else if( !strcmp( params, "config", true, 6 ) ) {
ShowVoteConfig( playerid );
}
else SendUsage( playerid, "/vote [RESET/START/END/CONFIG]" );
return 1;
}