HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include < amxmodx >
  2. #include < engine >
  3. #include < fakemeta >
  4. #include < hamsandwich >
  5.  
  6. static const BALL_BOUNCE_GROUND[ ] = "kickball/bounce.wav";
  7. static const g_szBallModel[ ] = "models/kickball/ball.mdl";
  8. static const g_szBallName[ ] = "ball";
  9.  
  10. new g_iBall, g_szFile[ 128 ], g_szMapname[ 32 ], g_iButtonsMenu, g_iTrailSprite;
  11. new bool:g_bNeedBall;
  12. new Float:g_vOrigin[ 3 ];
  13.  
  14. public plugin_init( ) {
  15. register_plugin( "SoccerJam Reloaded", "1.0", "xPaw & master4life" );
  16.  
  17. RegisterHam( Ham_ObjectCaps, "player", "FwdHamObjectCaps", 1 );
  18. register_logevent( "EventRoundStart", 2, "1=Round_Start" );
  19.  
  20. register_think( g_szBallName, "FwdThinkBall" );
  21. register_touch( g_szBallName, "player", "FwdTouchPlayer" );
  22.  
  23. new const szEntity[ ][ ] = {
  24. "info_target", "worldspawn", "func_wall", "func_door", "func_door_rotating",
  25. "func_wall_toggle", "func_breakable", "func_pushable", "func_train",
  26. "func_illusionary", "func_button", "func_rot_button", "func_rotating"
  27. }
  28.  
  29. for( new i; i < sizeof szEntity; i++ )
  30. register_touch( g_szBallName, szEntity[ i ], "FwdTouchWorld" );
  31.  
  32. register_touch( "myrun_wall", g_szBallName, "FwdTouchGoal" );
  33.  
  34. g_iButtonsMenu = menu_create( "\rLabda menü", "HandleButtonsMenu" );
  35.  
  36. menu_additem( g_iButtonsMenu, "Labda készítés", "1" );
  37. menu_additem( g_iButtonsMenu, "Labda törlés", "2" );
  38. menu_additem( g_iButtonsMenu, "Mentés", "3" );
  39.  
  40. register_clcmd( "say /labda", "CmdButtonsMenu", ADMIN_KICK );
  41. register_clcmd( "say /ujra", "UpdateBall" );
  42. }
  43.  
  44. public FwdTouchField( )
  45. return PLUGIN_CONTINUE;
  46.  
  47. public UpdateBall( id ) {
  48. if( !id || get_user_flags( id ) & ADMIN_KICK )
  49. ResetBall( );
  50.  
  51. return PLUGIN_HANDLED;
  52. }
  53.  
  54. public ResetBall( ) {
  55. if( is_valid_ent( g_iBall ) ) {
  56. entity_set_vector( g_iBall, EV_VEC_velocity, Float:{ 0.0, 0.0, 0.0 } ); // To be sure ?
  57. entity_set_origin( g_iBall, g_vOrigin );
  58.  
  59. entity_set_int( g_iBall, EV_INT_movetype, MOVETYPE_BOUNCE );
  60. entity_set_size( g_iBall, Float:{ -15.0, -15.0, 0.0 }, Float:{ 15.0, 15.0, 12.0 } );
  61. entity_set_int( g_iBall, EV_INT_iuser1, 0 );
  62. }
  63. }
  64.  
  65. public plugin_precache( ) {
  66. precache_model( g_szBallModel );
  67. precache_sound( BALL_BOUNCE_GROUND );
  68.  
  69. g_iTrailSprite = precache_model( "sprites/laserbeam.spr" );
  70.  
  71. get_mapname( g_szMapname, 31 );
  72. strtolower( g_szMapname );
  73.  
  74. // File
  75. new szDatadir[ 64 ];
  76. get_localinfo( "amxx_datadir", szDatadir, charsmax( szDatadir ) );
  77.  
  78. formatex( szDatadir, charsmax( szDatadir ), "%s", szDatadir );
  79.  
  80. if( !dir_exists( szDatadir ) )
  81. mkdir( szDatadir );
  82.  
  83. formatex( g_szFile, charsmax( g_szFile ), "%s/ball.ini", szDatadir );
  84.  
  85. if( !file_exists( g_szFile ) ) {
  86. write_file( g_szFile, "// Ball Spawn Editor", -1 );
  87. write_file( g_szFile, " ", -1 );
  88.  
  89. return; // We dont need to load file
  90. }
  91.  
  92. new szData[ 256 ], szMap[ 32 ], szOrigin[ 3 ][ 16 ];
  93. new iFile = fopen( g_szFile, "rt" );
  94.  
  95. while( !feof( iFile ) ) {
  96. fgets( iFile, szData, charsmax( szData ) );
  97.  
  98. if( !szData[ 0 ] || szData[ 0 ] == ';' || szData[ 0 ] == ' ' || ( szData[ 0 ] == '/' && szData[ 1 ] == '/' ) )
  99. continue;
  100.  
  101. parse( szData, szMap, 31, szOrigin[ 0 ], 15, szOrigin[ 1 ], 15, szOrigin[ 2 ], 15 );
  102.  
  103. if( equal( szMap, g_szMapname ) ) {
  104. new Float:vOrigin[ 3 ];
  105.  
  106. vOrigin[ 0 ] = str_to_float( szOrigin[ 0 ] );
  107. vOrigin[ 1 ] = str_to_float( szOrigin[ 1 ] );
  108. vOrigin[ 2 ] = str_to_float( szOrigin[ 2 ] );
  109.  
  110. CreateBall( 0, vOrigin );
  111.  
  112. g_vOrigin = vOrigin;
  113.  
  114. break;
  115. }
  116. }
  117.  
  118. fclose( iFile );
  119. }
  120.  
  121. public CmdButtonsMenu( id ) {
  122. if( get_user_flags( id ) & ADMIN_KICK )
  123. menu_display( id, g_iButtonsMenu, 0 );
  124.  
  125. return PLUGIN_HANDLED;
  126. }
  127.  
  128. public HandleButtonsMenu( id, iMenu, iItem ) {
  129. if( iItem == MENU_EXIT )
  130. return PLUGIN_HANDLED;
  131.  
  132. new szKey[ 2 ], _Access, _Callback;
  133. menu_item_getinfo( iMenu, iItem, _Access, szKey, 1, "", 0, _Callback );
  134.  
  135. new iKey = str_to_num( szKey );
  136.  
  137. switch( iKey ) {
  138. case 1: {
  139. if( pev_valid( g_iBall ) )
  140. return PLUGIN_CONTINUE;
  141.  
  142. CreateBall( id );
  143. }
  144. case 2: {
  145. new iEntity;
  146.  
  147. while( ( iEntity = find_ent_by_class( iEntity, g_szBallName ) ) > 0 )
  148. remove_entity( iEntity );
  149. }
  150. case 3: {
  151. new iBall, iEntity, Float:vOrigin[ 3 ];
  152.  
  153. while( ( iEntity = find_ent_by_class( iEntity, g_szBallName ) ) > 0 )
  154. iBall = iEntity;
  155.  
  156. if( iBall > 0 )
  157. entity_get_vector( iBall, EV_VEC_origin, vOrigin );
  158. else
  159. return PLUGIN_HANDLED;
  160.  
  161. new bool:bFound, iPos, szData[ 32 ], iFile = fopen( g_szFile, "r+" );
  162.  
  163. if( !iFile )
  164. return PLUGIN_HANDLED;
  165.  
  166. while( !feof( iFile ) ) {
  167. fgets( iFile, szData, 31 );
  168. parse( szData, szData, 31 );
  169.  
  170. iPos++;
  171.  
  172. if( equal( szData, g_szMapname ) ) {
  173. bFound = true;
  174.  
  175. new szString[ 256 ];
  176. formatex( szString, 255, "%s %f %f %f", g_szMapname, vOrigin[ 0 ], vOrigin[ 1 ], vOrigin[ 2 ] );
  177.  
  178. write_file( g_szFile, szString, iPos - 1 );
  179.  
  180. break;
  181. }
  182. }
  183.  
  184. if( !bFound )
  185. fprintf( iFile, "%s %f %f %f^n", g_szMapname, vOrigin[ 0 ], vOrigin[ 1 ], vOrigin[ 2 ] );
  186.  
  187. fclose( iFile );
  188.  
  189. client_print( id, print_chat, "* Sikeresen mentett labdát!" );
  190. }
  191. default: return PLUGIN_HANDLED;
  192. }
  193.  
  194. menu_display( id, g_iButtonsMenu, 0 );
  195.  
  196. return PLUGIN_HANDLED;
  197. }
  198.  
  199. public EventRoundStart( ) {
  200. if( !g_bNeedBall )
  201. return;
  202.  
  203. if( !is_valid_ent( g_iBall ) )
  204. CreateBall( 0, g_vOrigin );
  205. else {
  206. entity_set_vector( g_iBall, EV_VEC_velocity, Float:{ 0.0, 0.0, 0.0 } ); // To be sure ?
  207. entity_set_origin( g_iBall, g_vOrigin );
  208.  
  209. entity_set_int( g_iBall, EV_INT_solid, SOLID_BBOX );
  210. entity_set_int( g_iBall, EV_INT_movetype, MOVETYPE_BOUNCE );
  211. entity_set_size( g_iBall, Float:{ -15.0, -15.0, 0.0 }, Float:{ 15.0, 15.0, 12.0 } );
  212. entity_set_int( g_iBall, EV_INT_iuser1, 0 );
  213. }
  214. }
  215.  
  216. public FwdHamObjectCaps( id ) {
  217. if( pev_valid( g_iBall ) && is_user_alive( id ) ) {
  218. static iOwner; iOwner = pev( g_iBall, pev_iuser1 );
  219.  
  220. if( iOwner == id )
  221. KickBall( id );
  222. }
  223. }
  224.  
  225. // BALL BRAIN :)
  226. ////////////////////////////////////////////////////////////
  227. public FwdThinkBall( iEntity ) {
  228. if( !is_valid_ent( g_iBall ) )
  229. return PLUGIN_HANDLED;
  230.  
  231. entity_set_float( iEntity, EV_FL_nextthink, halflife_time( ) + 0.05 );
  232.  
  233. static Float:vOrigin[ 3 ], Float:vBallVelocity[ 3 ];
  234. entity_get_vector( iEntity, EV_VEC_origin, vOrigin );
  235. entity_get_vector( iEntity, EV_VEC_velocity, vBallVelocity );
  236.  
  237. static iOwner; iOwner = pev( iEntity, pev_iuser1 );
  238. static iSolid; iSolid = pev( iEntity, pev_solid );
  239.  
  240. // Trail --- >
  241. static Float:flGametime, Float:flLastThink;
  242. flGametime = get_gametime( );
  243.  
  244. if( flLastThink < flGametime ) {
  245. if( floatround( vector_length( vBallVelocity ) ) > 10 ) {
  246. message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
  247. write_byte( TE_KILLBEAM );
  248. write_short( g_iBall );
  249. message_end( );
  250.  
  251. message_begin( MSG_BROADCAST, SVC_TEMPENTITY );
  252. write_byte( TE_BEAMFOLLOW );
  253. write_short( g_iBall );
  254. write_short( g_iTrailSprite );
  255. write_byte( 10 );
  256. write_byte( 10 );
  257. write_byte( 0 );
  258. write_byte( 50 );
  259. write_byte( 255 );
  260. write_byte( 200 );
  261. message_end( );
  262. }
  263.  
  264. flLastThink = flGametime + 3.0;
  265. }
  266. // Trail --- <
  267.  
  268. if( iOwner > 0 ) {
  269. static Float:vOwnerOrigin[ 3 ];
  270. entity_get_vector( iOwner, EV_VEC_origin, vOwnerOrigin );
  271.  
  272. static const Float:vVelocity[ 3 ] = { 1.0, 1.0, 0.0 };
  273.  
  274. if( !is_user_alive( iOwner ) ) {
  275. entity_set_int( iEntity, EV_INT_iuser1, 0 );
  276.  
  277. vOwnerOrigin[ 2 ] += 5.0;
  278.  
  279. entity_set_origin( iEntity, vOwnerOrigin );
  280. entity_set_vector( iEntity, EV_VEC_velocity, vVelocity );
  281.  
  282. return PLUGIN_CONTINUE;
  283. }
  284.  
  285. if( iSolid != SOLID_NOT )
  286. set_pev( iEntity, pev_solid, SOLID_NOT );
  287.  
  288. static Float:vAngles[ 3 ], Float:vReturn[ 3 ];
  289. entity_get_vector( iOwner, EV_VEC_v_angle, vAngles );
  290.  
  291. vReturn[ 0 ] = ( floatcos( vAngles[ 1 ], degrees ) * 55.0 ) + vOwnerOrigin[ 0 ];
  292. vReturn[ 1 ] = ( floatsin( vAngles[ 1 ], degrees ) * 55.0 ) + vOwnerOrigin[ 1 ];
  293. vReturn[ 2 ] = vOwnerOrigin[ 2 ];
  294. vReturn[ 2 ] -= ( entity_get_int( iOwner, EV_INT_flags ) & FL_DUCKING ) ? 10 : 30;
  295.  
  296. entity_set_vector( iEntity, EV_VEC_velocity, vVelocity );
  297. entity_set_origin( iEntity, vReturn );
  298. } else {
  299. if( iSolid != SOLID_BBOX )
  300. set_pev( iEntity, pev_solid, SOLID_BBOX );
  301.  
  302. static Float:flLastVerticalOrigin;
  303.  
  304. if( vBallVelocity[ 2 ] == 0.0 ) {
  305. static iCounts;
  306.  
  307. if( flLastVerticalOrigin > vOrigin[ 2 ] ) {
  308. iCounts++;
  309.  
  310. if( iCounts > 10 ) {
  311. iCounts = 0;
  312.  
  313. UpdateBall( 0 );
  314. }
  315. } else {
  316. iCounts = 0;
  317.  
  318. if( PointContents( vOrigin ) != CONTENTS_EMPTY )
  319. UpdateBall( 0 );
  320. }
  321.  
  322. flLastVerticalOrigin = vOrigin[ 2 ];
  323. }
  324. }
  325.  
  326. return PLUGIN_CONTINUE;
  327. }
  328.  
  329. KickBall( id ) {
  330. static Float:vOrigin[ 3 ];
  331.  
  332. entity_get_vector( g_iBall, EV_VEC_origin, vOrigin );
  333.  
  334. if( PointContents( vOrigin ) != CONTENTS_EMPTY )
  335. return PLUGIN_HANDLED;
  336.  
  337. new Float:vVelocity[ 3 ];
  338. velocity_by_aim( id, 650, vVelocity );
  339.  
  340. set_pev( g_iBall, pev_solid, SOLID_BBOX );
  341. entity_set_size( g_iBall, Float:{ -15.0, -15.0, 0.0 }, Float:{ 15.0, 15.0, 12.0 } );
  342. entity_set_int( g_iBall, EV_INT_iuser1, 0 );
  343. entity_set_vector( g_iBall, EV_VEC_velocity, vVelocity );
  344.  
  345. return PLUGIN_CONTINUE;
  346. }
  347.  
  348. // BALL TOUCHES
  349. ////////////////////////////////////////////////////////////
  350. public FwdTouchPlayer( const iBall, const id ) {
  351. if( is_user_bot( id ) )
  352. return PLUGIN_CONTINUE;
  353.  
  354. static iOwner; iOwner = pev( iBall, pev_iuser1 );
  355.  
  356. if( iOwner == 0 )
  357. entity_set_int( iBall, EV_INT_iuser1, id );
  358.  
  359. return PLUGIN_CONTINUE;
  360. }
  361.  
  362. public FwdTouchWorld( const iBall, const World ) {
  363. static Float:vVelocity[ 3 ];
  364. entity_get_vector( iBall, EV_VEC_velocity, vVelocity );
  365.  
  366.  
  367. if( floatround( vector_length( vVelocity ) ) > 10 ) {
  368. vVelocity[ 0 ] *= 0.85;
  369. vVelocity[ 1 ] *= 0.85;
  370. vVelocity[ 2 ] *= 0.85;
  371.  
  372. entity_set_vector( iBall, EV_VEC_velocity, vVelocity );
  373.  
  374. emit_sound( iBall, CHAN_ITEM, BALL_BOUNCE_GROUND, 1.0, ATTN_NORM, 0, PITCH_NORM );
  375. }
  376. }
  377.  
  378. public FwdTouchGoal( const iGoal, const iBall ) {
  379.  
  380. if( entity_get_int( iGoal, EV_INT_iuser2 ) == 1 ||
  381. entity_get_int( iGoal, EV_INT_iuser2 ) == 2 ) {
  382. static iOwner; iOwner = entity_get_int( iBall, EV_INT_iuser1 );
  383. if( iOwner == 0 )
  384. return;
  385.  
  386. static szName[ 32 ]; get_user_name( iOwner, szName, charsmax( szName ) );
  387.  
  388. set_hudmessage( 128, 128, 128, -1.0, 0.5, 0, 0.0, 5.0, 0.4, 0.4, 3 );
  389. show_hudmessage( 0, "Igen GÓL!! %s lõtt egy gólt!", szName );
  390. }
  391. }
  392.  
  393. // ENTITIES CREATING
  394. ////////////////////////////////////////////////////////////
  395. CreateBall( id, Float:vOrigin[ 3 ] = { 0.0, 0.0, 0.0 } ) {
  396. if( !id && vOrigin[ 0 ] == 0.0 && vOrigin[ 1 ] == 0.0 && vOrigin[ 2 ] == 0.0 )
  397. return 0;
  398.  
  399. g_bNeedBall = true;
  400.  
  401. g_iBall = create_entity( "info_target" );
  402.  
  403. if( is_valid_ent( g_iBall ) ) {
  404. entity_set_string( g_iBall, EV_SZ_classname, g_szBallName );
  405. entity_set_int( g_iBall, EV_INT_solid, SOLID_BBOX );
  406. entity_set_int( g_iBall, EV_INT_movetype, MOVETYPE_BOUNCE );
  407. entity_set_model( g_iBall, g_szBallModel );
  408. entity_set_size( g_iBall, Float:{ -15.0, -15.0, 0.0 }, Float:{ 15.0, 15.0, 12.0 } );
  409.  
  410. entity_set_float( g_iBall, EV_FL_framerate, 0.0 );
  411. entity_set_int( g_iBall, EV_INT_sequence, 0 );
  412.  
  413. entity_set_float( g_iBall, EV_FL_nextthink, get_gametime( ) + 0.05 );
  414.  
  415. if( id > 0 ) {
  416. new iOrigin[ 3 ];
  417. get_user_origin( id, iOrigin, 3 );
  418. IVecFVec( iOrigin, vOrigin );
  419.  
  420. vOrigin[ 2 ] += 5.0;
  421.  
  422. entity_set_origin( g_iBall, vOrigin );
  423. } else
  424. entity_set_origin( g_iBall, vOrigin );
  425.  
  426. g_vOrigin = vOrigin;
  427.  
  428. return g_iBall;
  429. }
  430.  
  431. return -1;
  432. }