hlmod.hu

Magyar Half-Life Mód közösség!
Pontos idő: 2024.05.02. 16:23



Jelenlévő felhasználók

Jelenleg 539 felhasználó van jelen :: 1 regisztrált, 0 rejtett és 538 vendég

A legtöbb felhasználó (1565 fő) 2020.11.21. 11:26-kor tartózkodott itt.

Regisztrált felhasználók: Majestic-12 [Bot] az elmúlt 5 percben aktív felhasználók alapján

Utoljára aktív
Ahhoz hogy lásd ki volt utoljára aktív, be kell jelentkezned.



Az oldal teljeskörű
használatához regisztrálj.

Regisztráció

Kereső


Új téma nyitása  Hozzászólás a témához  [ 2 hozzászólás ] 
Szerző Üzenet
 Hozzászólás témája: zp 5.0 flashlight
HozzászólásElküldve: 2013.01.24. 15:32 
Offline
Őstag
Avatar

Csatlakozott: 2011.11.15. 16:29
Hozzászólások: 1142
Megköszönt másnak: 8 alkalommal
Megköszönték neki: 24 alkalommal
SMA Forráskód: [ Mindet kijelol ]
  1. /*================================================================================
  2.  
  3.   -----------------------
  4.   -*- [ZP] Flashlight -*-
  5.   -----------------------
  6.  
  7.   This plugin is part of Zombie Plague Mod and is distributed under the
  8.   terms of the GNU General Public License. Check ZP_ReadMe.txt for details.
  9.  
  10. ================================================================================*/
  11.  
  12. #include <amxmodx>
  13. #include <fakemeta>
  14. #include <hamsandwich>
  15. #include <xs>
  16. #include <cs_ham_bots_api>
  17. #include <zp50_core>
  18.  
  19. #define TASK_FLASHLIGHT 100
  20. #define TASK_CHARGE 200
  21. #define ID_FLASHLIGHT (taskid - TASK_FLASHLIGHT)
  22. #define ID_CHARGE (taskid - TASK_CHARGE)
  23.  
  24. // CS Player PData Offsets (win32)
  25. const PDATA_SAFE = 2
  26. const OFFSET_FLASHLIGHT_BATTERIES = 244
  27.  
  28. const IMPULSE_FLASHLIGHT = 100
  29.  
  30. new const g_sound_flashlight[] = "items/flashlight1.wav"
  31.  
  32. #define MAXPLAYERS 32
  33.  
  34. #define flag_get(%1,%2) (%1 & (1 << (%2 & 31)))
  35. #define flag_get_boolean(%1,%2) (flag_get(%1,%2) ? true : false)
  36. #define flag_set(%1,%2) %1 |= (1 << (%2 & 31))
  37. #define flag_unset(%1,%2) %1 &= ~(1 << (%2 & 31))
  38.  
  39. new g_MsgFlashlight, g_MsgFlashBat
  40.  
  41. new g_FlashlightActive
  42. new g_FlashlightCharge[MAXPLAYERS+1]
  43. new Float:g_FlashlightLastTime[MAXPLAYERS+1]
  44.  
  45. new cvar_flashlight_starting_charge
  46. new cvar_flashlight_custom, cvar_flashlight_radius
  47. new cvar_flashlight_distance, cvar_flashlight_show_all
  48. new cvar_flashlight_drain_rate, cvar_flashlight_charge_rate
  49. //new cvar_flashlight_color_R, cvar_flashlight_color_G, cvar_flashlight_color_B
  50. new Color[33][3]
  51.  
  52. public plugin_init()
  53. {
  54. register_plugin("[ZP] Flashlight", ZP_VERSION_STRING, "ZP Dev Team")
  55.  
  56. register_forward(FM_CmdStart, "fw_CmdStart")
  57. RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
  58. RegisterHamBots(Ham_Killed, "fw_PlayerKilled")
  59.  
  60. g_MsgFlashlight = get_user_msgid("Flashlight")
  61. g_MsgFlashBat = get_user_msgid("FlashBat")
  62. register_message(g_MsgFlashBat, "message_flashbat")
  63.  
  64. cvar_flashlight_starting_charge = register_cvar("zp_flashlight_starting_charge", "100")
  65. cvar_flashlight_custom = register_cvar("zp_flashlight_custom", "0")
  66. cvar_flashlight_radius = register_cvar("zp_flashlight_radius", "10")
  67. cvar_flashlight_distance = register_cvar("zp_flashlight_distance", "1000")
  68. cvar_flashlight_show_all = register_cvar("zp_flashlight_show_all", "1")
  69. cvar_flashlight_drain_rate = register_cvar("zp_flashlight_drain_rate", "1")
  70. cvar_flashlight_charge_rate = register_cvar("zp_flashlight_charge_rate", "5")
  71. /* cvar_flashlight_color_R = register_cvar("zp_flashlight_color_R", "100")
  72.   cvar_flashlight_color_G = register_cvar("zp_flashlight_color_G", "100")
  73.   cvar_flashlight_color_B = register_cvar("zp_flashlight_color_B", "100")*/
  74. }
  75.  
  76.  
  77. public plugin_natives()
  78. {
  79. register_library("zp50_flashlight")
  80. register_native("zp_flashlight_get_charge", "native_flashlight_get_charge")
  81. register_native("zp_flashlight_set_charge", "native_flashlight_set_charge")
  82. }
  83.  
  84. public native_flashlight_get_charge(plugin_id, num_params)
  85. {
  86. new id = get_param(1)
  87.  
  88. if (!is_user_connected(id))
  89. {
  90. log_error(AMX_ERR_NATIVE, "[ZP] Invalid Player (%d)", id)
  91. return -1;
  92. }
  93.  
  94. // Custom flashlight not enabled
  95. if (!get_pcvar_num(cvar_flashlight_custom))
  96. return -1;
  97.  
  98. return g_FlashlightCharge[id];
  99. }
  100.  
  101. public native_flashlight_set_charge(plugin_id, num_params)
  102. {
  103. new id = get_param(1)
  104. new charge = get_param(2)
  105.  
  106. if (!is_user_connected(id))
  107. {
  108. log_error(AMX_ERR_NATIVE, "[ZP] Invalid Player (%d)", id)
  109. return false;
  110. }
  111.  
  112. // Custom flashlight not enabled
  113. if (!get_pcvar_num(cvar_flashlight_custom))
  114. return false;
  115.  
  116. g_FlashlightCharge[id] = clamp(charge, 0, 100)
  117.  
  118. // Set the flashlight charge task to update batteries
  119. remove_task(id+TASK_CHARGE)
  120. set_task(1.0, "flashlight_charge_task", id+TASK_CHARGE, _, _, "b")
  121.  
  122. return true;
  123. }
  124.  
  125. public plugin_precache()
  126. {
  127. precache_sound(g_sound_flashlight)
  128. }
  129.  
  130. public plugin_cfg()
  131. {
  132. // Enables flashlight
  133. server_cmd("mp_flashlight 1")
  134. }
  135.  
  136. // Forward CmdStart
  137. public fw_CmdStart(id, handle)
  138. {
  139. // Not alive
  140. if (!is_user_alive(id))
  141. return;
  142.  
  143. // Check if it's a flashlight impulse
  144. if (get_uc(handle, UC_Impulse) != IMPULSE_FLASHLIGHT)
  145. return;
  146.  
  147. // Flashlight is being turned off
  148. if (pev(id, pev_effects) & EF_DIMLIGHT)
  149. return;
  150.  
  151. if (zp_core_is_zombie(id))
  152. {
  153. // Block it!
  154. set_uc(handle, UC_Impulse, 0)
  155. }
  156. else if (get_pcvar_num(cvar_flashlight_custom))
  157. {
  158. // Block it!
  159. set_uc(handle, UC_Impulse, 0)
  160.  
  161. // Should human's custom flashlight be turned on?
  162. if (g_FlashlightCharge[id] > 2 && get_gametime() - g_FlashlightLastTime[id] > 1.2)
  163. {
  164. // Prevent calling flashlight too quickly (bugfix)
  165. g_FlashlightLastTime[id] = get_gametime()
  166.  
  167. // Toggle custom flashlight
  168. if (flag_get(g_FlashlightActive, id))
  169. {
  170. // Remove flashlight task
  171. remove_task(id+TASK_FLASHLIGHT)
  172.  
  173. flag_unset(g_FlashlightActive, id)
  174. }
  175. else
  176. {
  177. Color[id][0] = random(255)
  178. Color[id][1] = random(255)
  179. Color[id][2] = random(255)
  180. // Set the custom flashlight task
  181. set_task(0.1, "custom_flashlight_task", id+TASK_FLASHLIGHT, _, _, "b")
  182.  
  183. flag_set(g_FlashlightActive, id)
  184. }
  185.  
  186. // Set the flashlight charge task
  187. remove_task(id+TASK_CHARGE)
  188. set_task(1.0, "flashlight_charge_task", id+TASK_CHARGE, _, _, "b")
  189.  
  190. // Play flashlight toggle sound
  191. emit_sound(id, CHAN_ITEM, g_sound_flashlight, 1.0, ATTN_NORM, 0, PITCH_NORM)
  192.  
  193. // Update flashlight status on HUD
  194. message_begin(MSG_ONE, g_MsgFlashlight, _, id)
  195. write_byte(flag_get_boolean(g_FlashlightActive, id)) // toggle
  196. write_byte(g_FlashlightCharge[id]) // batteries
  197. message_end()
  198. }
  199. }
  200. }
  201.  
  202. // Ham Player Killed Forward
  203. public fw_PlayerKilled(victim, attacker, shouldgib)
  204. {
  205. // Reset flashlight flags
  206. flag_unset(g_FlashlightActive, victim)
  207. remove_task(victim+TASK_FLASHLIGHT)
  208. remove_task(victim+TASK_CHARGE)
  209. }
  210.  
  211. public client_disconnect(id)
  212. {
  213. // Reset flashlight flags
  214. flag_unset(g_FlashlightActive, id)
  215. remove_task(id+TASK_FLASHLIGHT)
  216. remove_task(id+TASK_CHARGE)
  217. }
  218.  
  219. // Flashlight batteries messages
  220. public message_flashbat(msg_id, msg_dest, msg_entity)
  221. {
  222. // Block if custom flashlight is enabled instead
  223. if (get_pcvar_num(cvar_flashlight_custom))
  224. return PLUGIN_HANDLED;
  225.  
  226. // Block if zombie
  227. if (is_user_connected(msg_entity) && zp_core_is_zombie(msg_entity))
  228. return PLUGIN_HANDLED;
  229.  
  230. return PLUGIN_CONTINUE;
  231. }
  232.  
  233. public zp_fw_core_infect_post(id, attacker)
  234. {
  235. // Turn off zombies flashlight
  236. turn_off_flashlight(id)
  237. }
  238.  
  239. public zp_fw_core_cure_post(id, attacker)
  240. {
  241. // Turn off humans flashlight (prevents double flashlight bug/exploit after respawn)
  242. turn_off_flashlight(id)
  243. }
  244.  
  245. // Turn Off Flashlight and Restore Batteries
  246. turn_off_flashlight(id)
  247. {
  248. // Restore batteries to starting charge
  249. if (get_pcvar_num(cvar_flashlight_custom))
  250. g_FlashlightCharge[id] = get_pcvar_num(cvar_flashlight_starting_charge)
  251. else
  252. fm_cs_set_flash_batteries(id, get_pcvar_num(cvar_flashlight_starting_charge))
  253.  
  254. // Check if flashlight is on
  255. if (pev(id, pev_effects) & EF_DIMLIGHT)
  256. {
  257. // Turn it off
  258. set_pev(id, pev_impulse, IMPULSE_FLASHLIGHT)
  259. }
  260. else
  261. {
  262. // Clear any stored flashlight impulse (bugfix)
  263. set_pev(id, pev_impulse, 0)
  264.  
  265. // Update flashlight HUD
  266. message_begin(MSG_ONE, g_MsgFlashlight, _, id)
  267. write_byte(0) // toggle
  268. write_byte(get_pcvar_num(cvar_flashlight_starting_charge)) // batteries
  269. message_end()
  270. }
  271.  
  272. if (get_pcvar_num(cvar_flashlight_custom))
  273. {
  274. // Turn it off
  275. flag_unset(g_FlashlightActive, id)
  276.  
  277. // Remove previous tasks
  278. remove_task(id+TASK_CHARGE)
  279. remove_task(id+TASK_FLASHLIGHT)
  280. }
  281. }
  282.  
  283. // Custom Flashlight Task
  284. public custom_flashlight_task(taskid)
  285. {
  286. // Get player and aiming origins
  287. static Float:origin[3], Float:destorigin[3]
  288. pev(ID_FLASHLIGHT, pev_origin, origin)
  289. fm_get_aim_origin(ID_FLASHLIGHT, destorigin)
  290.  
  291. // Max distance check
  292. if (get_distance_f(origin, destorigin) > get_pcvar_float(cvar_flashlight_distance))
  293. return;
  294.  
  295. // Send to all players?
  296. if (get_pcvar_num(cvar_flashlight_show_all))
  297. engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, destorigin, 0)
  298. else
  299. message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, ID_FLASHLIGHT)
  300.  
  301. // Flashlight
  302. write_byte(TE_DLIGHT) // TE id
  303. engfunc(EngFunc_WriteCoord, destorigin[0]) // x
  304. engfunc(EngFunc_WriteCoord, destorigin[1]) // y
  305. engfunc(EngFunc_WriteCoord, destorigin[2]) // z
  306. write_byte(get_pcvar_num(cvar_flashlight_radius)) // radius
  307. /*write_byte(get_pcvar_num(cvar_flashlight_color_R)) // r
  308.   write_byte(get_pcvar_num(cvar_flashlight_color_G)) // g
  309.   write_byte(get_pcvar_num(cvar_flashlight_color_B)) // b */
  310. write_byte(Color[ID_FLASHLIGHT][0]) // r
  311. write_byte(Color[ID_FLASHLIGHT][1]) // g
  312. write_byte(Color[ID_FLASHLIGHT][2]) // b
  313. write_byte(3) // life
  314. write_byte(0) // decay rate
  315. message_end()
  316. }
  317.  
  318. // Flashlight Charge Task
  319. public flashlight_charge_task(taskid)
  320. {
  321. // Drain or charge?
  322. if (flag_get(g_FlashlightActive, ID_CHARGE))
  323. g_FlashlightCharge[ID_CHARGE] = max(g_FlashlightCharge[ID_CHARGE] - get_pcvar_num(cvar_flashlight_drain_rate), 0)
  324. else
  325. g_FlashlightCharge[ID_CHARGE] = min(g_FlashlightCharge[ID_CHARGE] + get_pcvar_num(cvar_flashlight_charge_rate), 100)
  326.  
  327. // Batteries fully charged
  328. if (g_FlashlightCharge[ID_CHARGE] == 100)
  329. {
  330. // Update flashlight batteries on HUD
  331. message_begin(MSG_ONE, g_MsgFlashBat, _, ID_CHARGE)
  332. write_byte(100) // batteries
  333. message_end()
  334.  
  335. // Task not needed anymore
  336. remove_task(taskid)
  337. return;
  338. }
  339.  
  340. // Batteries depleted
  341. if (g_FlashlightCharge[ID_CHARGE] == 0)
  342. {
  343. // Turn it off
  344. flag_unset(g_FlashlightActive, ID_CHARGE)
  345.  
  346. // Remove flashlight task for this player
  347. remove_task(ID_CHARGE+TASK_FLASHLIGHT)
  348.  
  349. // Play flashlight toggle sound
  350. emit_sound(ID_CHARGE, CHAN_ITEM, g_sound_flashlight, 1.0, ATTN_NORM, 0, PITCH_NORM)
  351.  
  352. // Update flashlight status on HUD
  353. message_begin(MSG_ONE, g_MsgFlashlight, _, ID_CHARGE)
  354. write_byte(0) // toggle
  355. write_byte(0) // batteries
  356. message_end()
  357.  
  358. return;
  359. }
  360.  
  361. // Update flashlight batteries on HUD
  362. message_begin(MSG_ONE_UNRELIABLE, g_MsgFlashBat, _, ID_CHARGE)
  363. write_byte(g_FlashlightCharge[ID_CHARGE]) // batteries
  364. message_end()
  365. }
  366.  
  367. // Set Flashlight Batteries
  368. stock fm_cs_set_flash_batteries(id, value)
  369. {
  370. // Prevent server crash if entity's private data not initalized
  371. if (pev_valid(id) != PDATA_SAFE)
  372. return;
  373.  
  374. set_pdata_int(id, OFFSET_FLASHLIGHT_BATTERIES, value)
  375. }
  376.  
  377. // Get entity's aim origins (from fakemeta_util)
  378. stock fm_get_aim_origin(id, Float:origin[3])
  379. {
  380. static Float:origin1F[3], Float:origin2F[3]
  381. pev(id, pev_origin, origin1F)
  382. pev(id, pev_view_ofs, origin2F)
  383. xs_vec_add(origin1F, origin2F, origin1F)
  384.  
  385. pev(id, pev_v_angle, origin2F);
  386. engfunc(EngFunc_MakeVectors, origin2F)
  387. global_get(glb_v_forward, origin2F)
  388. xs_vec_mul_scalar(origin2F, 9999.0, origin2F)
  389. xs_vec_add(origin1F, origin2F, origin2F)
  390.  
  391. engfunc(EngFunc_TraceLine, origin1F, origin2F, 0, id, 0)
  392. get_tr2(0, TR_vecEndPos, origin)
  393. }


