move ticket code into its own module cop/ticket.pwn

This commit is contained in:
Lorenc Pekaj 2019-01-01 18:20:43 +11:00
parent 8875c7654c
commit 615dd8f7ab
5 changed files with 138 additions and 98 deletions

View File

@ -10,3 +10,4 @@
#include "irresistible\cnr\features\cop\cop_chat.pwn"
#include "irresistible\cnr\features\cop\arrest.pwn"
#include "irresistible\cnr\features\cop\bail.pwn"
#include "irresistible\cnr\features\cop\ticket.pwn"

View File

@ -219,8 +219,6 @@ stock JailPlayer( playerid, seconds, admin = 0 )
PlayerTextDrawShow ( playerid, p_JailTimeTD[ playerid ] );
// External Variables to Jail (resetting)
p_TicketIssuer [ playerid ] = INVALID_PLAYER_ID; // Reset Tickets
p_TicketTimestamp [ playerid ] = 0; // Reset Tickets
p_Cuffed { playerid } = false;
p_InfectedHIV { playerid } = false;
//p_Detained { playerid } = false;

View File

@ -0,0 +1,137 @@
/*
* Irresistible Gaming (c) 2018
* Developed by Lorenc
* Module: cnr\features\cop\ticket.pwn
* Purpose: ticketing system for police
*/
/* ** Includes ** */
#include < YSI\y_hooks >
/* ** Variables ** */
static stock
p_TicketTimestamp [ MAX_PLAYERS ],
p_TicketIssuer [ MAX_PLAYERS ] = { INVALID_PLAYER_ID, ... }
;
/* ** Hooks ** */
hook OnPlayerDisconnect( playerid, reason )
{
p_TicketIssuer[ playerid ] = INVALID_PLAYER_ID;
p_TicketTimestamp[ playerid ] = 0;
return 1;
}
#if defined AC_INCLUDED
hook OnPlayerDeathEx( playerid, killerid, reason, Float: damage, bodypart )
#else
hook OnPlayerDeath( playerid, killerid, reason )
#endif
{
p_TicketIssuer[ playerid ] = INVALID_PLAYER_ID;
p_TicketTimestamp[ playerid ] = 0;
return 1;
}
hook OnPlayerUpdateEx( playerid )
{
// Failed to pay ticket
if ( p_TicketTimestamp[ playerid ] != 0 && g_iTime > p_TicketTimestamp[ playerid ] )
{
// inform user
SendServerMessage( playerid, "You have resisted to pay your ticket and have become a wanted criminal." );
SendClientMessageToCops( -1, ""COL_BLUE"[CRIME]"COL_WHITE" %s(%d) has resisted to pay his ticket.", ReturnPlayerName( playerid ), playerid );
// remove ticket
p_TicketTimestamp[ playerid ] = 0;
p_TicketIssuer[ playerid ] = INVALID_PLAYER_ID;
GivePlayerWantedLevel( playerid, 6 );
}
return 1;
}
hook OnPlayerJailed( playerid )
{
p_TicketIssuer[ playerid ] = INVALID_PLAYER_ID;
p_TicketTimestamp[ playerid ] = 0;
return 1;
}
/* ** Variables ** */
CMD:tk( playerid, params[ ] ) return cmd_ticket( playerid, params );
CMD:ticket( playerid, params[ ] )
{
new
pID = GetClosestPlayer( playerid );
TicketPlayer( pID, playerid );
SendServerMessage( playerid, "You can use your middle mouse button to easily ticket individuals that are near to you." );
return 1;
}
CMD:payticket( playerid, params[] )
{
if ( !p_WantedLevel[ playerid ] )
return SendError( playerid, "There's no point paying off a ticket when you don't have a wanted level." );
if ( p_WantedLevel[ playerid ] > 5 )
return SendError( playerid, "Your wanted level is excessive to pay a ticket." );
if ( !p_TicketTimestamp[ playerid ] )
return SendError( playerid, "You have not been ticketed!" );
if ( GetPlayerCash( playerid ) < 2000 )
return SendError( playerid, "You don't have money to pay for your ticket." );
new
copid = p_TicketIssuer[ playerid ];
// remove ticket
p_TicketTimestamp[ playerid ] = 0;
p_TicketIssuer[ playerid ] = INVALID_PLAYER_ID;
// remove wanted level
GivePlayerCash( playerid, -2000 );
GivePlayerWantedLevel( playerid, -6 );
SendClientMessageFormatted( playerid, -1, ""COL_GREEN"[TICKET]{FFFFFF} You have paid "COL_GOLD"$2,000{FFFFFF} dollars into paying your ticket." );
// pay cop
if ( IsPlayerConnected( copid ) ) {
GivePlayerScore( copid, 2 );
GivePlayerCash( copid, 1500 );
GivePlayerExperience( copid, E_POLICE, 0.5 );
GameTextForPlayer( copid, "~n~~g~~h~Ticket paid!", 2000, 4 );
SendClientMessageFormatted( copid, -1, ""COL_GREEN"[TICKET]{FFFFFF} %s(%d) has paid his ticket issues, you have earned "COL_GOLD"$1,500{FFFFFF}!", ReturnPlayerName( playerid ), playerid );
}
return 1;
}
/* ** Functions ** */
stock TicketPlayer( pID, playerid )
{
if ( p_Class[ playerid ] != CLASS_POLICE ) return SendError( playerid, "This is restricted to police only." );
else if ( GetDistanceBetweenPlayers( playerid, pID ) > 10.0 || !IsPlayerConnected( pID ) ) return SendError( playerid, "There are no players around to ticket." );
else if ( p_TicketIssuer[ pID ] == playerid ) return SendError( playerid, "You've already gave a ticket to this player." );
else if ( p_Class[ pID ] == CLASS_POLICE ) return SendError( playerid, "This player is in your team!" );
else if ( p_WantedLevel[ pID ] > 5 ) return SendError( playerid, "Wanted suspects cannot be issued a ticket." );
else if ( p_WantedLevel[ pID ] < 1 ) return SendError( playerid, "Innocent players cannot be issued a ticket." );
else if ( p_Jailed{ playerid } ) return SendError( playerid, "You cannot use this command in jail." );
//else if ( IsPlayerDetained( pID ) ) return SendError( playerid, "You cannot use this command on a detained player." );
else if ( g_iTime < p_TicketTimestamp[ pID ] ) return SendError( playerid, "This player has been ticketed recently, he will be fined in %d seconds.", g_iTime - p_TicketTimestamp[ pID ] );
else
{
if ( p_AdminOnDuty{ pID } == true ) return SendError( playerid, "This is an admin on duty!" );
if ( IsPlayerJailed( pID ) ) return SendError( playerid, "This player is jailed. He may be paused." );
if ( IsPlayerTied( pID ) ) return SendError( playerid, "This player is tied, you cannot ticket him unless he is untied." );
if ( GetPlayerState( pID ) == PLAYER_STATE_WASTED ) return SendError( playerid, "You cannot ticket wasted players." );
p_TicketTimestamp[ pID ] = g_iTime + 15;
p_TicketIssuer[ pID ] = playerid;
GameTextForPlayer( pID, "~n~~r~Ticketed!~n~~w~/payticket", 2000, 4 );
SendClientMessageFormatted( pID, -1, ""COL_RED"[TICKET]{FFFFFF} You have been issued a "COL_GOLD"$2,000{FFFFFF} ticket by %s(%d) for your recent criminal activity!", ReturnPlayerName( playerid ), playerid );
SendClientMessageFormatted( pID, -1, ""COL_RED"[TICKET]{FFFFFF} You have 15 seconds to "COL_GREY"/payticket"COL_WHITE" before you are wanted for resisting law enforcement." );
SendClientMessageFormatted( playerid, -1, ""COL_GREEN"[TICKET]{FFFFFF} You issued a ticket of "COL_GOLD"$2,000{FFFFFF} to %s(%d)!", ReturnPlayerName( pID ), pID );
}
return 1;
}

