code cleanup

This commit is contained in:
Lorenc Pekaj 2019-01-02 02:37:45 +11:00
parent 35f9d15e9b
commit 16b12b4610
13 changed files with 183 additions and 154 deletions

View File

@ -7,16 +7,16 @@
### Script Callbacks
- `public SetPlayerRandomSpawn( playerid )`
- `SetPlayerRandomSpawn( playerid )`
- Called when a player is attempting to be respawned somewhere randomly
- `public OnServerUpdate( )`
- `OnServerUpdate( )`
- Called every second (or sooner) indefinitely
- `public OnServerTickSecond( )`
- `OnServerTickSecond( )`
- Called every second (specifically) indefinitely
- `public OnPlayerUpdateEx( playerid )`
- `OnPlayerUpdateEx( playerid )`
- Same interval as OnServerUpdate, but it is called indefinitely for every player in-game
- When you wish to update something frequently, but not use OnPlayerUpdate
- `public OnPlayerTickSecond( playerid )`
- `OnPlayerTickSecond( playerid )`
- Called every second (specifically a second) for a player, indefinitely
- `OnServerGameDayEnd( )`
- Called every 24 minutes in-game (basically when a new day starts)

View File

@ -22,6 +22,9 @@
#define DISCORD_ROLE_VIP "191180697547833344"
#define DISCORD_ROLE_VOICE "364678874681966592"
/* ** Macros ** */
#define DQCMD:%1(%2) forward discord_%1(%2); public discord_%1(%2)
/* ** Variables ** */
new stock
DCC_Guild: discordGuild,

View File

