HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <cstrike>
  3. #include <fakemeta>
  4. #include <fakemeta_util>
  5. #include <engine>
  6. #include <hamsandwich>
  7.  
  8. #define PLUGIN "Deception"
  9. #define AUTHOR "joaquimandrade e luciaandrade"
  10. #define VERSION "1.0"
  11.  
  12. new msgBarTimeIndex
  13.  
  14. new Array:bodies
  15.  
  16. new BodyUser[33 char]
  17. new LastBodyWatched[33 char]
  18. new Float:BodiesTimeCounter[33]
  19.  
  20. new DeceptedPlayer[33 char]
  21. new bool:changedModel[33 char]
  22.  
  23. const ModelLen = 40
  24.  
  25. new Float:SuspectGaitSequences[] = {6.0,4.0}
  26. new Float:PreviousGaitSequence[33]
  27.  
  28. new Ham:HamWeaponEvents[] = {Ham_Weapon_PrimaryAttack,Ham_Weapon_SecondaryAttack,Ham_Weapon_Reload}
  29.  
  30. new MaxPlayers
  31.  
  32. new const CvarDeceptionCamouflageTimeDft[] = "2"
  33.  
  34. new CvarDeceptionCamouflageTime
  35. new CamouflageTime
  36.  
  37. new Float:CamouflageMaxDistance = 150.0
  38. new Float:DetectionMaxDistance = 800.0
  39.  
  40. enum MLData
  41. {
  42. CamouflagedStart,
  43. CamouflagedEnd
  44. }
  45.  
  46. new MLStrings[MLData][] = {"DECEPTION_CAMOUFLAGE_START","DECEPTION_CAMOUFLAGE_END"}
  47.  
  48. new const Dictionary[] = "deception.txt"
  49.  
  50. public plugin_init()
  51. {
  52. register_plugin(PLUGIN, VERSION, AUTHOR)
  53.  
  54. register_forward(FM_CmdStart,"FMCmdStart");
  55.  
  56. RegisterHam(Ham_Killed,"player","playerKilled",1)
  57.  
  58. register_message(get_user_msgid("ClCorpse"),"message_clcorpse")
  59.  
  60. register_event("HLTV","newRound","a","1=0","2=0")
  61.  
  62. RegisterHam(Ham_TraceAttack,"player","playerAttacked")
  63.  
  64. new weaponName[24];
  65.  
  66. get_weaponname(1,weaponName,charsmax (weaponName));
  67. for(new i=0;i<sizeof HamWeaponEvents;i++)
  68. RegisterHam(HamWeaponEvents[i],weaponName,"weaponUse");
  69.  
  70. for (new i=3, LastWeapon=30; i<=LastWeapon; i++)
  71. {
  72. get_weaponname (i,weaponName,charsmax(weaponName));
  73. for(new i=0;i<sizeof HamWeaponEvents;i++)
  74. RegisterHam(HamWeaponEvents[i],weaponName,"weaponUse");
  75. }
  76.  
  77. RegisterHam(Ham_Use,"grenade","grenadeUse")
  78.  
  79. register_forward(FM_SetClientKeyValue,"fw_SetClientKeyValue");
  80.  
  81. CvarDeceptionCamouflageTime = register_cvar("deception_camouflage_time",CvarDeceptionCamouflageTimeDft)
  82.  
  83. CamouflageTime = clamp(get_pcvar_num(CvarDeceptionCamouflageTime),1,5)
  84.  
  85. MaxPlayers = get_maxplayers()
  86.  
  87. register_dictionary(Dictionary)
  88. }
  89.  
  90. public grenadeUse(id, idcaller, idactivator, use_type, Float:value)
  91. {
  92. checkIfIsBeingWatched(idactivator)
  93. }
  94.  
  95. checkIfIsBeingWatched(id)
  96. {
  97. if(DeceptedPlayer{id} && (1<=id<=MaxPlayers))
  98. {
  99. new CsTeams:team = cs_get_user_team(id);
  100.  
  101. new Float:origin[3]
  102.  
  103. entity_get_vector(id,EV_VEC_origin,origin)
  104.  
  105. for(new i=1,CsTeams:teamViewer;i<=MaxPlayers;i++)
  106. {
  107. if(is_user_alive(i))
  108. {
  109. teamViewer = cs_get_user_team(i);
  110.  
  111. if(team != teamViewer)
  112. {
  113. if(fm_is_ent_visible_maxdistance(i,id,.maxdistance = DetectionMaxDistance) && is_in_viewcone(i,origin))
  114. {
  115. if(is_user_connected(DeceptedPlayer{id}))
  116. {
  117. checkRestoreModel(DeceptedPlayer{id})
  118. }
  119.  
  120. DeceptedPlayer{id} = 0
  121. doRestoreModel(id)
  122.  
  123. client_print(id,print_chat,"%L",id,MLStrings[CamouflagedEnd])
  124.  
  125. return true;
  126. }
  127. }
  128. }
  129. }
  130. }
  131.  
  132. return false
  133. }
  134.  
  135. public weaponUse(weaponID)
  136. {
  137. checkIfIsBeingWatched(pev(weaponID,pev_owner))
  138. }
  139.  
  140. doRestoreModel(id)
  141. {
  142. changedModel{id} = false
  143. dllfunc(DLLFunc_ClientUserInfoChanged,id,engfunc(EngFunc_GetInfoKeyBuffer,id));
  144. }
  145.  
  146. checkRestoreModel(id)
  147. {
  148. if(changedModel{id})
  149. {
  150. doRestoreModel(id)
  151. }
  152. }
  153.  
  154. public plugin_cfg()
  155. {
  156. bodies = ArrayCreate()
  157. msgBarTimeIndex = get_user_msgid("BarTime")
  158. }
  159.  
  160. addBody(id)
  161. {
  162. ArrayPushCell(bodies,id)
  163. }
  164.  
  165. removeBody(id)
  166. {
  167. for(new i=0;i<ArraySize(bodies);i++)
  168. {
  169. if(id == ArrayGetCell(bodies,i))
  170. {
  171. ArrayDeleteItem(bodies,i)
  172. break;
  173. }
  174. }
  175. }
  176.  
  177. public client_disconnect(id)
  178. {
  179. removeBody(id)
  180. changedModel{id} = false
  181. }
  182.  
  183. public newRound()
  184. {
  185. ArrayClear(bodies);
  186.  
  187. new newArray[33 char]
  188. BodyUser = newArray
  189.  
  190. new otherArray[33 char]
  191. DeceptedPlayer = otherArray
  192.  
  193. new bool:anotherArray[33 char]
  194. changedModel = anotherArray
  195.  
  196. CamouflageTime = clamp(get_pcvar_num(CvarDeceptionCamouflageTime),1,5)
  197. }
  198.  
  199. public message_clcorpse()
  200. {
  201. removeBody(get_msg_arg_int(12))
  202. }
  203.  
  204. public playerKilled(id,idattacker, shouldgib)
  205. {
  206. addBody(id)
  207. checkIfIsBeingWatched(id)
  208. }
  209.  
  210. public playerAttacked(id, idattacker, Float:damage, Float:direction[3], tracehandle, damagebits)
  211. {
  212. checkIfIsBeingWatched(id)
  213. }
  214.  
  215. public FMCmdStart(id,uc_handle,random_seed)
  216. {
  217. if(!DeceptedPlayer{id})
  218. {
  219. if((get_uc(uc_handle,UC_Buttons) & IN_USE) )
  220. {
  221. static Float:start[3], Float:view_ofs[3], Float:dest[3]
  222.  
  223. pev(id, pev_origin, start);
  224. pev(id, pev_view_ofs, view_ofs);
  225. xs_vec_add(start, view_ofs, start);
  226.  
  227. pev(id, pev_v_angle, dest);
  228. engfunc(EngFunc_MakeVectors, dest);
  229. global_get(glb_v_forward, dest);
  230. xs_vec_mul_scalar(dest, CamouflageMaxDistance, dest);
  231. xs_vec_add(start, dest, dest);
  232.  
  233. new watchingBody
  234.  
  235. for(new i=0, body, bodyUser, hit ;i<ArraySize(bodies);i++)
  236. {
  237. body = ArrayGetCell(bodies,i)
  238. bodyUser = BodyUser{body}
  239.  
  240. if((!bodyUser || (bodyUser == id)) && (cs_get_user_team(id) != cs_get_user_team(body)))
  241. {
  242. engfunc ( EngFunc_TraceModel, start, dest, HULL_POINT, body ,0)
  243. hit = get_tr2(0, TR_pHit);
  244.  
  245. if(hit == body)
  246. {
  247. watchingBody = body
  248. break;
  249. }
  250. }
  251. }
  252.  
  253. if(watchingBody)
  254. {
  255. if(LastBodyWatched{id} == watchingBody)
  256. {
  257. if(!increaseBodyWatchCounter(id,watchingBody))
  258. {
  259. LastBodyWatched{id} = 0
  260. BodyUser{watchingBody} = 0;
  261. }
  262. }
  263. else
  264. {
  265. if(LastBodyWatched{id})
  266. {
  267. resetBodyWatchCounter(id,LastBodyWatched{id});
  268. BodyUser{LastBodyWatched{id}} = 0
  269. }
  270.  
  271. LastBodyWatched{id} = watchingBody
  272. }
  273. }
  274. else if(LastBodyWatched{id})
  275. {
  276. resetBodyWatchCounter(id,LastBodyWatched{id});
  277. BodyUser{LastBodyWatched{id}} = 0
  278. LastBodyWatched{id} = 0
  279. }
  280. }
  281. else if(LastBodyWatched{id})
  282. {
  283. resetBodyWatchCounter(id,LastBodyWatched{id});
  284. BodyUser{LastBodyWatched{id}} = 0
  285. LastBodyWatched{id} = 0
  286. }
  287. }
  288. }
  289.  
  290. increaseBodyWatchCounter(id,body)
  291. {
  292. new Float:startTime = BodiesTimeCounter[body]
  293.  
  294. if(!startTime)
  295. {
  296. BodiesTimeCounter[body] = get_gametime()
  297.  
  298. message_begin(MSG_ONE_UNRELIABLE, msgBarTimeIndex, _, id)
  299. write_short(CamouflageTime)
  300. message_end()
  301. }
  302. else
  303. {
  304. new Float:timeTaken = get_gametime() - startTime;
  305.  
  306. if(timeTaken >= float(CamouflageTime) )
  307. {
  308. BodiesTimeCounter[body] = 0.0
  309.  
  310. if(is_user_connected(body))
  311. {
  312. DeceptedPlayer{id} = body;
  313.  
  314. static modelPlayer[ModelLen]
  315. static modelBody[ModelLen]
  316.  
  317. cs_get_user_model(id,modelPlayer,ModelLen-1)
  318. cs_get_user_model(body,modelBody,ModelLen-1)
  319.  
  320. changedModel{id} = true;
  321. changedModel{body} = true;
  322.  
  323. set_user_model(body,modelPlayer)
  324. set_user_model(id,modelBody)
  325.  
  326. removeBody(body)
  327.  
  328. client_print(id,print_chat,"%L",id,MLStrings[CamouflagedStart])
  329. }
  330.  
  331. return false;
  332. }
  333.  
  334. }
  335.  
  336. return true;
  337. }
  338.  
  339. resetBodyWatchCounter(id,body)
  340. {
  341. BodiesTimeCounter[body] = 0.0
  342.  
  343. message_begin(MSG_ONE_UNRELIABLE, msgBarTimeIndex, _, id)
  344. write_short(0)
  345. message_end()
  346. }
  347.  
  348. public client_PreThink(id)
  349. {
  350. if(DeceptedPlayer{id})
  351. {
  352. new Float:newSequence
  353. pev(id,pev_gaitsequence,newSequence)
  354.  
  355. if(PreviousGaitSequence[id] != newSequence)
  356. {
  357. for(new i=0;i<sizeof SuspectGaitSequences;i++)
  358. {
  359. if(newSequence == SuspectGaitSequences[i])
  360. {
  361. if(checkIfIsBeingWatched(id))
  362. PreviousGaitSequence[id] = 0.0
  363.  
  364. break;
  365. }
  366. }
  367.  
  368. PreviousGaitSequence[id] = newSequence
  369. }
  370. }
  371. }
  372.  
  373. set_user_model(id,model[])
  374. {
  375. engfunc(EngFunc_SetClientKeyValue,id,engfunc(EngFunc_GetInfoKeyBuffer,id),"model",model)
  376. }
  377.  
  378. public fw_SetClientKeyValue(id,const infobuffer[],const key[])
  379. {
  380. return equal(key,"model") && changedModel{id} ? FMRES_SUPERCEDE : FMRES_IGNORED
  381. }
  382.  
  383. bool:fm_is_ent_visible_maxdistance(index, entity,ignoremonsters = 0,Float:maxdistance)
  384. {
  385. new Float:start[3], Float:dest[3];
  386. pev(index, pev_origin, start);
  387. pev(index, pev_view_ofs, dest);
  388. xs_vec_add(start, dest, start);
  389.  
  390. pev(entity, pev_origin, dest);
  391.  
  392. if(vector_distance(start,dest) <= maxdistance)
  393. {
  394. engfunc(EngFunc_TraceLine, start, dest, ignoremonsters, index, 0);
  395.  
  396. new Float:fraction;
  397. get_tr2(0, TR_flFraction, fraction);
  398.  
  399. if (fraction == 1.0 || get_tr2(0, TR_pHit) == entity)
  400. return true
  401. }
  402.  
  403. return false;
  404. }
  405.  
  406.