搜索
查看: 2893|回复: 4

[AMXX 带源码] 送大家一份圣诞礼物!

[复制链接]
发表于 2010-12-24 16:48:04 | 显示全部楼层 |阅读模式 来自 广东广州
本帖最后由 kk阿朗 于 2010-12-24 16:51 编辑

  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fakemeta>

  4. new const MODEL[ ] = "models/christmas/c4-christmastree.mdl";

  5. public plugin_init( ) {
  6.         register_clcmd( "say /tree", "CmdTreeMenu" );
  7. }

  8. public plugin_precache( ) {
  9.         register_plugin( "Christmas tree spawner",  "0.1", "..." );
  10.         precache_model( MODEL );
  11.         engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "env_snow" ) );
  12.        
  13.         static szMapName[ 32 ], szConfig[ 128 ];
  14.         get_mapname( szMapName, charsmax( szMapName ) );
  15.         get_configsdir( szConfig, charsmax( szConfig ) );
  16.         format( szConfig, charsmax( szConfig ), "%s/%s.txt", szConfig, szMapName );
  17.        
  18.         if ( file_exists( szConfig ) ) {
  19.                 LoadTrees( szConfig )
  20.         }
  21. }

  22. public CmdTreeMenu( id ) {
  23.         if( !access( id, ADMIN_MAP ) )
  24.                 return PLUGIN_HANDLED;
  25.        
  26.         ShowTreeMenu( id );
  27.         return PLUGIN_HANDLED;
  28. }

  29. ShowTreeMenu( id ) {
  30.         new menu = menu_create( "Tree Menu", "m_TreeMenu" );
  31.        
  32.         menu_additem( menu, "Create Tree", "1" );
  33.         menu_additem( menu, "Delete All Tree", "2" );
  34.         menu_additem( menu, "Save Menu", "3" );
  35.        
  36.         menu_display( id, menu );
  37. }

  38. public m_TreeMenu( id, menu, item ) {
  39.         if( item == MENU_EXIT )
  40.         {
  41.                 menu_destroy( menu );
  42.                 return;
  43.         }
  44.        
  45.         static Float:flOrigin[ 3 ];
  46.         static _access, info[ 2 ], callback;
  47.         menu_item_getinfo( menu, item, _access, info, charsmax( info ), _,  _, callback );
  48.         menu_destroy( menu );
  49.        
  50.         pev( id, pev_origin, flOrigin );
  51.         switch( info[ 0 ] )
  52.         {
  53.                 case '1':
  54.                 {
  55.                         CreateTree( flOrigin );
  56.                         ShowTreeMenu( id );
  57.                 }
  58.                 case '2':
  59.                 {
  60.                         RemoveAllTrees();
  61.                         ShowTreeMenu( id );
  62.                 }
  63.                 case '3':
  64.                 {
  65.                         static szMapName[ 32 ], szConfig[ 128 ];
  66.                         get_mapname( szMapName, charsmax( szMapName ) );
  67.                         get_configsdir( szConfig, charsmax( szConfig ) );
  68.                         format( szConfig, charsmax( szConfig ), "%s/%s.txt", szConfig, szMapName );
  69.                        
  70.                         SaveTrees( szConfig );
  71.                 }
  72.         }
  73. }

  74. CreateTree( const Float:flOrigin[ 3 ] ) {
  75.         new iEntity = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "info_target" ) );
  76.        
  77.         if( !iEntity )
  78.                 return 0;
  79.        
  80.         set_pev( iEntity, pev_classname, "env_tree" );
  81.         set_pev( iEntity, pev_solid, SOLID_BBOX );
  82.         set_pev( iEntity, pev_movetype, MOVETYPE_NONE );
  83.        
  84.         engfunc( EngFunc_SetSize, iEntity, Float:{ -1.0, -1.0, -1.0 }, Float:{ 1.0,  1.0, 36.0 } );
  85.         engfunc( EngFunc_SetOrigin, iEntity, flOrigin );
  86.         engfunc( EngFunc_SetModel, iEntity, MODEL );
  87.        
  88.         engfunc( EngFunc_DropToFloor, iEntity );
  89.        
  90.         return iEntity;
  91. }

  92. SaveTrees( const szConfigFile[] ) {
  93.         if( file_exists( szConfigFile ) )
  94.                 delete_file( szConfigFile );
  95.        
  96.         new iFile = fopen( szConfigFile, "wt" );
  97.        
  98.         if( !iFile )
  99.                 return;
  100.        
  101.         new Float:flOrigin[ 3 ], iEntity;
  102.        
  103.         while( ( iEntity = engfunc( EngFunc_FindEntityByString, iEntity, "classname", "env_tree" ) ) > 0  ) {
  104.                 pev( iEntity, pev_origin, flOrigin );
  105.                
  106.                 fprintf( iFile, "%f %f %f^n", flOrigin[ 0 ], flOrigin[ 1 ],  flOrigin[ 2 ] );
  107.         }
  108.        
  109.         fclose( iFile );
  110. }

  111. LoadTrees( const szConfigFile[] ) {
  112.         new iFile = fopen( szConfigFile, "rt" );
  113.        
  114.         if( !iFile )
  115.                 return 0;
  116.        
  117.         new Float:flOrigin[ 3 ], x[ 16 ], y[ 16 ], z[ 16 ], szData[ sizeof( x ) + sizeof( y ) + sizeof( z ) + 3 ];
  118.        
  119.         while( !feof( iFile ) ) {
  120.                 fgets( iFile, szData, charsmax( szData ) );
  121.                 trim( szData );
  122.                
  123.                 if( !szData[ 0 ] || szData[ 0 ] == ';' || ( szData[ 0 ] == '/' && szData[ 1 ] == '/' ) )
  124.                         continue;
  125.                
  126.                 parse( szData, x, charsmax( x ), y, charsmax( y ), z, charsmax( z ) );
  127.                
  128.                 flOrigin[ 0 ] = str_to_float( x );
  129.                 flOrigin[ 1 ] = str_to_float( y );
  130.                 flOrigin[ 2 ] = str_to_float( z );
  131.                
  132.                 CreateTree( flOrigin );
  133.         }
  134.         return 1;
  135. }

  136. RemoveAllTrees( ) {
  137.         new iEntity = -1;
  138.        
  139.         while( ( iEntity = engfunc( EngFunc_FindEntityByString, iEntity, "classname", "env_tree" ) ) > 0 )
  140.                 engfunc( EngFunc_RemoveEntity, iEntity );
  141. }  
复制代码
这是我刚刚在官方网的代码求救区看到的一个贴子,于是我就拿过来自己加工了一下!
由于没有测试环境,所以没有测试,有兴趣的朋友可以下来玩玩!:lol
祝大家圣诞快乐哈!:loveliness:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注个册吧

×
发表于 2010-12-28 20:05:46 | 显示全部楼层 来自 辽宁沈阳
顶 就是看不懂
回复

使用道具 举报

发表于 2010-12-28 22:13:00 | 显示全部楼层 来自 云南曲靖
貌似是官网的东东啊
回复

使用道具 举报

发表于 2010-12-28 23:11:44 | 显示全部楼层 来自 四川泸州
这是什么插件源码?给个具体说明呀
回复

使用道具 举报

 楼主| 发表于 2010-12-28 23:18:45 | 显示全部楼层 来自 广东广州
顶 就是看不懂

这个是可以在读图上建立圣诞树!
貌似是官网的东东啊

请详细看一下我的说明!
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表