@ -11,6 +11,9 @@
/* ** Definitions ** */
#define MAX_ENTERS ( 300 )
/* ** Macros ** */
#define IsPlayerInEntrance(%0,%1) ( p_LastEnteredEntrance[ %0 ] == ( %1 ) )
/* ** Variables ** */
enum E_ENTER_DATA
{
@ -30,6 +33,9 @@ new
g_VIPLounge[ 3 ] = { -1, ... }
;
/* ** Forwards ** */
forward OnPlayerAccessEntrance( playerid, entranceid, worldid, interiorid );
/* ** Hooks ** */
hook OnScriptInit( )
{

View File

@ -34,7 +34,8 @@ static stock
p_JailObjectLS [ MAX_PLAYERS ] [ 3 ],
p_AlcatrazObject [ MAX_PLAYERS ] = { INVALID_OBJECT_ID, ... },
p_AlcatrazEscapeTS [ MAX_PLAYERS ],
g_alcatrazTimestamp = 0
g_alcatrazTimestamp = 0,
g_AlcatrazArea = -1
;
/* ** Forwards ** */
@ -42,6 +43,13 @@ forward OnPlayerJailed( playerid );
forward OnPlayerUnjailed( playerid, reasonid );
/* ** Hooks ** */
hook OnScriptInit( )
{
// Alcatraz
g_AlcatrazArea = CreateDynamicRectangle( -1921.6816, 1661.7448, -2172.4653, 1876.0469 );
return 1;
}
hook OnPlayerEnterDynamicCP( playerid, checkpointid ) {
if ( IsPlayerJailed( playerid ) ) {
return SendError( playerid, "You're jailed, and you accessed a checkpoint. I smell a cheater." ), KickPlayerTimed( playerid ), Y_HOOKS_BREAK_RETURN_1;

View File

@ -18,8 +18,8 @@
#define IsGangPrivate(%0) ( g_gangData[ %0 ] [ E_INVITE_ONLY ] )
#define GetGangSqlID(%0) ( g_gangData[ %0 ] [ E_SQL_ID ] )
#define GetPlayerGang(%0) ( p_GangID[ %0 ] )
#define IsValidGangID(%0) ( 0 <= %0 < MAX_GANGS && Iter_Contains( gangs, %0 ) )
#define IsPlayerInPlayerGang(%0,%1) ( p_Class[ %0 ] == p_Class[ %1 ] && p_Class[ %0 ] == CLASS_CIVILIAN && p_GangID[ %0 ] == p_GangID[ %1 ] && p_GangID[ %0 ] != INVALID_GANG_ID )
/* ** Variables ** */
enum e_gang_data

View File

@ -9,15 +9,9 @@
#include < YSI\y_hooks >
/* ** Definitions ** */
#define MAX_PAINTBALL_ARENAS ( 6 )
/* ** Macros ** */
#define SendClientMessageToPaintball(%0,%1,%2,%3) \
do{foreach(new fI : Player){if (p_inPaintBall{fI}&&p_PaintBallArena{fI}==(%0))format(szNormalString,sizeof(szNormalString),(%2),%3),SendClientMessage(fI,(%1),szNormalString);}}while(False)
/* ** Variables ** */
enum E_PAINTBALL_DATA
{
E_NAME[ 16 ], E_HOST, E_PASSWORD[ 5 ],
@ -58,7 +52,6 @@ new
;
/* ** Hooks ** */
#if defined AC_INCLUDED
hook OnPlayerDeathEx( playerid, killerid, reason, Float: damage, bodypart )
#else
@ -329,8 +322,108 @@ hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
return 1;
}
/* ** Functions ** */
/* ** Commands ** */
CMD:pb( playerid, params[ ] ) return cmd_paintball( playerid, params );
CMD:paintball( playerid, params[ ] )
{
if ( !IsPlayerInPaintBall( playerid ) )
return SendError( playerid, "You're not in any paintball lobby." );
if ( strmatch( params, "leave" ) )
{
if ( !IsPlayerInPaintBall( playerid ) )
return SendError( playerid, "You're not inside the paintball." );
LeavePlayerPaintball( playerid );
SetPlayerHealth( playerid, -1 );
SendServerMessage( playerid, "You have left the paintball arena." );
return 1;
}
if ( !hasPaintBallArena( playerid ) )
return SendError( playerid, "This command requires you to be the host of a lobby." );
new
id = p_PaintBallArena{ playerid },
pID
;
if ( strmatch( params, "edit" ) )
{
showPaintBallLobbyData( playerid, id, "Close" );
}
else if ( !strcmp( params, "kick", false, 4 ) )
{
if ( sscanf( params[ 5 ], "u", pID ) ) return SendUsage( playerid, "/paintball kick [PLAYER_ID]" );
else if ( !IsPlayerConnected( pID ) ) return SendError( playerid, "This player is not connected." );
else if ( !IsPlayerInPaintBall( pID ) ) return SendError( playerid, "This player is not in paintball." );
else if ( p_PaintBallArena{ pID } != id ) return SendError( playerid, "This player is not in your paintball lobby." );
else if ( pID == playerid ) return SendError( playerid, "You cannot kick yourself." );
else
{
SendClientMessageToPaintball( id, -1, ""COL_GREY"[PAINTBALL]"COL_WHITE" %s(%d) has left the lobby (KICKED)", ReturnPlayerName( pID ), pID );
LeavePlayerPaintball( pID );
SetPlayerHealth( pID, -1 );
}
}
else if ( !strcmp( params, "leader", false, 6 ) )
{
if ( sscanf( params[ 7 ], "u", pID ) ) return SendUsage( playerid, "/paintball paintball [PLAYER_ID]" );
else if ( !IsPlayerConnected( pID ) ) return SendError( playerid, "This player is not connected." );
else if ( !IsPlayerInPaintBall( pID ) ) return SendError( playerid, "This player is not in paintball." );
else if ( p_PaintBallArena{ pID } != id ) return SendError( playerid, "This player is not in your paintball lobby." );
else if ( pID == playerid ) return SendError( playerid, "You cannot apply this action to yourself." );
else
{
g_paintballData[ id ] [ E_HOST ] = pID;
SendClientMessageToPaintball( id, -1, ""COL_GREY"[PAINTBALL]"COL_WHITE" %s(%d) is the new paintball leader.", ReturnPlayerName( pID ), pID );
}
}
else if ( !strcmp( params, "countdown", false, 6 ) )
{
new
iSeconds;
if ( sscanf( params[ 10 ], "D(10)", iSeconds ) ) return SendUsage( playerid, "/paintball countdown [SECONDS]" );
else if ( iSeconds < 1 || iSeconds > 30 ) return SendError( playerid, "Please specify countdown seconds between 1 and 30." );
else
{
SendServerMessage( playerid, "You have started a countdown from %d in your paintball game.", iSeconds );
KillTimer( g_paintballData[ id ] [ E_CD_TIMER ] );
g_paintballData[ id ] [ E_CD_TIMER ] = SetTimerEx( "paintballCountDown", 960, false, "dd", id, iSeconds - 1 );
}
}
else
{
SendUsage( playerid, "/paintball [LEAVE/EDIT/KICK/COUNTDOWN/LEADER]" );
}
return 1;
}
CMD:p( playerid, params[ ] )
{
if ( !IsPlayerInPaintBall( playerid ) )
return SendError( playerid, "You're not in any paintball lobby." );
new
id = p_PaintBallArena{ playerid },
msg[ 90 ]
;
if ( sscanf( params, "s[90]", msg ) ) return SendUsage( playerid, "/p [MESSAGE]" );
else if ( textContainsIP( msg ) ) return SendServerMessage( playerid, "Please do not advertise." );
else if ( !g_paintballData[ id ] [ E_CHAT ] ) return SendError( playerid, "Paintball chat is disabled in this lobby." );
else
{
SendClientMessageToPaintball( id, -1, ""COL_GREY"<Paintball Chat> %s(%d):"COL_WHITE" %s", ReturnPlayerName( playerid ), playerid, msg );
}
return 1;
}
CMD:pleave( playerid, params[ ] ) return cmd_pb( playerid, "leave" );
/* ** Functions ** */
function paintballCountDown( paintballid, time )
{
if ( paintballid == -1 )
@ -571,104 +664,15 @@ stock IsPlayerLeavingPaintball( playerid ) {
return p_LeftPaintball{ playerid };
}
/* ** Commands ** */
stock SendClientMessageToPaintball( paintballid, colour, const format[ ], va_args<> )
{
static
out[ 144 ];
CMD:pb( playerid, params[ ] ) return cmd_paintball( playerid, params );
CMD:paintball( playerid, params[ ] )
{
if ( !IsPlayerInPaintBall( playerid ) )
return SendError( playerid, "You're not in any paintball lobby." );
va_format( out, sizeof( out ), format, va_start<3> );
if ( strmatch( params, "leave" ) )
{
if ( !IsPlayerInPaintBall( playerid ) )
return SendError( playerid, "You're not inside the paintball." );
LeavePlayerPaintball( playerid );
SetPlayerHealth( playerid, -1 );
SendServerMessage( playerid, "You have left the paintball arena." );
return 1;
}
if ( !hasPaintBallArena( playerid ) )
return SendError( playerid, "This command requires you to be the host of a lobby." );
new
id = p_PaintBallArena{ playerid },
pID
;
if ( strmatch( params, "edit" ) )
{
showPaintBallLobbyData( playerid, id, "Close" );
}
else if ( !strcmp( params, "kick", false, 4 ) )
{
if ( sscanf( params[ 5 ], "u", pID ) ) return SendUsage( playerid, "/paintball kick [PLAYER_ID]" );
else if ( !IsPlayerConnected( pID ) ) return SendError( playerid, "This player is not connected." );
else if ( !IsPlayerInPaintBall( pID ) ) return SendError( playerid, "This player is not in paintball." );
else if ( p_PaintBallArena{ pID } != id ) return SendError( playerid, "This player is not in your paintball lobby." );
else if ( pID == playerid ) return SendError( playerid, "You cannot kick yourself." );
else
{
SendClientMessageToPaintball( id, -1, ""COL_GREY"[PAINTBALL]"COL_WHITE" %s(%d) has left the lobby (KICKED)", ReturnPlayerName( pID ), pID );
LeavePlayerPaintball( pID );
SetPlayerHealth( pID, -1 );
}
}
else if ( !strcmp( params, "leader", false, 6 ) )
{
if ( sscanf( params[ 7 ], "u", pID ) ) return SendUsage( playerid, "/paintball paintball [PLAYER_ID]" );
else if ( !IsPlayerConnected( pID ) ) return SendError( playerid, "This player is not connected." );
else if ( !IsPlayerInPaintBall( pID ) ) return SendError( playerid, "This player is not in paintball." );
else if ( p_PaintBallArena{ pID } != id ) return SendError( playerid, "This player is not in your paintball lobby." );
else if ( pID == playerid ) return SendError( playerid, "You cannot apply this action to yourself." );
else
{
g_paintballData[ id ] [ E_HOST ] = pID;
SendClientMessageToPaintball( id, -1, ""COL_GREY"[PAINTBALL]"COL_WHITE" %s(%d) is the new paintball leader.", ReturnPlayerName( pID ), pID );
}
}
else if ( !strcmp( params, "countdown", false, 6 ) )
{
new
iSeconds;
if ( sscanf( params[ 10 ], "D(10)", iSeconds ) ) return SendUsage( playerid, "/paintball countdown [SECONDS]" );
else if ( iSeconds < 1 || iSeconds > 30 ) return SendError( playerid, "Please specify countdown seconds between 1 and 30." );
else
{
SendServerMessage( playerid, "You have started a countdown from %d in your paintball game.", iSeconds );
KillTimer( g_paintballData[ id ] [ E_CD_TIMER ] );
g_paintballData[ id ] [ E_CD_TIMER ] = SetTimerEx( "paintballCountDown", 960, false, "dd", id, iSeconds - 1 );
}
}
else
{
SendUsage( playerid, "/paintball [LEAVE/EDIT/KICK/COUNTDOWN/LEADER]" );
foreach ( new i : Player ) if ( p_inPaintBall{ i } && p_PaintBallArena{ i } == paintballid ) {
SendClientMessage( i, colour, out );
}
return 1;
}
CMD:p( playerid, params[ ] )
{
if ( !IsPlayerInPaintBall( playerid ) )
return SendError( playerid, "You're not in any paintball lobby." );
new
id = p_PaintBallArena{ playerid },
msg[ 90 ]
;
if ( sscanf( params, "s[90]", msg ) ) return SendUsage( playerid, "/p [MESSAGE]" );
else if ( textContainsIP( msg ) ) return SendServerMessage( playerid, "Please do not advertise." );
else if ( !g_paintballData[ id ] [ E_CHAT ] ) return SendError( playerid, "Paintball chat is disabled in this lobby." );
else
{
SendClientMessageToPaintball( id, -1, ""COL_GREY"<Paintball Chat> %s(%d):"COL_WHITE" %s", ReturnPlayerName( playerid ), playerid, msg );
}
return 1;
}
CMD:pleave( playerid, params[ ] ) return cmd_pb( playerid, "leave" );

View File

@ -18,6 +18,9 @@
#define STATE_ROBBED ( 1 )
#define STATE_PICKED ( 2 )
/* ** Macros ** */
#define IsPlayerRobbing(%0) ( p_UsingRobberySafe[ %0 ] != -1 )
/* ** Variables ** */
enum E_ROBBERY_SYSTEM
{
@ -137,7 +140,7 @@ hook OnProgressCompleted( playerid, progressid, params )
if ( progressid == PROGRESS_ROBBING )
{
new
robberyid = params,//p_UsingRobberySafe[ playerid ],
robberyid = params,
Float: distance = distanceFromSafe( playerid, robberyid )
;

View File

@ -90,5 +90,3 @@ hook OnPlayerUnloadTextdraws( playerid ) {
TextDrawHideForPlayer( playerid, g_NotManyPlayersTD );
return 1;
}
/* ** Functions ** */

View File

@ -794,9 +794,21 @@ static stock ShowPlayerVipRedeemedDialog( playerid )
ShowPlayerDialog( playerid, DIALOG_NULL, DIALOG_STYLE_MSGBOX, ""COL_GOLD"SF-CNR Donation", szLargeString, "Got it!", "" );
}
stock SendClientMessageToVips( colour, const format[ ], va_args<> )
{
static
out[ 144 ];
va_format( out, sizeof( out ), format, va_start<2> );
foreach ( new i : Player ) if ( p_VIPLevel[ i ] >= VIP_REGULAR ) {
SendClientMessage( i, colour, out );
}
return 1;
}
stock IsPlayerPlatinumVIP( playerid ) return p_VIPLevel[ playerid ] >= VIP_PLATINUM;
/* ** Macros ** */
stock Float: GetPlayerIrresistibleCoins( playerid ) {
return p_IrresistibleCoins[ playerid ];
}

View File

@ -33,8 +33,7 @@ new
bool: g_VipPrivateMsging = false,
g_iTime = 0,
g_VehicleLastAttacker [ MAX_VEHICLES ] = { INVALID_PLAYER_ID, ... },
g_VehicleLastAttacked [ MAX_VEHICLES ],
g_AlcatrazArea = -1
g_VehicleLastAttacked [ MAX_VEHICLES ]
;
/* ** Getters and Setters ** */

View File

@ -30,16 +30,27 @@
/* ** Hooks ** */
hook OnScriptInit( )
{
// set server query information
SetGameModeText( SERVER_MODE_TEXT );
SetServerRule( "hostname", SERVER_NAME );
SetServerRule( "language", SERVER_LANGUAGE );
SetServerRule( "mapname", SERVER_MAP );
// simple gameplay rules
UsePlayerPedAnims( );
AllowInteriorWeapons( 0 );
EnableStuntBonusForAll( 0 );
DisableInteriorEnterExits( );
// enable mysql debugging on debug mode
#if defined DEBUG_MODE
mysql_log( LOG_ERROR | LOG_WARNING );
#endif
// start map andreas (if enabled)
#if defined MAP_ANDREAS_MODE_MINIMAL
MapAndreas_Init( MAP_ANDREAS_MODE_MINIMAL );
#endif
return 1;
}

View File

@ -12,6 +12,7 @@
#define GetServerName(%0) g_igServerNames[%0]
#define ReturnPlayerIP(%0) (p_PlayerIP[(%0)])
#define ReturnPlayerName(%0) (p_PlayerName[(%0)])
#define IsPlayerNpcEx(%0) (IsPlayerNPC(%0) || strmatch(p_PlayerIP[%0], "127.0.0.1"))
/* ** Constants ** */
stock const

View File

@ -16,7 +16,7 @@
//#pragma option -d3
#pragma dynamic 7200000
#define DEBUG_MODE
// #define DEBUG_MODE
#if defined DEBUG_MODE
#pragma option -d3
@ -51,30 +51,17 @@ native WP_Hash ( buffer[ ], len, const str[ ] );
native IsValidVehicle ( vehicleid );
native gpci ( playerid, serial[ ], len );
new bool: False = false;
/* ** SF-CNR ** */
#include "irresistible\_main.pwn"
/* ** Useful macros ** */
#define DQCMD:%1(%2) forward discord_%1(%2); public discord_%1(%2)
#define IsPlayerRobbing(%0) IsPlayerAttachedObjectSlotUsed(%0,0)
#define hasTickcountPassed(%1,%2) ((GetTickCount()-%1)>(%2))
#define Ach_Unlock(%0,%1) (%0 >= %1 ?("{6EF83C}"):("{FFFFFF}"))
#define UpdatePlayerTime(%0) SetPlayerTime(%0,floatround(g_WorldClockSeconds/60),g_WorldClockSeconds-floatround((g_WorldClockSeconds/60)*60))
#define Ach_Unlock(%0,%1) (%0 >= %1 ?("{6EF83C}"):("{FFFFFF}"))
#define Achievement:: ach_
#define IsPlayerInEntrance(%0,%1) (p_LastEnteredEntrance[%0]==(%1))
#define IsPlayerInPlayerGang(%0,%1) (p_Class[%0] == p_Class[%1] && p_Class[%0] == CLASS_CIVILIAN && p_GangID[%0] == p_GangID[%1] && p_GangID[%0] != INVALID_GANG_ID)
#define IsPlayerNpcEx(%0) (IsPlayerNPC(%0) || strmatch(p_PlayerIP[%0], "127.0.0.1"))
/* Beast Functions */
#define SendClientMessageToVips(%1,%2,%3) \
do{foreach(new fI : Player){if (p_VIPLevel[fI]>=VIP_REGULAR)format(szNormalString,sizeof(szNormalString),(%2),%3),SendClientMessage(fI,(%1),szNormalString);}}while(False)
#define CreateBillboard(%0,%1,%2,%3,%4) SetDynamicObjectMaterialText(CreateDynamicObject(7246,%1,%2,%3,0,0,%4),0,(%0),120,"Arial",24,0,-1,-16777216,1)
#define MAX_WANTED_LVL 2048
#define MAX_TIME_TIED 180
#define MAX_VEH_ATTACHED_OBJECTS 2
@ -83,7 +70,6 @@ new bool: False = false;
public OnPlayerDriveVehicle( playerid, vehicleid );
public OnServerUpdateTimer( );
public OnServerSecondTick( );
public OnPlayerAccessEntrance( playerid, entranceid, worldid, interiorid );
public OnPlayerLoadTextdraws( playerid );
public OnPlayerUnloadTextdraws( playerid );
@ -94,13 +80,6 @@ main()
public OnGameModeInit()
{
#if defined DEBUG_MODE
mysql_log( LOG_ERROR | LOG_WARNING );
#endif
// start map andreas
MapAndreas_Init( MAP_ANDREAS_MODE_MINIMAL );
/* ** Server Variables ** */
AddServerVariable( "doublexp", "0", GLOBAL_VARTYPE_INT );
AddServerVariable( "eventbank", "0", GLOBAL_VARTYPE_INT );
@ -135,9 +114,6 @@ public OnGameModeInit()
SetDynamicObjectMaterialText( CreateDynamicObject( 7301, -2418.657714, 743.686523, 1058.593750, 0.000000, 0.000000, -44.899974 ), 0, "Use /shop!", 120, "impact", 100, 0, -65536, 0, 1 );
SetDynamicObjectMaterialText( CreateDynamicObject( 19353, -1496.6134, 920.0287, 6.0990, 0.0, -90.0, -180 ), 0, "BANK", 100, "Times New Roman", 100, 0, -9170, 0, 1 );
// Alcatraz
g_AlcatrazArea = CreateDynamicRectangle( -1921.6816, 1661.7448, -2172.4653, 1876.0469 );
/* ** Pickups ** */
CreateDynamicPickup( 371, 2, -1745.2754, 59.301500, 866.4556 ); // Parachute @Veloxity
@ -1639,9 +1615,11 @@ public OnPlayerText( playerid, text[ ] )
if ( textContainsIP( text ) )
return SendServerMessage( playerid, "Please do not advertise." ), 0;
if ( !hasTickcountPassed( p_AntiTextSpam[ playerid ], 750 ) )
new tick_count = GetTickCount( );
if ( p_AntiTextSpam[ playerid ] > tick_count )
{
p_AntiTextSpam[ playerid ] = GetTickCount( );
p_AntiTextSpam[ playerid ] = tick_count + 750;
p_AntiTextSpamCount{ playerid } ++;
SendError( playerid, "You must wait 0.75 seconds before posting again. "COL_GREY"[%d/3]", p_AntiTextSpamCount{ playerid } );
@ -1658,7 +1636,7 @@ public OnPlayerText( playerid, text[ ] )
SetPVarString( playerid, "last_message", text );
p_AntiTextSpamCount{ playerid } = 0;
p_AntiTextSpam[ playerid ] = GetTickCount( );
p_AntiTextSpam[ playerid ] = tick_count + 750;
if ( p_Muted{ playerid } )
{
@ -1827,13 +1805,19 @@ public OnPlayerCommandReceived(playerid, cmdtext[])
{
if ( p_AdminLevel[ playerid ] < 6 && ! IsPlayerServerMaintainer( playerid ) )
{
if ( !hasTickcountPassed( p_AntiCommandSpam[ playerid ], 1000 ) )
new
tick_count = GetTickCount( );
if ( p_AntiCommandSpam[ playerid ] > tick_count )
{
p_AntiCommandSpam[ playerid ] = GetTickCount( );
p_AntiCommandSpam[ playerid ] = tick_count + 1000;
SendError( playerid, "You must wait a second before submitting a command again." );
return 0;
}
else p_AntiCommandSpam[ playerid ] = GetTickCount( );
else
{
p_AntiCommandSpam[ playerid ] = tick_count + 1000;
}
if ( !IsPlayerSpawned( playerid ) || GetPlayerState( playerid ) == PLAYER_STATE_WASTED ) return SendError( playerid, "You cannot use commands while you're not spawned." ), 0;
}
@ -7290,7 +7274,7 @@ stock IsPlayerInMinigame( playerid ) {
return IsPlayerInPaintBall( playerid ) || IsPlayerDueling( playerid ) || IsPlayerPlayingPool( playerid ) || IsPlayerPlayingPoker( playerid );
}
stock SendClientMessageToCops( colour, const format[ ], va_args<> ) // Conversion to foreach 14 stuffed the define, not sure how...
stock SendClientMessageToCops( colour, const format[ ], va_args<> )
{
static
out[ 144 ];