2018-09-09 16:01:29 +00:00
/*
2018-09-10 19:00:02 +00:00
* Irresistible Gaming (c) 2018
2019-05-31 16:24:06 +00:00
* Developed by Stev
2018-09-10 19:00:02 +00:00
* Module: cnr/features/duel.pwn
2019-05-31 16:24:06 +00:00
* Purpose: player dueling system
2018-09-10 19:00:02 +00:00
*/
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
/* ** Includes ** */
#include < YSI\y_hooks >
2018-09-09 16:01:29 +00:00
/* ** Definitions ** */
#define COL_DUEL "{B74AFF}"
2018-09-10 19:00:02 +00:00
2018-09-09 16:01:29 +00:00
/* ** Variables ** */
2018-09-10 19:00:02 +00:00
enum E_DUEL_DATA
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
E_PLAYER, E_WEAPON[ 2 ], E_BET,
Float: E_ARMOUR, Float: E_HEALTH, E_COUNTDOWN,
E_TIMER, E_LOCATION_ID, E_ROUNDS,
2019-05-31 16:41:51 +00:00
bool: E_CAC
2018-09-09 16:01:29 +00:00
};
2018-09-10 19:00:02 +00:00
enum E_DUEL_LOCATION_DATA
2018-09-09 16:01:29 +00:00
{
2019-05-31 16:24:06 +00:00
E_NAME [ 22 ], Float: E_POS_ONE[ 3 ], Float: E_POS_TWO[ 3 ]
2018-09-09 16:01:29 +00:00
};
2018-09-16 06:05:27 +00:00
new
2018-09-10 19:00:02 +00:00
Float: g_DuelCoordinates [ 3 ] = { -2226.1938, 251.9206, 35.3203 },
g_WeaponList [ ] = { 0, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 },
g_duelData [ MAX_PLAYERS ][ E_DUEL_DATA ],
g_duelLocationData [ ][ E_DUEL_LOCATION_DATA ] =
2018-09-16 06:05:27 +00:00
{
2019-05-31 16:24:06 +00:00
{ "Santa Maria Beach", { 369.75770, -1831.576, 7.67190 }, { 369.65890, -1871.215, 7.67190 } },
{ "Greenglass College", { 1078.0353, 1084.4989, 10.8359 }, { 1095.4019, 1064.7239, 10.8359 } },
{ "Baseball Arena", { 1393.0995, 2177.4585, 9.75780 }, { 1377.7881, 2195.4214, 9.75780 } },
{ "Mount Chilliad", { -2318.471, -1632.880, 483.703 }, { -2329.174, -1604.657, 483.760 } },
{ "The Farm", { -1044.856, -996.8120, 129.218 }, { -1125.599, -996.7523, 129.218 } },
{ "Tennis Courts", { 755.93790, -1280.710, 13.5565 }, { 755.93960, -1238.688, 13.5516 } },
{ "Underwater World", { 520.59600, -2125.663, -28.257 }, { 517.96600, -2093.610, -28.257 } },
{ "Grove Street", { 2476.4580, -1668.631, 13.3249 }, { 2501.1560, -1667.655, 13.3559 } },
{ "Ocean Docks", { 2683.5440, -2485.137, 13.5425 }, { 2683.8470, -2433.726, 13.5553 } },
{ "Gacia Baseball Ground", { -2305.7549, 92.3505, 35.3516 }, { -2322.0908, 108.5021, 35.3984 } }
2018-09-09 16:01:29 +00:00
},
2018-09-24 21:21:20 +00:00
2018-09-10 19:00:02 +00:00
bool: p_playerDueling [ MAX_PLAYERS char ],
p_duelInvitation [ MAX_PLAYERS ][ MAX_PLAYERS ],
2018-09-09 16:01:29 +00:00
g_DuelCheckpoint = -1
;
/* ** Hooks ** */
2018-09-24 21:21:20 +00:00
hook OnScriptInit( )
2018-09-09 16:01:29 +00:00
{
2018-09-24 21:21:20 +00:00
CreateDynamicMapIcon( g_DuelCoordinates[ 0 ], g_DuelCoordinates[ 1 ], g_DuelCoordinates[ 2 ], 23, 0, -1, -1, -1, 750.0 );
g_DuelCheckpoint = CreateDynamicCP( g_DuelCoordinates[ 0 ], g_DuelCoordinates[ 1 ], g_DuelCoordinates[ 2 ], 1.5, 0, 0, -1 );
CreateDynamic3DTextLabel( ""COL_GOLD"[DUEL PLAYER]", -1, g_DuelCoordinates[ 0 ], g_DuelCoordinates[ 1 ], g_DuelCoordinates[ 2 ], 25.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, 0, 0, -1 );
2018-12-12 08:21:57 +00:00
2018-09-09 16:01:29 +00:00
return 1;
}
2018-09-10 19:00:02 +00:00
hook OnPlayerConnect( playerid )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
p_playerDueling{ playerid } = false;
g_duelData[ playerid ][ E_PLAYER ] = INVALID_PLAYER_ID;
g_duelData[ playerid ][ E_WEAPON ][ 0 ] = 0;
g_duelData[ playerid ][ E_WEAPON ][ 1 ] = 0;
g_duelData[ playerid ][ E_HEALTH ] = 100.0;
g_duelData[ playerid ][ E_ARMOUR ] = 100.0;
g_duelData[ playerid ][ E_BET ] = 0;
2018-09-09 16:01:29 +00:00
return 1;
}
2018-09-10 19:00:02 +00:00
hook OnPlayerDisconnect( playerid, reason )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
forfeitPlayerDuel( playerid );
2018-09-09 16:01:29 +00:00
return 1;
}
#if defined AC_INCLUDED
hook OnPlayerDeathEx(playerid, killerid, reason, Float: damage, bodypart)
#else
hook OnPlayerDeath(playerid, killerid, reason)
#endif
{
2018-09-10 19:00:02 +00:00
forfeitPlayerDuel( playerid );
2018-09-09 16:01:29 +00:00
return 1;
}
2018-09-10 19:00:02 +00:00
hook SetPlayerRandomSpawn( playerid )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
if ( IsPlayerDueling( playerid ))
2018-09-09 16:01:29 +00:00
{
// teleport back to pb
2018-09-10 19:00:02 +00:00
SetPlayerPos( playerid, g_DuelCoordinates[0], g_DuelCoordinates[1], g_DuelCoordinates[2] );
SetPlayerInterior( playerid, 0 );
SetPlayerVirtualWorld( playerid, 0 );
2018-09-09 16:01:29 +00:00
// reset duel variables
2018-09-10 19:00:02 +00:00
p_playerDueling{ playerid } = false;
g_duelData[ playerid ][ E_PLAYER ] = INVALID_PLAYER_ID;
2018-09-09 16:01:29 +00:00
return Y_HOOKS_BREAK_RETURN_1;
}
return 1;
}
2018-09-10 19:00:02 +00:00
hook OnPlayerEnterDynamicCP( playerid, checkpointid )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
if ( GetPlayerState( playerid ) == PLAYER_STATE_SPECTATING ) {
2018-09-09 16:01:29 +00:00
return 1;
}
2018-09-10 19:00:02 +00:00
if ( checkpointid == g_DuelCheckpoint )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
return 1;
}
return 1;
}
2018-09-10 19:00:02 +00:00
hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[] )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
if ( ( dialogid == DIALOG_DUEL ) && response )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
erase ( szBigString );
2018-09-16 06:05:27 +00:00
2018-09-10 19:00:02 +00:00
switch ( listitem )
2018-09-09 16:01:29 +00:00
{
2018-09-24 21:21:20 +00:00
case 0: ShowPlayerDialog( playerid, DIALOG_DUEL_PLAYER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Select a Player", ""COL_WHITE"Please type the name of the player you wish to duel:\n\n"COL_GREY"Note: You can enter partially their names.", "Select", "Back");
2018-09-10 19:00:02 +00:00
case 1: ShowPlayerDialog( playerid, DIALOG_DUEL_HEALTH, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Health", ""COL_WHITE"Enter the amount of health you will begin with:\n\n"COL_GREY"Note: The default health is 100.0.", "Select", "Back");
case 2: ShowPlayerDialog( playerid, DIALOG_DUEL_ARMOUR, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Armour", ""COL_WHITE"Enter the amount of armour you will begin with:\n\n"COL_GREY"Note: The default armour is 100.0.", "Select", "Back");
2018-09-09 16:01:29 +00:00
case 3:
{
2018-09-16 06:05:27 +00:00
new
2018-09-10 19:00:02 +00:00
iWeapon = g_duelData [ playerid ] [ E_WEAPON ] [ 0 ];
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
for ( new i = 0; i < sizeof( g_WeaponList ); i ++) {
2018-09-24 21:21:20 +00:00
format( szBigString, sizeof( szBigString ), "%s%s%s\n", szBigString, iWeapon == g_WeaponList [ i ] ? ( COL_GREY ) : ( COL_WHITE ), ReturnWeaponName( g_WeaponList[ i ] ) );
2018-09-09 16:01:29 +00:00
}
2018-09-10 19:00:02 +00:00
ShowPlayerDialog( playerid, DIALOG_DUEL_WEAPON, DIALOG_STYLE_LIST, ""COL_WHITE"Duel Settings - Change Primary Weapon", szBigString, "Select", "Back");
2018-09-09 16:01:29 +00:00
}
case 4:
{
2018-09-16 06:05:27 +00:00
new
2018-09-10 19:00:02 +00:00
iWeapon = g_duelData [ playerid ] [ E_WEAPON ] [ 1 ];
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
for ( new i = 0; i < sizeof( g_WeaponList ); i ++ ) {
2018-09-24 21:21:20 +00:00
format( szBigString, sizeof( szBigString ), "%s%s%s\n", szBigString, iWeapon == g_WeaponList [ i ] ? ( COL_GREY ) : ( COL_WHITE ), ReturnWeaponName( g_WeaponList [ i ]) );
2018-09-09 16:01:29 +00:00
}
2018-09-10 19:00:02 +00:00
ShowPlayerDialog( playerid, DIALOG_DUEL_WEAPON_TWO, DIALOG_STYLE_LIST, ""COL_WHITE"Duel Settings - Change Secondary Weapon", szBigString, "Select", "Back");
2018-09-09 16:01:29 +00:00
}
case 5:
{
2018-09-16 06:05:27 +00:00
new
2018-09-10 19:00:02 +00:00
iLocationID = g_duelData [ playerid ][ E_LOCATION_ID ];
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
for ( new i = 0; i < sizeof( g_duelLocationData ); i ++ ) {
2018-09-24 21:21:20 +00:00
format( szBigString, sizeof( szBigString ), "%s%s%s\n", szBigString, iLocationID == i ? ( COL_GREY ) : ( COL_WHITE ), g_duelLocationData[ i ][ E_NAME ] );
2018-09-09 16:01:29 +00:00
}
2018-09-10 19:00:02 +00:00
ShowPlayerDialog(playerid, DIALOG_DUEL_LOCATION, DIALOG_STYLE_LIST, ""COL_WHITE"Duel Settings - Change Location", szBigString, "Select", "Back");
2018-09-09 16:01:29 +00:00
}
2018-09-10 19:00:02 +00:00
case 6: ShowPlayerDialog(playerid, DIALOG_DUEL_WAGER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Set A Wager", ""COL_WHITE"Please enter the wager for this duel:", "Select", "Back");
2018-09-09 16:01:29 +00:00
case 7:
2019-05-31 16:41:51 +00:00
{
g_duelData[ playerid ][ E_CAC ] = !g_duelData[ playerid ][ E_CAC ];
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]{FFFFFF} You have %s "COL_GREY"CAC Only"COL_WHITE".", g_duelData[ playerid ][ E_CAC ] ? ( "enabled" ) : ( "disabled" ) );
2019-05-31 18:08:05 +00:00
ShowPlayerDuelMenu( playerid );
2019-05-31 16:41:51 +00:00
}
case 8:
2018-09-09 16:01:29 +00:00
{
2018-09-16 06:05:27 +00:00
new
2018-09-10 19:00:02 +00:00
pID = g_duelData [ playerid ][ E_PLAYER ];
2018-09-09 16:01:29 +00:00
2018-09-24 21:21:20 +00:00
if ( !IsPlayerConnected( pID ) )
{
2018-09-10 19:00:02 +00:00
SendError( playerid, "You haven't selected anyone to duel!" );
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
}
2023-12-28 22:48:17 +00:00
// if ( g_duelData[ playerid ][ E_CAC ] && ( ! IsPlayerUsingSampAC( pID ) && ! IsPlayerUsingSampAC( playerid ) ) )
// {
// SendError( playerid, "You and your opponent must be using CAC to duel!" );
// return ShowPlayerDuelMenu( playerid );
// }
2019-05-31 16:41:51 +00:00
2018-09-10 19:00:02 +00:00
p_duelInvitation[ playerid ][ pID ] = gettime( ) + 60;
2019-05-31 16:41:51 +00:00
ShowPlayerHelpDialog( pID, 10000, "%s wants to duel!~n~~n~~y~Location: ~w~%s~n~~y~Weapon: ~w~%s and %s~n~~y~Wager: ~w~%s~n~~y~CAC: ~w~%s", ReturnPlayerName( playerid ), g_duelLocationData [ g_duelData[ playerid ][ E_LOCATION_ID ] ][ E_NAME ], ReturnWeaponName( g_duelData[ playerid ][ E_WEAPON ][ 0 ] ), ReturnWeaponName( g_duelData[ playerid ][ E_WEAPON ][ 1 ] ), cash_format(g_duelData[ playerid ][ E_BET ] ), g_duelData[ playerid ][ E_CAC ] ? ( "~g~Yes" ) : ( "~r~No" ) );
2018-09-16 06:05:27 +00:00
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" You have sent a duel invitation to %s for "COL_GOLD"%s"COL_WHITE".", ReturnPlayerName( pID ), cash_format( g_duelData[ playerid ][ E_BET ] ) );
SendClientMessageFormatted( pID, -1, ""COL_DUEL"[DUEL]"COL_WHITE" You are invited to duel %s for "COL_GOLD"%s"COL_WHITE", use \"/duel accept %d\".", ReturnPlayerName( playerid ), cash_format( g_duelData[ playerid ][ E_BET ] ), playerid );
2018-09-09 16:01:29 +00:00
}
}
return 1;
}
2018-09-10 19:00:02 +00:00
else if ( dialogid == DIALOG_DUEL_PLAYER )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
if ( !response )
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
2018-09-16 06:05:27 +00:00
new
2018-09-10 19:00:02 +00:00
pID
;
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( sscanf( inputtext, "u", pID) )
2018-09-24 21:21:20 +00:00
return ShowPlayerDialog( playerid, DIALOG_DUEL_PLAYER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Select a Player", ""COL_WHITE"Please type the name of the player you wish to duel:\n\n"COL_GREY"Note: You can enter partially their names.", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( pID == playerid )
2018-09-24 21:21:20 +00:00
return ShowPlayerDialog( playerid, DIALOG_DUEL_PLAYER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Select a Player", ""COL_WHITE"Please type the name of the player you wish to duel:\n\n"COL_RED"You can't invite yourself to duel!", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( pID == INVALID_PLAYER_ID || !IsPlayerConnected( pID ) )
2018-09-24 21:21:20 +00:00
return ShowPlayerDialog( playerid, DIALOG_DUEL_PLAYER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Select a Player", ""COL_WHITE"Please type the name of the player you wish to duel:\n\n"COL_RED"Player is not connected!", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( IsPlayerDueling( playerid ) )
2018-09-24 21:21:20 +00:00
return ShowPlayerDialog( playerid, DIALOG_DUEL_PLAYER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Select a Player", ""COL_WHITE"Please type the name of the player you wish to duel:\n\n"COL_RED"You are already in a duel!", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( IsPlayerDueling( pID ) )
2018-09-24 21:21:20 +00:00
return ShowPlayerDialog( playerid, DIALOG_DUEL_PLAYER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Select a Player", ""COL_WHITE"Please type the name of the player you wish to duel:\n\n"COL_RED"This player is already in a duel!", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( GetPlayerWantedLevel( pID ) )
2018-09-24 21:21:20 +00:00
return ShowPlayerDialog( playerid, DIALOG_DUEL_PLAYER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Select a Player", ""COL_WHITE"Please type the name of the player you wish to duel:\n\n"COL_RED"You can't duel this person right now, they are wanted", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( GetDistanceBetweenPlayers( playerid, pID ) > 25.0 )
2018-09-24 21:21:20 +00:00
return ShowPlayerDialog( playerid, DIALOG_DUEL_PLAYER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Select a Player", ""COL_WHITE"Please type the name of the player you wish to duel:\n\n"COL_RED"The player you wish to duel is not near you.", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( IsPlayerJailed( pID ) )
2018-09-24 21:21:20 +00:00
return ShowPlayerDialog( playerid, DIALOG_DUEL_PLAYER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Select a Player", ""COL_WHITE"Please type the name of the player you wish to duel:\n\n"COL_RED"You can't duel this person right now, they are currently in jail.", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]{FFFFFF} You have selected {C0C0C0}%s {FFFFFF}as your opponent.", ReturnPlayerName( pID ) );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
g_duelData[ playerid ][ E_PLAYER ] = pID;
2018-09-24 21:21:20 +00:00
return ShowPlayerDuelMenu( playerid ), 1;
2018-09-09 16:01:29 +00:00
}
2018-09-10 19:00:02 +00:00
else if ( dialogid == DIALOG_DUEL_LOCATION )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
if ( !response )
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( g_duelData[ playerid ][ E_LOCATION_ID ] == listitem )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
SendError( playerid, "You have already selected this location!" );
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
}
2018-09-10 19:00:02 +00:00
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" You have changed the duel location to {C0C0C0}%s{FFFFFF}.", g_duelLocationData [ listitem ][ E_NAME ]);
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
g_duelData[ playerid ][ E_LOCATION_ID ] = listitem;
ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
return 1;
}
2018-09-10 19:00:02 +00:00
else if ( dialogid == DIALOG_DUEL_WEAPON )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
if ( !response )
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( g_duelData[ playerid ][ E_WEAPON ][ 0 ] == g_WeaponList[ listitem ] )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
SendError( playerid, "You have already selected this weapon!");
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
}
2018-09-10 19:00:02 +00:00
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" You have changed Primary Weapon to {C0C0C0}%s{FFFFFF}.", ReturnWeaponName( g_WeaponList[ listitem ]) );
g_duelData[ playerid ][ E_WEAPON ][ 0 ] = g_WeaponList[ listitem ];
ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
return 1;
}
2018-09-10 19:00:02 +00:00
else if ( dialogid == DIALOG_DUEL_WEAPON_TWO )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
if ( !response )
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( g_duelData[ playerid ][ E_WEAPON ][ 1 ] == g_WeaponList[ listitem ] )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
SendError( playerid, "You have already selected this weapon!");
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
}
2018-09-10 19:00:02 +00:00
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" You have changed Secondary Weapon to {C0C0C0}%s{FFFFFF}.", ReturnWeaponName( g_WeaponList[ listitem ]) );
g_duelData[ playerid ][ E_WEAPON ][ 1 ] = g_WeaponList[ listitem ];
ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
return 1;
}
2018-09-10 19:00:02 +00:00
else if ( dialogid == DIALOG_DUEL_HEALTH )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
if ( !response )
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
2018-09-16 06:05:27 +00:00
new
2018-09-24 21:21:20 +00:00
Float: fHealth;
2018-09-09 16:01:29 +00:00
2018-09-24 21:21:20 +00:00
if ( sscanf( inputtext, "f", fHealth ) )
return ShowPlayerDialog( playerid, DIALOG_DUEL_HEALTH, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Health", ""COL_WHITE"Enter the amount of health you will begin with:\n\n"COL_GREY"Note: The default health is 100.0.", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-24 21:21:20 +00:00
if ( !( 1.0 <= fHealth <= 100.0 ) )
return ShowPlayerDialog( playerid, DIALOG_DUEL_HEALTH, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Health", ""COL_WHITE"Enter the amount of health you will begin with:\n\n"COL_RED"The amount you have entered is a invalid amount, 1 to 100 only!", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-24 21:21:20 +00:00
SendClientMessageFormatted(playerid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" You have changed Health to {C0C0C0}%0.2f%%"COL_WHITE".", fHealth);
2018-09-10 19:00:02 +00:00
g_duelData[ playerid ][ E_HEALTH ] = fHealth;
ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
return 1;
}
else if (dialogid == DIALOG_DUEL_ARMOUR)
{
2018-09-24 21:21:20 +00:00
if ( !response )
2018-09-10 19:00:02 +00:00
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
2018-09-16 06:05:27 +00:00
new
2018-09-24 21:21:20 +00:00
Float: fArmour;
2018-09-09 16:01:29 +00:00
2018-09-24 21:21:20 +00:00
if ( sscanf( inputtext, "f", fArmour ) )
return ShowPlayerDialog( playerid, DIALOG_DUEL_ARMOUR, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Armour", ""COL_WHITE"Enter the amount of armour you will begin with:\n\n"COL_GREY"Note: The default armour is 100.0.", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-24 21:21:20 +00:00
if ( !( 0.0 <= fArmour <= 100.0 ) )
return ShowPlayerDialog( playerid, DIALOG_DUEL_ARMOUR, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Armour", ""COL_WHITE"Enter the amount of armour you will begin with:\n\n"COL_RED"The amount you have entered is a invalid amount, 0 to 100 only!", "Select", "Back" );
2018-09-09 16:01:29 +00:00
2018-09-24 21:21:20 +00:00
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" You have changed Armour to {C0C0C0}%0.2f%%"COL_WHITE".", fArmour );
2018-09-10 19:00:02 +00:00
g_duelData[ playerid ][ E_ARMOUR ] = fArmour;
ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
return 1;
}
else if (dialogid == DIALOG_DUEL_WAGER)
{
2018-09-24 21:21:20 +00:00
if ( IsPlayerDueling( playerid ) ) // prevent spawning money
return SendError( playerid, "You cannot use this at the moment." );
2018-09-09 16:01:29 +00:00
2018-09-24 21:21:20 +00:00
if ( !response )
2018-09-10 19:00:02 +00:00
return ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
2018-09-16 06:05:27 +00:00
new
2018-09-10 19:00:02 +00:00
iBet
;
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( sscanf( inputtext, "d", iBet ) )
2018-09-24 21:21:20 +00:00
return ShowPlayerDialog( playerid, DIALOG_DUEL_WAGER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Set A Wager", ""COL_WHITE"Please enter the wager for this duel:", "Select", "Back");
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( ! ( 0 <= iBet < 10000000 ) )
2018-09-24 21:21:20 +00:00
return ShowPlayerDialog( playerid, DIALOG_DUEL_WAGER, DIALOG_STYLE_INPUT, ""COL_WHITE"Duel Settings - Set A Wager", ""COL_WHITE"Please enter the wager for this duel:\n\n"COL_RED"Wagers must be between $0 and $10,000,000.", "Select", "Back");
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
g_duelData[playerid][ E_BET ] = iBet;
2018-09-24 21:21:20 +00:00
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" You have changed the wager to %s.", cash_format(g_duelData[playerid][ E_BET ]));
2018-09-10 19:00:02 +00:00
ShowPlayerDuelMenu( playerid );
2018-09-09 16:01:29 +00:00
return 1;
}
return 1;
}
/* ** Commands ** */
2018-09-10 19:00:02 +00:00
CMD:duel( playerid, params[ ] )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
if ( !strcmp(params, "accept", false, 6))
2018-09-09 16:01:29 +00:00
{
new
targetid;
2018-12-25 16:35:25 +00:00
if ( sscanf( params[ 7 ], "u", targetid ) )
2018-09-10 19:00:02 +00:00
return SendUsage( playerid, "/duel accept [PLAYER_ID]");
2018-09-09 16:01:29 +00:00
2018-12-25 16:35:25 +00:00
if ( !IsPlayerConnected( targetid ) )
2018-09-10 19:00:02 +00:00
return SendError( playerid, "You do not have any duel invitations to accept.");
2018-09-09 16:01:29 +00:00
2018-12-25 16:35:25 +00:00
if ( gettime( ) > p_duelInvitation[ targetid ][ playerid ] )
2018-09-10 19:00:02 +00:00
return SendError( playerid, "You have not been invited by %s to duel or it has expired.");
2018-09-09 16:01:29 +00:00
2018-12-25 16:35:25 +00:00
if ( IsPlayerDueling( playerid ) )
2018-09-10 19:00:02 +00:00
return SendError( playerid, "You cannot accept this invite as you are currently dueling.");
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( GetDistanceBetweenPlayers( playerid, targetid ) > 25.0)
return SendError( playerid, "You must be within 25.0 meters of your opponent!");
2018-09-09 16:01:29 +00:00
2018-09-16 06:05:27 +00:00
new
2018-09-10 19:00:02 +00:00
waged_amount = g_duelData[ targetid ][ E_BET ];
2018-09-09 16:01:29 +00:00
2018-12-25 16:35:25 +00:00
if ( g_duelData[ targetid ][ E_BET ] != 0 )
2018-09-09 16:01:29 +00:00
{
2018-12-25 16:35:25 +00:00
if ( GetPlayerCash( targetid ) < waged_amount )
2018-09-09 16:01:29 +00:00
{
2018-09-16 06:05:27 +00:00
SendClientMessageFormatted( targetid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" %s has accepted but you don't have money to wage (%s).", ReturnPlayerName( playerid ), cash_format( waged_amount ) );
2018-09-10 19:00:02 +00:00
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" You have accepted %s's duel invitation but they don't have money.", ReturnPlayerName( targetid ) );
2018-09-09 16:01:29 +00:00
return 1;
}
2018-12-25 16:35:25 +00:00
else if ( GetPlayerCash( playerid ) < waged_amount )
2018-09-09 16:01:29 +00:00
{
2018-09-16 06:05:27 +00:00
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" %s requires you to wage %s.", ReturnPlayerName( targetid ), cash_format( waged_amount ) );
2018-09-10 19:00:02 +00:00
SendClientMessageFormatted( targetid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" %s has accepted the duel invitation but they don't have money to wage.", ReturnPlayerName( playerid ) );
2018-09-09 16:01:29 +00:00
return 1;
}
else
{
2018-09-10 19:00:02 +00:00
GivePlayerCash( playerid, -waged_amount );
GivePlayerCash( targetid, -waged_amount );
2018-09-09 16:01:29 +00:00
}
}
2018-09-10 19:00:02 +00:00
SendClientMessageFormatted( targetid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" %s has accepted your duel invitation.", ReturnPlayerName( playerid ) );
SendClientMessageFormatted( playerid, -1, ""COL_DUEL"[DUEL]"COL_WHITE" You have accepted %s's duel invitation.", ReturnPlayerName( targetid ) );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
p_playerDueling{ targetid } = true;
p_playerDueling{ playerid } = true;
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
g_duelData[ targetid ][ E_PLAYER ] = playerid;
g_duelData[ playerid ][ E_PLAYER ] = targetid;
g_duelData[ playerid ][ E_BET ] = g_duelData[targetid][ E_BET ];
g_duelData[ playerid ][ E_ROUNDS ] = 1;
g_duelData[ targetid ][ E_ROUNDS ] = 1;
2018-09-09 16:01:29 +00:00
2018-09-16 06:05:27 +00:00
new
2018-09-10 19:00:02 +00:00
iLocation = g_duelData[ targetid ][ E_LOCATION_ID ];
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
ResetPlayerWeapons( targetid );
RemovePlayerFromVehicle( targetid );
SetPlayerArmour( targetid, g_duelData[ targetid ][ E_ARMOUR ]);
SetPlayerHealth( targetid, g_duelData[ targetid ][ E_HEALTH ]);
SetPlayerVirtualWorld( targetid, targetid + 1 );
SetPlayerPos( targetid, g_duelLocationData[ iLocation ][ E_POS_TWO ][0], g_duelLocationData[ iLocation ][ E_POS_TWO ][1], g_duelLocationData[ iLocation ][ E_POS_TWO ][2] );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
ResetPlayerWeapons( playerid );
RemovePlayerFromVehicle( playerid );
SetPlayerArmour( playerid, g_duelData[ targetid ][ E_ARMOUR ]);
SetPlayerHealth( playerid, g_duelData[ targetid ][ E_HEALTH ]);
SetPlayerVirtualWorld( playerid, targetid + 1 );
SetPlayerPos( playerid, g_duelLocationData[ iLocation ][ E_POS_ONE ][0], g_duelLocationData[ iLocation ][ E_POS_ONE ][1], g_duelLocationData[ iLocation ][ E_POS_ONE ][2] );
2018-09-09 16:01:29 +00:00
// freeze
2018-09-10 19:00:02 +00:00
TogglePlayerControllable( playerid, 0 );
TogglePlayerControllable( targetid, 0 );
2018-09-09 16:01:29 +00:00
// start countdown
2018-09-10 19:00:02 +00:00
g_duelData[ targetid ][ E_COUNTDOWN ] = 10;
g_duelData[ targetid ][ E_TIMER ] = SetTimerEx( "OnDuelTimer", 960, true, "d", targetid );
2018-09-09 16:01:29 +00:00
// give weapon
2018-09-10 19:00:02 +00:00
GivePlayerWeapon( playerid, g_duelData[ targetid ][ E_WEAPON ][0], 5000);
GivePlayerWeapon( targetid, g_duelData[ targetid ][ E_WEAPON ][0], 5000);
GivePlayerWeapon( playerid, g_duelData[ targetid ][ E_WEAPON ][1], 5000);
GivePlayerWeapon( targetid, g_duelData[ targetid ][ E_WEAPON ][1], 5000);
2018-09-09 16:01:29 +00:00
// clear invites for safety
for (new i = 0; i < MAX_PLAYERS; i ++) {
2018-09-10 19:00:02 +00:00
p_duelInvitation[ playerid ][ i ] = 0;
p_duelInvitation[ targetid ][ i ] = 0;
2018-09-09 16:01:29 +00:00
}
return 1;
}
2018-12-25 16:35:25 +00:00
else if ( strmatch( params, "cancel" ) )
2018-09-09 16:01:29 +00:00
{
2018-12-25 16:35:25 +00:00
if ( ClearDuelInvites( playerid ) )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
return SendServerMessage( playerid, "You have cancelled every duel offer that you have made." );
2018-09-09 16:01:29 +00:00
}
else
{
2018-09-10 19:00:02 +00:00
return SendError( playerid, "You have not made any duel offers recently." );
2018-09-09 16:01:29 +00:00
}
}
2018-09-10 19:00:02 +00:00
return SendUsage( playerid, "/duel [ACCEPT/CANCEL]" );
2018-09-09 16:01:29 +00:00
}
/* ** Functions ** */
2018-09-10 19:00:02 +00:00
static stock ClearDuelInvites( playerid )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
new current_time = gettime( );
2018-09-09 16:01:29 +00:00
new count = 0;
2018-09-10 19:00:02 +00:00
for ( new i = 0; i < MAX_PLAYERS; i ++ )
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
if ( p_duelInvitation[ playerid ][ i ] != 0 && current_time > p_duelInvitation[ playerid ][ i ])
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
p_duelInvitation[ playerid ][ i ] = 0;
2018-09-09 16:01:29 +00:00
count ++;
}
}
return count;
}
2018-09-24 21:21:20 +00:00
stock IsPlayerDueling( playerid ) {
return p_playerDueling{ playerid };
2018-09-09 16:01:29 +00:00
}
2018-12-25 16:35:25 +00:00
stock ShowPlayerDuelMenu( playerid )
2018-09-09 16:01:29 +00:00
{
2018-09-24 21:21:20 +00:00
if ( p_Class[ playerid ] != CLASS_CIVILIAN )
2018-09-10 19:00:02 +00:00
return SendError( playerid, "You can only use this feature whist being a civilian.");
2018-09-09 16:01:29 +00:00
2018-09-24 21:21:20 +00:00
if ( p_WantedLevel[ playerid ] > 0 )
2018-09-10 19:00:02 +00:00
return SendError( playerid, "You cannot duel whilst having a wanted level.");
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
format( szBigString, sizeof(szBigString),
2019-05-31 16:41:51 +00:00
"Player\t"COL_GREY"%s\nHealth\t"COL_GREY"%.2f%%\nArmour\t"COL_GREY"%.2f%%\nPrimary Weapon\t"COL_GREY"%s\nSecondary Weapon\t"COL_GREY"%s\nLocation\t"COL_GREY"%s\nWager\t"COL_GREY"%s\nCAC Only\t"COL_GREY"%s\n"COL_GOLD"Send Invite\t"COL_GOLD">>>",
2018-12-25 16:35:25 +00:00
( ! IsPlayerConnected( g_duelData[ playerid ][ E_PLAYER ] ) ? ( ""COL_RED"No-one" ) : ( ReturnPlayerName( g_duelData[ playerid ][ E_PLAYER ] ) ) ),
2018-09-10 19:00:02 +00:00
g_duelData[ playerid ][ E_HEALTH ],
g_duelData[ playerid ][ E_ARMOUR ],
2018-09-24 21:21:20 +00:00
ReturnWeaponName( g_duelData[ playerid ][ E_WEAPON ][ 0 ] ),
ReturnWeaponName( g_duelData[ playerid ][ E_WEAPON ][ 1 ] ),
2018-09-10 19:00:02 +00:00
g_duelLocationData[ g_duelData[ playerid ][ E_LOCATION_ID ] ][ E_NAME ],
2019-05-31 16:41:51 +00:00
cash_format( g_duelData[ playerid ][ E_BET ] ),
( g_duelData[ playerid ][ E_CAC ] ? ( ""COL_GREEN"ENABLED" ) : ( ""COL_RED"DISABLED" ) )
2018-09-09 16:01:29 +00:00
);
2018-09-24 21:21:20 +00:00
2018-12-25 16:35:25 +00:00
ShowPlayerDialog( playerid, DIALOG_DUEL, DIALOG_STYLE_TABLIST, ""COL_WHITE"Duel Settings", szBigString, "Select", "Cancel" );
2018-09-09 16:01:29 +00:00
return 1;
}
static stock forfeitPlayerDuel(playerid)
{
2018-12-25 16:35:25 +00:00
if ( !IsPlayerDueling( playerid ) )
2018-09-09 16:01:29 +00:00
return 0;
2018-09-10 19:00:02 +00:00
ClearDuelInvites( playerid );
2018-09-09 16:01:29 +00:00
new
2018-09-10 19:00:02 +00:00
winnerid = g_duelData[ playerid ][ E_PLAYER ];
2018-09-09 16:01:29 +00:00
2018-12-25 16:35:25 +00:00
if ( ! IsPlayerConnected( winnerid ) || ! IsPlayerDueling( winnerid ) )
2018-09-09 16:01:29 +00:00
return 0;
// begin wager info
new
2018-09-10 19:00:02 +00:00
amount_waged = g_duelData[ playerid ][ E_BET ];
2018-09-09 16:01:29 +00:00
2018-12-25 16:35:25 +00:00
SpawnPlayer( winnerid );
ClearDuelInvites( winnerid );
2018-09-09 16:01:29 +00:00
// decrement rounds
2018-09-10 19:00:02 +00:00
g_duelData[ playerid ][ E_ROUNDS ] --;
g_duelData[ winnerid ][ E_ROUNDS ] = g_duelData[ playerid ][ E_ROUNDS ];
2018-09-09 16:01:29 +00:00
// check if theres a remaining round
2018-12-25 16:35:25 +00:00
if ( g_duelData[ playerid ][ E_ROUNDS ] == 0)
2018-09-24 21:21:20 +00:00
{
if ( 0 < amount_waged < 10000000 )
{
2018-09-16 06:05:27 +00:00
new
2018-09-24 21:21:20 +00:00
winning_prize = floatround( float( amount_waged ) * 1.95 ); // We take 2.5% of the total pot
2018-12-12 08:21:57 +00:00
2018-09-24 21:21:20 +00:00
GivePlayerCash( winnerid, winning_prize );
SendClientMessageToAllFormatted( -1, ""COL_DUEL"[DUEL]"COL_WHITE" %s(%d) has won the duel against %s(%d) for %s!", ReturnPlayerName( winnerid ), winnerid, ReturnPlayerName( playerid ), playerid, cash_format( winning_prize ) );
}
else
{
SendClientMessageToAllFormatted( -1, ""COL_DUEL"[DUEL]"COL_WHITE" %s(%d) has won the duel against %s(%d)!", ReturnPlayerName( winnerid ), winnerid, ReturnPlayerName( playerid ), playerid );
2018-09-09 16:01:29 +00:00
}
}
return 1;
}
2018-12-25 16:35:25 +00:00
function OnDuelTimer( targetid )
2018-09-09 16:01:29 +00:00
{
new
2018-12-25 16:35:25 +00:00
playerid = g_duelData[ targetid ][ E_PLAYER ];
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
g_duelData[ targetid ][ E_COUNTDOWN ] --;
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
if ( g_duelData[ targetid ][ E_COUNTDOWN ] <= 0)
2018-09-09 16:01:29 +00:00
{
2018-09-10 19:00:02 +00:00
GameTextForPlayer( targetid, "~g~~h~FIGHT!", 1500, 4 );
GameTextForPlayer( playerid, "~g~~h~FIGHT!", 1500, 4 );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
PlayerPlaySound( targetid, 1057, 0.0, 0.0, 0.0 );
PlayerPlaySound( playerid, 1057, 0.0, 0.0, 0.0 );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
TogglePlayerControllable( playerid, 1 );
TogglePlayerControllable( targetid, 1 );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
KillTimer( g_duelData[ targetid ][ E_TIMER ] );
2018-09-09 16:01:29 +00:00
}
else
{
2018-12-25 16:35:25 +00:00
format( szSmallString, sizeof( szSmallString ), "~w~%d", g_duelData[ targetid ][ E_COUNTDOWN ] );
2018-09-10 19:00:02 +00:00
GameTextForPlayer( targetid, szSmallString, 1500, 4 );
GameTextForPlayer( playerid, szSmallString, 1500, 4 );
2018-09-09 16:01:29 +00:00
2018-09-10 19:00:02 +00:00
PlayerPlaySound( targetid, 1056, 0.0, 0.0, 0.0 );
PlayerPlaySound( playerid, 1056, 0.0, 0.0, 0.0 );
2018-09-09 16:01:29 +00:00
}
return 1;
}