HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include < amxmodx >
  2. #include < amxmisc >
  3.  
  4. #include < fakemeta >
  5. #include < hamsandwich >
  6. #include < cstrike >
  7. #include < engine >
  8. #include < fun >
  9.  
  10. #include < xs >
  11.  
  12. #pragma semicolon 1
  13.  
  14. #define PLUGIN_VERSION "#1.0.6.0"
  15.  
  16. #if AMXX_VERSION_NUM < 183
  17. #define MAX_PLAYERS 32
  18. #endif
  19.  
  20. #define BREAK_COMPUTER 6
  21.  
  22. enum
  23. {
  24. STATUS_BUILDING,
  25. STATUS_ACTIVE
  26. };
  27.  
  28. enum _: iColorAndCoords
  29. {
  30. x_r = 0,
  31. y_g,
  32. z_b
  33. };
  34.  
  35. new const gDamageSounds[ ][ ] =
  36. {
  37. "debris/metal1.wav",
  38. "debris/metal2.wav",
  39. "debris/metal3.wav"
  40. };
  41.  
  42. new const szBuildingMessages[ ][ ] =
  43. {
  44. "Adagoló épül ezen a helyen...",
  45. "Egy adagoló rendezése",
  46. "Adagoló jön most!",
  47. "Adagoló közeledik egészen elöl"
  48. };
  49.  
  50. new const gDispenserClassname[ ] = "NiceDispenser:D";
  51.  
  52. new const gDispenserActive[ ] = "buttons/button9.wav";
  53. new const gDispenserMdl[ ] = "models/dispenser.mdl";
  54. new const gMetalGibsMdl[ ] = "models/computergibs.mdl";
  55. new const gHealingSprite[ ] = "sprites/laserbeam.spr";
  56.  
  57. new gHealingBeam;
  58. new gMetalGibs;
  59. new gMaxPlayers;
  60. new gHudSync;
  61.  
  62. new gCvarEnabled;
  63. new gDispenserCost;
  64. new gCvarDispenserHealth;
  65. new gCvarBuildTime;
  66. new gCvarReplenishRadius;
  67. new gCvarSpinDispenser;
  68. new gCvarMaxHealth;
  69. new gCvarMaxArmor;
  70.  
  71. new Float:gDispenserOrigin[ MAX_PLAYERS + 1 ][ iColorAndCoords ];
  72. new gBeamcolor[ MAX_PLAYERS + 1 ][ iColorAndCoords ];
  73.  
  74. new Float:gDispenserHealthOff[ MAX_PLAYERS + 1 ];
  75. new bool:bDispenserBuild[ MAX_PLAYERS + 1 ];
  76.  
  77. public plugin_init( )
  78. {
  79. register_plugin( "Build Dispenser", PLUGIN_VERSION, "tuty" );
  80.  
  81. register_event( "TextMsg", "EVENT_TextMsg", "a", "2&#Game_C", "2&#Game_w", "2&#Game_will_restart_in" );
  82. register_logevent( "LOG_RoundEnd", 2, "1=Round_End" );
  83.  
  84. static szDispenserClassname[ ] = "info_target";
  85.  
  86. RegisterHam( Ham_TakeDamage, szDispenserClassname, "bacon_TakeDamage", 1 );
  87. RegisterHam( Ham_TraceAttack, szDispenserClassname, "bacon_TraceAttack" );
  88.  
  89. register_think( gDispenserClassname, "DispenserThink" );
  90. register_clcmd( "drop", "CommandDispenserBuild" );
  91.  
  92. gCvarEnabled = register_cvar( "dispenser_enabled", "1" );
  93. gDispenserCost = register_cvar( "dispenser_cost", "1500" );
  94. gCvarDispenserHealth = register_cvar( "dispenser_health", "900" );
  95. gCvarBuildTime = register_cvar( "dispenser_buildtime", "5" );
  96. gCvarReplenishRadius = register_cvar( "dispenser_radius", "300" );
  97. gCvarSpinDispenser = register_cvar( "dispenser_spin", "1" );
  98. gCvarMaxHealth = register_cvar( "dispenser_playermax_health", "100" );
  99. gCvarMaxArmor = register_cvar( "dispenser_playermax_armor", "100" );
  100.  
  101. gMaxPlayers = get_maxplayers( );
  102.  
  103. gHudSync = CreateHudSyncObj( );
  104. }
  105.  
  106. public client_connect( id )
  107. {
  108. bDispenserBuild[ id ] = false;
  109. }
  110.  
  111. public plugin_precache( )
  112. {
  113. gHealingBeam = precache_model( gHealingSprite );
  114. gMetalGibs = precache_model( gMetalGibsMdl );
  115.  
  116. precache_model( gDispenserMdl );
  117. precache_sound( gDispenserActive );
  118.  
  119. new i;
  120. for( i = 0; i < sizeof gDamageSounds; i++ )
  121. {
  122. precache_sound( gDamageSounds[ i ] );
  123. }
  124. }
  125.  
  126. public CommandDispenserBuild( id )
  127. {
  128. if( !is_user_alive( id )
  129. || get_user_weapon( id ) != CSW_KNIFE
  130. || get_pcvar_num( gCvarEnabled ) != 1 )
  131. {
  132. return PLUGIN_CONTINUE;
  133. }
  134.  
  135. if( !( pev( id, pev_flags ) & FL_ONGROUND ) )
  136. {
  137. client_print( id, print_center, "A földön kell lenned, ahhoz hogy építeni tudj!" );
  138.  
  139. return PLUGIN_HANDLED;
  140. }
  141.  
  142. if( bDispenserBuild[ id ] == true )
  143. {
  144. client_print( id, print_center, "Már építettél adagolót!" );
  145.  
  146. return PLUGIN_HANDLED;
  147. }
  148.  
  149. new iMoney = cs_get_user_money( id );
  150. new iCost = get_pcvar_num( gDispenserCost );
  151.  
  152. if( iMoney < iCost )
  153. {
  154. client_print( id, print_chat, "[Adagoló] Nincs elég pénzed az építéshez. Kell:(%d$)", iCost );
  155.  
  156. return PLUGIN_HANDLED;
  157. }
  158.  
  159. new Float:flPlayerOrigin[ 3 ];
  160. pev( id, pev_origin, flPlayerOrigin );
  161.  
  162. new Float:flHealth = float( get_pcvar_num( gCvarDispenserHealth ) );
  163.  
  164. new iEntity = create_entity( "info_target" );
  165.  
  166. if( !pev_valid( iEntity ) )
  167. {
  168. return PLUGIN_HANDLED;
  169. }
  170.  
  171. set_pev( iEntity, pev_classname, gDispenserClassname );
  172. engfunc( EngFunc_SetModel, iEntity, gDispenserMdl );
  173. engfunc( EngFunc_SetSize, iEntity, Float:{ -12.0, -10.0, -12.0 }, Float:{ 12.0, 10.0, 12.0 } );
  174. set_pev( iEntity, pev_origin, flPlayerOrigin );
  175. set_pev( iEntity, pev_solid, SOLID_NOT );
  176. set_pev( iEntity, pev_movetype, MOVETYPE_TOSS );
  177. set_pev( iEntity, pev_health, flHealth );
  178. set_pev( iEntity, pev_takedamage, DAMAGE_YES );
  179. set_pev( iEntity, pev_iuser2, id );
  180. set_pev( iEntity, pev_iuser3, STATUS_BUILDING );
  181. set_pev( iEntity, pev_nextthink, get_gametime( ) + 0.1 );
  182.  
  183. gDispenserOrigin[ id ][ x_r ] = flPlayerOrigin[ 0 ];
  184. gDispenserOrigin[ id ][ y_g ] = flPlayerOrigin[ 1 ];
  185. gDispenserOrigin[ id ][ z_b ] = flPlayerOrigin[ 2 ];
  186.  
  187. gDispenserHealthOff[ id ] = flHealth;
  188. bDispenserBuild[ id ] = true;
  189.  
  190. set_task( float( get_pcvar_num( gCvarBuildTime ) ), "BuildDispenserSolid", iEntity );
  191. cs_set_user_money( id, iMoney - iCost, 1 );
  192.  
  193. client_print( id, print_center, szBuildingMessages[ random_num( 0, charsmax( szBuildingMessages ) ) ] );
  194.  
  195. return PLUGIN_HANDLED;
  196. }
  197.  
  198. public bacon_TakeDamage( ent, idinflictor, idattacker, Float:damage, damagebits )
  199. {
  200. new szClassname[ 32 ];
  201. pev( ent, pev_classname, szClassname, charsmax( szClassname ) );
  202.  
  203. if( equal( szClassname, gDispenserClassname ) )
  204. {
  205. new iOwner = pev( ent, pev_iuser2 );
  206.  
  207. if( pev( ent, pev_health ) <= 0.0 )
  208. {
  209. new szName[ 32 ];
  210. get_user_name( idattacker, szName, charsmax( szName ) );
  211.  
  212. new Float:flOrigin[ 3 ];
  213. pev( ent, pev_origin, flOrigin );
  214.  
  215. UTIL_BreakModel( flOrigin, gMetalGibs, BREAK_COMPUTER );
  216. set_pev( ent, pev_flags, pev( ent, pev_flags ) | FL_KILLME );
  217.  
  218. if( idattacker == iOwner )
  219. {
  220. client_print( iOwner, print_center, "Leromboltad az adagolódat!" );
  221. }
  222.  
  223. else
  224. {
  225. client_print( iOwner, print_center, "[Adagoló] %s lerombolta az adagolódat!", szName );
  226. }
  227.  
  228. client_cmd( iOwner, "speak ^"vox/bizwarn computer destroyed^"" );
  229. bDispenserBuild[ iOwner ] = false;
  230. }
  231.  
  232. gDispenserHealthOff[ iOwner ] = float( pev( ent, pev_health ) );
  233. emit_sound( ent, CHAN_STATIC, gDamageSounds[ random_num( 0, charsmax( gDamageSounds ) ) ], VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
  234. }
  235. }
  236.  
  237. public bacon_TraceAttack( iVictim, iAttacker, Float:flDamage, Float:flDirection[ 3 ], iTr, iDamageBits )
  238. {
  239. new szClassname[ 32 ];
  240. pev( iVictim, pev_classname, szClassname, charsmax( szClassname ) );
  241.  
  242. if( equal( szClassname, gDispenserClassname ) )
  243. {
  244. new Float:flEndOrigin[ 3 ];
  245. get_tr2( iTr, TR_vecEndPos, flEndOrigin );
  246.  
  247. UTIL_Sparks( flEndOrigin );
  248. }
  249. }
  250.  
  251. public DispenserThink( iEnt )
  252. {
  253. if( pev_valid( iEnt ) )
  254. {
  255. new iStatus = pev( iEnt, pev_iuser3 );
  256. new iOwner = pev( iEnt, pev_iuser2 );
  257.  
  258. switch( iStatus )
  259. {
  260. case STATUS_BUILDING:
  261. {
  262. set_rendering( iEnt, kRenderFxDistort, 255, 255, 255, kRenderTransAdd, 70 );
  263. }
  264.  
  265. case STATUS_ACTIVE:
  266. {
  267. new id;
  268. for( id = 1; id <= gMaxPlayers; id++ )
  269. {
  270. if( is_user_connected( iOwner )
  271. && is_user_connected( id )
  272. && is_user_alive( id )
  273. && cs_get_user_team( id ) == cs_get_user_team( iOwner ) )
  274. {
  275. new Float:flOrigin[ 3 ];
  276. pev( id, pev_origin, flOrigin );
  277.  
  278. if( get_distance_f( gDispenserOrigin[ iOwner ], flOrigin ) <= float( get_pcvar_num( gCvarReplenishRadius ) ) )
  279. {
  280. if( UTIL_IsVisible( id, iEnt ) )
  281. {
  282. UTIL_GiveWeaponAmmo( id );
  283.  
  284. // people will ask why i didn't used if and else if...
  285. // because i want to recharge health and armor and ammo in same time if needed :D
  286.  
  287. if( get_user_health( id ) < get_pcvar_num( gCvarMaxHealth ) )
  288. {
  289. set_user_health( id, get_user_health( id ) + 1 );
  290. }
  291.  
  292. if( get_user_armor( id ) < get_pcvar_num( gCvarMaxArmor ) )
  293. {
  294. set_user_armor( id, get_user_armor( id ) + 1 );
  295. }
  296.  
  297. UTIL_BeamEnts( gDispenserOrigin[ iOwner ], flOrigin, gBeamcolor[ iOwner ][ x_r ], gBeamcolor[ iOwner ][ y_g ], gBeamcolor[ iOwner ][ z_b ] );
  298. }
  299. }
  300. }
  301. }
  302.  
  303. set_hudmessage( gBeamcolor[ iOwner ][ x_r ], gBeamcolor[ iOwner ][ y_g ], gBeamcolor[ iOwner ][ z_b ], 0.0, 0.21, 1, 6.0, 0.2 );
  304. ShowSyncHudMsg( iOwner, gHudSync, ">>>[ Adagoló ]<<<^n^nÉlet: [%d]", floatround( gDispenserHealthOff[ iOwner ] ) );
  305. }
  306. }
  307.  
  308. if( get_pcvar_num( gCvarSpinDispenser ) == 1 )
  309. {
  310. new Float:flAngles[ 3 ];
  311. pev( iEnt, pev_angles, flAngles );
  312.  
  313. flAngles[ 1 ] += 1.0;
  314.  
  315. set_pev( iEnt, pev_angles, flAngles );
  316. }
  317.  
  318. set_pev( iEnt, pev_nextthink, get_gametime( ) + 0.1 );
  319. }
  320. }
  321.  
  322. public BuildDispenserSolid( iEntity )
  323. {
  324. if( pev_valid( iEntity ) )
  325. {
  326. new iOwner = pev( iEntity, pev_iuser2 );
  327.  
  328. if( is_user_connected( iOwner ) )
  329. {
  330. switch( cs_get_user_team( iOwner ) )
  331. {
  332. case CS_TEAM_T:
  333. {
  334. gBeamcolor[ iOwner ][ x_r ] = 255, gBeamcolor[ iOwner ][ y_g ] = 0, gBeamcolor[ iOwner ][ z_b ] = 0;
  335. set_rendering( iEntity, kRenderFxGlowShell, gBeamcolor[ iOwner ][ x_r ], gBeamcolor[ iOwner ][ y_g ], gBeamcolor[ iOwner ][ z_b ], kRenderNormal, 3 );
  336. }
  337.  
  338. case CS_TEAM_CT:
  339. {
  340. gBeamcolor[ iOwner ][ x_r ] = 0, gBeamcolor[ iOwner ][ y_g ] = 0, gBeamcolor[ iOwner ][ z_b ] = 255;
  341. set_rendering( iEntity, kRenderFxGlowShell, gBeamcolor[ iOwner ][ x_r ], gBeamcolor[ iOwner ][ y_g ], gBeamcolor[ iOwner ][ z_b ], kRenderNormal, 3 );
  342. }
  343. }
  344. }
  345.  
  346. set_pev( iEntity, pev_solid, SOLID_BBOX );
  347. set_pev( iEntity, pev_iuser3, STATUS_ACTIVE );
  348.  
  349. engfunc( EngFunc_DropToFloor, iEntity );
  350.  
  351. emit_sound( iEntity, CHAN_STATIC, gDispenserActive, VOL_NORM, ATTN_NORM, 0, PITCH_NORM );
  352. }
  353. }
  354.  
  355. public EVENT_TextMsg( )
  356. {
  357. UTIL_DestroyDispensers( );
  358. }
  359.  
  360. public LOG_RoundEnd( )
  361. {
  362. UTIL_DestroyDispensers( );
  363. }
  364.  
  365.  
  366. /*
  367. ~~~~~~~~~~~~~~~~~~~~~~~
  368. Stocks
  369. ~~~~~~~~~~~~~~~~~~~~~~~
  370. */
  371.  
  372.  
  373. stock UTIL_DestroyDispensers( )
  374. {
  375. new iEnt = FM_NULLENT;
  376.  
  377. while( ( iEnt = find_ent_by_class( iEnt, gDispenserClassname ) ) )
  378. {
  379. new iOwner = pev( iEnt, pev_iuser2 );
  380.  
  381. bDispenserBuild[ iOwner ] = false;
  382. set_pev( iEnt, pev_flags, pev( iEnt, pev_flags ) | FL_KILLME );
  383. }
  384. }
  385.  
  386. stock UTIL_BreakModel( Float:flOrigin[ 3 ], model, flags )
  387. {
  388. engfunc( EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, flOrigin, 0 );
  389. write_byte( TE_BREAKMODEL );
  390. engfunc( EngFunc_WriteCoord, flOrigin[ 0 ] );
  391. engfunc( EngFunc_WriteCoord, flOrigin[ 1 ] );
  392. engfunc( EngFunc_WriteCoord, flOrigin[ 2 ] );
  393. write_coord( 16 );
  394. write_coord( 16 );
  395. write_coord( 16 );
  396. write_coord( random_num( -20, 20 ) );
  397. write_coord( random_num( -20, 20 ) );
  398. write_coord( 10 );
  399. write_byte( 10 );
  400. write_short( model );
  401. write_byte( 10 );
  402. write_byte( 9 );
  403. write_byte( flags );
  404. message_end( );
  405. }
  406.  
  407. stock UTIL_BeamEnts( Float:flStart[ 3 ], Float:flEnd[ 3 ], r, g, b )
  408. {
  409. engfunc( EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, flStart );
  410. write_byte( TE_BEAMPOINTS );
  411. engfunc( EngFunc_WriteCoord, flStart[ 0 ] );
  412. engfunc( EngFunc_WriteCoord, flStart[ 1 ] );
  413. engfunc( EngFunc_WriteCoord, flStart[ 2 ] );
  414. engfunc( EngFunc_WriteCoord, flEnd[ 0 ] );
  415. engfunc( EngFunc_WriteCoord, flEnd[ 1 ] );
  416. engfunc( EngFunc_WriteCoord, flEnd[ 2 ] );
  417. write_short( gHealingBeam );
  418. write_byte( 5 );
  419. write_byte( 2 );
  420. write_byte( 1 );
  421. write_byte( 80 );
  422. write_byte( 1 );
  423. write_byte( r );
  424. write_byte( g );
  425. write_byte( b );
  426. write_byte( 130 );
  427. write_byte( 0 );
  428. message_end( );
  429. }
  430.  
  431. stock UTIL_GiveWeaponAmmo( index )
  432. {
  433. new szCopyAmmoData[ 40 ];
  434.  
  435. switch( get_user_weapon( index ) )
  436. {
  437. case CSW_P228: copy( szCopyAmmoData, charsmax( szCopyAmmoData ), "ammo_357sig" );
  438. case CSW_SCOUT, CSW_G3SG1, CSW_AK47: copy( szCopyAmmoData, charsmax( szCopyAmmoData ), "ammo_762nato" );
  439. case CSW_XM1014, CSW_M3: copy( szCopyAmmoData, charsmax( szCopyAmmoData ), "ammo_buckshot" );
  440. case CSW_MAC10, CSW_UMP45, CSW_USP: copy( szCopyAmmoData, charsmax( szCopyAmmoData ), "ammo_45acp" );
  441. case CSW_SG550, CSW_GALIL, CSW_FAMAS, CSW_M4A1, CSW_SG552, CSW_AUG: copy( szCopyAmmoData, charsmax( szCopyAmmoData ), "ammo_556nato" );
  442. case CSW_ELITE, CSW_GLOCK18, CSW_MP5NAVY, CSW_TMP: copy( szCopyAmmoData, charsmax( szCopyAmmoData ), "ammo_9mm" );
  443. case CSW_AWP: copy( szCopyAmmoData, charsmax( szCopyAmmoData ), "ammo_338magnum" );
  444. case CSW_M249: copy( szCopyAmmoData, charsmax( szCopyAmmoData ), "ammo_556natobox" );
  445. case CSW_FIVESEVEN, CSW_P90: copy( szCopyAmmoData, charsmax( szCopyAmmoData ), "ammo_57mm" );
  446. case CSW_DEAGLE: copy( szCopyAmmoData, charsmax( szCopyAmmoData ), "ammo_50ae" );
  447. }
  448.  
  449. give_item( index, szCopyAmmoData );
  450. }
  451.  
  452. stock UTIL_Sparks( Float:flOrigin[ 3 ] )
  453. {
  454. engfunc( EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, flOrigin, 0 );
  455. write_byte( TE_SPARKS );
  456. engfunc( EngFunc_WriteCoord, flOrigin[ 0 ] );
  457. engfunc( EngFunc_WriteCoord, flOrigin[ 1 ] );
  458. engfunc( EngFunc_WriteCoord, flOrigin[ 2 ] );
  459. message_end( );
  460. }
  461.  
  462. stock bool:UTIL_IsVisible( index, entity, ignoremonsters = 0 )
  463. {
  464. new Float:flStart[ 3 ], Float:flDest[ 3 ];
  465. pev( index, pev_origin, flStart );
  466. pev( index, pev_view_ofs, flDest );
  467.  
  468. xs_vec_add( flStart, flDest, flStart );
  469.  
  470. pev( entity, pev_origin, flDest );
  471. engfunc( EngFunc_TraceLine, flStart, flDest, ignoremonsters, index, 0 );
  472.  
  473. new Float:flFraction;
  474. get_tr2( 0, TR_flFraction, flFraction );
  475.  
  476. if( flFraction == 1.0 || get_tr2( 0, TR_pHit) == entity )
  477. {
  478. return true;
  479. }
  480.  
  481. return false;
  482. }
  483.  
  484. /*
  485. ~~~~~~~~~~~~~~~~~~~~~~~
  486. End of Code
  487. ~~~~~~~~~~~~~~~~~~~~~~~
  488. */
  489.