|
发表于 2010-12-24 16:48:04
|
显示全部楼层
|阅读模式
来自 中国–广东–广州
本帖最后由 kk阿朗 于 2010-12-24 16:51 编辑
- #include <amxmodx>
- #include <amxmisc>
- #include <fakemeta>
- new const MODEL[ ] = "models/christmas/c4-christmastree.mdl";
- public plugin_init( ) {
- register_clcmd( "say /tree", "CmdTreeMenu" );
- }
- public plugin_precache( ) {
- register_plugin( "Christmas tree spawner", "0.1", "..." );
- precache_model( MODEL );
- engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "env_snow" ) );
-
- static szMapName[ 32 ], szConfig[ 128 ];
- get_mapname( szMapName, charsmax( szMapName ) );
- get_configsdir( szConfig, charsmax( szConfig ) );
- format( szConfig, charsmax( szConfig ), "%s/%s.txt", szConfig, szMapName );
-
- if ( file_exists( szConfig ) ) {
- LoadTrees( szConfig )
- }
- }
- public CmdTreeMenu( id ) {
- if( !access( id, ADMIN_MAP ) )
- return PLUGIN_HANDLED;
-
- ShowTreeMenu( id );
- return PLUGIN_HANDLED;
- }
- ShowTreeMenu( id ) {
- new menu = menu_create( "Tree Menu", "m_TreeMenu" );
-
- menu_additem( menu, "Create Tree", "1" );
- menu_additem( menu, "Delete All Tree", "2" );
- menu_additem( menu, "Save Menu", "3" );
-
- menu_display( id, menu );
- }
- public m_TreeMenu( id, menu, item ) {
- if( item == MENU_EXIT )
- {
- menu_destroy( menu );
- return;
- }
-
- static Float:flOrigin[ 3 ];
- static _access, info[ 2 ], callback;
- menu_item_getinfo( menu, item, _access, info, charsmax( info ), _, _, callback );
- menu_destroy( menu );
-
- pev( id, pev_origin, flOrigin );
- switch( info[ 0 ] )
- {
- case '1':
- {
- CreateTree( flOrigin );
- ShowTreeMenu( id );
- }
- case '2':
- {
- RemoveAllTrees();
- ShowTreeMenu( id );
- }
- case '3':
- {
- static szMapName[ 32 ], szConfig[ 128 ];
- get_mapname( szMapName, charsmax( szMapName ) );
- get_configsdir( szConfig, charsmax( szConfig ) );
- format( szConfig, charsmax( szConfig ), "%s/%s.txt", szConfig, szMapName );
-
- SaveTrees( szConfig );
- }
- }
- }
- CreateTree( const Float:flOrigin[ 3 ] ) {
- new iEntity = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) );
-
- if( !iEntity )
- return 0;
-
- set_pev( iEntity, pev_classname, "env_tree" );
- set_pev( iEntity, pev_solid, SOLID_BBOX );
- set_pev( iEntity, pev_movetype, MOVETYPE_NONE );
-
- engfunc( EngFunc_SetSize, iEntity, Float:{ -1.0, -1.0, -1.0 }, Float:{ 1.0, 1.0, 36.0 } );
- engfunc( EngFunc_SetOrigin, iEntity, flOrigin );
- engfunc( EngFunc_SetModel, iEntity, MODEL );
-
- engfunc( EngFunc_DropToFloor, iEntity );
-
- return iEntity;
- }
- SaveTrees( const szConfigFile[] ) {
- if( file_exists( szConfigFile ) )
- delete_file( szConfigFile );
-
- new iFile = fopen( szConfigFile, "wt" );
-
- if( !iFile )
- return;
-
- new Float:flOrigin[ 3 ], iEntity;
-
- while( ( iEntity = engfunc( EngFunc_FindEntityByString, iEntity, "classname", "env_tree" ) ) > 0 ) {
- pev( iEntity, pev_origin, flOrigin );
-
- fprintf( iFile, "%f %f %f^n", flOrigin[ 0 ], flOrigin[ 1 ], flOrigin[ 2 ] );
- }
-
- fclose( iFile );
- }
- LoadTrees( const szConfigFile[] ) {
- new iFile = fopen( szConfigFile, "rt" );
-
- if( !iFile )
- return 0;
-
- new Float:flOrigin[ 3 ], x[ 16 ], y[ 16 ], z[ 16 ], szData[ sizeof( x ) + sizeof( y ) + sizeof( z ) + 3 ];
-
- while( !feof( iFile ) ) {
- fgets( iFile, szData, charsmax( szData ) );
- trim( szData );
-
- if( !szData[ 0 ] || szData[ 0 ] == ';' || ( szData[ 0 ] == '/' && szData[ 1 ] == '/' ) )
- continue;
-
- parse( szData, x, charsmax( x ), y, charsmax( y ), z, charsmax( z ) );
-
- flOrigin[ 0 ] = str_to_float( x );
- flOrigin[ 1 ] = str_to_float( y );
- flOrigin[ 2 ] = str_to_float( z );
-
- CreateTree( flOrigin );
- }
- return 1;
- }
- RemoveAllTrees( ) {
- new iEntity = -1;
-
- while( ( iEntity = engfunc( EngFunc_FindEntityByString, iEntity, "classname", "env_tree" ) ) > 0 )
- engfunc( EngFunc_RemoveEntity, iEntity );
- }
复制代码 这是我刚刚在官方网的代码求救区看到的一个贴子,于是我就拿过来自己加工了一下!
由于没有测试环境,所以没有测试,有兴趣的朋友可以下来玩玩!:lol
祝大家圣诞快乐哈!:loveliness: |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注个册吧
×
|