| edon1337 |
08-05-2018 08:36 |
Ent has null Private Data | Array not being read
I'm getting
PHP Code:
[HAMSANDWICH] Entity has null private data
Everytime on this line
PHP Code:
ExecuteHamB( Ham_Spawn, WeaponEntity );
I tried everything, made sure every weapon name is being parsed into the array correctly, made sure to use pev_valid == 2 (entity valid + entity valid for private data usage), BUT STILL, I keep getting this... What is this error ?
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < hamsandwich >
#include < fakemeta >
#include < fun >
#include < rog >
#include < stripweapons >
#include < cs_battleroyale_faketeams >
#include < cs_battleroyale_roundmanager >
#include < orpheu >
#include < orpheu_advanced >
#define VERSION "1.2"
#if AMXX_VERSION_NUM >= 182
#define CSW_GLOCK 2
#endif
//#define DUMP_ORIGIN_DATA
#define DEFAULT_MAXSPEED 250.0
#define DEFAULT_GRAVITY 1.0
#define MAX_ORIGINS 100
#define AIRDROP_CLASSNAME "ent_airdrop"
#define AIRPLANE_CLASSNAME "ent_airplane"
enum
{
VIEW_NONE,
VIEW_3RDPERSON
};
enum ( += 8764 )
{
TASK_PARACHUTE_DEPLOY = 6436,
TASK_AIRDROP,
TASK_AIRDROP_AFK
};
enum
{
deploy,
idle,
detach
};
enum _:AirDropData
{
AirDrop_Model_Flying[ 128 ],
AirDrop_Model_Ground[ 128 ]
};
enum _:AirPlaneData
{
AirPlane_Model[ 128 ]
};
enum
{
RARITY_GREY = 1,
RARITY_GREEN,
RARITY_BLUE,
RARITY_PURPLE,
RARITY_GOLD
};
enum _:WeaponData
{
Weapon_Name[ 32 ],
Weapon_Rarity
};
enum _:SoundEffects
{
Parachute_Deploy_Sound[ 128 ],
Landing_Sound[ 128 ],
AirDrop_Appear_Sound[ 128 ],
AirDrop_Land_Sound[ 128 ]
};
enum _:AmmoIndexData
{
AmmoIndex,
AmmoCount
};
new g_iSprite;
new g_iAirDrops;
new g_iSpriteIndexExplosion;
new g_iAirPlaneEnt;
new g_iDummyResult;
new g_iFwOpenAirDrop;
new g_iFwJumpPlane;
new g_iFwUrgentJumpPlane;
new g_iFwDeployParachute;
new Float:g_fCachedParachuteVelocity;
new Float:g_fCachedAirDropVelocity;
new IntClassNameString;
new OrpheuFunction:HandleCreateNamedEntityFunc;
new OrpheuFunction:HandlePackWeaponFunc;
new CWeaponBoxKill_Address;
new g_iDataAirDrop[ AirDropData ];
new g_iDataAirPlane[ AirPlaneData ];
new g_iSounds[ SoundEffects ];
new g_eAmmoIndex[ 31 ][ AmmoIndexData ];
new g_iPlayerView[ 33 ];
new g_iCvars[ 10 ];
new g_IntAmmoNames[ 16 ];
new bool:g_bPlayerInPlane[ 33 ];
new bool:g_bIsPlayerInParachute[ 33 ];
new bool:g_bLandedPlayer[ 33 ];
new const g_szGameSounds[ ] = "GameSounds.ini";
new const g_szGameModels[ ] = "GameModels.ini";
new const g_szGameWeapons[ ] = "GameWeapons.ini";
new const g_szValues[ ][ ] =
{
"RARITY_GREY",
"RARITY_GREEN",
"RARITY_BLUE",
"RARITY_PURPLE",
"RARITY_GOLD"
};
new const g_iValues[ ] =
{
RARITY_GREY,
RARITY_GREEN,
RARITY_BLUE,
RARITY_PURPLE,
RARITY_GOLD
};
new const g_szPossibleAirDropWeapons[ ] =
{
CSW_M249,
CSW_AWP,
CSW_G3SG1,
CSW_SG550
}
new Array:g_aWeaponData;
new Trie:g_tRarityTrie;
new const g_szMaxBpAmmo[ ] =
{ -1, 52, -1, 90, 1, 32, 1, 100, 90, 1, 120, 100, 100, 90, 90, 90, 100, 120,
30, 120, 200, 32, 90, 120, 90, 2, 35, 90, 90, -1, 100
};
new const g_szAmmoType[ ][ ] =
{ "", "357sig", "", "762nato", "", "buckshot", "", "45acp", "556nato", "", "9mm", "57mm", "45acp",
"556nato", "556nato", "556nato", "45acp", "9mm", "338magnum", "9mm", "556natobox", "buckshot",
"556nato", "9mm", "762nato", "", "50ae", "556nato", "762nato", "", "57mm"
};
new const WeaponBoxModels[ ][ ] =
{
"", "models/w_p228.mdl", "",
"models/w_scout.mdl", "models/w_hegrenade.mdl", "models/w_xm1014.mdl",
"", "models/w_mac10.mdl", "models/w_aug.mdl", "models/w_smokegrenade.mdl",
"models/w_elite.mdl", "models/w_fiveseven.mdl", "models/w_ump45.mdl",
"models/w_sg550.mdl", "models/w_galil.mdl", "models/w_famas.mdl",
"models/w_usp.mdl", "models/w_glock18.mdl", "models/w_awp.mdl",
"models/w_mp5.mdl", "models/w_m249.mdl", "models/w_m3.mdl",
"models/w_m4a1.mdl", "models/w_tmp.mdl", "models/w_g3sg1.mdl",
"models/w_flashbang.mdl", "models/w_deagle.mdl", "models/w_sg552.mdl", "models/w_ak47.mdl",
"", "models/w_p90.mdl", "", ""
};
new const g_szForbiddenWeapons[ ][ ] =
{
"weapon_c4",
"weapon_knife",
"weapon_kevlar"
};
new const m_rgpPlayerItems_CWeaponBox[ 6 ] = { 34, 35, ... };
new const g_szStringAmmoNames[ ][ ] =
{
"",
"338Magnum",
"762Nato",
"556NatoBox",
"556Nato",
"buckshot",
"45ACP",
"57mm",
"50AE",
"357SIG",
"9mm",
"Flashbang",
"HEGrenade",
"SmokeGrenade",
"C4"
};
new OrpheuFunction:HandlePackAmmoFunc;
const XO_CWEAPONBOX = 4;
const m_iId = 43;
const m_pfnThink = 4;
const m_iType = 34;
const m_iCount = 35;
const m_bHasPrimary = 116;
const m_pActiveItem = 373;
new const SKIP_THESE_WEAPONS = ( ( 1 << CSW_KNIFE ) | ( 1 << CSW_HEGRENADE ) | ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_SMOKEGRENADE ) | ( 1 << CSW_C4 ) | ( 1 << CSW_GLOCK ) );
public plugin_init( )
{
register_plugin( "CS Battle Royale Core", VERSION, "DoNii" );
register_dictionary( "cs_battleroyale.txt" );
register_cvar( "cs_battleroyale_version", VERSION, FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED );
ROGInitialize( 500.0, "CheckOrigin" );
#if defined DUMP_ORIGIN_DATA
ROGDumpOriginData( );
#endif
register_message( get_user_msgid( "StatusIcon" ), "OnMessageStatusIcon" ); // Hook StatusIcon
set_msg_block( get_user_msgid( "Radar" ), BLOCK_SET ); // Block radar, we don't want players cheating
// Orpheu
IntClassNameString = engfunc( EngFunc_AllocString, "weaponbox" ); // Allocate weaponbox ent
HandleCreateNamedEntityFunc = OrpheuGetFunction( "CREATE_NAMED_ENTITY" );
HandlePackWeaponFunc = OrpheuGetFunction( "PackWeapon", "CWeaponBox" );
CWeaponBoxKill_Address = OrpheuGetFunctionAddress( OrpheuGetFunction( "Kill", "CWeaponBox" ) );
HandlePackAmmoFunc = OrpheuGetFunction( "PackAmmo", "CWeaponBox" );
// cvars
g_iCvars[ 0 ] = register_cvar( "csbr_parachute_deploy_time", "1.0" ); // time to deploy parachute after spawning ( seconds)
g_iCvars[ 1 ] = register_cvar( "csbr_parachute_fall_speed", "-250.0" ); // player parachute fall speed
g_iCvars[ 2 ] = register_cvar( "csbr_camera_switch", "1" ); // allow camera switch
g_iCvars[ 3 ] = register_cvar( "csbr_airdrop_freq_min", "15.0" ); // minimum time of an airdrop
g_iCvars[ 4 ] = register_cvar( "csbr_airdrop_freq_max", "30.0" ); // maximum time of an airdrop, ex: 180.0, 360.0 --> random_float( 180.0, 360.0 )
g_iCvars[ 5 ] = register_cvar( "csbr_airdrop_count", "3" ); // number of airdrops in 1 round
g_iCvars[ 6 ] = register_cvar( "csbr_airdrop_velocity", "-50.0" ); // airdrop fall velocity
g_iCvars[ 7 ] = register_cvar( "csbr_airdrop_open_distance", "100.0" ); // distance to allow opening of airdrop
g_iCvars[ 8 ] = register_cvar( "csbr_airplane_disappear_time", "20.0" ); // time task for the airplane to disappear
g_iCvars[ 9 ] = register_cvar( "csbr_glow_extra_damage", "2" ); // extra damage to give to each glow
// register_logevent FORWARDS
register_logevent( "OnRoundStart", 2, "1=Round_Start" ); // hook round start
// HAM FORWARDS
RegisterHam( Ham_TakeDamage, "player", "@HamTakeDamage_Pre", 0 );
RegisterHam( Ham_Player_ImpulseCommands, "player", "@HamPlayerImpulseCommands_Pre", 0 );
RegisterHam( Ham_Player_Jump, "player", "@HamPlayerJump_Post", 1 );
RegisterHam( Ham_Spawn, "player", "@HamSpawn_Post", 1 );
// FM FORWARDS
register_forward( FM_CmdStart, "@CmdStart" );
register_forward( FM_SetModel, "@SetModel" );
register_forward( FM_AddToFullPack, "@AddToFullPack_Post", 1 );
// Engine FORWARDS
register_think( AIRDROP_CLASSNAME, "@AirDropThink" ); // make airdrop think
// Remove Armoury
remove_entity_name( "armoury_entity" ); // remove all armoury_entity in the map
g_iFwOpenAirDrop = CreateMultiForward( "PlayerOpenAirDrop", ET_IGNORE, FP_CELL, FP_CELL );
g_iFwJumpPlane = CreateMultiForward( "PlayerJumpPlane", ET_IGNORE, FP_CELL );
g_iFwUrgentJumpPlane = CreateMultiForward( "PlayerUrgentJump", ET_IGNORE, FP_CELL );
g_iFwDeployParachute = CreateMultiForward( "PlayerDeployParachute", ET_IGNORE, FP_CELL );
}
public plugin_precache( )
{
g_aWeaponData = ArrayCreate( WeaponData ); // create array for weapons
g_tRarityTrie = TrieCreate( ); // create trie -> int map
RemoveObjectives( );
RegisterWeaponList( .id = get_user_msgid( "WeaponList" ) );
new i;
for( i = 0; i < sizeof g_szValues; i++ )
{
TrieSetCell( g_tRarityTrie, g_szValues[ i ], g_iValues[ i ] ); // assign int values to trie
}
for( i = 1; i < sizeof g_szStringAmmoNames; i++)
{
g_IntAmmoNames[ i ] = engfunc( EngFunc_AllocString, g_szStringAmmoNames[ i ] ); // allocate ammo names
}
precache_model( "models/rpgrocket.mdl" ); // needed for camera view, server will crash without precaching it
g_iSpriteIndexExplosion = precache_model( "sprites/zerogxplode.spr" ); // airdrop explosion effect
g_iSprite = precache_model( "sprites/Arrow_Icon.spr" ); // arrow icon to show on teammates head
ReadModels( ); // read our models
ReadSounds( ); // read our sounds
log_to_file( "DebugWeapons.txt", "Reading started" );
ReadWeapons( ); // read our weapons
}
public CheckOrigin( Float:fOrigin[ 3 ] )
{
if( fOrigin[ 2 ] < -425.0 ) // we don't want our entities to be spawned in the under-ground area
{
return 0;
}
return 1;
}
@RegUserMsg( const szName[ ], const iSize )
{
if( equal( szName, "WeaponList" ) )
{
RegisterWeaponList( .id = get_orig_retval( ) );
}
}
RegisterWeaponList( const id = 0 )
{
static iForwardHandle = -1;
if( ! id )
{
iForwardHandle = register_forward( FM_RegUserMsg, "@RegUserMsg", ._post = true );
return;
}
if( iForwardHandle != -1 )
{
unregister_forward( FM_RegUserMsg, iForwardHandle, .post = true );
}
register_message( id, "@OnMessageWeaponList" );
}
@OnMessageWeaponList( const iMsgId, const iMsgType, const iEnt )
{
new iAmmoIndex = get_msg_arg_int( 2 ); // get ammo index
new iAmmoCount = get_msg_arg_int( 3 ); // get ammo count
new iWeaponID = get_msg_arg_int( 8 ); // get weapon id
g_eAmmoIndex[ iWeaponID ][ AmmoIndex ] = iAmmoIndex; // save ammo index
g_eAmmoIndex[ iWeaponID ][ AmmoCount ] = iAmmoCount; // save ammo count
}
@HamPlayerJump_Post( id ) // player jump
{
if( ! g_bPlayerInPlane[ id ] ) // if hes not in airplane, no need to continue
return HAM_IGNORED;
set_pev( id, pev_solid, SOLID_SLIDEBOX ); // set player solidity to default
set_pev( id, pev_movetype, MOVETYPE_TOSS ); // set player movetype to default
g_bPlayerInPlane[ id ] = false; // player left plane
g_bIsPlayerInParachute[ id ] = true; // player is in parachute now
set_user_rendering( id ); // reset his rendering (make him visible)
set_pev( id, pev_gravity, DEFAULT_GRAVITY ); // reset his gravity to default
set_user_maxspeed( id, DEFAULT_MAXSPEED ); // reset his speed to default
g_iPlayerView[ id ] = VIEW_NONE; // reset player camera view
set_pev( id, pev_sequence, deploy ); // make new sequence
set_task( get_pcvar_float( g_iCvars[ 0 ] ), "OnDeployParachute", id+TASK_PARACHUTE_DEPLOY ); // task for parachute
client_cmd( id, "spk sound/%s", g_iSounds[ Parachute_Deploy_Sound ] ); // emit parachute deploy sound
ExecuteForward( g_iFwJumpPlane, g_iDummyResult, id );
return HAM_IGNORED;
}
@AddToFullPack_Post( ES_Handle, E, iEnt, iHost, iHostFlags, iPlayer, iSet)
{
if( ! is_user_alive( iEnt ) || ! is_user_alive( iHost ) )
return FMRES_IGNORED;
if( GetPlayerTeam( iEnt ) == GetPlayerTeam( iHost ) && ( iEnt != iHost ) ) // check if the player in sight is our teammate and is not the host himself
{
message_begin( MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, iHost )
write_byte( TE_PLAYERATTACHMENT );
write_byte( iEnt );
write_coord( 45 );
write_short( g_iSprite );
write_short( 20 );
message_end( );
}
return FMRES_IGNORED;
}
public OnDeployParachute( id )
{
id -= TASK_PARACHUTE_DEPLOY;
g_bIsPlayerInParachute[ id ] = true;
ExecuteForward( g_iFwDeployParachute, g_iDummyResult, id );
remove_task( id + TASK_PARACHUTE_DEPLOY );
}
@HamSpawn_Post( id )
{
if( is_user_alive( id ) )
{
strip_user_weapons( id ); // remove all weapons
give_item( id, "weapon_knife" ); // give him a knife, poor guy
set_view( id, CAMERA_NONE ); // set his camera to default
g_iPlayerView[ id ] = VIEW_NONE; // assign default view to var
}
return HAM_IGNORED;
}
public OnRoundStart( )
{
g_fCachedParachuteVelocity = get_pcvar_float( g_iCvars[ 1 ] ); // cache our parachute velocity, we dont wanna retrieve same value every frame
g_fCachedAirDropVelocity = get_pcvar_float( g_iCvars[ 6 ] ); // same as above
ROGShuffleOrigins( ); // randomize our origins
RemoveAllWeaponBox( );
remove_entity_name( AIRDROP_CLASSNAME ); // remove all airdrops
remove_entity_name( AIRPLANE_CLASSNAME ); // remove airplane
remove_task( TASK_AIRDROP ); // end task airdrop
g_iAirDrops = 0;
g_iAirPlaneEnt = 0;
new szPlayers[ 32 ], iNum, iTempID;
get_players( szPlayers, iNum );
for( new i; i < iNum; i++ )
{
iTempID = szPlayers[ i ];
remove_task( iTempID + TASK_PARACHUTE_DEPLOY ); // just to make sure
g_bLandedPlayer[ iTempID ] = false;
}
return PLUGIN_CONTINUE;
}
public RoundStarted( )
{
MakeAirPlane( ); // create airplane
set_task( get_pcvar_float( g_iCvars[ 8 ] ), "DropAfkPlayers", TASK_AIRDROP_AFK ); // if there's AFK players who forgot to jump, force them to jump
new Float:fOrigin[ 3 ], WeaponEntity, iArraySize = ArraySize( g_aWeaponData ), eData[ WeaponData ];
for( new i; i < iArraySize; i++ )
{
ArrayGetArray( g_aWeaponData, i, eData );
log_to_file( "Newdebug.txt", "Weapon Name: %s | Weapon Rarity: %d", eData[ Weapon_Name ], eData[ Weapon_Rarity ] );
ROGGetOrigin( fOrigin );
new WeaponBoxEntity = OrpheuCall( HandleCreateNamedEntityFunc, IntClassNameString ) ;
if( pev_valid( WeaponBoxEntity ) != 2 )
{
return 0;
}
engfunc( EngFunc_SetOrigin, WeaponBoxEntity, fOrigin );
ExecuteHam( Ham_Spawn, WeaponBoxEntity );
WeaponEntity = create_entity( eData[ Weapon_Name ] );
if( pev_valid( WeaponEntity ) != 2 )
{
remove_entity( WeaponBoxEntity );
}
ExecuteHamB( Ham_Spawn, WeaponEntity );
new WeaponID = cs_get_weapon_id( WeaponEntity );
OrpheuCall( HandlePackWeaponFunc, WeaponBoxEntity, WeaponEntity );
if( WeaponBoxModels[ WeaponID ][ 0 ] != EOS )
{
engfunc( EngFunc_SetModel, WeaponBoxEntity, WeaponBoxModels[ WeaponID ] );
}
set_pdata_int( WeaponBoxEntity, m_pfnThink, CWeaponBoxKill_Address, 0 );
new iAmmoIndex = g_eAmmoIndex[ WeaponID ][ AmmoIndex ];
new iAmmoCount = g_eAmmoIndex[ WeaponID ][ AmmoCount ];
if( iAmmoIndex )
{
OrpheuCall( HandlePackAmmoFunc, WeaponBoxEntity, g_IntAmmoNames[ iAmmoIndex ], iAmmoCount );
}
set_pev( WeaponEntity, pev_iuser2, eData[ Weapon_Rarity ] );
GlowWeapon( WeaponBoxEntity, eData[ Weapon_Rarity ] );
}
new Float:fTimeAirDrop = random_float( get_pcvar_float( g_iCvars[ 3 ] ), get_pcvar_float( g_iCvars[ 4 ] ) ); // random time between 2 cvar floats
set_task( fTimeAirDrop, "OnCreateAirDrop", TASK_AIRDROP, _, _, "b" );
return PLUGIN_CONTINUE;
}
public DropAfkPlayers( )
{
engfunc( EngFunc_RemoveEntity, g_iAirPlaneEnt ); // remove airplane
new szPlayers[ 32 ], iNum, iTempID;
get_players( szPlayers, iNum, "a" );
for( new i; i < iNum; i++ )
{
iTempID = szPlayers[ i ];
if( g_bPlayerInPlane[ iTempID ] )
{
ExecuteHamB( Ham_Player_Jump, iTempID ); // make them jump
client_print( iTempID, print_center, "%L", iTempID, "EMERGENCY_DROP" );
ExecuteForward( g_iFwUrgentJumpPlane, g_iDummyResult, iTempID );
}
}
}
@SetModel( iEnt, szModel[ ] ) // set weapons glow
{
if( ! pev_valid( iEnt ) )
return FMRES_IGNORED;
new szClassName[ 32 ];
pev( iEnt, pev_classname, szClassName, charsmax( szClassName ) );
if( ! equal( szClassName, "weaponbox" ) )
return FMRES_IGNORED;
new iWeaponEntity = GetWeaponBoxWeaponType( iEnt ); // get weapon entity
new iRarity = pev( iWeaponEntity, pev_iuser2 );
if( iRarity )
GlowWeapon( iEnt, iRarity ); // set glow
return FMRES_IGNORED;
}
public OnMessageStatusIcon( iMsgId, iMsgDest, id )
{
static szIcon[ 8 ];
get_msg_arg_string( 2, szIcon, charsmax( szIcon ) );
if( equal( szIcon, "buyzone" ) && get_msg_arg_int( 1 ) ) // block buyzone, not needed in this mod
{
set_pdata_int( id, 235, get_pdata_int( id, 235 ) & ~ ( 1 << 0 ) );
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
@CmdStart( id, iHandle ) // when opening airdrop, you have to press IN_USE
{
if( ! is_user_alive( id ) )
return FMRES_IGNORED;
static iButtons;
iButtons = get_uc( iHandle, UC_Buttons );
if( iButtons & IN_USE )
{
new Float:fOriginPlayer[ 3 ], Float:fOriginEnt[ 3 ], iEnt = -1;
pev( id, pev_origin, fOriginPlayer );
while( ( iEnt = find_ent_by_class( iEnt, AIRDROP_CLASSNAME ) ) )
{
pev( iEnt, pev_origin, fOriginEnt );
if( ( get_distance_f( fOriginPlayer, fOriginEnt ) <= get_pcvar_float( g_iCvars[ 7 ] ) ) && ( pev( iEnt, pev_flags ) & FL_ONGROUND ) ) // check if distance between player and airdrop is lower than cvar and airdrop has landed
{
OpenAirDrop( id, iEnt ); // open the airdrop
}
}
}
return FMRES_IGNORED;
}
@HamTakeDamage_Pre( iVictim, iInflicter, iAttacker, Float:fDamage ) // give extra damage to each glow
{
if( ! is_user_connected( iAttacker ) )
return HAM_IGNORED;
new iEnt = get_pdata_cbase( iAttacker, m_pActiveItem );
new iGlow = pev( iEnt, pev_iuser2 );
if( ! iGlow )
return HAM_IGNORED;
new iExtraDamage = GetExtraDamage( iGlow );
SetHamParamFloat( 4, fDamage + iExtraDamage );
return HAM_IGNORED;
}
@AirDropThink( iEnt )
{
if( pev_valid( iEnt ) != 2 )
return PLUGIN_CONTINUE;
new Float:fVelocity[ 3 ];
pev( iEnt, pev_velocity, fVelocity );
set_pev( iEnt, pev_nextthink, get_gametime( ) + 0.01 );
if( ( pev( iEnt, pev_flags ) & FL_ONGROUND ) || ( pev( iEnt, pev_flags ) & FL_INWATER ) ) // has landed on ground / in water
{
if( ! pev( iEnt, pev_iuser2 ) )
{
engfunc( EngFunc_SetModel, iEnt, g_iDataAirDrop[ AirDrop_Model_Ground ] );
engfunc( EngFunc_SetSize, iEnt, Float:{ -35.0, -40.0, -65.0 }, Float:{ 35.0, 40.0, 65.0 } );
set_pev( iEnt, pev_movetype, MOVETYPE_TOSS );
client_cmd( 0, "spk sound/%s", g_iSounds[ AirDrop_Land_Sound ] );
set_pev( iEnt, pev_iuser2, 1 );
}
}
else if( fVelocity[ 2 ] < 0.0 ) // still in air
{
fVelocity[ 2 ] = g_fCachedAirDropVelocity;
set_pev( iEnt, pev_velocity, fVelocity );
}
return PLUGIN_CONTINUE;
}
public OnCreateAirDrop( )
{
if( g_iAirDrops <= get_pcvar_num( g_iCvars[ 5 ] ) ) // create as many AirDrops as described in the cvar
{
MakeAirDropEnt( );
g_iAirDrops++;
}
else
{
remove_task( TASK_AIRDROP ); // remove airdrop task, no more airdrops needed
}
}
public client_PreThink( id )
{
if( ! is_user_alive( id ) )
return PLUGIN_CONTINUE;
if( g_bIsPlayerInParachute[ id ] )
{
new Float:fVelocity[ 3 ];
pev( id, pev_velocity, fVelocity );
if( ! g_bLandedPlayer[ id ] && ( ( pev( id, pev_flags ) & FL_ONGROUND ) || ( pev( id, pev_flags ) & FL_INWATER ) ) ) // player has landed on ground/ in water
{
g_bIsPlayerInParachute[ id ] = false; // not in parachute anymore
set_pev( id, pev_sequence, detach );
set_pev( id, pev_movetype, MOVETYPE_WALK );
client_cmd( id, "spk sound/%s", g_iSounds[ Landing_Sound ] ); // emit landing sound
g_bLandedPlayer[ id ] = true;
}
else if( fVelocity[ 2 ] < 0.0 ) // still in air
{
fVelocity[ 2 ] = g_fCachedParachuteVelocity;
set_pev( id, pev_velocity, fVelocity );
}
}
return PLUGIN_CONTINUE;
}
@HamPlayerImpulseCommands_Pre( id ) // block spray and replace it with camera
{
if( ! is_user_alive( id ) )
return HAM_IGNORED;
if( ! get_pcvar_num( g_iCvars[ 2 ] ) )
return HAM_IGNORED;
if( pev( id, pev_impulse ) == 201 )
{
g_iPlayerView[ id ] = g_iPlayerView[ id ] == VIEW_3RDPERSON ? VIEW_NONE : VIEW_3RDPERSON;
set_view( id, g_iPlayerView[ id ] );
set_pev( id, pev_impulse, 0 );
}
return HAM_IGNORED;
}
public client_connect( id ) // reset vars
{
g_iPlayerView[ id ] = VIEW_NONE;
g_bIsPlayerInParachute[ id ] = false;
g_bPlayerInPlane[ id ] = false;
g_bLandedPlayer[ id ] = false;
}
ReadWeapons( ) // read our weapons from .ini
{
new szConfigsName[ 256 ], szFilename[ 512 ], eData[ WeaponData ], szWeaponName[ 32 ], szRarity[ 18 ], szData[ 128 ];
get_configsdir( szConfigsName, charsmax( szConfigsName ) );
formatex( szFilename, charsmax( szFilename ), "%s/%s", szConfigsName, g_szGameWeapons );
new iFile = fopen( szFilename, "rt" );
if( iFile )
{
while( ! feof( iFile ) )
{
fgets( iFile, szData, charsmax( szData ) );
trim( szData );
switch( szData[ 0 ] )
{
case EOS, '#', ';':
{
continue;
}
default:
{
if( parse( szData, szWeaponName, charsmax( szWeaponName ), szRarity, charsmax( szRarity ) ) < 2 )
continue;
for( new i; i < sizeof g_szForbiddenWeapons; i++ )
{
if( equal( szWeaponName, g_szForbiddenWeapons[ i ] ) )
{
continue;
}
}
new iRarity;
if( TrieGetCell( g_tRarityTrie, szRarity, iRarity ) )
{
if( ! ( RARITY_GREY <= iRarity <= RARITY_GOLD ) )
{
continue;
}
eData[ Weapon_Rarity ] = iRarity;
}
eData[ Weapon_Name ] = szWeaponName;
ArrayPushArray( g_aWeaponData, eData );
log_to_file( "debugold.txt", "%s %d", eData[ Weapon_Name ], eData[ Weapon_Rarity ] );
}
}
}
fclose( iFile );
}
}
ReadModels( ) // read our models from .ini
{
new szConfigsName[ 256 ], szFilename[ 512 ];
get_configsdir( szConfigsName, charsmax( szConfigsName ) );
formatex( szFilename, charsmax( szFilename ), "%s/%s", szConfigsName, g_szGameModels );
new iFile = fopen( szFilename, "r" );
if( iFile )
{
new szData[ 128 ], szValue[ 64 ], szKey[ 32 ];
while( ! feof( iFile ) )
{
fgets( iFile, szData, charsmax( szData ) );
trim( szData );
switch( szData[ 0 ] )
{
case EOS, '#', ';':
continue;
default:
{
strtok( szData, szKey, charsmax( szKey ), szValue, charsmax( szValue ), '=' );
trim( szKey );
trim( szValue );
if( ! szValue[ 0 ] )
continue;
if( equal( szKey, "AIRDROP_MODEL_FLYING" ) )
{
g_iDataAirDrop[ AirDrop_Model_Flying ] = szValue;
precache_model( szValue );
}
else if( equal( szKey, "AIRDROP_MODEL_GROUND" ) )
{
g_iDataAirDrop[ AirDrop_Model_Ground ] = szValue;
precache_model( szValue );
}
else if( equal( szKey, "AIRPLANE_MODEL" ) )
{
g_iDataAirPlane[ AirPlane_Model ] = szValue;
precache_model( szValue );
}
}
}
}
}
fclose( iFile );
}
ReadSounds( ) // read our sounds from .ini
{
new szConfigsName[ 256 ], szFilename[ 512 ];
get_configsdir( szConfigsName, charsmax( szConfigsName ) );
formatex( szFilename, charsmax( szFilename ), "%s/%s", szConfigsName, g_szGameSounds );
new iFile = fopen( szFilename, "r" );
if( iFile )
{
new szData[ 128 ], szValue[ 64 ], szKey[ 32 ];
while( ! feof( iFile ) )
{
fgets( iFile, szData, charsmax( szData ) );
trim( szData );
switch( szData[ 0 ] )
{
case EOS, '#', ';':
continue;
default:
{
strtok( szData, szKey, charsmax( szKey ), szValue, charsmax( szValue ), '=' );
trim( szKey );
trim( szValue );
if( ! szValue[ 0 ] )
continue;
if( equal( szKey, "PARACHUTE_DEPLOY_SOUND" ) )
{
g_iSounds[ Parachute_Deploy_Sound ] = szValue;
precache_sound( szValue );
}
else if( equal( szKey, "LANDING_SOUND" ) )
{
g_iSounds[ Landing_Sound ] = szValue;
precache_sound( szValue );
}
else if( equal( szKey, "AIRDROP_APPEAR_SOUND" ) )
{
g_iSounds[ AirDrop_Appear_Sound ] = szValue;
precache_sound( szValue );
}
else if( equal( szKey, "AIRDROP_LAND_SOUND" ) )
{
g_iSounds[ AirDrop_Land_Sound ] = szValue;
precache_sound( szValue );
}
}
}
}
}
fclose( iFile );
}
MakeAirPlane( )
{
new Float:fOrigin[ 3 ], Float:fAngle[ 3 ] , Float:fVelocity[ 3 ];
GetPlaneDirection( fOrigin, fAngle, fVelocity ) ;
g_iAirPlaneEnt = create_entity( "info_target" );
set_pev( g_iAirPlaneEnt, pev_classname, AIRPLANE_CLASSNAME );
set_pev( g_iAirPlaneEnt, pev_solid, SOLID_NOT ); // we dont want it to collide with players who jump
set_pev( g_iAirPlaneEnt, pev_movetype, MOVETYPE_FLY ); // its gonna fly, so..
engfunc( EngFunc_SetModel, g_iAirPlaneEnt, g_iDataAirPlane[ AirPlane_Model ] );
engfunc( EngFunc_SetOrigin, g_iAirPlaneEnt, fOrigin );
set_pev( g_iAirPlaneEnt, pev_angles, fAngle ); // set correct angles, we don't want a plane going backwards
set_pev( g_iAirPlaneEnt, pev_velocity, fVelocity );
fOrigin[ 2 ] -= 5.0; // reduce the Z axi a little bit, find the best place for players to stand
new szPlayers[ 32 ], iNum, iTempID;
get_players( szPlayers, iNum, "ach" );
for( new i; i < iNum; i++ )
{
iTempID = szPlayers[ i ];
AttachPlayerToPlane( iTempID, fOrigin, fAngle, fVelocity ); // attach the players to the plane
}
}
AttachPlayerToPlane( id, Float:fOrigin[ 3 ], Float:fAngle[ 3 ], Float:fVelocity[ 3 ] )
{
set_user_rendering( id, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, 0 ); // make player invisibile
engfunc( EngFunc_SetOrigin, id, fOrigin );
set_pev( id, pev_angles, fAngle );
set_pev( id, pev_fixangle, 1 ); // idk if its really needed
set_pev( id, pev_velocity, fVelocity );
set_pev( id, pev_gravity, 0.00001 ); // 0.0 doesnt work so lets set an extra small value
set_pev( id, pev_maxspeed, 0.00001 ); // same as above
g_bIsPlayerInParachute[ id ] = false; // player isnt in parachute
g_bPlayerInPlane[ id ] = true; // but hes in airplane
set_pev( id, pev_solid, SOLID_NOT ); // make him SOLID_NOT so he doesnt collide with the others
}
GetPlaneDirection( Float:fOrigin[ 3 ] , Float:fAngle[ 3 ], Float:fVelocity[ 3 ] ) // get a random hard-coded direction for the plane, impossible to do without hard-coding
{
switch( random_num( 1, 2 ) )
{
case 1:
{
fOrigin[ 0 ] = 3284.0;
fOrigin[ 1 ] = -3284.3;
fOrigin[ 2 ] = 3931.9;
fAngle[ 0 ] = -0.6;
fAngle[ 1 ] = 137.1;
fAngle[ 2 ] = 0.0;
fVelocity[ 0 ] = -219.9;
fVelocity[ 1 ] = 203.7;
fVelocity[ 2 ] = -10.0;
}
case 2:
{
fOrigin[ 0 ] = -2767.5;
fOrigin[ 1 ] = -1382.9;
fOrigin[ 2 ] = 3931.9;
fAngle[ 0 ] = -1.3;
fAngle[ 1 ] = 20.5;
fAngle[ 2 ] = 0.0;
fVelocity[ 0 ] = 280.2;
fVelocity[ 1 ] = 104.8;
fVelocity[ 2 ] = -20.8;
}
}
}
MakeAirDropEnt( )
{
new iEnt = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) );
new Float:fOrigin[ 3 ];
ROGGetOrigin( fOrigin ); // get a valid origin
fOrigin[ 2 ] = 3850.0; // max height, as we're gonna stick to one map, hard-code it
engfunc( EngFunc_SetOrigin, iEnt, fOrigin );
set_pev( iEnt, pev_classname, AIRDROP_CLASSNAME );
set_pev( iEnt, pev_movetype, MOVETYPE_TOSS ); // if it lands on the moving boat, to follow the boat instead of levitating
set_pev( iEnt, pev_solid, SOLID_BBOX );
engfunc( EngFunc_SetModel, iEnt, g_iDataAirDrop[ AirDrop_Model_Flying ] );
engfunc( EngFunc_SetSize, iEnt, Float:{ -35.0, -40.0, -5.0 }, Float:{ 35.0, 40.0, 5.0 } );
set_pev( iEnt, pev_nextthink, get_gametime( ) + 0.01 ); // make it think
client_cmd( 0, "spk sound/%s", g_iSounds[ AirDrop_Appear_Sound ] ); // emit airdrop appear sound
client_print( 0, print_center, "%L", LANG_PLAYER, "AIRDROP_ARRIVED" );
}
OpenAirDrop( id, iEnt ) // player is opening airdrop
{
new Float:fOrigin[ 3 ];
pev( iEnt, pev_origin, fOrigin );
message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
write_byte( TE_EXPLOSION ); // make effect
engfunc( EngFunc_WriteCoord, fOrigin[ 0 ] );
engfunc( EngFunc_WriteCoord, fOrigin[ 1 ] );
engfunc( EngFunc_WriteCoord, fOrigin[ 2 ] );
write_short( g_iSpriteIndexExplosion );
write_byte( 30 );
write_byte( 15 );
write_byte( TE_EXPLFLAG_NONE );
message_end( );
engfunc( EngFunc_RemoveEntity, iEnt ); // remove the ent
new iWeapon = g_szPossibleAirDropWeapons[ random( sizeof g_szPossibleAirDropWeapons ) ]; // retrieve a random entry
StripWeapons( id, Primary, false ); // strip his primary weapon
GivePlayerSpecialWeapon( id, iWeapon ); // give him a special weapon
return PLUGIN_CONTINUE;
}
GivePlayerSpecialWeapon( id, iWeapon )
{
new szWeaponName[ 32 ], iNumWeapons, iWeaponID, szWeapons[ 32 ];
get_weaponname( iWeapon, szWeaponName, charsmax( szWeaponName ) );
new iEnt = give_item( id, szWeaponName );
if( pev_valid( iEnt ) )
{
set_pev( iEnt, pev_iuser2, RandomGlowByChance( ) );
get_user_weapons( id, szWeapons, iNumWeapons );
for( new i; i < iNumWeapons; i++ )
{
iWeaponID = szWeapons[ i ];
if ( ( 1 << iWeapon ) & SKIP_THESE_WEAPONS )
continue;
ExecuteHamB( Ham_GiveAmmo, id, g_szMaxBpAmmo[ iWeaponID ], g_szAmmoType[ iWeaponID ], g_szMaxBpAmmo[ iWeaponID ] );
}
ExecuteForward( g_iFwOpenAirDrop, g_iDummyResult, id, iWeapon );
}
}
RandomGlowByChance( ) // stock to pick a glow by chances
{
new iReturnValue;
const iPercentage = 100;
new iRandomNum = random_num( 0, iPercentage );
switch( iRandomNum )
{
case 0 .. 40:
iReturnValue = RARITY_BLUE;
case 41 .. 75:
iReturnValue = RARITY_PURPLE;
case 76 .. 100:
iReturnValue = RARITY_GOLD;
}
return iReturnValue
}
GlowWeapon( iEnt, iColor ) // glow the weapon
{
switch( iColor )
{
case RARITY_GREY:
set_rendering( iEnt, kRenderFxGlowShell, 192, 192, 192, kRenderNormal, 50 );
case RARITY_GREEN:
set_rendering( iEnt, kRenderFxGlowShell, 0, 255, 0, kRenderNormal, 50 );
case RARITY_BLUE:
set_rendering( iEnt, kRenderFxGlowShell, 0, 181, 255, kRenderNormal, 50 );
case RARITY_PURPLE:
set_rendering( iEnt, kRenderFxGlowShell, 128, 0, 128, kRenderNormal, 50 );
case RARITY_GOLD:
set_rendering( iEnt, kRenderFxGlowShell, 255, 215, 0, kRenderNormal, 50 );
}
}
GetExtraDamage( iGlowColor ) // get damage according to glow
{
return iGlowColor * get_pcvar_num( g_iCvars[ 9 ] );
}
RemoveAllWeaponBox( )
{
new iEnt = -1;
while( ( iEnt = find_ent_by_class( iEnt, "weaponbox" ) ) != 0 )
{
set_pdata_int( iEnt, m_pfnThink, CWeaponBoxKill_Address, 0 );
}
}
GetWeaponBoxWeaponType( iEnt )
{
new iWeapon;
for( new i = 1; i <= 5; i++ )
{
iWeapon = get_pdata_cbase( iEnt, m_rgpPlayerItems_CWeaponBox[ i ], XO_CWEAPONBOX );
if( iWeapon > 0 )
{
return iWeapon;
}
}
return 0;
}
RemoveObjectives( )
{
remove_entity_name( "info_bomb_target" );
remove_entity_name( "func_bomb_target" );
}
When parsing info into array:
PHP Code:
L 08/05/2018 - 15:43:49: Log file started (file "cstrike/addons/amxmodx/logs/debugold.txt") (game "cstrike") (amx "1.8.2")
L 08/05/2018 - 15:43:49: weapon_p228 1
L 08/05/2018 - 15:43:49: weapon_glock 2
L 08/05/2018 - 15:43:49: weapon_scout 3
L 08/05/2018 - 15:43:49: weapon_hegrenade 4
L 08/05/2018 - 15:43:49: weapon_xm1014 5
L 08/05/2018 - 15:43:49: weapon_mac10 1
L 08/05/2018 - 15:43:49: weapon_aug 2
L 08/05/2018 - 15:43:49: weapon_smokegrenade 3
L 08/05/2018 - 15:43:49: weapon_elite 4
L 08/05/2018 - 15:43:49: weapon_fiveseven 5
L 08/05/2018 - 15:43:49: weapon_ump45 1
L 08/05/2018 - 15:43:49: weapon_sg550 2
L 08/05/2018 - 15:43:49: weapon_galil 3
L 08/05/2018 - 15:43:49: weapon_famas 4
L 08/05/2018 - 15:43:49: weapon_usp 5
L 08/05/2018 - 15:43:49: weapon_glock18 1
L 08/05/2018 - 15:43:49: weapon_awp 2
L 08/05/2018 - 15:43:49: weapon_mp5navy 3
L 08/05/2018 - 15:43:49: weapon_m249 4
L 08/05/2018 - 15:43:49: weapon_m3 5
L 08/05/2018 - 15:43:49: weapon_m4a1 1
L 08/05/2018 - 15:43:49: weapon_tmp 2
L 08/05/2018 - 15:43:49: weapon_g3sg1 3
L 08/05/2018 - 15:43:49: weapon_flashbang 4
L 08/05/2018 - 15:43:49: weapon_deagle 5
L 08/05/2018 - 15:43:49: weapon_sg552 1
L 08/05/2018 - 15:43:49: weapon_ak47 2
L 08/05/2018 - 15:43:49: weapon_p90 3
L 08/05/2018 - 15:43:49: weapon_p228 1
L 08/05/2018 - 15:43:49: weapon_glock 2
L 08/05/2018 - 15:43:49: weapon_scout 3
L 08/05/2018 - 15:43:49: weapon_hegrenade 4
L 08/05/2018 - 15:43:49: weapon_xm1014 5
L 08/05/2018 - 15:43:49: weapon_mac10 1
L 08/05/2018 - 15:43:49: weapon_aug 2
L 08/05/2018 - 15:43:49: weapon_smokegrenade 3
L 08/05/2018 - 15:43:49: weapon_elite 4
L 08/05/2018 - 15:43:49: weapon_fiveseven 5
L 08/05/2018 - 15:43:49: weapon_ump45 1
L 08/05/2018 - 15:43:49: weapon_sg550 2
L 08/05/2018 - 15:43:49: weapon_galil 3
L 08/05/2018 - 15:43:49: weapon_famas 4
L 08/05/2018 - 15:43:49: weapon_usp 5
L 08/05/2018 - 15:43:49: weapon_glock18 1
L 08/05/2018 - 15:43:49: weapon_awp 2
L 08/05/2018 - 15:43:49: weapon_mp5navy 3
L 08/05/2018 - 15:43:49: weapon_m249 4
L 08/05/2018 - 15:43:49: weapon_m3 5
L 08/05/2018 - 15:43:49: weapon_m4a1 1
L 08/05/2018 - 15:43:49: weapon_tmp 2
L 08/05/2018 - 15:43:49: weapon_g3sg1 3
L 08/05/2018 - 15:43:49: weapon_flashbang 4
L 08/05/2018 - 15:43:49: weapon_deagle 5
L 08/05/2018 - 15:43:49: weapon_sg552 1
L 08/05/2018 - 15:43:49: weapon_ak47 2
L 08/05/2018 - 15:43:49: weapon_p90 3
L 08/05/2018 - 15:43:49: weapon_p228 1
L 08/05/2018 - 15:43:49: weapon_glock 2
L 08/05/2018 - 15:43:49: weapon_scout 3
L 08/05/2018 - 15:43:49: weapon_hegrenade 4
L 08/05/2018 - 15:43:49: weapon_xm1014 5
L 08/05/2018 - 15:43:49: weapon_mac10 1
L 08/05/2018 - 15:43:49: weapon_aug 2
L 08/05/2018 - 15:43:49: weapon_smokegrenade 3
L 08/05/2018 - 15:43:49: weapon_elite 4
L 08/05/2018 - 15:43:49: weapon_fiveseven 5
L 08/05/2018 - 15:43:49: weapon_ump45 1
L 08/05/2018 - 15:43:49: weapon_sg550 2
L 08/05/2018 - 15:43:49: weapon_galil 3
L 08/05/2018 - 15:43:49: weapon_famas 4
L 08/05/2018 - 15:43:49: weapon_usp 5
L 08/05/2018 - 15:43:49: weapon_glock18 1
L 08/05/2018 - 15:43:49: weapon_awp 2
L 08/05/2018 - 15:43:49: weapon_mp5navy 3
L 08/05/2018 - 15:43:49: weapon_m249 4
L 08/05/2018 - 15:43:49: weapon_m3 5
L 08/05/2018 - 15:43:49: weapon_m4a1 1
L 08/05/2018 - 15:43:49: weapon_tmp 2
L 08/05/2018 - 15:43:49: weapon_g3sg1 3
L 08/05/2018 - 15:43:49: weapon_flashbang 4
L 08/05/2018 - 15:43:49: weapon_deagle 5
L 08/05/2018 - 15:43:49: weapon_sg552 1
L 08/05/2018 - 15:43:49: weapon_ak47 2
L 08/05/2018 - 15:43:49: weapon_p90 3
L 08/05/2018 - 15:43:49: weapon_p228 1
L 08/05/2018 - 15:43:49: weapon_glock 2
L 08/05/2018 - 15:43:49: weapon_scout 3
L 08/05/2018 - 15:43:49: weapon_hegrenade 4
L 08/05/2018 - 15:43:49: weapon_xm1014 5
L 08/05/2018 - 15:43:49: weapon_mac10 1
L 08/05/2018 - 15:43:49: weapon_aug 2
L 08/05/2018 - 15:43:49: weapon_smokegrenade 3
L 08/05/2018 - 15:43:49: weapon_elite 4
L 08/05/2018 - 15:43:49: weapon_fiveseven 5
L 08/05/2018 - 15:43:49: weapon_ump45 1
L 08/05/2018 - 15:43:49: weapon_sg550 2
L 08/05/2018 - 15:43:49: weapon_galil 3
L 08/05/2018 - 15:43:49: weapon_famas 4
L 08/05/2018 - 15:43:49: weapon_usp 5
L 08/05/2018 - 15:43:49: weapon_glock18 1
L 08/05/2018 - 15:43:49: weapon_awp 2
L 08/05/2018 - 15:43:49: weapon_mp5navy 3
L 08/05/2018 - 15:43:49: weapon_m249 4
L 08/05/2018 - 15:43:49: weapon_m3 5
L 08/05/2018 - 15:43:49: weapon_m4a1 1
L 08/05/2018 - 15:43:49: weapon_tmp 2
L 08/05/2018 - 15:43:49: weapon_g3sg1 3
L 08/05/2018 - 15:43:49: weapon_flashbang 4
L 08/05/2018 - 15:43:49: weapon_deagle 5
L 08/05/2018 - 15:43:49: weapon_sg552 1
L 08/05/2018 - 15:43:49: weapon_ak47 2
L 08/05/2018 - 15:43:49: weapon_p90 3
When retrieving
PHP Code:
L 08/05/2018 - 15:44:17: Weapon Name: weapon_p228 | Weapon Rarity: 1
L 08/05/2018 - 15:44:17: Weapon Name: weapon_glock | Weapon Rarity: 2
|