View File

@ -39,8 +39,6 @@ new
bool: p_Kidnapped [ MAX_PLAYERS char ],
bool: p_ToggledViewPM [ MAX_PLAYERS char ],
bool: p_ToggleCopChat [ MAX_PLAYERS char ],
p_TicketTimestamp [ MAX_PLAYERS ],
p_TicketIssuer [ MAX_PLAYERS ] = { INVALID_PLAYER_ID, ... },
p_CheckpointEnterTick [ MAX_PLAYERS ],
bool: p_pausedToLoad [ MAX_PLAYERS char ],
bool: p_CantUseReport [ MAX_PLAYERS char ],

View File

@ -333,19 +333,6 @@ public OnServerUpdateTimer( )
}
}
// Failed to pay ticket
if ( p_TicketTimestamp[ playerid ] != 0 && g_iTime > p_TicketTimestamp[ playerid ] )
{
// inform user
SendServerMessage( playerid, "You have resisted to pay your ticket and have become a wanted criminal." );
SendClientMessageToCops( -1, ""COL_BLUE"[CRIME]"COL_WHITE" %s(%d) has resisted to pay his ticket.", ReturnPlayerName( playerid ), playerid );
// remove ticket
p_TicketTimestamp[ playerid ] = 0;
p_TicketIssuer[ playerid ] = INVALID_PLAYER_ID;
GivePlayerWantedLevel( playerid, 6 );
}
new
aiming_player = GetPlayerTargetPlayer( playerid );
@ -860,7 +847,6 @@ public OnPlayerDisconnect( playerid, reason )
p_PmResponder [ playerid ] = INVALID_PLAYER_ID;
p_ViewingStats [ playerid ] = INVALID_PLAYER_ID;
p_Spectating { playerid } = false;
p_TicketIssuer [ playerid ] = INVALID_PLAYER_ID;
//p_DetainedBy [ playerid ] = INVALID_PLAYER_ID;
p_GangID [ playerid ] = INVALID_GANG_ID;
p_InfectedHIV { playerid } = false;
@ -900,7 +886,6 @@ public OnPlayerDisconnect( playerid, reason )
p_DeathMessage [ playerid ] [ 0 ] = '\0';
p_Fireworks [ playerid ] = 0;
p_AddedEmail { playerid } = false;
p_TicketTimestamp[ playerid ] = 0;
p_ExtraAssetSlots{ playerid } = 0;
p_OwnedBusinesses[ playerid ] = 0;
p_ExplosiveBullets[ playerid ] = 0;
@ -1632,11 +1617,9 @@ public OnPlayerDeath( playerid, killerid, reason )
DestroyDynamic3DTextLabel( p_WeedLabel[ playerid ] );
p_WeedLabel[ playerid ] = Text3D: INVALID_3DTEXT_ID;
p_Tied{ playerid } = false;
p_TicketTimestamp[ playerid ] = 0;
p_Kidnapped{ playerid } = false;
//p_Detained{ playerid } = false;
p_ClassSelection{ playerid } = false;
p_TicketIssuer[ playerid ] = INVALID_PLAYER_ID;
KillTimer( p_TrackingTimer[ playerid ] );
p_TrackingTimer[ playerid ] = -1;
DeletePVar( playerid, "AlcatrazWantedCD" );
@ -4332,83 +4315,6 @@ CMD:search( playerid, params[ ] )
return 1;
}
CMD:tk( playerid, params[ ] ) return cmd_ticket( playerid, params );
CMD:ticket( playerid, params[ ] )
{
new
pID = GetClosestPlayer( playerid );
TicketPlayer( pID, playerid );
SendServerMessage( playerid, "You can use your middle mouse button to easily ticket individuals that are near to you." );
return 1;
}
stock TicketPlayer( pID, playerid )
{
if ( p_Class[ playerid ] != CLASS_POLICE ) return SendError( playerid, "This is restricted to police only." );
else if ( GetDistanceBetweenPlayers( playerid, pID ) > 10.0 || !IsPlayerConnected( pID ) ) return SendError( playerid, "There are no players around to ticket." );
else if ( p_TicketIssuer[ pID ] == playerid ) return SendError( playerid, "You've already gave a ticket to this player." );
else if ( p_Class[ pID ] == CLASS_POLICE ) return SendError( playerid, "This player is in your team!" );
else if ( p_WantedLevel[ pID ] > 5 ) return SendError( playerid, "Wanted suspects cannot be issued a ticket." );
else if ( p_WantedLevel[ pID ] < 1 ) return SendError( playerid, "Innocent players cannot be issued a ticket." );
else if ( p_Jailed{ playerid } ) return SendError( playerid, "You cannot use this command in jail." );
//else if ( IsPlayerDetained( pID ) ) return SendError( playerid, "You cannot use this command on a detained player." );
else if ( g_iTime < p_TicketTimestamp[ pID ] ) return SendError( playerid, "This player has been ticketed recently, he will be fined in %d seconds.", g_iTime - p_TicketTimestamp[ pID ] );
else
{
if ( p_AdminOnDuty{ pID } == true ) return SendError( playerid, "This is an admin on duty!" );
if ( IsPlayerJailed( pID ) ) return SendError( playerid, "This player is jailed. He may be paused." );
if ( IsPlayerTied( pID ) ) return SendError( playerid, "This player is tied, you cannot ticket him unless he is untied." );
if ( GetPlayerState( pID ) == PLAYER_STATE_WASTED ) return SendError( playerid, "You cannot ticket wasted players." );
p_TicketTimestamp[ pID ] = g_iTime + 15;
p_TicketIssuer[ pID ] = playerid;
GameTextForPlayer( pID, "~n~~r~Ticketed!~n~~w~/payticket", 2000, 4 );
SendClientMessageFormatted( pID, -1, ""COL_RED"[TICKET]{FFFFFF} You have been issued a "COL_GOLD"$2,000{FFFFFF} ticket by %s(%d) for your recent criminal activity!", ReturnPlayerName( playerid ), playerid );
SendClientMessageFormatted( pID, -1, ""COL_RED"[TICKET]{FFFFFF} You have 15 seconds to "COL_GREY"/payticket"COL_WHITE" before you are wanted for resisting law enforcement." );
SendClientMessageFormatted( playerid, -1, ""COL_GREEN"[TICKET]{FFFFFF} You issued a ticket of "COL_GOLD"$2,000{FFFFFF} to %s(%d)!", ReturnPlayerName( pID ), pID );
}
return 1;
}
CMD:payticket( playerid, params[] )
{
if ( !p_WantedLevel[ playerid ] )
return SendError( playerid, "There's no point paying off a ticket when you don't have a wanted level." );
if ( p_WantedLevel[ playerid ] > 5 )
return SendError( playerid, "Your wanted level is excessive to pay a ticket." );
if ( !p_TicketTimestamp[ playerid ] )
return SendError( playerid, "You have not been ticketed!" );
if ( GetPlayerCash( playerid ) < 2000 )
return SendError( playerid, "You don't have money to pay for your ticket." );
new
copid = p_TicketIssuer[ playerid ];
// remove ticket
p_TicketTimestamp[ playerid ] = 0;
p_TicketIssuer[ playerid ] = INVALID_PLAYER_ID;
// remove wanted level
GivePlayerCash( playerid, -2000 );
GivePlayerWantedLevel( playerid, -6 );
SendClientMessageFormatted( playerid, -1, ""COL_GREEN"[TICKET]{FFFFFF} You have paid "COL_GOLD"$2,000{FFFFFF} dollars into paying your ticket." );
// pay cop
if ( IsPlayerConnected( copid ) ) {
GivePlayerScore( copid, 2 );
GivePlayerCash( copid, 1500 );
GivePlayerExperience( copid, E_POLICE, 0.5 );
GameTextForPlayer( copid, "~n~~g~~h~Ticket paid!", 2000, 4 );
SendClientMessageFormatted( copid, -1, ""COL_GREEN"[TICKET]{FFFFFF} %s(%d) has paid his ticket issues, you have earned "COL_GOLD"$1,500{FFFFFF}!", ReturnPlayerName( playerid ), playerid );
}
return 1;
}
CMD:rob( playerid, params[ ] )
{
/* ** ANTI ROB SPAM ** */