Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <engine>
- #include <fakemeta>
- #include <hamsandwich>
- #include <xs>
- #include <zp50_gamemodes>
- #include <zp50_ammopacks>
- #include <zombieplague>
- #include <amx_settings_api>
- #include <zp50_items>
- #include <zp50_class_dragon>
- #include <zp50_class_nightcrawler>
- #include <zp50_colorchat>
- #define ZP_ITEM_NAME "Sandbag"
- #define ZP_ITEM_DESC "Protective breakable wall"
- #define ZP_ITEM_COST 30
- #define ZP_ITEM_LIMIT_PLAYER 2
- #define ZP_ITEM_LIMIT_ROUND 0
- new const g_szGameFile[ ] = "zp_items.ini"
- new g_iBarricadesPerPurchase = 1
- // Max stuff
- #define MAX_ENTITIES 1024
- // Custom forwards
- enum _:CustomForwards( )
- {
- FW_BARRICADE_SPAWN = 0,
- FW_BARRICADE_DELETE,
- FW_BARRICADE_TAKE_DAMAGE,
- FW_BARRICADE_DESTROYED
- };
- enum ( += 100 )
- {
- TASK_BARRICADE_SPAWN = 100,
- TASK_BARRICADE_DELETE,
- TASK_BARRICADE_INFO
- };
- #define ID_BARRICADE_SPAWN ( task_id - TASK_BARRICADE_SPAWN )
- #define ID_BARRICADE_DELETE ( task_id - TASK_BARRICADE_DELETE )
- #define ID_BARRICADE_INFO ( task_id - TASK_BARRICADE_INFO )
- enum ( )
- {
- matGlass = 0,
- matWood,
- matMetal,
- matFlesh,
- matCinderBlock,
- matCeilingTile,
- matComputer,
- matUnbreakableGlass,
- matRocks,
- matNone,
- matLastMaterial
- };
- new const g_szEntityBarricade[ ] = "func_barricade";
- new const g_szEntityBreakable[ ] = "func_breakable";
- new const g_szBarricadeModel[ ] = "models/pallet_with_bags.mdl";
- new const g_szSoundCrateHit[ ][ ] =
- {
- "debris/bustcrate1.wav",
- "debris/bustcrate2.wav",
- "debris/bustcrate3.wav"
- };
- const OFFSET_CSMENUCODE = 205
- new bool:g_bIsBarricadeDestroyed[ MAX_ENTITIES ];
- new g_iForward[ CustomForwards ];
- new g_iForwardReturn;
- new g_iBarricadeCached[ MAX_PLAYERS + 1 ];
- new g_iBarricadeSet[ MAX_PLAYERS + 1 ];
- new g_iBarricadeLimit[ MAX_PLAYERS + 1 ];
- new g_iAmmoPacks[ MAX_PLAYERS + 1 ], g_iItemID
- // Cvar binds (Floats)
- new Float:g_fBarricadeHealth;
- // Cvar binds (Intgers)
- new g_iBarricadeSetDistanceMax;
- new g_iBarricadeSetDistanceMin;
- new g_iBarricadeSetTime;
- new g_iBarricadeDeleteDistance;
- new g_iBarricadeDeleteTime;
- new g_iBarricadeRewardDestroy;
- new g_msgBarTime;
- public plugin_init( )
- {
- register_plugin( "[ZP] Barricade", "2.0.0", "Taurus" );
- // Cvars (Floats)
- bind_pcvar_float( register_cvar( "zp_barricade_health", "600.0" ), g_fBarricadeHealth );
- // Cvars (Integers)
- bind_pcvar_num( register_cvar( "zp_barricade_set_distance_max", "300" ), g_iBarricadeSetDistanceMax );
- bind_pcvar_num( register_cvar( "zp_barricade_set_distance_min", "50" ), g_iBarricadeSetDistanceMin );
- bind_pcvar_num( register_cvar( "zp_barricade_set_time", "2" ), g_iBarricadeSetTime );
- bind_pcvar_num( register_cvar( "zp_barricade_delete_distance", "150" ), g_iBarricadeDeleteDistance );
- bind_pcvar_num( register_cvar( "zp_barricade_delete_time", "1" ), g_iBarricadeDeleteTime );
- bind_pcvar_num( register_cvar( "zp_barricade_reward_destroy", "6" ), g_iBarricadeRewardDestroy );
- // Player messages
- g_msgBarTime = get_user_msgid( "BarTime" );
- // Custom forwards
- g_iForward[ FW_BARRICADE_SPAWN ] = CreateMultiForward( "zp_fw_barricade_spawn", ET_IGNORE, FP_CELL, FP_CELL );
- g_iForward[ FW_BARRICADE_DELETE ] = CreateMultiForward( "zp_fw_barricade_delete", ET_IGNORE, FP_CELL, FP_CELL );
- g_iForward[ FW_BARRICADE_TAKE_DAMAGE ] = CreateMultiForward( "zp_fw_barricade_take_damage", ET_CONTINUE, FP_CELL, FP_CELL );
- g_iForward[ FW_BARRICADE_DESTROYED ] = CreateMultiForward( "zp_fw_barricade_destroyed", ET_IGNORE, FP_CELL, FP_CELL );
- // Client commands
- register_clcmd( "+setbc", "ClCmd_StartSetBarricade" );
- register_clcmd( "-setbc", "ClCmd_ResetSetBarricade" );
- register_clcmd( "+delbc", "ClCmd_StartDelBarricade" );
- register_clcmd( "-delbc", "ClCmd_ResetDelBarricade" );
- register_clcmd( "say /ra_bc", "ClCmd_RemoveBarricade" );
- register_clcmd( "say ra_bc", "ClCmd_RemoveBarricade" );
- // Ham forwards
- RegisterHamPlayer( Ham_Killed, "fw_Killed" );
- RegisterHamPlayer( Ham_Killed, "fw_Killed_Post", true )
- register_clcmd("say /sb","show_the_menu");
- register_clcmd("say_team /sb","show_the_menu")
- g_iItemID = zp_items_register( ZP_ITEM_NAME, ZP_ITEM_DESC, ZP_ITEM_COST, ZP_ITEM_LIMIT_PLAYER, ZP_ITEM_LIMIT_ROUND );
- }
- public plugin_precache( )
- {
- // Barricade model
- precache_model( g_szBarricadeModel );
- // Precache sounds
- for( new iLoop = 0; iLoop < sizeof( g_szSoundCrateHit ); iLoop ++ )
- precache_sound( g_szSoundCrateHit[ iLoop ] );
- // I don't know what exactly does this thing do, apparently it makes the server happy!
- new iEntity = CreateBarricade( 0 );
- if( !pev_valid( iEntity ) )
- return;
- set_pev( iEntity, pev_flags, pev( iEntity, pev_flags ) | FL_KILLME );
- if( !amx_load_setting_int( g_szGameFile, ZP_ITEM_NAME, "BARRICADES PER PURCHASE", g_iBarricadesPerPurchase ) )
- amx_save_setting_int( g_szGameFile, ZP_ITEM_NAME, "BARRICADES PER PURCHASE", g_iBarricadesPerPurchase );
- }
- public zp_fw_items_select_pre( id, item_id )
- {
- if( item_id != g_iItemID )
- return ZP_ITEM_AVAILABLE
- if(zp_core_is_zombie(id))
- return ZP_ITEM_DONT_SHOW
- return ZP_ITEM_AVAILABLE
- }
- public zp_fw_items_select_post( id, item_id )
- {
- if( item_id != g_iItemID )
- return
- g_iBarricadeLimit[id] += g_iBarricadesPerPurchase
- zp_colored_print(id, "!tType !g/sb !tto bring up the !gsandbag menu.")
- show_the_menu(id)
- }
- public show_the_menu(id)
- {
- new menuid = menu_create("\ySandbags:", "menu_command")
- menu_additem(menuid, "Place a sandbag")
- menu_additem(menuid, "Remove a sandbag")
- if (!zp_core_is_zombie(id) && is_user_alive(id))
- {
- set_pdata_int(id, OFFSET_CSMENUCODE, 0)
- menu_display(id, menuid)
- }
- }
- public menu_command(id, menuid, item)
- {
- // Menu was closed
- if (item == MENU_EXIT)
- {
- menu_destroy(menuid)
- return PLUGIN_HANDLED
- }
- // Dead players are not allowed to buy items
- if (zp_core_is_zombie(id) || !is_user_alive(id))
- {
- menu_destroy(menuid)
- return PLUGIN_HANDLED
- }
- switch(item)
- {
- case 0: ClCmd_StartSetBarricade(id)
- case 1: ClCmd_StartDelBarricade(id)
- }
- menu_destroy(menuid)
- return PLUGIN_HANDLED
- }
- public plugin_natives( )
- {
- register_library("zp_barricade")
- register_native("open_sb_menu", "_open_sb_menu", 1)
- register_native("zp_barricade_get", "native_barricade_get", 1)
- register_native("zp_barricade_set", "native_barricade_set", 1)
- }
- public native_barricade_get(id)
- {
- if( !is_user_connected( id ) )
- {
- log_error( AMX_ERR_NATIVE, "[ZP] Player is not in-game (%d)", id );
- return -1
- }
- return g_iBarricadeLimit[ id ]
- }
- public native_barricade_set( id, amount )
- {
- if( !is_user_connected( id ) )
- {
- log_error( AMX_ERR_NATIVE, "[ZP] Player is not in-game (%d)", id );
- return -1
- }
- g_iBarricadeLimit[ id ] += amount
- return true
- }
- public _open_sb_menu(id)
- {
- if(!is_user_connected(id))
- {
- log_error( AMX_ERR_NATIVE, "[ZP] Player is not in-game (%d)", id )
- return false
- }
- show_the_menu(id)
- return true
- }
- public client_disconnected( id )
- {
- // Remove spawn task
- if( task_exists( id + TASK_BARRICADE_SPAWN ) )
- remove_task( id + TASK_BARRICADE_SPAWN );
- // Remove delete task
- if( task_exists( id + TASK_BARRICADE_DELETE ) )
- remove_task( id + TASK_BARRICADE_DELETE );
- // Remove info task
- if( task_exists( id + TASK_BARRICADE_INFO ) )
- remove_task( id + TASK_BARRICADE_INFO );
- // Remove barricade put by player
- RemoveBarricadesByOwner( id, true );
- }
- public client_PreThink( id )
- {
- // Player is not alive
- if (!is_user_alive(id))
- return;
- // Delete barricade task in progress?
- if( task_exists( id + TASK_BARRICADE_DELETE ) )
- {
- // Get aim entity
- new iEntity, iPart;
- get_user_aiming( id, iEntity, iPart );
- // Is that entity a valid one?
- if( !pev_valid( iEntity ) && task_exists( id + TASK_BARRICADE_DELETE ) )
- {
- remove_task( id + TASK_BARRICADE_DELETE );
- SendBarTime( id );
- return;
- }
- }
- // Spawning barricade
- else if( task_exists( id + TASK_BARRICADE_SPAWN ) )
- UpdateEntityPosition( id );
- }
- public zp_fw_core_spawn_post( id )
- {
- // Player is not longer connected
- if( !is_user_connected( id ) )
- return
- // Show barricade info (Have to check task's existence so we do not call multiple tasks pointlessly)
- if( !task_exists( id + TASK_BARRICADE_INFO ) )
- set_task( 0.1, "_tBarricadeInfo", id + TASK_BARRICADE_INFO, _, _, "b" );
- }
- public zp_fw_core_infect_post( id, attacker_id )
- {
- // Remove spawn task
- if( task_exists( id + TASK_BARRICADE_SPAWN ) )
- {
- remove_task( id + TASK_BARRICADE_SPAWN );
- // Remove bartime message
- SendBarTime( id );
- }
- // Remove delete task
- if( task_exists( id + TASK_BARRICADE_DELETE ) )
- {
- remove_task( id + TASK_BARRICADE_DELETE );
- // Remove bartime message
- SendBarTime( id );
- }
- // Reward player for having victim's barricades removed
- if( id != attacker_id && is_user_alive( attacker_id ) )
- {
- // Get barricade count
- new iCount = GetCountBarricadesByOwner( id );
- if( !iCount )
- return;
- // Reward player for how many barricades have been removed
- new ammopacks_reward = iCount * g_iBarricadeRewardDestroy;
- zp_ammopacks_set( attacker_id, g_iAmmoPacks[ attacker_id ] + ammopacks_reward );
- // Notify players about barricade removal reward
- static szName[ 2 ][ 32 ];
- get_user_name( attacker_id, szName[ 0 ], charsmax( szName[ ] ) );
- get_user_name( id, szName[ 1 ], charsmax( szName[ ] ) );
- zp_colored_print( 0, "%L", LANG_SERVER, "MSG_BARRICADE_DESTROYED_ALL", szName[ 0 ], szName[ 1 ], ammopacks_reward );
- }
- // Remove barricade when a player to be infected
- RemoveBarricadesByOwner( id, true );
- }
- public zp_fw_gamemodes_end( )
- {
- // When the round ends, remove all barricades!
- RemoveBarricades( );
- }
- public zp_fw_ammopacks_update( id, iAmount )
- {
- // Player is not longer connected
- if( !is_user_connected( id ) )
- return;
- // Update player's ammo packs (Less natives used)
- g_iAmmoPacks[ id ] = iAmount;
- }
- public ClCmd_StartSetBarricade( id )
- {
- // Player is not alive?
- if (!is_user_alive(id) || zp_core_is_zombie(id))
- return PLUGIN_HANDLED;
- // Limit has been exceeded?
- if( g_iBarricadeSet[ id ] >= g_iBarricadeLimit[ id ] )
- return PLUGIN_HANDLED;
- // Let's try creating our entity
- new iEntity = CreateBarricade( id );
- // Invalid entity?
- if( !pev_valid( iEntity ) )
- return PLUGIN_HANDLED;
- // Check distance between entity and owner, and glow it!
- if( CheckEntityDistance( iEntity, id ) > g_iBarricadeSetDistanceMin )
- set_pev( iEntity, pev_rendercolor, Float:{ 0.0, 255.0, 0.0 } );
- else
- set_pev( iEntity, pev_rendercolor, Float:{ 255.0, 0.0, 0.0 } );
- // Send bartime message in order to show how much left to finish placing barricades!
- SendBarTime( id, g_iBarricadeSetTime );
- // Set task to placing a barricades
- set_task( float( g_iBarricadeSetTime ), "_tBarricadeSpawn", id + TASK_BARRICADE_SPAWN );
- return PLUGIN_HANDLED;
- }
- public ClCmd_ResetSetBarricade( id )
- {
- // Player is not alive?
- if (!is_user_alive(id) || zp_core_is_zombie(id))
- return PLUGIN_HANDLED;
- // Spawn task does not exist?
- if( !task_exists( id + TASK_BARRICADE_SPAWN ) )
- return PLUGIN_HANDLED;
- // Get cached entity
- new iEntity = g_iBarricadeCached[ id ];
- // Valid entity? Remove it!
- if( pev_valid( iEntity ) )
- engfunc( EngFunc_RemoveEntity, iEntity );
- // Remove bartime message, we do not need it anymore!
- SendBarTime( id );
- // Remove barricade spawn task
- remove_task( id + TASK_BARRICADE_SPAWN );
- return PLUGIN_HANDLED;
- }
- public ClCmd_StartDelBarricade( id )
- {
- // Player is not alive?
- if (!is_user_alive(id) || zp_core_is_zombie(id))
- return PLUGIN_HANDLED;
- // Spwan task exists?
- if( task_exists( id + TASK_BARRICADE_SPAWN ) )
- return PLUGIN_HANDLED;
- // Get aim entity
- new iEntity, iPart;
- get_user_aiming( id, iEntity, iPart );
- // Are we aiming at a valid barricade entity?
- if( !CheckEntityByName( iEntity, g_szEntityBarricade ) )
- return PLUGIN_HANDLED;
- // Not owner?
- if( pev( iEntity, pev_iuser1 ) != id )
- {
- zp_colored_print( id, "!t%L", id, "MSG_BARRICADE_NOT_OWNER" );
- return PLUGIN_HANDLED;
- }
- // Not close enough?
- if( CheckEntityDistance( iEntity, id ) > g_iBarricadeDeleteDistance )
- return PLUGIN_HANDLED;
- // Get entity health
- new Float:fHealth;
- pev( iEntity, pev_health, fHealth );
- // Damaged entity?
- if( fHealth < g_fBarricadeHealth )
- {
- zp_colored_print( id, "!t%L", id, "MSG_BARRICADE_DAMAGED" );
- return PLUGIN_HANDLED;
- }
- // Start progress
- SendBarTime( id, g_iBarricadeDeleteTime );
- // Remove barricade after that defined time
- set_task( float( g_iBarricadeDeleteTime ), "_tBarricadeDelete", id + TASK_BARRICADE_DELETE );
- return PLUGIN_HANDLED;
- }
- public ClCmd_ResetDelBarricade( id )
- {
- // Player is not alive?
- if (!is_user_alive(id) || zp_core_is_zombie(id))
- return PLUGIN_HANDLED;
- // Spawn task does not exist?
- if( !task_exists( id + TASK_BARRICADE_DELETE ) )
- return PLUGIN_HANDLED;
- // Reset progress
- SendBarTime( id );
- // Terminate barricade deletion task
- remove_task( id + TASK_BARRICADE_DELETE );
- return PLUGIN_HANDLED;
- }
- public ClCmd_RemoveBarricade( id )
- {
- // Player is not alive?
- if (!is_user_alive(id) || zp_core_is_zombie(id))
- return PLUGIN_HANDLED;
- // Remove barricades by owner
- RemoveBarricadesByOwner( id );
- return PLUGIN_HANDLED;
- }
- public fw_Killed( victim_id, attacker_id )
- {
- // Player is no longer connected
- if( !is_user_connected( victim_id ) || !is_user_connected(attacker_id))
- return;
- // Remove task
- if( task_exists( victim_id + TASK_BARRICADE_INFO ) )
- remove_task( victim_id + TASK_BARRICADE_INFO )
- // Reward player for having victim's barricades removed
- if( victim_id != attacker_id && is_user_alive( attacker_id ) )
- {
- // Get barricade count
- new iCount = GetCountBarricadesByOwner( victim_id );
- if( !iCount )
- return;
- // Reward player for how many barricades have been removed
- new ammopacks_reward = iCount * g_iBarricadeRewardDestroy;
- zp_ammopacks_set( attacker_id, g_iAmmoPacks[ attacker_id ] + ammopacks_reward );
- // Notify players about barricade removal reward
- static szName[ 2 ][ 32 ];
- get_user_name( attacker_id, szName[ 0 ], charsmax( szName[ ] ) );
- get_user_name( victim_id, szName[ 1 ], charsmax( szName[ ] ) );
- zp_colored_print( 0, "!t%L", LANG_SERVER, "MSG_BARRICADE_DESTROYED_ALL", szName[ 0 ], szName[ 1 ], ammopacks_reward );
- }
- }
- public fw_Killed_Post( victim_id, attacker_id )
- {
- // Remove spawn task
- if( task_exists( victim_id + TASK_BARRICADE_SPAWN ) )
- {
- remove_task( victim_id + TASK_BARRICADE_SPAWN );
- // Remove progress (Bar message)
- SendBarTime( victim_id );
- }
- // Remove delete task
- if( task_exists( victim_id + TASK_BARRICADE_DELETE ) )
- {
- remove_task( victim_id + TASK_BARRICADE_DELETE );
- // Remove progress (Bar message)
- SendBarTime( victim_id );
- }
- // Remove barricades put by player
- RemoveBarricadesByOwner( victim_id, true );
- }
- public Ham_BarricadeTakeDamage_Pre( victim_id, inflictor_id, attacker_id, Float:fDamage, iDamageBits )
- {
- // Is the victim a valid barricade?
- if( !CheckEntityByName( victim_id, g_szEntityBarricade ) )
- return HAM_IGNORED;
- // Check who's attacking it?
- if( pev( victim_id, pev_iuser1 ) == attacker_id || !zp_core_is_zombie(attacker_id))
- return HAM_SUPERCEDE;
- // Maybe other plugins want to prevent barricade from taking damage! (victim, attacker)
- ExecuteForward( g_iForward[ FW_BARRICADE_TAKE_DAMAGE ], g_iForwardReturn, victim_id, attacker_id );
- if( g_iForwardReturn >= PLUGIN_HANDLED )
- return HAM_SUPERCEDE;
- return HAM_IGNORED;
- }
- public Ham_BarricadeTakeDamage_Post( victim_id, inflictor_id, attacker_id, Float:fDamage, iDamageBits )
- {
- // Is the victim a valid barricade?
- if( !CheckEntityByName( victim_id, g_szEntityBarricade ) )
- return HAM_IGNORED;
- // Get barricade health
- new Float:fHealth;
- pev( victim_id, pev_health, fHealth );
- // barricade's health is now 0, means it is destroyed!
- if( fHealth <= 0.0 && !g_bIsBarricadeDestroyed[ victim_id ] )
- {
- // Now it is destroyed
- g_bIsBarricadeDestroyed[ victim_id ] = true;
- // Boom! Our barricade has been destroyed! :/
- ExecuteForward( g_iForward[ FW_BARRICADE_DESTROYED ], g_iForwardReturn, victim_id, attacker_id );
- // Reward player for destroying a barricade
- zp_ammopacks_set( attacker_id, g_iAmmoPacks[ attacker_id ] + g_iBarricadeRewardDestroy );
- // Notify all players that barricade has been destroyed
- static szName[ 32 ];
- get_user_name( attacker_id, szName, charsmax( szName ) );
- zp_colored_print( 0, "!t%L", LANG_SERVER, "MSG_BARRICADE_DESTROYED", szName, g_iBarricadeRewardDestroy );
- return HAM_IGNORED;
- }
- new Float:fColour[ 3 ];
- ComputeColours( fHealth * 100.0 / g_fBarricadeHealth, fColour );
- set_pev( victim_id, pev_rendercolor, fColour );
- return HAM_IGNORED;
- }
- public _tBarricadeSpawn( task_id )
- {
- // Player is not alive?
- if( !is_user_alive( ID_BARRICADE_SPAWN ) )
- return;
- // Get our entity :)
- new iEntity = g_iBarricadeCached[ ID_BARRICADE_SPAWN ];
- // Is our entity a valid one?
- if( !pev_valid( iEntity ) )
- return;
- // Play cannot place barricade?
- if( !pev( iEntity, pev_iuser2 ) )
- {
- engfunc( EngFunc_RemoveEntity, iEntity );
- SendBarTime( ID_BARRICADE_SPAWN );
- zp_colored_print( ID_BARRICADE_SPAWN, "!t%L", ID_BARRICADE_SPAWN, "MSG_BARRICADE_NOT_SPAWN" );
- return;
- }
- // Make our entity a solid one
- set_pev( iEntity, pev_solid, SOLID_BBOX );
- // Make our entity take damage and set health for it
- set_pev( iEntity, pev_takedamage, 1.0 );
- set_pev( iEntity, pev_health, g_fBarricadeHealth );
- // Make our entity glow a normal one
- set_pev( iEntity, pev_renderfx, kRenderFxGlowShell );
- set_pev( iEntity, pev_renderamt, 5.0 );
- // Once it has spawned, let's register some stuff!
- RegisterHamFromEntity( Ham_TakeDamage, iEntity, "Ham_BarricadeTakeDamage_Pre", false );
- RegisterHamFromEntity( Ham_TakeDamage, iEntity, "Ham_BarricadeTakeDamage_Post", true );
- // This entity was never destroyed before!
- g_iBarricadeSet[ ID_BARRICADE_SPAWN ] ++
- g_bIsBarricadeDestroyed[ iEntity ] = false;
- // Notify all players that someone planted a barricade
- static szName[ 32 ];
- get_user_name( ID_BARRICADE_SPAWN, szName, charsmax( szName ) );
- zp_colored_print( 0, "%L", LANG_SERVER, "MSG_BARRICADE_SPAWNED", szName );
- // Now that the entity spawned, call a forward (entity, owner)
- ExecuteForward( g_iForward[ FW_BARRICADE_SPAWN ], g_iForwardReturn, iEntity, ID_BARRICADE_SPAWN );
- if (g_iBarricadeLimit[ID_BARRICADE_SPAWN] > 0)
- show_the_menu(ID_BARRICADE_SPAWN)
- }
- public _tBarricadeDelete( task_id )
- {
- // Player is not alive?
- if( !is_user_alive( ID_BARRICADE_DELETE ) )
- return;
- // Get aim entity
- new iEntity, iPart;
- get_user_aiming( ID_BARRICADE_DELETE, iEntity, iPart );
- // Is the victim a valid barricade?
- if( !CheckEntityByName( iEntity, g_szEntityBarricade ) )
- return;
- // Not the owner of the barricade
- if( pev( iEntity, pev_iuser1 ) != ID_BARRICADE_DELETE )
- return;
- // Remove barricade
- RemoveBarricadeByOwner( iEntity, ID_BARRICADE_DELETE );
- // Now that the entity spawned, call a forward (entity, owner)
- ExecuteForward( g_iForward[ FW_BARRICADE_DELETE ], g_iForwardReturn, iEntity, ID_BARRICADE_DELETE );
- if (g_iBarricadeLimit[ID_BARRICADE_DELETE] > 0)
- show_the_menu(ID_BARRICADE_DELETE)
- }
- public _tBarricadeInfo( task_id )
- {
- new iPart, iEntity;
- get_user_aiming( ID_BARRICADE_INFO, iEntity, iPart, g_iBarricadeSetDistanceMax );
- if( !CheckEntityByName( iEntity, g_szEntityBarricade ) )
- return;
- new owner_id = pev( iEntity, pev_iuser1 );
- if( !is_user_alive( owner_id ) )
- return;
- static szName[ 32 ];
- get_user_name( owner_id, szName, charsmax( szName ) );
- new Float:fHealth;
- pev( iEntity, pev_health, fHealth );
- if( fHealth <= 0.0 )
- return;
- new iHealth = floatround( fHealth );
- static msgHudSync;
- if( !msgHudSync )
- msgHudSync = CreateHudSyncObj( );
- set_hudmessage( 0, 100, 200, -1.0, 0.55, 0, 0.0, 0.1, 0.1, 0.1, 3 );
- ShowSyncHudMsg( ID_BARRICADE_INFO, msgHudSync, "Owner: %s | Health: %d", szName, iHealth );
- }
- CreateBarricade( id )
- {
- // Create a breakable entity
- static func_breakable_id;
- if( !func_breakable_id )
- func_breakable_id = engfunc( EngFunc_AllocString, g_szEntityBreakable );
- new iEntity = engfunc( EngFunc_CreateNamedEntity, func_breakable_id );
- // Invalid entity created?
- if( !pev_valid( iEntity ) )
- return FM_NULLENT;
- // Make it a woody material
- static szMaterial[ 3 ];
- num_to_str( matWood, szMaterial, charsmax( szMaterial ) );
- DispatchKeyValue( iEntity, "material", szMaterial );
- // Spawn entity!
- dllfunc( DLLFunc_Spawn, iEntity );
- if( !id )
- return iEntity;
- // Set entity information
- set_pev( iEntity, pev_classname, g_szEntityBarricade );
- // Set entity owner
- set_pev( iEntity, pev_iuser1, id );
- // Set entity nature
- set_pev( iEntity, pev_solid, SOLID_NOT );
- set_pev( iEntity, pev_movetype, MOVETYPE_FLY );
- // Entity cannot take any damage while being created!
- set_pev( iEntity, pev_takedamage, 0.0 );
- // Entity glow
- set_pev( iEntity, pev_renderfx, kRenderFxGlowShell );
- set_pev( iEntity, pev_renderamt, 5.0 );
- // Set entity model and size
- engfunc( EngFunc_SetModel, iEntity, g_szBarricadeModel );
- engfunc( EngFunc_SetSize, iEntity, Float:{ -27.260000, -22.280001, -22.290001 }, Float:{ 27.340000, 26.629999, 29.020000 } );
- // Check entity position again!
- CheckEntityPosition( iEntity, id );
- // Set player's cached entity
- g_iBarricadeCached[ id ] = iEntity;
- // Return entity id?
- return iEntity;
- }
- UpdateEntityPosition( id )
- {
- // Player is not alive?
- if( !is_user_alive( id ) )
- return;
- // Get our entity :)
- new iEntity = g_iBarricadeCached[ id ];
- // Is it a valid one?
- if( !pev_valid( iEntity ) )
- return;
- // Spawn task exists?
- if( task_exists( id + TASK_BARRICADE_SPAWN ) )
- {
- if( CheckEntityPosition( iEntity, id ) )
- {
- set_pev( iEntity, pev_rendercolor, Float:{ 0.0, 255.0, 0.0 } );
- set_pev( iEntity, pev_iuser2, 1 );
- }
- else
- {
- set_pev( iEntity, pev_rendercolor, Float:{ 255.0, 0.0, 0.0 } );
- set_pev( iEntity, pev_iuser2, 0 );
- }
- }
- }
- CheckEntityPosition( iEntity, id )
- {
- // Is entity valid?
- if( !pev_valid( iEntity ) )
- return false;
- // Trace direction
- new Float:fOrigin[ 3 ];
- GetAimOrigin( id, fOrigin );
- // Check fraction
- new Float:fFraction;
- get_tr2( 0, TR_flFraction, fFraction );
- // Normal vector
- new Float:fNormal[ 3 ];
- // We hit something
- if( fFraction < 1.0 )
- {
- get_tr2( 0, TR_vecEndPos, fOrigin );
- get_tr2( 0, TR_vecPlaneNormal, fNormal );
- }
- // Update normal vector and new origin
- xs_vec_mul_scalar( fNormal, 8.0, fNormal );
- xs_vec_add( fOrigin, fNormal, fOrigin );
- fOrigin[ 2 ] += 16.0;
- // Set entity's origin
- engfunc( EngFunc_SetOrigin, iEntity, fOrigin );
- // Check for collides
- if( CheckEntityCollides( fOrigin, 17.0 ) )
- return false;
- // Follow terrain
- EntityFollowTerrain( iEntity, fOrigin, 0 );
- // Check placement points
- new iPointContents = engfunc( EngFunc_PointContents, fOrigin );
- if( iPointContents != CONTENTS_EMPTY )
- return false;
- // Check if it is hitting an entity we don't want glitch
- new iHit = get_tr2( 0, TR_pHit );
- if( pev_valid( iHit ) && !CheckEntityHitAllowed( iHit ) )
- return false;
- // Entity is too close?
- if( CheckEntityDistance( iEntity, id ) <= g_iBarricadeSetDistanceMin )
- return false;
- // Entity is too far?
- if( CheckEntityDistance( iEntity, id ) > g_iBarricadeSetDistanceMax )
- return false;
- return true;
- }
- CheckEntityDistance( iEntity, id )
- {
- // Get entity and player origin
- new Float:fOrigin[ 2 ][ 3 ];
- pev( iEntity, pev_origin, fOrigin[ 0 ] );
- pev( id, pev_origin, fOrigin[ 1 ] );
- // Return distance as an integer
- return floatround( get_distance_f( fOrigin[ 0 ], fOrigin[ 1 ] ) );
- }
- CheckEntityByName( iEntity, const szClassName[ ] )
- {
- // Is it a valid entity?
- if( !pev_valid( iEntity ) )
- return false;
- // Check entity name
- static szNameCheck[ 32 ];
- pev( iEntity, pev_classname, szNameCheck, charsmax( szNameCheck ) );
- // Class name maches?
- if( equal( szClassName, szNameCheck ) )
- return true;
- return false;
- }
- // Sends bar message, iTime = 0 means cancel bar message
- SendBarTime( id, iTime = 0 )
- {
- // Send BarTime message to a player
- message_begin( MSG_ONE, g_msgBarTime, _, id );
- write_byte( iTime );
- write_byte( 0 );
- message_end( );
- }
- // Removes a barricade by a specified owner
- RemoveBarricadeByOwner( iEntity, id )
- {
- // Remove entity
- engfunc( EngFunc_RemoveEntity, iEntity );
- // Decrease deployed count
- g_iBarricadeSet[ id ] --;
- }
- // Removes ALL barricades by a specified owner
- RemoveBarricadesByOwner( id, bool:bIgnoreHealth = false )
- {
- // Get our start index
- new iEntity = FM_NULLENT, iCount = 0;
- if( bIgnoreHealth )
- {
- // Loop through all entities, find our barricade with the respective owner! If found, remove it!
- while( ( iEntity = engfunc( EngFunc_FindEntityByString, iEntity, "classname", g_szEntityBarricade ) ) != 0 )
- {
- if( pev( iEntity, pev_iuser1 ) == id )
- engfunc( EngFunc_RemoveEntity, iEntity );
- }
- // Reset player data
- g_iBarricadeCached[ id ] = FM_NULLENT;
- g_iBarricadeSet[ id ] = 0;
- g_iBarricadeLimit[ id ] = 0;
- }
- else
- {
- // Loop through all entities, find our barricade with the respective owner! If found, remove it!
- while( ( iEntity = engfunc( EngFunc_FindEntityByString, iEntity, "classname", g_szEntityBarricade ) ) != 0 )
- {
- // Get entity health
- new Float:fHealth;
- pev( iEntity, pev_health, fHealth );
- if( pev( iEntity, pev_iuser1 ) == id && !g_bIsBarricadeDestroyed[ iEntity ] && fHealth >= g_fBarricadeHealth )
- {
- // Remove entity
- engfunc( EngFunc_RemoveEntity, iEntity );
- // How many barricades have been removed
- iCount ++;
- }
- }
- // Reset player data
- g_iBarricadeCached[ id ] = FM_NULLENT;
- g_iBarricadeSet[ id ] -= iCount;
- }
- }
- // Removes ALL barricades from the map
- RemoveBarricades( )
- {
- // Get our start index
- new iEntity = FM_NULLENT;
- // Loop through all entities, find our barricade and if found, remove it!
- while( ( iEntity = engfunc( EngFunc_FindEntityByString, iEntity, "classname", g_szEntityBarricade ) ) != 0 )
- engfunc( EngFunc_RemoveEntity, iEntity );
- // Loop through all players and reset their data
- for( new id = 1; id <= MaxClients; id ++ )
- {
- // Player is not connected? Ignore!
- if(!is_user_connected(id))
- continue
- g_iBarricadeCached[ id ] = FM_NULLENT;
- g_iBarricadeSet[ id ] = 0;
- g_iBarricadeLimit[ id ] = 0;
- // Remove spawn task
- if( task_exists( id + TASK_BARRICADE_SPAWN ) )
- remove_task( id + TASK_BARRICADE_SPAWN );
- // Remove delete task
- if( task_exists( id + TASK_BARRICADE_DELETE ) )
- remove_task( id + TASK_BARRICADE_DELETE );
- // If there is a progress bar, remove it!
- SendBarTime( id );
- }
- }
- // Returns the count of barricades owned by the specified owner
- GetCountBarricadesByOwner( id )
- {
- // Get our start index
- new iEntity = FM_NULLENT, iCount = 0;
- // Loop through all entities, find our barricade with the respective owner! If found, remove it!
- while( ( iEntity = engfunc( EngFunc_FindEntityByString, iEntity, "classname", g_szEntityBarricade ) ) != 0 )
- {
- if( pev( iEntity, pev_iuser1 ) == id && !g_bIsBarricadeDestroyed[ iEntity ] )
- iCount ++;
- }
- // Return the count
- return iCount;
- }
- // Calculate colours according to a specified percentage
- ComputeColours( Float:fPercent, Float:fColour[ 3 ] )
- {
- // Percent is not valid anymore
- if( fPercent < 0.0 )
- return;
- // Calculate colours according to the percent :P
- fColour[ 1 ] = 255.0 * fPercent / 100.0;
- fColour[ 0 ] = 255.0 - fColour[ 1 ];
- fColour[ 2 ] = 0.0;
- }
- CheckEntityCollides( Float:fOrigin[ 3 ], Float:fBounds )
- {
- new Float:fTraceEnd[ 8 ][ 3 ];
- // Calculate X, Y and Z
- fTraceEnd[ 0 ][ 0 ] = fOrigin[ 0 ] - fBounds;
- fTraceEnd[ 0 ][ 1 ] = fOrigin[ 1 ] - fBounds;
- fTraceEnd[ 0 ][ 2 ] = fOrigin[ 2 ] - fBounds;
- fTraceEnd[ 1 ][ 0 ] = fOrigin[ 0 ] - fBounds;
- fTraceEnd[ 1 ][ 1 ] = fOrigin[ 1 ] - fBounds;
- fTraceEnd[ 1 ][ 2 ] = fOrigin[ 2 ] + fBounds;
- fTraceEnd[ 2 ][ 0 ] = fOrigin[ 0 ] - fBounds;
- fTraceEnd[ 2 ][ 1 ] = fOrigin[ 1 ] + fBounds;
- fTraceEnd[ 2 ][ 2 ] = fOrigin[ 2 ] + fBounds;
- fTraceEnd[ 3 ][ 0 ] = fOrigin[ 0 ] + fBounds;
- fTraceEnd[ 3 ][ 1 ] = fOrigin[ 1 ] + fBounds;
- fTraceEnd[ 3 ][ 2 ] = fOrigin[ 2 ] + fBounds;
- fTraceEnd[ 4 ][ 0 ] = fOrigin[ 0 ] + fBounds;
- fTraceEnd[ 4 ][ 1 ] = fOrigin[ 1 ] - fBounds;
- fTraceEnd[ 4 ][ 2 ] = fOrigin[ 2 ] - fBounds;
- fTraceEnd[ 5 ][ 0 ] = fOrigin[ 0 ] + fBounds;
- fTraceEnd[ 5 ][ 1 ] = fOrigin[ 1 ] + fBounds;
- fTraceEnd[ 5 ][ 2 ] = fOrigin[ 2 ] - fBounds;
- fTraceEnd[ 6 ][ 0 ] = fOrigin[ 0 ] + fBounds;
- fTraceEnd[ 6 ][ 1 ] = fOrigin[ 1 ] - fBounds;
- fTraceEnd[ 6 ][ 2 ] = fOrigin[ 2 ] + fBounds;
- fTraceEnd[ 7 ][ 0 ] = fOrigin[ 0 ] - fBounds;
- fTraceEnd[ 7 ][ 1 ] = fOrigin[ 1 ] + fBounds;
- fTraceEnd[ 7 ][ 2 ] = fOrigin[ 2 ] - fBounds;
- // Get trace hits, and check point contents
- new Float:fTraceHit[ 3 ], iLoop, iPointContents, iHit, iInnerLoop;
- for( iLoop = 0; iLoop < sizeof( fTraceEnd ); iLoop ++ )
- {
- // Get point contents
- iPointContents = engfunc( EngFunc_PointContents, fTraceEnd[ iLoop ] );
- if( iPointContents != CONTENTS_EMPTY )
- return true;
- // Is it hitting something?
- iHit = trace_line( 0, fOrigin, fTraceEnd[ iLoop ], fTraceHit );
- if( iHit != 0 )
- return true;
- for( iInnerLoop = 0; iInnerLoop < sizeof( fTraceHit ); iInnerLoop ++ )
- {
- if( fTraceEnd[ iLoop ][ iInnerLoop ] != fTraceHit[ iInnerLoop ] )
- return true;
- }
- }
- // No collision!
- return false;
- }
- CheckEntityHitAllowed( iEntity )
- {
- // Class names on which we cannot place our barricades!
- new const szClassNameHitDenied[ ][ ] =
- {
- "func_door",
- "func_door_rotating",
- "func_plat",
- "func_rotating",
- "func_train",
- "func_conveyor",
- "hostage_entity",
- "player"
- };
- // Get class name of the entity that has been hit
- static szClassName[ 32 ];
- pev( iEntity, pev_classname, szClassName, charsmax( szClassName ) );
- // Check if it is hitting a denied class name
- for( new iLoop = 0; iLoop < sizeof( szClassNameHitDenied ); iLoop ++ )
- {
- if( equali( szClassName, szClassNameHitDenied[ iLoop ] ) )
- return false;
- }
- return true;
- }
- // Makes entity follow terrain
- EntityFollowTerrain( iEntity, Float:fOrigin[ 3 ], iTraceResult )
- {
- // Trace
- new Float:fTraceTo[ 3 ];
- xs_vec_sub( fOrigin, Float:{ 0.0, 0.0, 10.0 }, fTraceTo );
- // Get angles
- new Float:fAngles[ 2 ][ 3 ];
- pev( iEntity, pev_angles, fAngles[ 0 ] );
- // Get forward vector
- new Float:fForward[ 3 ];
- angle_vector( fAngles[ 0 ], ANGLEVECTOR_FORWARD, fForward );
- // Get up vector
- new Float:fVectorUp[ 3 ];
- get_tr2( iTraceResult, TR_vecPlaneNormal, fVectorUp );
- // Calculate vectors
- new Float:fVectorRight[ 3 ], Float:fVectorForward[ 3 ];
- xs_vec_cross( fForward, fVectorUp, fVectorRight );
- xs_vec_cross( fVectorUp, fVectorRight, fVectorForward );
- vector_to_angle( fVectorForward, fAngles[ 0 ] );
- vector_to_angle( fVectorRight, fAngles[ 1 ] );
- // Update angles
- fAngles[ 0 ][ 2 ] = -1.0 * fAngles[ 1 ][ 0 ];
- // Set angles that we calculated
- set_pev( iEntity, pev_angles, fAngles[ 0 ] );
- }
- GetAimOrigin( id, Float:fOriginAim[ 3 ], Float:fMaximumAimDistance = 8192.0 )
- {
- // Get player's origin and view ofs
- static Float:fOrigin[ 3 ], Float:fViewOfs[ 3 ];
- pev( id, pev_origin, fOrigin );
- pev( id, pev_view_ofs, fViewOfs );
- // Do some calculation stuff
- xs_vec_add( fOrigin, fViewOfs, fOrigin );
- // Get player's view angles
- pev( id, pev_v_angle, fViewOfs );
- // Make vectors
- engfunc( EngFunc_MakeVectors, fViewOfs );
- // Get forward vector
- global_get( glb_v_forward, fViewOfs );
- // Do some calculations
- xs_vec_mul_scalar( fViewOfs, fMaximumAimDistance, fViewOfs );
- xs_vec_add( fOrigin, fViewOfs, fViewOfs );
- // Trace line?
- engfunc( EngFunc_TraceLine, fOrigin, fViewOfs, DONT_IGNORE_MONSTERS, id, 0 );
- // Get aim origin by trace line result
- get_tr2( 0, TR_vecEndPos, fOriginAim );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement