HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <fakemeta_util>
  4. #include <hamsandwich>
  5.  
  6. #define PLUGIN "CSO Emotion"
  7. #define VERSION "2.3"
  8. #define AUTHOR "Dias"
  9.  
  10. #define MAX_EMOTION 6
  11. #define BUTTON_HOLDTIME 0.5
  12. #define USE_TYPE 1 // 1 = J Button (Cheer); 2 = Hold R Button
  13.  
  14. #define TASK_EMOTION 1962
  15. #define TASK_HOLDTIME 1963
  16.  
  17. new const p_model[] = "models/cso_emotion/cso_emotion2.mdl"
  18. new const v_model[] = "models/cso_emotion/v_cso_emotion_v23.mdl"
  19. new const Resource_Sound[MAX_EMOTION][] =
  20. {
  21. "cso_emotion/man_angry.wav",
  22. "cso_emotion/man_dance.wav",
  23. "cso_emotion/man_hi.wav",
  24. "cso_emotion/man_joy.wav",
  25. "cso_emotion/man_procoke.wav",
  26. "cso_emotion/man_special.wav"
  27. }
  28.  
  29. new Emotion_Name[MAX_EMOTION][] =
  30. {
  31. "Hi",
  32. "Provokalo",
  33. "Jo Kedv",
  34. "Duhos",
  35. "Tanc",
  36. "Specialis 1 (Enzo)"
  37. }
  38.  
  39. new Float:Emotion_Time[MAX_EMOTION] =
  40. {
  41. 3.0,
  42. 7.0,
  43. 4.5,
  44. 3.8,
  45. 6.7,
  46. 6.0
  47. }
  48.  
  49. enum
  50. {
  51. EMO_HI = 0,
  52. EMO_PROVOKE,
  53. EMO_JOY,
  54. EMO_ANGRY,
  55. EMO_DANCE,
  56. EMO_SPECIAL1
  57. }
  58.  
  59. new g_InDoingEmo[33], g_AnimEnt[33], g_AvtEnt[33], g_OldWeapon[33], g_OldKnifeModel[33][128]
  60. new g_MaxPlayers, g_HoldingButton[33], g_UseType
  61.  
  62. public plugin_init()
  63. {
  64. register_plugin(PLUGIN, VERSION, AUTHOR)
  65.  
  66. register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
  67. register_event("DeathMsg", "Event_DeathMsg", "a")
  68.  
  69. register_forward(FM_CmdStart, "fw_CmdStart")
  70. register_forward(FM_AddToFullPack, "fw_AddToFullPack_Post", 1)
  71. register_forward(FM_Think, "fw_Think")
  72.  
  73. RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
  74.  
  75. g_UseType = USE_TYPE
  76. if(g_UseType == 1) register_clcmd("cheer", "Open_EmoMenu")
  77.  
  78. g_MaxPlayers = get_maxplayers()
  79. }
  80.  
  81. public plugin_precache()
  82. {
  83. engfunc(EngFunc_PrecacheModel, p_model)
  84. engfunc(EngFunc_PrecacheModel, v_model)
  85.  
  86. for(new i = 0; i < sizeof(Resource_Sound); i++)
  87. engfunc(EngFunc_PrecacheSound, Resource_Sound[i])
  88. }
  89.  
  90. public Event_NewRound()
  91. {
  92. for(new i = 0; i < g_MaxPlayers; i++)
  93. {
  94. if(!is_user_connected(i))
  95. continue
  96.  
  97. Reset_Var(i)
  98. }
  99. }
  100.  
  101. public Event_DeathMsg()
  102. {
  103. static Victim; Victim = read_data(2)
  104. Do_Reset_Emotion(Victim)
  105. }
  106.  
  107. public fw_PlayerSpawn_Post(id)
  108. {
  109. if(g_UseType == 1)
  110. client_printc(id, "!g[CSO Emotion]!n Nyomd meg a !g[J]!n -t hogy hasznald az !tErzelmet!n")
  111. else if(g_UseType == 2)
  112. client_printc(id, "!g[CSO Emotion]!n Tarsd nyomva az !g[R]!n -t hogy hasznald a !tErzelmet!n")
  113. }
  114.  
  115. public Reset_Var(id)
  116. {
  117. if(!is_user_connected(id))
  118. return
  119.  
  120. if(g_InDoingEmo[id])
  121. {
  122. if(get_user_weapon(id) == CSW_KNIFE)
  123. set_pev(id, pev_viewmodel2, g_OldKnifeModel[id])
  124. }
  125.  
  126. if(task_exists(id+TASK_EMOTION)) remove_task(id+TASK_EMOTION)
  127.  
  128. Set_Entity_Invisible(id, 0)
  129.  
  130. if(pev_valid(g_AnimEnt[id])) engfunc(EngFunc_RemoveEntity, g_AnimEnt[id])
  131. if(pev_valid(g_AvtEnt[id])) engfunc(EngFunc_RemoveEntity, g_AvtEnt[id])
  132.  
  133. g_InDoingEmo[id] = 0
  134. g_AnimEnt[id] = g_AvtEnt[id] = 0
  135. g_HoldingButton[id] = 0
  136. }
  137.  
  138. public Open_EmoMenu2(id)
  139. {
  140. id -= TASK_HOLDTIME
  141. Open_EmoMenu(id)
  142. }
  143.  
  144. public Open_EmoMenu(id)
  145. {
  146. if(!is_user_alive(id))
  147. return
  148. if(g_InDoingEmo[id])
  149. return
  150.  
  151. static menu, NumberId[6]
  152. menu = menu_create("CSO Emotion", "MenuHandle_Emo")
  153.  
  154. for(new i = 0; i < MAX_EMOTION; i++)
  155. {
  156. num_to_str(i, NumberId, sizeof(NumberId))
  157. menu_additem(menu, Emotion_Name[i], NumberId)
  158. }
  159.  
  160. menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
  161. menu_display(id, menu, 0)
  162. }
  163.  
  164. public MenuHandle_Emo(id, menu, item)
  165. {
  166. if(item == MENU_EXIT)
  167. {
  168. menu_destroy(menu)
  169. return
  170. }
  171. if(!is_user_alive(id))
  172. return
  173. if(g_InDoingEmo[id])
  174. return
  175.  
  176. static Data[6], Name[64], Access, Callback
  177. menu_item_getinfo(menu, item, Access, Data, charsmax(Data), Name, charsmax(Name), Callback)
  178.  
  179. static EmoId; EmoId = str_to_num(Data)
  180.  
  181. if(EmoId >= MAX_EMOTION)
  182. return
  183.  
  184. Set_Emotion_Start(id, EmoId)
  185. }
  186.  
  187. public Set_Emotion_Start(id, EmoId)
  188. {
  189. g_InDoingEmo[id] = 1
  190. Set_Entity_Invisible(id, 1)
  191.  
  192. Create_AvtEnt(id)
  193. Create_AnimEnt(id)
  194.  
  195. if(!Check_Avalible(id)) return
  196.  
  197. Do_Set_Emotion(id, EmoId)
  198. }
  199.  
  200. public Create_AvtEnt(id)
  201. {
  202. if(pev_valid(g_AvtEnt[id]))
  203. return
  204.  
  205. g_AvtEnt[id] = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  206.  
  207. if(!pev_valid(g_AvtEnt[id]))
  208. return
  209.  
  210. static ent; ent = g_AvtEnt[id]
  211. set_pev(ent, pev_classname, "avatar")
  212. set_pev(ent, pev_owner, id)
  213. set_pev(ent, pev_movetype, MOVETYPE_FOLLOW)
  214. set_pev(ent, pev_solid, SOLID_NOT)
  215.  
  216. // Set Model
  217. static PlayerModel[64]
  218. fm_cs_get_user_model(id, PlayerModel, sizeof(PlayerModel))
  219.  
  220. format(PlayerModel, sizeof(PlayerModel), "models/player/%s/%s.mdl", PlayerModel, PlayerModel)
  221. engfunc(EngFunc_SetModel, g_AvtEnt[id], PlayerModel)
  222.  
  223. // Set Avatar
  224. set_pev(ent, pev_body, pev(id, pev_body))
  225. set_pev(ent, pev_skin, pev(id, pev_skin))
  226.  
  227. set_pev(ent, pev_renderamt, pev(id, pev_renderamt))
  228. static Float:Color[3]; pev(id, pev_rendercolor, Color)
  229. set_pev(ent, pev_rendercolor, Color)
  230. set_pev(ent, pev_renderfx, pev(id, pev_renderfx))
  231. set_pev(ent, pev_rendermode, pev(id, pev_rendermode))
  232.  
  233. Set_Entity_Invisible(ent, 0)
  234. }
  235.  
  236. public Create_AnimEnt(id)
  237. {
  238. if(pev_valid(g_AnimEnt[id]))
  239. return
  240.  
  241. g_AnimEnt[id] = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  242.  
  243. if(!pev_valid(g_AnimEnt[id]))
  244. return
  245.  
  246. static ent; ent = g_AnimEnt[id]
  247. set_pev(ent, pev_classname, "AnimEnt")
  248. set_pev(ent, pev_owner, id)
  249. set_pev(ent, pev_movetype, MOVETYPE_TOSS)
  250.  
  251. engfunc(EngFunc_SetModel, ent, p_model)
  252. engfunc(EngFunc_SetSize, ent, {-16.0, -16.0, 0.0}, {16.0, 16.0, 72.0})
  253. set_pev(ent, pev_solid, SOLID_BBOX)
  254.  
  255. engfunc(EngFunc_DropToFloor, ent)
  256. Set_Entity_Invisible(ent, 0)
  257.  
  258. set_pev(ent, pev_nextthink, get_gametime() + 0.1)
  259. }
  260.  
  261. public Check_Avalible(id)
  262. {
  263. if(!pev_valid(g_AnimEnt[id]) || !pev_valid(g_AvtEnt[id]))
  264. {
  265. Do_Reset_Emotion(id)
  266. return 0
  267. }
  268.  
  269. return 1
  270. }
  271.  
  272. public Do_Set_Emotion(id, EmoId)
  273. {
  274. // Set Player Emotion
  275. static Float:Origin[3], Float:Angles[3], Float:Velocity[3]
  276.  
  277. pev(id, pev_origin, Origin); pev(id, pev_angles, Angles); pev(id, pev_velocity, Velocity)
  278.  
  279. Origin[2] -= 36.0
  280. set_pev(g_AnimEnt[id], pev_origin, Origin)
  281.  
  282. Angles[0] = 0.0; Angles[2] = 0.0
  283. set_pev(g_AnimEnt[id], pev_angles, Angles)
  284. set_pev(g_AnimEnt[id], pev_velocity, Velocity)
  285.  
  286. set_pev(g_AvtEnt[id], pev_aiment, g_AnimEnt[id])
  287. Set_Entity_Anim(g_AnimEnt[id], EmoId, 1)
  288.  
  289. // Set Hand Emotion
  290. g_OldWeapon[id] = get_user_weapon(id)
  291. fm_give_item(id, "weapon_knife")
  292. engclient_cmd(id, "weapon_knife")
  293.  
  294. pev(id, pev_viewmodel2, g_OldKnifeModel[id], 127)
  295. set_pev(id, pev_viewmodel2, v_model)
  296. Set_Weapon_Anim(id, EmoId)
  297.  
  298. static KnifeEnt; KnifeEnt = fm_get_user_weapon_entity(id, CSW_KNIFE)
  299. if(pev_valid(KnifeEnt)) set_pdata_float(KnifeEnt, 48, Emotion_Time[EmoId], 4)
  300.  
  301. if(task_exists(id+TASK_EMOTION)) remove_task(id+TASK_EMOTION)
  302. set_task(Emotion_Time[EmoId], "Reset_Emotion", id+TASK_EMOTION)
  303. }
  304.  
  305. public Reset_Emotion(id)
  306. {
  307. id -= TASK_EMOTION
  308.  
  309. if(!is_user_connected(id))
  310. return
  311. if(!g_InDoingEmo[id])
  312. return
  313.  
  314. Do_Reset_Emotion(id)
  315. }
  316.  
  317. public Do_Reset_Emotion(id)
  318. {
  319. if(!is_user_connected(id))
  320. return
  321. if(!g_InDoingEmo[id])
  322. return
  323.  
  324. if(task_exists(id+TASK_EMOTION)) remove_task(id+TASK_EMOTION)
  325. Set_Entity_Invisible(id, 0)
  326.  
  327. if(pev_valid(g_AnimEnt[id])) engfunc(EngFunc_RemoveEntity, g_AnimEnt[id])
  328. if(pev_valid(g_AvtEnt[id])) engfunc(EngFunc_RemoveEntity, g_AvtEnt[id])
  329.  
  330. g_AnimEnt[id] = g_AvtEnt[id] = 0
  331.  
  332. if(is_user_alive(id))
  333. {
  334. if(get_user_weapon(id) == CSW_KNIFE)
  335. set_pev(id, pev_viewmodel2, g_OldKnifeModel[id])
  336.  
  337. static MyOldWeapon; MyOldWeapon = g_OldWeapon[id]
  338. static Classname[64]; get_weaponname(MyOldWeapon, Classname, sizeof(Classname))
  339. engclient_cmd(id, Classname)
  340. }
  341.  
  342. g_InDoingEmo[id] = 0
  343. }
  344.  
  345. public fw_CmdStart(id, uc_handle, seed)
  346. {
  347. if(!is_user_alive(id))
  348. return
  349.  
  350.  
  351. if(!g_InDoingEmo[id] && g_UseType == 2)
  352. {
  353. static UseButton, UseOldButton
  354. UseButton = (get_uc(uc_handle, UC_Buttons) & IN_RELOAD)
  355. UseOldButton = (pev(id, pev_oldbuttons) & IN_RELOAD)
  356.  
  357. if(UseButton)
  358. {
  359. if(!UseOldButton && !g_InDoingEmo[id])
  360. {
  361. g_HoldingButton[id] = 1
  362. set_task(BUTTON_HOLDTIME, "Open_EmoMenu2", id+TASK_HOLDTIME)
  363. }
  364. } else {
  365. if(UseOldButton && g_HoldingButton[id])
  366. {
  367. if(task_exists(id+TASK_HOLDTIME))
  368. {
  369. remove_task(id+TASK_HOLDTIME)
  370. g_HoldingButton[id] = 0
  371. }
  372. }
  373. }
  374.  
  375. return
  376. }
  377.  
  378. static CurButton; CurButton = get_uc(uc_handle, UC_Buttons)
  379.  
  380. if((CurButton & IN_ATTACK) || (CurButton & IN_ATTACK2) || (CurButton & IN_DUCK) || (CurButton & IN_JUMP))
  381. {
  382. Do_Reset_Emotion(id)
  383. return
  384. }
  385.  
  386. static Float:Velocity[3], Float:Vector
  387. pev(id, pev_velocity, Velocity); Vector = vector_length(Velocity)
  388.  
  389. if(Vector != 0.0)
  390. {
  391. Do_Reset_Emotion(id)
  392. return
  393. }
  394.  
  395. /*
  396. if(get_user_weapon(id) != CSW_KNIFE)
  397. {
  398. Do_Reset_Emotion(id)
  399. return
  400. }*/
  401. }
  402.  
  403. public fw_AddToFullPack_Post(es_handle, e , ent, host, hostflags, player, pSet)
  404. {
  405. if(!is_user_alive(host) && !pev_valid(ent))
  406. return FMRES_IGNORED
  407. if(g_AnimEnt[host] != ent)
  408. return FMRES_IGNORED
  409.  
  410. set_es(es_handle, ES_Effects, get_es(es_handle, ES_Effects) | EF_NODRAW)
  411. return FMRES_IGNORED
  412. }
  413.  
  414. public fw_Think(ent)
  415. {
  416. if(!pev_valid(ent))
  417. return
  418.  
  419. static Classname[64]
  420. pev(ent, pev_classname, Classname, sizeof(Classname))
  421.  
  422. if(equal(Classname, "AnimEnt"))
  423. {
  424. static id; id = pev(ent, pev_owner)
  425. if(!is_user_alive(id))
  426. return
  427.  
  428. // Set Player Emotion
  429. static Float:Angles[3], Float:Angles2[3]
  430.  
  431. pev(id, pev_angles, Angles)
  432. pev(ent, pev_angles, Angles2)
  433.  
  434. Angles[0] = 0.0; Angles[2] = 0.0
  435.  
  436. if(Angles[1] != Angles2[1]) set_pev(ent, pev_angles, Angles)
  437. set_pev(ent, pev_nextthink, get_gametime() + 0.05)
  438.  
  439. if(pev(ent, pev_effects) == (pev(ent, pev_effects) | EF_NODRAW)) Set_Entity_Invisible(ent, 0)
  440. }
  441. }
  442.  
  443. stock fm_cs_get_user_model(id, Model[], Len)
  444. {
  445. if(!is_user_connected(id))
  446. return
  447.  
  448. engfunc(EngFunc_InfoKeyValue, engfunc(EngFunc_GetInfoKeyBuffer, id), "model", Model, Len)
  449. }
  450.  
  451. stock Set_Entity_Invisible(ent, Invisible = 1)
  452. {
  453. if(!pev_valid(ent))
  454. return
  455.  
  456. set_pev(ent, pev_effects, Invisible == 0 ? pev(ent, pev_effects) & ~EF_NODRAW : pev(ent, pev_effects) | EF_NODRAW)
  457. }
  458.  
  459. stock Set_Entity_Anim(ent, Anim, ResetFrame)
  460. {
  461. if(!pev_valid(ent))
  462. return
  463.  
  464. set_pev(ent, pev_animtime, get_gametime())
  465. set_pev(ent, pev_framerate, 1.0)
  466. set_pev(ent, pev_sequence, Anim)
  467. if(ResetFrame) set_pev(ent, pev_frame, 0)
  468. }
  469.  
  470.  
  471. stock Set_Weapon_Anim(id, Anim)
  472. {
  473. if(!is_user_alive(id))
  474. return
  475.  
  476. set_pev(id, pev_weaponanim, Anim)
  477.  
  478. message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, _, id)
  479. write_byte(Anim)
  480. write_byte(pev(id, pev_body))
  481. message_end()
  482. }
  483.  
  484. stock client_printc(index, const text[], any:...)
  485. {
  486. new szMsg[128];
  487. vformat(szMsg, sizeof(szMsg) - 1, text, 3);
  488.  
  489. replace_all(szMsg, sizeof(szMsg) - 1, "!g", "^x04");
  490. replace_all(szMsg, sizeof(szMsg) - 1, "!n", "^x01");
  491. replace_all(szMsg, sizeof(szMsg) - 1, "!t", "^x03");
  492.  
  493. if(index == 0)
  494. {
  495. for(new i = 0; i < g_MaxPlayers; i++)
  496. {
  497. if(!is_user_connected(i))
  498. continue
  499.  
  500. message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, i)
  501. write_byte(i)
  502. write_string(szMsg)
  503. message_end()
  504. }
  505. } else {
  506. message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, index);
  507. write_byte(index);
  508. write_string(szMsg);
  509. message_end();
  510. }
  511. }
  512. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  513. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
  514. */
  515.