valaki megbírná nekem csinálni , hogy gyors legyen a ki / be kapcsolás ... mert ha felkapcsolom akkor lassan csinálja és kikapcsoláskor is várni kell sokat...:S

_________________
[url=http://www.gametracker.com/server_info/188.227.227.114:27286/][img]http://cache.www.gametracker.com/server_info/188.227.227.114:27286/b_350_20_323957_202743_F19A15_111111.png[/img][/url]


Hozzászólás jelentése
Vissza a tetejére
   
 Hozzászólás témája: Re: zp 5.0 flashlight
HozzászólásElküldve: 2013.02.01. 14:30 
Offline
Signore Senior
Avatar

Csatlakozott: 2011.09.09. 17:39
Hozzászólások: 4020
Megköszönt másnak: 12 alkalommal
Megköszönték neki: 139 alkalommal
ctrl+f --> set_task --> 1.0 helyett 0.1

(Megjegyzés: Nem csak egy helyen kell átírni)


Hozzászólás jelentése
Vissza a tetejére
   
Hozzászólások megjelenítése:  Rendezés  
Új téma nyitása  Hozzászólás a témához  [ 2 hozzászólás ] 


Ki van itt

Jelenlévő fórumozók: nincs regisztrált felhasználó valamint 23 vendég


Nyithatsz új témákat ebben a fórumban.
Válaszolhatsz egy témára ebben a fórumban.
Nem szerkesztheted a hozzászólásaidat ebben a fórumban.
Nem törölheted a hozzászólásaidat ebben a fórumban.
Nem küldhetsz csatolmányokat ebben a fórumban.

Keresés:
Ugrás:  
Powered by phpBB® Forum Software © phpBB Limited
Magyar fordítás © Magyar phpBB Közösség
Portal: Kiss Portal Extension © Michael O'Toole