Advertisement
Guest User

Untitled

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