HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1.  
  2. #include <amxmodx>
  3. #include <amxmisc>
  4.  
  5. #include <cstrike>
  6.  
  7. #include <engine>
  8. #include <fakemeta>
  9. #include <hamsandwich>
  10.  
  11. #include <xs>
  12.  
  13. new ModelWeapon[] = "models/p_glock18.mdl"
  14. new ModelWeaponID
  15.  
  16. new Models[CsTeams][] =
  17. {
  18. "",
  19. "models/player/leet/leet.mdl",
  20. "models/player/sas/sas.mdl",
  21. ""
  22. }
  23.  
  24. new ModelsIDs[CsTeams]
  25.  
  26. new const Plugin[] = "Lucia Hallucination"
  27. new const Author[] = "joaquimandrade"
  28. new const Version[] = "1.0"
  29.  
  30. enum EntityData
  31. {
  32. Origin[3],
  33. Angles[3],
  34. CsTeams:Team
  35. }
  36.  
  37. const MaxSlots = 32
  38.  
  39. new bool:OnFirstPersonView[MaxSlots+1]
  40. new SpectatingUser[MaxSlots+1]
  41.  
  42. new UserNeedsEntity[MaxSlots+1]
  43. new UserEntityData[MaxSlots+1][EntityData]
  44. new HasPermissions[MaxSlots+1]
  45.  
  46. new Float:LastTimeViewedAnEntity[MaxSlots+1]
  47.  
  48. const PermissionFlag = ADMIN_BAN
  49.  
  50. new CheckVisibilityForward
  51.  
  52. new CurrentHost
  53. new CurrentEnt
  54.  
  55. new Float:VectorNormalHideStartFactor = 46.0
  56. new Float:VectorNormalHideEndFactor = 40.0
  57.  
  58. new Float:VectorNormalHideStep = 1.0
  59.  
  60. new const Float:PlayerRay = 22.0
  61. new const Float:HullFactor = 0.5
  62.  
  63. const Float:PlayerHideMaxDistance = 1200.0
  64.  
  65. new CsTeams:Teams = CS_TEAM_T + CS_TEAM_CT
  66.  
  67. new OnFirstPersonViewN
  68.  
  69. new ForwardAddToFullPackPre
  70. new ForwardAddToFullPackPost
  71.  
  72. new ForwardCmdStart
  73.  
  74. public plugin_precache()
  75. {
  76. ModelWeaponID = precache_model(ModelWeapon)
  77.  
  78. ModelsIDs[CS_TEAM_T] = precache_model(Models[CS_TEAM_T])
  79. ModelsIDs[CS_TEAM_CT] = precache_model(Models[CS_TEAM_CT])
  80. }
  81. public plugin_init()
  82. {
  83. register_plugin(Plugin,Version,Author)
  84.  
  85. register_event("TextMsg","specMode","b","2&#Spec_Mode")
  86. register_event("StatusValue","specTarget","bd","1=2")
  87. register_event("SpecHealth2","specTarget","bd")
  88.  
  89. RegisterHam(Ham_Spawn,"player","playerSpawn",1)
  90.  
  91. register_cvar("luciaHallucination",Version,FCVAR_SERVER|FCVAR_SPONLY);
  92.  
  93. register_clcmd("luciaToggle","luciaToggle",PermissionFlag)
  94. }
  95.  
  96. public luciaToggle(id,level,cid)
  97. {
  98. if(cmd_access(id,level,cid,0))
  99. {
  100. toggle(id)
  101. return PLUGIN_HANDLED
  102. }
  103.  
  104. return PLUGIN_CONTINUE
  105. }
  106.  
  107. public checkVisibility(id,pset)
  108. {
  109. if(CurrentEnt == id)
  110. {
  111. unregister_forward(FM_CheckVisibility,CheckVisibilityForward)
  112. CheckVisibilityForward = 0
  113.  
  114. forward_return(FMV_CELL,1)
  115. return FMRES_SUPERCEDE
  116. }
  117.  
  118. return FMRES_IGNORED
  119. }
  120.  
  121. public addToFullPackPre(es, e, ent, host, hostflags, player, pSet)
  122. {
  123. if(player && (host != ent) && is_user_alive(ent))
  124. {
  125. if((LastTimeViewedAnEntity[host] != get_gametime()) && (((UserNeedsEntity[host]) && (cs_get_user_team(host) != cs_get_user_team(ent))) || (OnFirstPersonView[host] && UserNeedsEntity[SpectatingUser[host]] && (cs_get_user_team(SpectatingUser[host]) != cs_get_user_team(ent)))))
  126. {
  127. if(!engfunc(EngFunc_CheckVisibility,ent,pSet))
  128. {
  129. CurrentEnt = ent
  130. CurrentHost = host
  131.  
  132. if(!CheckVisibilityForward)
  133. {
  134. CheckVisibilityForward = register_forward(FM_CheckVisibility,"checkVisibility")
  135. }
  136. }
  137. }
  138. }
  139. }
  140.  
  141. public addToFullPackPost(es, e, ent, host, hostflags, player, pSet)
  142. {
  143. if((host == CurrentHost) && (ent == CurrentEnt))
  144. {
  145. LastTimeViewedAnEntity[CurrentHost] = get_gametime()
  146.  
  147. new CsTeams:team
  148.  
  149. if(OnFirstPersonView[host])
  150. {
  151. new spectated = SpectatingUser[host]
  152.  
  153. team = UserEntityData[spectated][Team]
  154.  
  155. static Float:origin[3]
  156. pev(spectated,pev_origin,origin)
  157.  
  158. engfunc(EngFunc_TraceLine,origin,Float:UserEntityData[spectated][Origin],0,spectated,0)
  159.  
  160. get_tr2(0,TR_EndPos,origin)
  161.  
  162. set_es(es,ES_Origin,origin)
  163. set_es(es,ES_Angles,Float:UserEntityData[spectated][Angles])
  164.  
  165. set_es(es,ES_RenderMode,kRenderTransAlpha)
  166. set_es(es,ES_RenderAmt,170)
  167.  
  168. }
  169. else
  170. {
  171. team = UserEntityData[host][Team]
  172.  
  173. set_es(es,ES_Origin,Float:UserEntityData[host][Origin])
  174. set_es(es,ES_Angles,Float:UserEntityData[host][Angles])
  175. }
  176.  
  177. new CsTeams:enemyTeam = Teams - team
  178.  
  179.  
  180. set_es(es,ES_Team,_:enemyTeam)
  181. set_es(es,ES_ModelIndex,ModelsIDs[enemyTeam])
  182. set_es(es,ES_WeaponModel,ModelWeaponID)
  183. set_es(es,ES_Effects,EF_INVLIGHT)
  184. }
  185.  
  186. CurrentHost = CurrentEnt = 0
  187. }
  188.  
  189. hullCheck(Float:origin[3])
  190. {
  191. static Float:margin[3]
  192.  
  193. xs_vec_copy(origin,margin)
  194.  
  195. for(new i=0;i<3;i++)
  196. margin[i] += HullFactor
  197.  
  198. engfunc(EngFunc_TraceHull,origin,margin,1,HULL_POINT,0,0)
  199. return get_tr2(0,TR_AllSolid)
  200.  
  201. }
  202.  
  203. bool:isSafeHideOrigin(Float:origin[3])
  204. {
  205. static Float:centerPointsZDistanceMultiply[] = {1.2,0.5,0.0,-0.5,-1.0,-1.5}
  206. static Float:centerPoints[sizeof centerPointsZDistanceMultiply][3]
  207.  
  208. for(new i=0;i<sizeof centerPointsZDistanceMultiply;i++)
  209. {
  210. xs_vec_copy(origin,centerPoints[i])
  211. centerPoints[i][2] += centerPointsZDistanceMultiply[i] * (PlayerRay)
  212.  
  213. if(!hullCheck(centerPoints[i]))
  214. {
  215. return false
  216. }
  217.  
  218. static Float:borderPointsXYDistanceMultiply[4][2] = {{0.0,1.2},{1.2,0.0},{0.0,-1.2},{-1.2,0.0}}
  219.  
  220. for(new j=0;j<4;j++)
  221. {
  222. static Float:borderPoint[3]
  223. xs_vec_copy(centerPoints[i],borderPoint)
  224.  
  225. for(new k=0;k<2;k++)
  226. {
  227. borderPoint[k] += borderPointsXYDistanceMultiply[j][k] * (PlayerRay)
  228. }
  229.  
  230. if(!hullCheck(borderPoint))
  231. {
  232. return false
  233. }
  234. }
  235. }
  236.  
  237. return true
  238. }
  239.  
  240. getEntityData(id)
  241. {
  242. static Float:origin[3],Float:viewAngles[3],Float:viewOfs[3]
  243.  
  244. pev(id,pev_origin,origin)
  245. pev(id,pev_view_ofs,viewOfs)
  246.  
  247. xs_vec_add(origin,viewOfs,origin)
  248.  
  249. pev(id,pev_v_angle,viewAngles)
  250.  
  251. static Float:path[3]
  252.  
  253. angle_vector(viewAngles,ANGLEVECTOR_FORWARD,path)
  254. xs_vec_normalize(path,path)
  255.  
  256. xs_vec_mul_scalar(path,PlayerHideMaxDistance,path)
  257.  
  258. static Float:end[3]
  259.  
  260. xs_vec_add(origin,path,end)
  261.  
  262. engfunc(EngFunc_TraceLine,origin,end,0,id,0);
  263.  
  264. static Float:fraction
  265. get_tr2(0,TR_flFraction,fraction)
  266.  
  267. if((fraction != 1.0) && (get_tr2(0,TR_Hit) == -1))
  268. {
  269. get_tr2(0,TR_EndPos,end)
  270.  
  271. static Float:normal[3]
  272. get_tr2(0,TR_vecPlaneNormal,normal)
  273.  
  274. static Float:normalPath[3]
  275.  
  276. for(new Float:i=VectorNormalHideStartFactor;i>=VectorNormalHideEndFactor;i-=VectorNormalHideStep)
  277. {
  278. xs_vec_mul_scalar(normal,-i,normalPath)
  279. xs_vec_add(end,normalPath,normalPath)
  280.  
  281. if(isSafeHideOrigin(normalPath))
  282. {
  283. static Float:angles[3]
  284.  
  285. vector_to_angle(normal,angles)
  286.  
  287. if(angles[0] > 0.0)
  288. angles[0] = 0.0
  289.  
  290. xs_vec_copy(angles,Float:UserEntityData[id][Angles])
  291. xs_vec_copy(normalPath,Float:UserEntityData[id][Origin])
  292.  
  293. UserEntityData[id][Team] = _:cs_get_user_team(id)
  294.  
  295. return true
  296. }
  297. }
  298. }
  299.  
  300. return false
  301. }
  302.  
  303. toggle(id)
  304. {
  305. if(OnFirstPersonView[id])
  306. {
  307. if(UserNeedsEntity[SpectatingUser[id]])
  308. {
  309. client_print(id,print_chat,"[Lucia Hallucination] Leallitva")
  310.  
  311. UserNeedsEntity[SpectatingUser[id]] = false
  312. }
  313. else
  314. {
  315. if(getEntityData(SpectatingUser[id]))
  316. {
  317. client_print(id,print_chat,"[Lucia Hallucination] Elinditva")
  318.  
  319. UserNeedsEntity[SpectatingUser[id]] = true
  320. }
  321. else
  322. {
  323. client_print(id,print_chat,"[Lucia Hallucination] Nem talalhato ez a hely")
  324. }
  325. }
  326. }
  327. }
  328.  
  329. public cmdStart(id)
  330. {
  331. if((get_user_button(id) & IN_RELOAD) && (~get_user_oldbutton(id) & IN_RELOAD))
  332. toggle(id)
  333. }
  334.  
  335. handleJoiningFirstPersonView(id)
  336. {
  337. OnFirstPersonView[id] = true
  338.  
  339. if(!OnFirstPersonViewN++)
  340. {
  341. ForwardAddToFullPackPre = register_forward(FM_AddToFullPack,"addToFullPackPre",0);
  342. ForwardAddToFullPackPost = register_forward(FM_AddToFullPack,"addToFullPackPost",1)
  343. ForwardCmdStart = register_forward(FM_CmdStart,"cmdStart")
  344. }
  345. }
  346.  
  347. handleQuitingFirstPersonView(id)
  348. {
  349. OnFirstPersonView[id] = false
  350. UserNeedsEntity[SpectatingUser[id]] = false
  351. SpectatingUser[id] = 0
  352.  
  353. if(!--OnFirstPersonViewN)
  354. {
  355. unregister_forward(FM_AddToFullPack,ForwardAddToFullPackPre)
  356. unregister_forward(FM_AddToFullPack,ForwardAddToFullPackPost,1)
  357. unregister_forward(FM_CmdStart,ForwardCmdStart)
  358. }
  359. }
  360.  
  361. public playerSpawn(id)
  362. {
  363. if(OnFirstPersonView[id] && is_user_alive(id))
  364. {
  365. handleQuitingFirstPersonView(id)
  366. }
  367. }
  368.  
  369. public client_authorized(id)
  370. {
  371. HasPermissions[id] = get_user_flags(id) & PermissionFlag
  372. }
  373.  
  374. public client_disconnect(id)
  375. {
  376. if(OnFirstPersonView[id])
  377. {
  378. handleQuitingFirstPersonView(id)
  379. }
  380. }
  381.  
  382. public specMode(id)
  383. {
  384. if(HasPermissions[id])
  385. {
  386. new specMode[12]
  387. read_data(2,specMode,11)
  388.  
  389. if(specMode[10] == '4')
  390. {
  391. handleJoiningFirstPersonView(id)
  392. }
  393. else if(OnFirstPersonView[id])
  394. {
  395. handleQuitingFirstPersonView(id)
  396. }
  397. }
  398. }
  399.  
  400. public specTarget(id)
  401. {
  402. new spectated = read_data(2);
  403.  
  404. if(spectated)
  405. {
  406. if(OnFirstPersonView[id])
  407. {
  408. if(spectated != SpectatingUser[id])
  409. {
  410. handleQuitingFirstPersonView(id)
  411. SpectatingUser[id] = spectated;
  412. handleJoiningFirstPersonView(id)
  413. }
  414. }
  415. else
  416. {
  417. SpectatingUser[id] = spectated;
  418. }
  419. }
  420. }
  421.