Code: Select all
#include <amxmodx>#include <amxmisc>#include <fakemeta>#include <hamsandwich>#include <engine>#include <rcsgo> #define PLUGIN "Supply Crates"#define AUTHOR "TBagT"#define VERSION "2.0" // Entity specifics //new entSupply[ ] = "supply_box_entity";new Float:minModel[ 3 ] = { -8.01, -8.09, 0.0 }new Float:maxModel[ 3 ] = { 8.12, 8.09, 22.26 }new const SupplyBoxModel[ ] = { "models/w_supplybox.mdl" }new const PickupSound[ ] = { "supply_boxes/pickup.wav" }new const SUPPLY_BOX_SOUND[ ] = { "supply_boxes/inbound.wav" } // Player specifics //new bool:can_pickup[ 33 ];new pickupCount[ 33 ]; // Supply box specifics //#define TASK_ID_SPAWN_BOXES 150new Array:SupplyBoxes, Array:EmptyCfgLines; // <- Information holders //enum _: SupplyBoxesArray { // <- Array variables // line_id, Float:box_origin[ 3 ], Float:box_angles[ 3 ]}new Array:SupplyBoxesContents; // <- Content holder //enum _: SupplyContentsArray { box_id, box_name[ 35 ], pickupForwardItem}// Server specifics //new cvar_pickupTimes, cvar_timesPerRound, cvar_amountSpawn, cvar_team, cvar_spawnEvery;new maxPlayers, mapName[ 32 ], configurationFile[ 258 ], lines;new forwardResult, spawnCount; public plugin_precache( ) { precache_model( SupplyBoxModel ); precache_sound( PickupSound ); precache_sound( SUPPLY_BOX_SOUND ); SupplyBoxes = ArrayCreate( SupplyBoxesArray ); SupplyBoxesContents = ArrayCreate( SupplyContentsArray ); EmptyCfgLines = ArrayCreate( 1, 1 );} public plugin_init( ) { register_plugin( PLUGIN, VERSION, AUTHOR ); cvar_spawnEvery = register_cvar( "sb_spawn_every", "60.0" ); cvar_pickupTimes = register_cvar( "sb_pickup_times", "3" ); cvar_timesPerRound = register_cvar( "sb_times_per_round", "2" ); cvar_amountSpawn = register_cvar( "sb_spawn_amount", "3" ); cvar_team = register_cvar( "sb_team", "0" ); register_touch( entSupply, "player", "supply_box_pickup" ); register_logevent( "RoundEnd", 2, "1=Round_End" ); register_logevent( "RoundStart", 2, "1=Round_Start" ); RegisterHam( Ham_Spawn, "player", "playerSpawn", 1 ); register_clcmd( "say /supply", "supplyAdminMenu" ); maxPlayers = get_maxplayers( );} public plugin_cfg( ) { get_mapname( mapName, charsmax( mapName ) ); add( mapName, charsmax( mapName ), ".cfg", 0 ); get_configsdir( configurationFile, charsmax( configurationFile ) ); add( configurationFile, charsmax( configurationFile ), "/SupplyBoxes/", 0 ); if( !dir_exists( configurationFile ) ) mkdir( configurationFile ); add( configurationFile, charsmax( configurationFile ), mapName, 0 ); if( !file_exists( configurationFile ) ) { new m_map_cfg = fopen( configurationFile, "wt" ); fclose( m_map_cfg ); } fillSupplyArray( );} public plugin_natives( ) { register_native( "register_box_content", "native_register_content" );} public client_disconnect( id ) { can_pickup[ id ] = false; pickupCount[ id ] = 0;} public client_putinserver( id ) { can_pickup[ id ] = false; pickupCount[ id ] = 0;} public RoundStart( ) { if( get_pcvar_float( cvar_spawnEvery ) < 30.0 ) set_task( 30.0, "spawnSupplyBoxes", TASK_ID_SPAWN_BOXES, _, _, "b" ); else set_task( get_pcvar_float( cvar_spawnEvery ), "spawnSupplyBoxes", TASK_ID_SPAWN_BOXES, _, _, "b" );} public RoundEnd( ) { remove_task( TASK_ID_SPAWN_BOXES ); for( new index = 1; index < maxPlayers; index++ ) pickupCount[ index ] = 0; spawnCount = 0; remove_supply_boxes( );} public playerSpawn( id ) { if( !is_user_alive( id ) || get_user_team( id ) != get_pcvar_num( cvar_team ) ) can_pickup[ id ] = false; else can_pickup[ id ] = true;} public fillSupplyArray( ) { new data[ 258 ]; new Float:Origin[ 3 ], Float:Angles[ 3 ]; new const text_parser[ 6 ][ 8 ]; new file = fopen( configurationFile, "r" ); while( fgets( file, data, charsmax( data ) - 1 ) ) { lines++; if( data[ 0 ] == ' ' ) { ArrayPushCell( EmptyCfgLines, lines ); continue; } parse( data, text_parser[ 0 ], 7, text_parser[ 1 ], 7, text_parser[ 2 ], 7, text_parser[ 3 ], 7, text_parser[ 4 ], 7, text_parser[ 5 ], 7 ); Origin[ 0 ] = str_to_float( text_parser[ 0 ] ); Origin[ 1 ] = str_to_float( text_parser[ 1 ] ); Origin[ 2 ] = str_to_float( text_parser[ 2 ] ); Angles[ 0 ] = str_to_float( text_parser[ 3 ] ); Angles[ 1 ] = str_to_float( text_parser[ 4 ] ); Angles[ 2 ] = str_to_float( text_parser[ 5 ] ); AddSupplyToArray( Origin, Angles, lines ); } fclose( file );} public supplyAdminMenu( id ) { if( !( get_user_flags( id ) & ADMIN_IMMUNITY ) || !is_user_alive( id ) ) return PLUGIN_HANDLED; new menu = menu_create( "Supply boxes v1", "supply_menu_handler" ); menu_additem( menu, "Put supply box", "1" ); menu_additem( menu, "Delete supply box", "2" ); menu_setprop( menu, MPROP_EXIT, MEXIT_ALL ); menu_display( id, menu, 0 ); return PLUGIN_HANDLED;} public supply_menu_handler( id, menu, item ) { if( !is_user_alive( id ) ) return PLUGIN_HANDLED; if( item == MENU_EXIT ) { menu_destroy( menu ); return PLUGIN_HANDLED; } new data[ 6 ], name[ 64 ], access, callback, key; menu_item_getinfo( menu, item, access, data, 5, name, charsmax( name ), callback ); key = str_to_num( data ); switch( key ) { case 1: { new TargetOrigin[ 3 ], Float:Target[ 3 ], Float:Angles[ 3 ]; get_user_origin( id, TargetOrigin, 3 ); Target[ 0 ] = float( TargetOrigin[ 0 ] ); Target[ 1 ] = float( TargetOrigin[ 1 ] ); Target[ 2 ] = float( TargetOrigin[ 2 ] ); entity_get_vector( id, EV_VEC_v_angle, Angles ); Angles[ 0 ] = 0.0; CreateSupplyBox( Target, Angles ); } case 2: { new entity, body; get_user_aiming( id, entity, body, 500 ); deleteSupplyBox( entity ); } } supplyAdminMenu( id ); return PLUGIN_HANDLED;} public CreateSupplyBox( Float:Origins[ 3 ], Float:Angles[ 3 ] ) { new szData[ 248 ], line_to_item; format( szData, charsmax( szData ), "%f %f %f %f %f %f", Origins[ 0 ], Origins[ 1 ], Origins[ 2 ], Angles[ 0 ], Angles[ 1 ], Angles[ 2 ] ); if( ArraySize( EmptyCfgLines ) > 0 ) { new emptyLineId = ArrayGetCell( EmptyCfgLines, 0 ); ArrayDeleteItem( EmptyCfgLines, 0 ); write_file( configurationFile, szData, emptyLineId - 1 ); line_to_item = emptyLineId; } else { lines++; write_file( configurationFile, szData ); line_to_item = lines; } AddSupplyToArray( Origins, Angles, line_to_item ); spawnSupplyBox( Origins, Angles, line_to_item );} public AddSupplyToArray( Float:Origin[ 3 ], Float:Angles[ 3 ], id ) { new Data[ SupplyBoxesArray ]; Data[ line_id ] = id; Data[ box_origin ] = _:Origin; Data[ box_angles ] = _:Angles; ArrayPushArray( SupplyBoxes, Data );} public deleteSupplyBox( ent ) { if( pev_valid( ent ) ) { new class_name_ent[ 64 ]; entity_get_string( ent, EV_SZ_classname, class_name_ent, charsmax( class_name_ent ) ); if( equal( class_name_ent, entSupply ) ) { new size = ArraySize( SupplyBoxes ); new item_id = pev( ent, pev_iuser1 ); for( new i = 0; i < size; i++ ) { new DataArray[ SupplyBoxesArray ]; ArrayGetArray( SupplyBoxes, i, DataArray ); if( DataArray[ line_id ] == item_id ) { lines--; remove_entity( ent ); ArrayPushCell( EmptyCfgLines, item_id ); write_file( configurationFile, " ", item_id - 1 ); ArrayDeleteItem( SupplyBoxes, i ); break; } } } } } public spawnSupplyBoxes( ) { if( ArraySize( SupplyBoxes ) < 1 || ArraySize( SupplyBoxesContents ) < 1 || spawnCount >= get_pcvar_num( cvar_timesPerRound ) ) { remove_task( TASK_ID_SPAWN_BOXES ); return; } remove_supply_boxes( ); spawnCount++; new Float:Orig[ 3 ], Float:Angl[ 3 ]; new AmountCvar = get_pcvar_num( cvar_amountSpawn ); new ArraySizeBox = ArraySize( SupplyBoxes ); new size = ( AmountCvar == 0 || AmountCvar > ArraySizeBox ) ? ArraySizeBox : AmountCvar; new Data[ SupplyBoxesArray ]; new count, randomId; new Array:Boxes = ArrayCreate( SupplyBoxesArray ); for( new index = 0; index < ArraySizeBox; index++ ) { ArrayGetArray( SupplyBoxes, index, Data ); ArrayPushArray( Boxes, Data ); } do { randomId = random( ArraySizeBox ); ArrayGetArray( Boxes, randomId, Data ); Orig[ 0 ] = Data[ box_origin ][ 0 ]; Angl[ 0 ] = Data[ box_angles ][ 0 ]; Orig[ 1 ] = Data[ box_origin ][ 1 ]; Angl[ 1 ] = Data[ box_angles ][ 1 ]; Orig[ 2 ] = Data[ box_origin ][ 2 ]; Angl[ 2 ] = Data[ box_angles ][ 2 ]; spawnSupplyBox( Orig, Angl, Data[ line_id ] ); count++; ArrayDeleteItem( Boxes, randomId ); ArraySizeBox--; } while( count < size ); client_cmd( 0, "spk %s", SUPPLY_BOX_SOUND );} public remove_supply_boxes( ) { new ent = -1; while( ( ent = engfunc( EngFunc_FindEntityByString, ent, "classname", entSupply ) ) ) remove_entity( ent );} public spawnSupplyBox( Float:pOrigins[ 3 ], Float:pAngles[ 3 ], line_idas ) { new entity = create_entity( "info_target" ); entity_set_string( entity, EV_SZ_classname, entSupply ); entity_set_int( entity, EV_INT_solid, SOLID_BBOX ); entity_set_origin( entity, pOrigins ); entity_set_vector( entity, EV_VEC_angles, pAngles ); entity_set_model( entity, SupplyBoxModel ); entity_set_size( entity, minModel, maxModel ); entity_set_int( entity, EV_INT_renderfx, kRenderFxGlowShell ); entity_set_vector( entity, EV_VEC_rendercolor, Float:{ 221.0, 173.0, 237.0 } ); set_pev( entity, pev_iuser1, line_idas );} public supply_box_pickup( box, player ) { if( !is_user_alive( player ) || !can_pickup[ player ] ) return; new randomDrop = random( ArraySize( SupplyBoxesContents ) ); new Data[ SupplyContentsArray ]; ArrayGetArray( SupplyBoxesContents, randomDrop, Data ); ExecuteForward( Data[ pickupForwardItem ], forwardResult, player ); if( get_pcvar_num( cvar_pickupTimes ) > 0 ) { pickupCount[ player ]++; if( pickupCount[ player ] >= get_pcvar_num( cvar_pickupTimes ) ) can_pickup[ player ] = false; } client_print( player, print_chat, "You picked up %s !", Data[ box_name ] ); client_cmd( player, "spk %s", PickupSound ); remove_entity( box );} public native_register_content( plugin_id, paramaters_num ) { new BoxName[ 32 ]; get_string( 1, BoxName, charsmax( BoxName ) ); new Data[ SupplyContentsArray ]; Data[ box_id ] = ArraySize( SupplyBoxesContents ); Data[ box_name ] = BoxName; Data[ pickupForwardItem ] = CreateOneForward( plugin_id, "sb_pickup_event", FP_CELL ); ArrayPushArray( SupplyBoxesContents, Data ); // Debuging // // log_amx( "Registered box content name: %s and id: %d", BoxName, Data[ box_id ] ); // Return id to original plugin // return Data[ box_id ];}
Nebereikia...
