Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.40 KB | None | 0 0
  1. /* AMX Mod X
  2. * Snowball war
  3. *
  4. * / \ / \ ___________________________
  5. * / / \_/ \ \ / \
  6. * \__/\ /\__/ / GIVE ME A CARROT OR I WILL \
  7. * \O O/ \ BLOW UP YOUR HOUSE /
  8. * ___/ ^ \___ / ___________________________/
  9. * \___/ /_/
  10. * _/ \_
  11. * __// \\__
  12. * /___\/_\/___\
  13. *
  14. * (c) Copyright 2008 by FakeNick
  15. *
  16. * This file is provided as is (no warranties)
  17. *
  18. * DESCRIPTION
  19. * My plugin is changing an HE grenade for snowball. When player spawns he receives only
  20. * knife and HE. When snowball hit's wall it will explode with nice spalt effect.
  21. * In this mod there are two teams : blue (CT's) and red (T's). They must kill their opponents
  22. * with snowball. When player gets hit, his health is decreasing and there's
  23. * a chance that player will be chilled. In this mod target is to kill your opponents,soldier!
  24. * Snowball war includes very simple deathmatch (default off). It is also changing players models
  25. * to santa's (T's) and snow soldiers (CT's) - this model can be changed by plugin user.
  26. * Snowball war enables snow effect on server (comment line 171 to disable).
  27. *
  28. * MODULES
  29. * fakemeta
  30. * hamsandwich
  31. *
  32. * CVARS
  33. * sw_toggle - is mod on/off? (default ON - 1)
  34. * sw_friendly - is friendly fire on/off? (default OFF - 0)
  35. * sw_damage - damage done by snowball (default 100)
  36. * sw_life - life of snowball splat (default 3.0)
  37. * sw_dm - is deathmatch on/off? (defualt OFF - 0)
  38. * sw_dm_time - time to respawn (default 2.0)
  39. * sw_chill_chance - chance to chill player (from 0 - off, to 100 - maximum chance, default 30)
  40. * sw_chill_duration - duration of chill (default 5.0)
  41. * sw_chill_speed - percentage of speed that player receives when chilled (default 50.0)
  42. * sw_snowball_gravity - gravity of snowball (default 0.3)
  43. * sw_snowball_velocity - how many times snowball velocity will be multipied (default 2.0 times)
  44. * sw_crosshair_remove - will be crosshair removed (default ON - 1)
  45. * sw_spawn_protection - is spawn protection on? (default ON - 1)
  46. * sw_spawn_protection_time - time of spawn protection (default 3.0)
  47. *
  48. *
  49. * Changelog
  50. * Version 3.0 :
  51. * - Initial release
  52. *
  53. * Version 3.01 :
  54. * - Added game description changer
  55. *
  56. * Version 3.02 :
  57. * - Added change velocity of snowball
  58. * - Added change gravity of snowball
  59. * - Added crsoshair remover for more realism
  60. *
  61. * Version 3.03 :
  62. * - Added breaking glass when unchilling player
  63. * - Added random snow skybox generator
  64. * - Added spawn protection
  65. *
  66. * Version 3.04 :
  67. * - Fixed server crashing bug
  68. *
  69. * Version 3.05 :
  70. * - Added support for bots (code from ZP)
  71. *
  72. *
  73. */
  74. #include <amxmodx>
  75. #include <amxmisc>
  76. #include <hamsandwich>
  77. #include <fakemeta>
  78. #include <fakemeta_util>
  79.  
  80. /*================================================================================
  81. [Plugin Customization]
  82. =================================================================================*/
  83.  
  84. //Do not touch this!
  85. new const model_nade_world[] = "models/sw/w_snowball.mdl"
  86. new const model_nade_view[] = "models/sw/v_snowball.mdl"
  87. new const model_nade_player[] = "models/sw/p_snowball.mdl"
  88. new const model_splash[] = "sprites/bhit.spr"
  89.  
  90. //Randomly chosen models and sounds, add as many, as you want
  91.  
  92. new const model_red[][] = { "red1" }
  93. new const model_blue[][] = { "blue1" }
  94.  
  95. new const sound_pain[][] = { "player/pl_pain2.wav","player/pl_pain4.wav","player/pl_pain5.wav","player/pl_pain6.wav","player/pl_pain7.wav" }
  96. new const sound_hit[][] = { "player/pl_snow1.wav","player/pl_snow2.wav","player/pl_snow3.wav","player/pl_snow4.wav","player/pl_snow5.wav","player/pl_snow6.wav" }
  97. new const sound_chill[][] = { "sw/chill.wav" }
  98. new const sound_unchill[][] = { "sw/unchill.wav" }
  99. new const sound_win_blue[][] = { "sw/blue1.wav" }
  100. new const sound_win_red[][] = { "sw/red1.wav" }
  101. new const sound_win_no_one[][] = { "sw/draw.wav" }
  102.  
  103. /*================================================================================
  104. [CUSTOMIZATION ENDS HERE!]
  105. =================================================================================*/
  106.  
  107. /*================================================================================
  108. [Enums]
  109. =================================================================================*/
  110.  
  111. enum(+=100)
  112. {
  113. TASK_WELCOME = 100,
  114. TASK_AMMO,
  115. TASK_RESPAWN,
  116. TASK_UNCHILL,
  117. TASK_MODEL,
  118. TASK_GOD
  119. }
  120.  
  121. enum
  122. {
  123. CS_TEAM_UNASSIGNED = 0,
  124. CS_TEAM_T,
  125. CS_TEAM_CT,
  126. CS_TEAM_SPECTATOR
  127. }
  128.  
  129. /*================================================================================
  130. [Pcvars]
  131. =================================================================================*/
  132.  
  133. new pcvar_on,pcvar_friendly,pcvar_dmg,pcvar_life,pcvar_dm,pcvar_dm_time,pcvar_chill_chance,
  134. pcvar_chill_duration,pcvar_chill_speed,pcvar_gravity,pcvar_velocity,pcvar_crosshair,
  135. pcvar_spawn,pcvar_spawn_duration,pcvar_bots
  136.  
  137. /*================================================================================
  138. [Player variables]
  139. =================================================================================*/
  140.  
  141. new g_red[33],g_blue[33],g_IsChilled[33],Float:g_maxspeed[33],Float:g_ChillySpeed[33],
  142. g_has_custom_model[33],g_player_model[33][32],g_god[33],g_bots
  143.  
  144. /*================================================================================
  145. [Global Variables]
  146. =================================================================================*/
  147.  
  148. new g_money,g_weapon,g_crosshair,g_fwSpawn,g_sync,g_maxplayers,g_death,g_endround,
  149. g_spray,g_glass,g_drop,gmsgScreenFade,Float:g_models_counter
  150.  
  151. //This can affect gameplay
  152. new const g_not_needed[][] =
  153. {
  154. "weaponbox",
  155. "armoury_entity",
  156. "grenade",
  157. "func_bomb_target",
  158. "info_bomb_target",
  159. "info_vip_start",
  160. "func_vip_safetyzone",
  161. "func_escapezone",
  162. "hostage_entity",
  163. "monster_scientist",
  164. "func_hostage_rescue",
  165. "info_hostage_rescue"
  166. }
  167.  
  168. //Grenade bounce sounds
  169. new const g_bouncelist[4][64] =
  170. {
  171. "weapons/grenade_hit1.wav",
  172. "weapons/grenade_hit2.wav",
  173. "weapons/grenade_hit3.wav",
  174. "weapons/he_bounce-1.wav"
  175. }
  176.  
  177. //Mod name
  178. new const g_modname[] = "Snowball war"
  179.  
  180. //Skyboxes
  181. new const g_skybox[][] = { "snow","office" }
  182.  
  183.  
  184. /*================================================================================
  185. [Offsets and Constants]
  186. =================================================================================*/
  187.  
  188. #if cellbits == 32
  189. const OFFSET_CSTEAMS = 114
  190. const OFFSET_CSMONEY = 115
  191. const OFFSET_HE_AMMO = 388
  192. #else
  193. const OFFSET_CSTEAMS = 139
  194. const OFFSET_CSMONEY = 140
  195. const OFFSET_HE_AMMO = 437
  196. #endif
  197. const OFFSET_LINUX = 5
  198.  
  199. //To hide money displaying
  200. const HIDE_MONEY = (1<<5)
  201.  
  202. //To hide crosshair
  203. const HIDE_CROSSHAIR = (1<<6)
  204.  
  205. //For screen fade
  206. const FFADE_IN = 0x0000
  207.  
  208. //For break glass effect
  209. const BREAK_GLASS = 0x01
  210.  
  211. //Snow effect on server. Comment this line to disable
  212. #define EFFECT_SNOW
  213.  
  214. //If you experience many SVC_BAD kicks. increase this (for example set it to 0.5)
  215. const Float:MODEL_DELAY = 0.2
  216.  
  217. //Version information
  218. new const VERSION[] = "3.05"
  219.  
  220. /*================================================================================
  221. [Code ;)]
  222. =================================================================================*/
  223.  
  224. public plugin_precache()
  225. {
  226. new a,modelpath[200]
  227.  
  228. for(a = 0; a < sizeof sound_win_blue; a++)
  229. engfunc(EngFunc_PrecacheSound,sound_win_blue[a])
  230. for(a = 0; a < sizeof sound_win_blue; a++)
  231. engfunc(EngFunc_PrecacheSound,sound_win_red[a])
  232. for(a = 0; a < sizeof sound_win_blue; a++)
  233. engfunc(EngFunc_PrecacheSound,sound_win_no_one[a])
  234. for(a = 0; a < sizeof sound_pain; a++)
  235. engfunc(EngFunc_PrecacheSound,sound_pain[a])
  236. for(a = 0; a < sizeof sound_hit; a++)
  237. engfunc(EngFunc_PrecacheSound,sound_hit[a])
  238. for(a = 0; a < sizeof sound_chill; a++)
  239. engfunc(EngFunc_PrecacheSound,sound_chill[a])
  240. for(a = 0; a < sizeof sound_unchill; a++)
  241. engfunc(EngFunc_PrecacheSound,sound_unchill[a])
  242.  
  243. for(a = 0;a < sizeof model_blue; a++)
  244. {
  245. formatex(modelpath, sizeof modelpath - 1, "models/player/%s/%s.mdl", model_blue[a], model_blue[a])
  246. engfunc(EngFunc_PrecacheModel,modelpath)
  247. }
  248. for(a = 0;a < sizeof model_red; a++)
  249. {
  250. formatex(modelpath, sizeof modelpath - 1, "models/player/%s/%s.mdl", model_red[a], model_red[a])
  251. engfunc(EngFunc_PrecacheModel,modelpath)
  252. }
  253.  
  254. engfunc(EngFunc_PrecacheModel,model_nade_world)
  255. engfunc(EngFunc_PrecacheModel,model_nade_view)
  256. engfunc(EngFunc_PrecacheModel,model_nade_player)
  257. engfunc(EngFunc_PrecacheModel,model_splash)
  258.  
  259. g_drop = engfunc(EngFunc_PrecacheModel,"sprites/blood.spr")
  260. g_spray = engfunc(EngFunc_PrecacheModel,"sprites/bloodspray.spr")
  261. g_glass = engfunc(EngFunc_PrecacheModel,"models/glassgibs.mdl")
  262.  
  263. #if defined EFFECT_SNOW
  264. engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_snow"))
  265. #endif
  266.  
  267. //Fake hostage to force round ending
  268. new ent
  269. ent = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"hostage_entity"))
  270.  
  271. if(pev_valid(ent))
  272. {
  273. engfunc(EngFunc_SetOrigin, ent, Float:{8192.0 ,8192.0 ,8192.0})
  274. dllfunc(DLLFunc_Spawn, ent)
  275. }
  276.  
  277. //Prevent some etnities form spawning
  278. g_fwSpawn = register_forward(FM_Spawn,"fw_SpawnEntity")
  279.  
  280. }
  281.  
  282. public plugin_init()
  283. {
  284. register_plugin("Snowball war", VERSION, "FakeNick")
  285.  
  286. pcvar_on = register_cvar("sw_toggle","1")
  287.  
  288. //Make sure that plugin is on
  289. if(!get_pcvar_num(pcvar_on))
  290. return
  291.  
  292. //Register dictionary
  293. register_dictionary("sw.txt")
  294.  
  295. //Events
  296. register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
  297. register_event("CurWeapon","event_modelchange","be","1=1")
  298. register_logevent("logevent_round_end",2,"1=Round_End")
  299.  
  300. //Forwards
  301. RegisterHam(Ham_Spawn,"player","fw_PlayerSpawn",1)
  302. RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
  303. RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
  304.  
  305. register_forward(FM_SetModel,"fw_SetModel")
  306. register_forward(FM_Touch,"fw_Touch")
  307. register_forward(FM_EmitSound,"fw_EmitSound")
  308. register_forward(FM_Think,"fw_Think")
  309. register_forward(FM_SetClientKeyValue, "fw_SetClientKeyValue")
  310. register_forward(FM_ClientUserInfoChanged, "fw_ClientUserInfoChanged")
  311. register_forward(FM_GetGameDescription,"fw_GameDesc")
  312.  
  313. unregister_forward(FM_Spawn,g_fwSpawn)
  314.  
  315. //Pcvars
  316. pcvar_friendly = register_cvar("sw_friendly","0")
  317. pcvar_dmg = register_cvar("sw_damage","100")
  318. pcvar_life = register_cvar("sw_life","3.0")
  319. pcvar_dm = register_cvar("sw_dm","0")
  320. pcvar_dm_time = register_cvar("sw_dm_time","2.0")
  321. pcvar_chill_chance = register_cvar("sw_chill_chance","30")
  322. pcvar_chill_duration = register_cvar("sw_chill_duration","5.0")
  323. pcvar_chill_speed = register_cvar("sw_chill_speed","50.0")
  324. pcvar_gravity = register_cvar("sw_snowball_gravity","0.3")
  325. pcvar_velocity = register_cvar("sw_snowball_velocity","2.0")
  326. pcvar_crosshair = register_cvar("sw_crosshair_remove","1")
  327. pcvar_spawn = register_cvar("sw_spawn_protection","1")
  328. pcvar_spawn_duration = register_cvar("sw_spawn_protection_time","3.0")
  329.  
  330. pcvar_bots = get_cvar_pointer("bot_quota")
  331.  
  332. //For version recognize and see what server is running this plugin
  333. register_cvar("sw_version",VERSION,FCVAR_SERVER | FCVAR_SPONLY)
  334.  
  335. //Set skybox
  336. set_cvar_string("sv_skyname", g_skybox[random_num(0, sizeof g_skybox - 1)])
  337.  
  338. //Other stuff
  339. g_money = get_user_msgid("Money")
  340. g_weapon = get_user_msgid("HideWeapon")
  341. g_crosshair = get_user_msgid("Crosshair")
  342. g_death = get_user_msgid("DeathMsg")
  343. gmsgScreenFade = get_user_msgid("ScreenFade")
  344.  
  345. g_sync = CreateHudSyncObj()
  346.  
  347. g_maxplayers = get_maxplayers()
  348.  
  349. //Messsages
  350. register_message(get_user_msgid("TextMsg"), "message_textmsg")
  351. register_message(get_user_msgid("SendAudio"),"message_audio")
  352. register_message(get_user_msgid("HostagePos"), "message_hostagepos")
  353. register_message(get_user_msgid("Scenario"), "message_scenario")
  354. }
  355. public plugin_cfg()
  356. {
  357. // Get configs dir
  358. new cfgdir[32],file[192]
  359.  
  360. get_configsdir(cfgdir, sizeof cfgdir - 1)
  361.  
  362. formatex(file,sizeof file - 1,"%s/sw.cfg",cfgdir)
  363.  
  364. if(file_exists(file))
  365. {
  366. // Execute config file (sw.cfg)
  367. server_cmd("exec %s", file)
  368. }else{
  369. log_amx("[SW] Snowball War config file doesn't exist!")
  370. }
  371. }
  372. /*================================================================================
  373. [Events]
  374. =================================================================================*/
  375. public event_round_start()
  376. {
  377. //It's not round end
  378. g_endround = false
  379.  
  380. //Reset models counter
  381. g_models_counter = 0.0
  382.  
  383. //Remove old welcome task and make a new one
  384. remove_task(TASK_WELCOME)
  385. set_task(2.5,"func_welcome",TASK_WELCOME)
  386.  
  387. }
  388. public event_modelchange(id)
  389. {
  390. new weapon = read_data(2)
  391.  
  392. if(weapon == CSW_HEGRENADE)
  393. {
  394. //Set view model and player model
  395. set_pev(id,pev_viewmodel2,model_nade_view)
  396. set_pev(id,pev_weaponmodel2,model_nade_world)
  397.  
  398. //Remove crosshair
  399. if(get_pcvar_num(pcvar_crosshair))
  400. {
  401. message_begin( MSG_ONE_UNRELIABLE, g_weapon, _, id )
  402. write_byte(HIDE_CROSSHAIR)
  403. message_end()
  404. }
  405.  
  406. }
  407. }
  408. public logevent_round_end()
  409. {
  410. // Prevent this from getting called twice when restarting (bugfix)
  411. static Float:last
  412. if (get_gametime() - last < 0.5) return;
  413. last = get_gametime()
  414.  
  415. g_endround = true
  416.  
  417. // Show HUD notice, play win sound
  418. if (!sw_GetBlue())
  419. {
  420. //Red team wins
  421. set_hudmessage(200, 0, 0, -1.0, 0.17, 0, 0.0, 3.0, 2.0, 1.0, -1)
  422. ShowSyncHudMsg(0, g_sync, "%L", LANG_PLAYER, "WIN_RED")
  423.  
  424. // Play win sound
  425. sw_sound(sound_win_red[random_num(0, sizeof sound_win_red -1)])
  426. }
  427. else if (!sw_GetRed())
  428. {
  429. //Blue team wins
  430. set_hudmessage(0, 0, 200, -1.0, 0.17, 0, 0.0, 3.0, 2.0, 1.0, -1)
  431. ShowSyncHudMsg(0, g_sync, "%L", LANG_PLAYER, "WIN_BLUE")
  432.  
  433. // Play win sound
  434. sw_sound(sound_win_blue[random_num(0, sizeof sound_win_blue -1)])
  435. }
  436. else
  437. {
  438. // No one wins
  439. set_hudmessage(0, 200, 0, -1.0, 0.17, 0, 0.0, 3.0, 2.0, 1.0, -1)
  440. ShowSyncHudMsg(0, g_sync, "%L", LANG_PLAYER, "WIN_NO_ONE")
  441.  
  442. sw_sound(sound_win_no_one[random_num(0, sizeof sound_win_no_one -1)])
  443. }
  444. }
  445. /*================================================================================
  446. [Main Part]
  447. =================================================================================*/
  448. public func_welcome()
  449. {
  450. client_print(0,print_chat,"%L",LANG_PLAYER,"MSG_WELCOME",VERSION)
  451. }
  452. public client_connect(id)
  453. {
  454. if(!get_pcvar_num(pcvar_on))
  455. return
  456.  
  457. #if defined EFFECT_SNOW
  458. client_cmd(id, "cl_weather 1")
  459. #endif
  460. }
  461. public client_putinserver(id)
  462. {
  463. // Plugin disabled?
  464. if (!get_pcvar_num(pcvar_on))
  465. return;
  466.  
  467. // Initialize player vars
  468. g_IsChilled[id] = false
  469. g_blue[id] = false
  470. g_red[id]= false
  471. g_god[id] = false
  472.  
  473. // CZ bots seem to use a different "classtype" for player entities
  474. // (or something like that) which needs to be hooked separately
  475. if (!g_bots && pcvar_bots && is_user_bot(id))
  476. {
  477. // Set a task to let the private data initialize
  478. set_task(0.1, "task_bots", id)
  479. }
  480. }
  481. public client_disconnect(id)
  482. {
  483. if(!get_pcvar_num(pcvar_on))
  484. return
  485.  
  486. g_IsChilled[id] = false
  487. g_blue[id] = false
  488. g_red[id]= false
  489. g_god[id] = false
  490. }
  491. /*================================================================================
  492. [Forwards]
  493. =================================================================================*/
  494.  
  495. public fw_PlayerSpawn(id)
  496. {
  497. if(!is_user_alive(id))
  498. return
  499.  
  500. g_blue[id] = false
  501. g_red[id] = false
  502. g_IsChilled[id] = false
  503. g_god[id] = false
  504.  
  505. //Strip player weapons
  506. fm_strip_user_weapons(id)
  507.  
  508. //Give him knife and "snowball"
  509. fm_give_item(id,"weapon_knife")
  510. fm_give_item(id,"weapon_hegrenade")
  511.  
  512. //Reset his model
  513. sw_reset_user_model(id)
  514.  
  515. //Strip his cash ;]
  516. sw_set_user_money(id,0,0)
  517.  
  518. //Hide money displaying
  519. sw_money(id)
  520.  
  521. //Set his team variable
  522. switch(sw_get_user_team(id))
  523. {
  524. case CS_TEAM_CT : g_blue[id] = true
  525. case CS_TEAM_T : g_red[id] = true
  526. }
  527.  
  528. //Set his new model
  529. remove_task(id + TASK_MODEL)
  530.  
  531. // Store our custom model in g_player_model[id]
  532. if(g_blue[id])
  533. {
  534. copy(g_player_model[id], sizeof g_player_model[] - 1, model_blue[random_num(0, sizeof model_blue -1)])
  535.  
  536. }else if(g_red[id])
  537. {
  538. copy(g_player_model[id], sizeof g_player_model[] - 1, model_red[random_num(0, sizeof model_red -1)])
  539. }
  540.  
  541. // Get the current model
  542. new currentmodel[32]
  543. sw_get_user_model(id, currentmodel, sizeof currentmodel - 1)
  544.  
  545. // Check whether it matches the custom model
  546. if (!equal(currentmodel, g_player_model[id]))
  547. {
  548. // If not, set a task to change it
  549. set_task(1.0 + g_models_counter, "task_set_model", id + TASK_MODEL)
  550.  
  551. // Add a delay between every model change
  552. g_models_counter += MODEL_DELAY
  553. }
  554.  
  555. //Check if spawn protection is on
  556. if(get_pcvar_num(pcvar_spawn))
  557. {
  558. //Set god
  559. g_god[id] = true
  560.  
  561. //Remove an old task and make a new one
  562. remove_task(id + TASK_GOD)
  563. set_task(get_pcvar_float(pcvar_spawn_duration),"task_UnGod",id + TASK_GOD)
  564.  
  565. //Set glow
  566. switch(sw_get_user_team(id))
  567. {
  568. case CS_TEAM_CT : fm_set_user_rendering(id,kRenderFxGlowShell,0,0,255,kRenderNormal,25)
  569. case CS_TEAM_T : fm_set_user_rendering(id,kRenderFxGlowShell,255,0,0,kRenderNormal,25)
  570. }
  571.  
  572. }
  573.  
  574. }
  575. public fw_SpawnEntity(entity)
  576. {
  577. // Invalid entity
  578. if (!pev_valid(entity)) return FMRES_IGNORED
  579.  
  580. // Get classname
  581. new classname[32]
  582. pev(entity, pev_classname, classname, sizeof classname - 1)
  583.  
  584. // Check whether it needs to be removed
  585. for (new i = 0; i < sizeof g_not_needed; i++)
  586. {
  587. if (equal(classname, g_not_needed[i]))
  588. {
  589. engfunc(EngFunc_RemoveEntity, entity)
  590. return FMRES_SUPERCEDE
  591. }
  592. }
  593.  
  594. return FMRES_IGNORED
  595. }
  596. public fw_SetModel(ent,const model[])
  597. {
  598. //Check ent validity
  599. if(!pev_valid(ent))
  600. return FMRES_IGNORED
  601.  
  602. //If model is equal to HE model, change it to snowball model
  603. if(equali(model,"models/w_hegrenade.mdl"))
  604. {
  605. //get owner to renew his ammo
  606. new Float:velocity[3],owner = pev(ent,pev_owner)
  607.  
  608. //remove an old task an set a new one
  609. remove_task(owner + TASK_AMMO)
  610. set_task(0.01,"task_ammo",owner + TASK_AMMO)
  611.  
  612. //Set model
  613. engfunc(EngFunc_SetModel,ent,model_nade_world)
  614.  
  615. //Block from exploding
  616. set_pev(ent, pev_dmgtime, get_gametime() + 9999.0)
  617.  
  618. //Set less gravity, so it will be "real" snowball
  619. set_pev(ent,pev_gravity,get_pcvar_float(pcvar_gravity))
  620.  
  621. //Get grenade velocity
  622. pev(ent, pev_velocity, velocity)
  623.  
  624. //Calculate new velocity
  625. velocity[0] *= get_pcvar_float(pcvar_velocity)
  626. velocity[1] *= get_pcvar_float(pcvar_velocity)
  627. velocity[2] *= get_pcvar_float(pcvar_velocity)
  628.  
  629. //Set new velocity
  630. set_pev(ent, pev_velocity,velocity)
  631.  
  632. return FMRES_SUPERCEDE
  633. }
  634. return FMRES_IGNORED
  635. }
  636. public fw_Touch(ent,id)
  637. {
  638. if(!pev_valid(ent))
  639. return FMRES_IGNORED
  640.  
  641. //Create some variables
  642. new classname[20],classname2[20],Float:origin[3],owner = pev(ent,pev_owner)
  643.  
  644. pev(ent,pev_origin,origin)
  645. pev(id,pev_classname,classname2,sizeof classname2 - 1)
  646. pev(ent,pev_classname,classname,sizeof classname - 1)
  647.  
  648. //Player get's hit
  649. if(equali(classname,"grenade") && equali(classname2,"player"))
  650. {
  651. if(is_user_alive(id))
  652. {
  653. //Check friendly fire
  654. if (get_user_team(owner) == get_user_team(id))
  655. if (!get_pcvar_num(pcvar_friendly))
  656. return FMRES_IGNORED
  657.  
  658. //Check god mode
  659. if(g_god[id])
  660. return FMRES_IGNORED
  661.  
  662. if(get_user_health(id) > get_pcvar_float(pcvar_dmg))
  663. {
  664. //Players health is greater than snowball damage
  665.  
  666. //Calculate chill chance
  667. if(random_num(0,100) <= get_pcvar_num(pcvar_chill_chance))
  668. {
  669. //Chill only non-chilled player
  670. if(!g_IsChilled[id])
  671. {
  672. //Emit sound
  673. engfunc(EngFunc_EmitSound,id,CHAN_AUTO,sound_chill[random_num(0, sizeof sound_chill - 1)],1.0,ATTN_NORM,0,PITCH_NORM)
  674.  
  675. //Make light effect
  676. sw_light(origin)
  677.  
  678. //Chill him!
  679. sw_ChillPlayer(id)
  680.  
  681. //Set unchill task
  682. remove_task(id + TASK_UNCHILL)
  683. set_task(get_pcvar_float(pcvar_chill_duration),"task_UnChill",id + TASK_UNCHILL)
  684. }
  685. }
  686.  
  687. //Create nice effect
  688. sw_effect(origin)
  689.  
  690. //Emit pain sound
  691. engfunc(EngFunc_EmitSound,id,CHAN_VOICE,sound_pain[random_num(0, sizeof sound_pain - 1)],1.0,ATTN_NORM,0,PITCH_NORM)
  692.  
  693. //Emit hit sound
  694. engfunc(EngFunc_EmitSound,ent,CHAN_AUTO,sound_hit[random_num(0, sizeof sound_hit - 1)],1.0,ATTN_NORM,0,PITCH_NORM)
  695.  
  696. //Do damage to player
  697. fm_set_user_health(id, get_user_health(id) - floatround(get_pcvar_float(pcvar_dmg)))
  698.  
  699. //Make white splash
  700. sw_splash(ent,origin)
  701.  
  702. }else if(get_user_health(id) <= get_pcvar_float(pcvar_dmg))
  703. {
  704. //Players health is lower or equal to snowball damage
  705.  
  706. //Emit hit sound
  707. engfunc(EngFunc_EmitSound,ent,CHAN_AUTO,sound_hit[random_num(0, sizeof sound_hit - 1)],1.0,ATTN_NORM,0,PITCH_NORM)
  708.  
  709. //Make nice effect
  710. sw_effect(origin)
  711.  
  712. //Remove entity
  713. engfunc(EngFunc_RemoveEntity,ent)
  714.  
  715. //Kill player
  716. sw_kill(owner,id,"snowball",0)
  717. }
  718. }else{
  719. //Snowball hits something (not player)
  720. sw_splash(ent,origin)
  721. }
  722.  
  723. }else if(equali(classname,"grenade"))
  724. {
  725. sw_effect(origin)
  726.  
  727. //Snowball hit's something, f.e. wall, etc.
  728. sw_splash(ent,origin)
  729.  
  730. //Emit hit sound
  731. engfunc(EngFunc_EmitSound,ent,CHAN_AUTO,sound_hit[random_num(0, sizeof sound_hit - 1)],1.0,ATTN_NORM,0,PITCH_NORM)
  732. }
  733.  
  734. return FMRES_IGNORED
  735. }
  736. public fw_EmitSound(ent,channel,const sound[])
  737. {
  738. //Check if emited sound is equal to one for our list
  739. for(new a; a < sizeof g_bouncelist;a++)
  740. {
  741. //If it's equal - block it
  742. if(equali(sound,g_bouncelist[a]))
  743. return FMRES_SUPERCEDE
  744. }
  745. return FMRES_IGNORED
  746. }
  747. public fw_Think(ent)
  748. {
  749. //Check validity
  750. if(!pev_valid(ent))
  751. return FMRES_IGNORED
  752.  
  753. //Retrieve class
  754. static class[20]
  755. pev(ent,pev_classname,class,sizeof class - 1)
  756.  
  757. //If class is equal to snow_splash, remove entity
  758. if(equali(class,"snow_splash"))
  759. engfunc(EngFunc_RemoveEntity,ent)
  760.  
  761. return FMRES_IGNORED
  762. }
  763. public fw_SetClientKeyValue(id, const infobuffer[], const key[])
  764. {
  765. // Block CS model changes
  766. if (g_has_custom_model[id] && equal(key, "model"))
  767. return FMRES_SUPERCEDE
  768.  
  769. return FMRES_IGNORED
  770. }
  771. public fw_ClientUserInfoChanged(id)
  772. {
  773. // Player doesn't have a custom model
  774. if (!g_has_custom_model[id])
  775. return FMRES_IGNORED
  776.  
  777. // Get current model
  778. static currentmodel[32]
  779. sw_get_user_model(id, currentmodel, sizeof currentmodel - 1)
  780.  
  781. // Check whether it matches the custom model - if not, set it again
  782. if (!equal(currentmodel, g_player_model[id]))
  783. sw_set_user_model(id, g_player_model[id])
  784.  
  785. return FMRES_IGNORED
  786. }
  787. public fw_PlayerKilled(victim, attacker, shouldgib)
  788. {
  789. //Check if deathmatch is on
  790. if(!get_pcvar_num(pcvar_dm))
  791. return
  792.  
  793. //Make sure that it's not round end
  794. if(!g_endround)
  795. {
  796. remove_task(victim + TASK_RESPAWN)
  797. set_task(get_pcvar_float(pcvar_dm_time),"task_respawn",victim + TASK_RESPAWN)
  798. }
  799.  
  800. }
  801. //Block knife damage
  802. public fw_TakeDamage(victim, inflictor, attacker, Float:damage, damage_type)
  803. {
  804. // Non-player damage or self damage
  805. if (victim == attacker || !is_user_connected(attacker))
  806. return HAM_IGNORED
  807.  
  808. return HAM_SUPERCEDE
  809. }
  810. //Change game name
  811. public fw_GameDesc()
  812. {
  813. forward_return(FMV_STRING,g_modname)
  814. return FMRES_SUPERCEDE
  815. }
  816. /*================================================================================
  817. [Messages]
  818. =================================================================================*/
  819.  
  820. // Block some text messages
  821. public message_textmsg()
  822. {
  823. static textmsg[22]
  824. get_msg_arg_string(2, textmsg, sizeof textmsg - 1)
  825.  
  826. // Game restarting, reset scores and call round end to balance the teams
  827. if (equal(textmsg, "#Game_will_restart_in"))
  828. {
  829. logevent_round_end()
  830. }
  831. // Block round end related messages
  832. else if (equal(textmsg, "#Hostages_Not_Rescued") || equal(textmsg, "#Round_Draw") || equal(textmsg, "#Terrorists_Win") || equal(textmsg, "#CTs_Win"))
  833. {
  834. return PLUGIN_HANDLED
  835. }
  836.  
  837. //Block "Fire in the hole!" text
  838. if(get_msg_args() == 5)
  839. {
  840. if(get_msg_argtype(5) == ARG_STRING)
  841. {
  842. new value5[64]
  843. get_msg_arg_string(5 ,value5 ,63)
  844. if(equal(value5, "#Fire_in_the_hole"))
  845. {
  846. return PLUGIN_HANDLED
  847. }
  848. }
  849. }
  850. else if(get_msg_args() == 6)
  851. {
  852. if(get_msg_argtype(6) == ARG_STRING)
  853. {
  854. new value6[64]
  855. get_msg_arg_string(6 ,value6 ,63)
  856. if(equal(value6 ,"#Fire_in_the_hole"))
  857. {
  858. return PLUGIN_HANDLED
  859. }
  860. }
  861. }
  862.  
  863. return PLUGIN_CONTINUE
  864. }
  865.  
  866. //Block some audio messages
  867. public message_audio()
  868. {
  869. //Create variable
  870. static sample[20]
  871.  
  872. //Get message arguments
  873. get_msg_arg_string(2, sample, sizeof sample - 1)
  874.  
  875. //Check argument, if it's equal - block it
  876. if(equal(sample[1], "!MRAD_FIREINHOLE"))
  877. return PLUGIN_HANDLED
  878.  
  879. if(equal(sample[7], "terwin") || equal(sample[7], "ctwin") || equal(sample[7], "rounddraw"))
  880. return PLUGIN_HANDLED
  881.  
  882. return PLUGIN_CONTINUE
  883. }
  884.  
  885. //Block hostage from appearing on the radar
  886. public message_hostagepos()
  887. {
  888. return PLUGIN_HANDLED
  889. }
  890. // Block hostage HUD display
  891. public message_scenario()
  892. {
  893. if (get_msg_args() > 1)
  894. {
  895. static sprite[8]
  896. get_msg_arg_string(2, sprite, sizeof sprite - 1)
  897.  
  898. if (equal(sprite, "hostage"))
  899. return PLUGIN_HANDLED
  900. }
  901.  
  902. return PLUGIN_CONTINUE
  903. }
  904. /*================================================================================
  905. [TASKS]
  906. =================================================================================*/
  907. public task_ammo(id)
  908. {
  909. id -= TASK_AMMO
  910.  
  911. sw_set_user_bpammo(id,1)
  912. }
  913. public task_respawn(id)
  914. {
  915. id -= TASK_RESPAWN
  916.  
  917. ExecuteHamB(Ham_CS_RoundRespawn,id)
  918. }
  919. public task_UnChill(id)
  920. {
  921. id -= TASK_UNCHILL
  922.  
  923. new Float:origin[3]
  924.  
  925. pev(id,pev_origin,origin)
  926.  
  927. sw_UnChill(id,origin)
  928. }
  929. public task_set_model(id)
  930. {
  931. id -= TASK_MODEL
  932.  
  933. sw_set_user_model(id, g_player_model[id])
  934. }
  935. public task_UnGod(id)
  936. {
  937. id -= TASK_GOD
  938.  
  939. g_god[id] = false
  940.  
  941. fm_set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderNormal,25)
  942. }
  943. public task_bots(id)
  944. {
  945. // Make sure it's a CZ bot and it's still connected
  946. if (g_bots || !get_pcvar_num(pcvar_bots) || !is_user_connected(id) || !is_user_bot(id))
  947. return;
  948.  
  949. RegisterHamFromEntity(Ham_Spawn, id, "fw_PlayerSpawn", 1)
  950. RegisterHamFromEntity(Ham_Killed, id, "fw_PlayerKilled")
  951. RegisterHamFromEntity(Ham_TakeDamage, id, "fw_TakeDamage")
  952.  
  953. // Ham forwards for CZ bots succesfully registered
  954. g_bots = true
  955.  
  956. // If the bot has already spawned, call the forward manually for him
  957. if (is_user_alive(id)) fw_PlayerSpawn(id)
  958. }
  959. /*================================================================================
  960. [Stocks]
  961. =================================================================================*/
  962.  
  963. //Set player money
  964. stock sw_set_user_money(id,money,flash=1)
  965. {
  966. set_pdata_int(id,OFFSET_CSMONEY,money,OFFSET_LINUX)
  967.  
  968. message_begin(MSG_ONE,g_money,{0,0,0},id)
  969. write_long(money)
  970. write_byte(flash)
  971. message_end()
  972. }
  973. // Get User Team
  974. stock sw_get_user_team(id)
  975. {
  976. return get_pdata_int(id, OFFSET_CSTEAMS, OFFSET_LINUX)
  977. }
  978. //With this stock we can set player model
  979. stock sw_set_user_model(player, const modelname[])
  980. {
  981. engfunc(EngFunc_SetClientKeyValue, player, engfunc(EngFunc_GetInfoKeyBuffer, player), "model", modelname)
  982.  
  983. g_has_custom_model[player] = true
  984. }
  985. //With this stock we can get player model
  986. stock sw_get_user_model(player, model[], len)
  987. {
  988. engfunc(EngFunc_InfoKeyValue, engfunc(EngFunc_GetInfoKeyBuffer, player), "model", model, len)
  989. }
  990. //With this stock we can reset player model
  991. stock sw_reset_user_model(player)
  992. {
  993. g_has_custom_model[player] = false
  994.  
  995. dllfunc(DLLFunc_ClientUserInfoChanged, player, engfunc(EngFunc_GetInfoKeyBuffer, player))
  996. }
  997. //Set user snowballs
  998. stock sw_set_user_bpammo(id,amount)
  999. {
  1000. set_pdata_int(id, OFFSET_HE_AMMO, amount, OFFSET_LINUX)
  1001. }
  1002. //Make death msg
  1003. stock sw_kill(killer, victim, weapon[],headshot)
  1004. {
  1005. set_msg_block(g_death , BLOCK_SET)
  1006. user_kill(victim,1)
  1007. set_msg_block(g_death, BLOCK_NOT)
  1008.  
  1009. message_begin(MSG_ALL, g_death, {0,0,0}, 0)
  1010. write_byte(killer)
  1011. write_byte(victim)
  1012. write_byte(headshot)
  1013. write_string(weapon)
  1014. message_end()
  1015.  
  1016. if(get_user_team(killer)!= get_user_team(victim))
  1017. {
  1018. fm_set_user_frags(killer,get_user_frags(killer) + 1)
  1019.  
  1020. }else{
  1021. fm_set_user_frags(killer,get_user_frags(killer) - 1)
  1022. }
  1023. }
  1024. /*================================================================================
  1025. [Other stuff]
  1026. =================================================================================*/
  1027. sw_GetBlue()
  1028. {
  1029. static iCt, id
  1030. iCt = 0
  1031.  
  1032. for (id = 1; id <= g_maxplayers; id++)
  1033. {
  1034. if (is_user_connected(id))
  1035. {
  1036. if(is_user_alive(id) && g_blue[id])
  1037. iCt++
  1038. }
  1039. }
  1040.  
  1041. return iCt
  1042. }
  1043. sw_GetRed()
  1044. {
  1045. static iT, id
  1046. iT = 0
  1047.  
  1048. for (id = 1; id <= g_maxplayers; id++)
  1049. {
  1050. if (is_user_connected(id))
  1051. {
  1052. if(is_user_alive(id) && g_red[id])
  1053. iT++
  1054. }
  1055. }
  1056.  
  1057. return iT
  1058. }
  1059. sw_money(id)
  1060. {
  1061. message_begin(MSG_ONE,g_weapon,_,id)
  1062. write_byte(HIDE_MONEY)
  1063. message_end()
  1064. message_begin(MSG_ONE,g_crosshair,_,id)
  1065. write_byte(0)
  1066. message_end()
  1067. }
  1068. sw_sound(const sound[])
  1069. {
  1070. client_cmd(0, "spk ^"%s^"", sound)
  1071. }
  1072. sw_splash(ent,Float:origin[3])
  1073. {
  1074. set_pev(ent, pev_velocity, Float:{0.0, 0.0, 0.0})
  1075. set_pev(ent, pev_classname, "snow_splash")
  1076. set_pev(ent, pev_solid, SOLID_NOT)
  1077. set_pev(ent, pev_movetype, MOVETYPE_NONE)
  1078. engfunc(EngFunc_SetOrigin, ent, origin)
  1079. engfunc(EngFunc_SetModel, ent, model_splash)
  1080. set_pev(ent,pev_nextthink,get_gametime() + get_pcvar_float(pcvar_life))
  1081. fm_set_rendering(ent, kRenderFxNoDissipation, 255, 255, 255, kRenderGlow, 255)
  1082. }
  1083. sw_effect(Float:fOrigin[3])
  1084. {
  1085. new origin[3]
  1086. FVecIVec(fOrigin,origin)
  1087.  
  1088. message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
  1089. write_byte(TE_BLOODSPRITE)
  1090. write_coord(origin[0]+random_num(-20,20))
  1091. write_coord(origin[1]+random_num(-20,20))
  1092. write_coord(origin[2]+random_num(-20,20))
  1093. write_short(g_spray)
  1094. write_short(g_drop)
  1095. write_byte(255)
  1096. write_byte(15)
  1097. message_end()
  1098. }
  1099. sw_light(Float:originF[3])
  1100. {
  1101. new origin[3]
  1102. FVecIVec(originF,origin)
  1103.  
  1104. // light effect
  1105. message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
  1106. write_byte(TE_DLIGHT)
  1107. write_coord(origin[0]) // x
  1108. write_coord(origin[1]) // y
  1109. write_coord(origin[2]) // z
  1110. write_byte(floatround(240.0/5.0)) // radius
  1111. write_byte(0) // r
  1112. write_byte(206)// g
  1113. write_byte(209) // b
  1114. write_byte(8) // life
  1115. write_byte(60) // decay rate
  1116. message_end()
  1117. }
  1118. sw_ChillPlayer(id)
  1119. {
  1120. //Set glow
  1121. fm_set_user_rendering(id,kRenderFxGlowShell,0,206,209,kRenderNormal,25)
  1122.  
  1123. //Set chill state
  1124. g_IsChilled[id] = true
  1125.  
  1126. //Retrieve player old maxspeed
  1127. pev(id,pev_maxspeed,g_maxspeed[id])
  1128.  
  1129. //Calculate his new maxspeed
  1130. g_ChillySpeed[id] = g_maxspeed[id] * get_pcvar_float(pcvar_chill_speed) / 100.0
  1131.  
  1132. //Set his new maxspeed
  1133. set_pev(id,pev_maxspeed,g_ChillySpeed[id])
  1134.  
  1135. //Add blue fade on players screen
  1136. message_begin(MSG_ONE,gmsgScreenFade,_,id)
  1137. write_short(floatround(4096.0 * get_pcvar_float(pcvar_chill_duration))) // duration
  1138. write_short(floatround(3072.0 * get_pcvar_float(pcvar_chill_duration))) // hold time
  1139. write_short(FFADE_IN) // flags
  1140. write_byte(0) // red
  1141. write_byte(206) // green
  1142. write_byte(209) // blue
  1143. write_byte(100) // alpha
  1144. message_end()
  1145. }
  1146. sw_UnChill(id,Float:fOrigin[3])
  1147. {
  1148. //Make some variables
  1149. new origin[3]
  1150.  
  1151. //Change origin from float to integer
  1152. FVecIVec(fOrigin,origin)
  1153.  
  1154. //Delete glow
  1155. fm_set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderNormal,25)
  1156.  
  1157. //Restore his maxspeed
  1158. set_pev(id,pev_maxspeed,g_maxspeed[id])
  1159.  
  1160. //Set chill state
  1161. g_IsChilled[id] = false
  1162.  
  1163. // clear tint
  1164. message_begin(MSG_ONE,gmsgScreenFade,_,id)
  1165. write_short(0) // duration
  1166. write_short(0) // hold time
  1167. write_short(FFADE_IN) // flags
  1168. write_byte(0) // red
  1169. write_byte(0) // green
  1170. write_byte(0) // blue
  1171. write_byte(255)// alpha
  1172. message_end()
  1173.  
  1174. //Make glass effect
  1175. message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
  1176. write_byte(TE_BREAKMODEL)
  1177. write_coord(origin[0]) // x
  1178. write_coord(origin[1]) // y
  1179. write_coord(origin[2] + 24) // z
  1180. write_coord(16) // size x
  1181. write_coord(16) // size y
  1182. write_coord(16) // size z
  1183. write_coord(random_num(-50,50)) // velocity x
  1184. write_coord(random_num(-50,50)) // velocity y
  1185. write_coord(25) // velocity z
  1186. write_byte(10) // random velocity
  1187. write_short(g_glass) // model
  1188. write_byte(10) // count
  1189. write_byte(25) // life
  1190. write_byte(BREAK_GLASS) // flags
  1191. message_end()
  1192.  
  1193. //Emit sound
  1194. engfunc(EngFunc_EmitSound,id,CHAN_AUTO,sound_unchill[random_num(0, sizeof sound_unchill - 1)],1.0,ATTN_NORM,0,PITCH_NORM)
  1195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement