From 615dd8f7abc2f1bbe0654410d74614a1227315f7 Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Tue, 1 Jan 2019 18:20:43 +1100 Subject: [PATCH] move ticket code into its own module cop/ticket.pwn --- .../irresistible/cnr/features/cop/_cop.pwn | 1 + .../irresistible/cnr/features/cop/jail.pwn | 2 - .../irresistible/cnr/features/cop/ticket.pwn | 137 ++++++++++++++++++ gamemodes/irresistible/cnr/player.pwn | 2 - gamemodes/sf-cnr.pwn | 94 ------------ 5 files changed, 138 insertions(+), 98 deletions(-) create mode 100644 gamemodes/irresistible/cnr/features/cop/ticket.pwn diff --git a/gamemodes/irresistible/cnr/features/cop/_cop.pwn b/gamemodes/irresistible/cnr/features/cop/_cop.pwn index dbe8ecd..ab2b9d4 100644 --- a/gamemodes/irresistible/cnr/features/cop/_cop.pwn +++ b/gamemodes/irresistible/cnr/features/cop/_cop.pwn @@ -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" diff --git a/gamemodes/irresistible/cnr/features/cop/jail.pwn b/gamemodes/irresistible/cnr/features/cop/jail.pwn index 8f4678f..8df5d78 100644 --- a/gamemodes/irresistible/cnr/features/cop/jail.pwn +++ b/gamemodes/irresistible/cnr/features/cop/jail.pwn @@ -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; diff --git a/gamemodes/irresistible/cnr/features/cop/ticket.pwn b/gamemodes/irresistible/cnr/features/cop/ticket.pwn new file mode 100644 index 0000000..5ab5fbb --- /dev/null +++ b/gamemodes/irresistible/cnr/features/cop/ticket.pwn @@ -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; +} \ No newline at end of file diff --git a/gamemodes/irresistible/cnr/player.pwn b/gamemodes/irresistible/cnr/player.pwn index 739a9df..4016f9f 100644 --- a/gamemodes/irresistible/cnr/player.pwn +++ b/gamemodes/irresistible/cnr/player.pwn @@ -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 ], diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index 30d88e1..58d5dfc 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -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 ** */