Advertisement
Sokarbestfrag

Untitled

Feb 26th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.01 KB | None | 0 0
  1. /* AMX Mod X - Script
  2. *
  3. * Admin Spectator ESP v1.3
  4. * Copyright (C) 2006 by KoST
  5. *
  6. * this plugin along with its compiled version can de downloaded here:
  7. * http://www.amxmodx.org/forums/viewtopic.php?t=24787
  8. *
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  23. * or download here: http://www.gnu.org/licenses/gpl.txt
  24. *
  25. * In addition, as a special exception, the author gives permission to
  26. * link the code of this program with the Half-Life Game Engine ("HL
  27. * Engine") and Modified Game Libraries ("MODs") developed by Valve,
  28. * L.L.C ("Valve"). You must obey the GNU General Public License in all
  29. * respects for all of the code used other than the HL Engine and MODs
  30. * from Valve. If you modify this file, you may extend this exception
  31. * to your version of the file, but you are not obligated to do so. If
  32. * you do not wish to do so, delete this exception statement from your
  33. * version.
  34. */
  35. //--------------------------------------------------------------------------------------------------
  36.  
  37. #include <amxmodx>
  38. #include <engine>
  39.  
  40. // Here you can adjust the required admin level if needed
  41. // there is a list of all levels http://www.amxmodx.org/funcwiki.php?go=module&id=1#const_admin
  42.  
  43. #define REQUIRED_ADMIN_LEVEL ADMIN_KICK
  44.  
  45. //--------------------------------------------------------------------------------------------------
  46.  
  47. #define PLUGIN "Admin Spectator ESP"
  48. #define VERSION "1.3"
  49. #define AUTHOR "KoST"
  50.  
  51. enum {
  52. ESP_ON=0,
  53. ESP_LINE,
  54. ESP_BOX,
  55. ESP_NAME,
  56. ESP_HEALTH_ARMOR,
  57. ESP_WEAPON,
  58. ESP_CLIP_AMMO,
  59. ESP_DISTANCE,
  60. ESP_TEAM_MATES,
  61. ESP_AIM_VEC,
  62. }
  63.  
  64. new bool:admin[33] // is/is not admin
  65. new bool:first_person[33] //is/is not in first person view
  66. new spec[33] // spec[player_id]=the players id if
  67. new laser // precached model
  68. new max_players // if you start hlds with +maxplayers 20 for example this would be 20
  69. new team_colors[4][3]={{0,0,0},{150,0,0},{0,0,150},{0,150,0}}
  70. new esp_colors[5][3]={{0,255,0},{100,60,60},{60,60,100},{255,0,255},{128,128,128}}
  71. new bool:ducking[33] //is/is not player ducked
  72. new damage_done_to[33] //damage_done_to[p1]=p2 // p1 has hit p2
  73. new view_target[33] // attackers victim
  74. new bool:admin_options[33][10] // individual esp options
  75. new bool:is_in_menu[33] // has esp menu open
  76.  
  77. // weapon strings
  78. new weapons[30][10]={"None","P228","Scout","HE","XM1014","C4",
  79. "MAC-10","AUG","Smoke","Elite","Fiveseven",
  80. "UMP45","SIG550","Galil","Famas","USP",
  81. "Glock","AWP","MP5","M249","M3","M4A1",
  82. "TMP","G3SG1","Flash","Deagle","SG552",
  83. "AK47","Knife","P90"}
  84.  
  85. public plugin_precache(){
  86. laser=precache_model("sprites/laserbeam.spr")
  87. }
  88.  
  89. public plugin_init(){
  90. register_plugin(PLUGIN,VERSION,AUTHOR)
  91. server_print("^n^t%s v%s, Copyright (C) 2006 by %s^n",PLUGIN,VERSION,AUTHOR)
  92.  
  93. // cvars
  94. register_cvar("esp","1")
  95. register_cvar("esp_timer","0.3")
  96. register_cvar("esp_allow_all","0")
  97. register_cvar("esp_disable_default_keys","0")
  98. register_cvar("aesp_version",VERSION,FCVAR_SERVER|FCVAR_UNLOGGED|FCVAR_SPONLY)
  99.  
  100. // client commands
  101. register_clcmd("esp_menu","cmd_esp_menu",REQUIRED_ADMIN_LEVEL,"Shows ESP Menu")
  102. register_clcmd("esp_toggle","cmd_esp_toggle",REQUIRED_ADMIN_LEVEL,"Toggle ESP on/off")
  103. register_clcmd("say /esp_menu","cmd_esp_menu",REQUIRED_ADMIN_LEVEL,"Shows ESP Menu")
  104. register_clcmd("say /esp_toggle","cmd_esp_toggle",REQUIRED_ADMIN_LEVEL,"Toggle ESP on/off")
  105. register_clcmd("esp_settings","cmd_esp_settings",REQUIRED_ADMIN_LEVEL," ESP adasdsassdasd")
  106.  
  107.  
  108. // events
  109. register_event("StatusValue","spec_target","bd","1=2")
  110. register_event("SpecHealth2","spec_target","bd")
  111. register_event("TextMsg","spec_mode","b","2&#Spec_Mode")
  112. register_event("Damage", "event_Damage", "b", "2!0", "3=0", "4!0")
  113. register_event("ResetHUD", "reset_hud_alive", "be")
  114.  
  115.  
  116. // menu
  117. new keys=MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9
  118. register_menucmd(register_menuid("Admin Specator ESP"),keys,"menu_esp")
  119.  
  120. max_players=get_maxplayers()
  121.  
  122. // start esp_timer for the first time
  123. set_task(1.0,"esp_timer")
  124. }
  125.  
  126. public reset_hud_alive(id){
  127. spec[id]=0
  128. return PLUGIN_CONTINUE
  129. }
  130.  
  131. public cmd_esp_settings(id){
  132. if (admin[id]){
  133. new out[11]
  134. read_argv(1,out,10)
  135. new len=strlen(out)
  136. for (new i=0;i<len;i++){
  137. if (out[i]=='1'){
  138. admin_options[id][i]=true
  139. }else{
  140. admin_options[id][i]=false
  141. }
  142. }
  143. }
  144. }
  145.  
  146. public cmd_esp_menu(id){
  147. if (admin[id] && get_cvar_num("esp")==1){
  148. show_esp_menu(id)
  149. }
  150. }
  151.  
  152. public cmd_esp_toggle(id){
  153. if (admin[id] && get_cvar_num("esp")==1){
  154. change_esp_status(id,!admin_options[id][0])
  155. }
  156. }
  157.  
  158. public show_esp_menu(id){
  159. is_in_menu[id]=true
  160. new menu[301]
  161. new keys=MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9
  162. new onoff[2][]={{"\roff\w"},{"\yon\w"}} // \r=red \y=yellow \w white
  163. new text[2][]={{"(use move forward/backward to switch on/off)"},{"(use esp_toggle command to toggle)"}} // \r=red \y=yellow \w white
  164. new text_index=get_cvar_num("esp_disable_default_keys")
  165. if (text_index!=1) text_index=0
  166. format(menu, 300, "Admin Specator ESP^nis %s %s^n^n1. Line is %s^n2. Box is %s^n3. Name is %s^n4. Health/Armor is %s^n5. Weapon is %s^n6. Clip/Ammo is %s^n7. Distance is %s^n8. Show TeamMates is %s^n9. Show AimVector is %s^n^n0. Exit",
  167. onoff[admin_options[id][ESP_ON]],
  168. text[text_index],
  169. onoff[admin_options[id][ESP_LINE]],
  170. onoff[admin_options[id][ESP_BOX]],
  171. onoff[admin_options[id][ESP_NAME]],
  172. onoff[admin_options[id][ESP_HEALTH_ARMOR]],
  173. onoff[admin_options[id][ESP_WEAPON]],
  174. onoff[admin_options[id][ESP_CLIP_AMMO]],
  175. onoff[admin_options[id][ESP_DISTANCE]],
  176. onoff[admin_options[id][ESP_TEAM_MATES]],
  177. onoff[admin_options[id][ESP_AIM_VEC]])
  178. show_menu(id,keys,menu)
  179.  
  180. return PLUGIN_HANDLED
  181. }
  182.  
  183. public menu_esp(id,key){
  184. if (key==9){ // exit
  185. is_in_menu[id]=false
  186. return PLUGIN_HANDLED
  187. }
  188. // toggle esp options
  189. if (admin_options[id][key+1]){
  190. admin_options[id][key+1]=false
  191. }else{
  192. admin_options[id][key+1]=true
  193. }
  194. show_esp_menu(id)
  195. return PLUGIN_HANDLED
  196. }
  197.  
  198. public event_Damage(id){
  199. if (id>0) {
  200. new attacker=get_user_attacker(id)
  201. if (attacker>0 && attacker<=max_players){
  202. if (view_target[attacker]==id){
  203. damage_done_to[attacker]=id
  204. }
  205. }
  206. }
  207. return PLUGIN_CONTINUE
  208. }
  209.  
  210. public spec_mode(id){
  211. // discover if in first_person_view
  212. new specMode[12]
  213. read_data(2,specMode,11)
  214.  
  215. if(equal(specMode,"#Spec_Mode4")){
  216. first_person[id]=true
  217. }else{
  218. first_person[id]=false
  219. }
  220. return PLUGIN_CONTINUE
  221. }
  222.  
  223. public spec_target(id){
  224. if (id>0){
  225. new target=read_data(2)
  226. if (target!=0){
  227. spec[id]=target
  228. }
  229. }
  230. return PLUGIN_CONTINUE
  231. }
  232.  
  233. public client_putinserver(id){
  234. first_person[id]=false
  235. if ((get_user_flags(id) & REQUIRED_ADMIN_LEVEL) || get_cvar_num("esp_allow_all")==1){
  236. admin[id]=true
  237. init_admin_options(id)
  238.  
  239. }else{
  240. admin[id]=false
  241. }
  242. }
  243.  
  244. public init_admin_options(id){
  245.  
  246. for (new i=0;i<10;i++){
  247. admin_options[id][i]=true
  248. }
  249. admin_options[id][ESP_TEAM_MATES]=false
  250. load_vault_data(id)
  251. }
  252.  
  253. public save2vault(id){
  254. if (admin[id]){
  255. new authid[35]
  256. get_user_authid (id,authid,34)
  257. new tmp[11]
  258.  
  259. for (new s=0;s<10;s++){
  260.  
  261. if (admin_options[id][s]){
  262. tmp[s]='1';
  263. }else{
  264. tmp[s]='0';
  265. }
  266. }
  267. tmp[10]=0
  268.  
  269. //server_print("STEAMID: %s OPTIONS: %s",authid,tmp);
  270. new key[41]
  271. format(key,40,"AESP_%s",authid)
  272.  
  273. set_vaultdata(key,tmp)
  274. }
  275. }
  276.  
  277. public load_vault_data(id){
  278. if (admin[id]){
  279. new data[11]
  280. new authid[35]
  281. get_user_authid (id,authid,34)
  282. new key[41]
  283. format(key,40,"AESP_%s",authid)
  284. get_vaultdata(key,data,10)
  285. if (strlen(data)>0){
  286. for (new s=0;s<10;s++){
  287. if (data[s]=='1'){
  288. admin_options[id][s]=true
  289. }else{
  290. admin_options[id][s]=false
  291. }
  292. }
  293. }
  294. }
  295.  
  296. }
  297.  
  298. public client_disconnect(id){
  299. save2vault(id)
  300. admin[id]=false
  301. spec[id]=0
  302. }
  303.  
  304. public change_esp_status(id,bool:on){
  305. if (on){
  306. admin_options[id][0]=true
  307. if (!is_in_menu[id]) client_print(id,print_chat,"[%s] ON",PLUGIN)
  308. if (is_in_menu[id]) show_esp_menu(id)
  309. }else{
  310. admin_options[id][0]=false
  311. if (!is_in_menu[id]) client_print(id,print_chat,"[%s] OFF",PLUGIN)
  312. if (is_in_menu[id]) show_esp_menu(id)
  313. }
  314. }
  315.  
  316. public client_PreThink(id){
  317. if (!is_user_connected(id)) return PLUGIN_CONTINUE
  318.  
  319. new button=get_user_button(id)
  320. if (button==0) return PLUGIN_CONTINUE // saves a lot of cpu
  321.  
  322. new oldbutton=get_user_oldbutton(id)
  323.  
  324. if (button & IN_DUCK){
  325. ducking[id]=true
  326. }else{
  327. ducking[id]=false
  328. }
  329.  
  330. if ((get_cvar_num("esp")==1) && (get_cvar_num("esp_disable_default_keys")!=1)){
  331. if (admin[id]){
  332. if (first_person[id] && !is_user_alive(id)){
  333. if ((button & IN_RELOAD) && !(oldbutton & IN_RELOAD)){
  334. show_esp_menu(id)
  335. }
  336. if ((button & IN_FORWARD) && !(oldbutton & IN_FORWARD) && !admin_options[id][0]){
  337. change_esp_status(id,true)
  338. }
  339. if ((button & IN_BACK) && !(oldbutton & IN_BACK) && admin_options[id][0]){
  340. change_esp_status(id,false)
  341. }
  342. }
  343. }
  344. }
  345. return PLUGIN_CONTINUE
  346. }
  347.  
  348. public draw_aim_vector(i,s,len){
  349. new Float:endpoint[3]
  350. new tmp[3]
  351. new Float:vec1[3]
  352. get_user_origin(s, tmp, 1)
  353. IVecFVec(tmp,vec1)
  354. vec1[2]-=6.0
  355. VelocityByAim(s,len,endpoint) // get aim vector
  356. addVec(endpoint,vec1) // add origin to get absolute coordinates
  357. make_TE_BEAMPOINTS(i,4,vec1,endpoint,10,0,255)
  358. return PLUGIN_CONTINUE
  359. }
  360.  
  361. public esp_timer(){
  362.  
  363. if (get_cvar_num("esp")!=1) { // if esp is not 1, it is off
  364. set_task(1.0,"esp_timer") // check for reactivation in 1 sec intervals
  365. return PLUGIN_CONTINUE
  366. }
  367.  
  368. for (new i=1;i<=max_players;i++){ // loop through players
  369.  
  370. if (admin_options[i][ESP_ON] && first_person[i] && is_user_connected(i) && admin[i] && (!is_user_alive(i)) && (spec[i]>0) && is_user_alive(spec[i])){ // :)
  371.  
  372. new spec_id=spec[i]
  373. new Float:my_origin[3]
  374. entity_get_vector(i,EV_VEC_origin,my_origin) // get origin of spectating admin
  375. new my_team
  376. my_team=get_team(spec_id) // get team of spectated :)
  377.  
  378. new Float:smallest_angle=180.0
  379. new smallest_id=0
  380. new Float:xp=2.0,Float:yp=2.0 // x,y of hudmessage
  381. new Float:dist
  382.  
  383. for (new s=1;s<=max_players;s++){ // loop through the targets
  384. if (is_user_alive(s)){ // target must be alive
  385. new target_team=get_team(s) // get team of target
  386. if (!(target_team==3)){ //if not spectator
  387. if (spec_id!=s){ // do not target myself
  388. // if the target is in the other team and not spectator
  389.  
  390. if (((my_team!=target_team && (target_team==1 || target_team==2)) || admin_options[i][ESP_TEAM_MATES])){
  391.  
  392. new Float:target_origin[3]
  393. // get origin of target
  394. entity_get_vector(s,EV_VEC_origin,target_origin)
  395.  
  396.  
  397. // get distance from me to target
  398. new Float:distance=vector_distance(my_origin,target_origin)
  399.  
  400. if (admin_options[i][ESP_LINE]){
  401.  
  402. new width
  403. if (distance<2040.0){
  404. // calculate width according to distance
  405. width=(255-floatround(distance/8.0))/3
  406. }else{
  407. width=1
  408. }
  409. // create temp_ent
  410. make_TE_BEAMENTPOINT(i,target_origin,width,target_team)
  411. }
  412.  
  413.  
  414. // get vector from me to target
  415. new Float:v_middle[3]
  416. subVec(target_origin,my_origin,v_middle)
  417.  
  418. // trace from me to target, getting hitpoint
  419. new Float:v_hitpoint[3]
  420. trace_line (-1,my_origin,target_origin,v_hitpoint)
  421.  
  422. // get distance from me to hitpoint (nearest wall)
  423. new Float:distance_to_hitpoint=vector_distance(my_origin,v_hitpoint)
  424.  
  425. // scale
  426. new Float:scaled_bone_len
  427. if (ducking[spec_id]){
  428. scaled_bone_len=distance_to_hitpoint/distance*(50.0-18.0)
  429. }else{
  430. scaled_bone_len=distance_to_hitpoint/distance*50.0
  431. }
  432. scaled_bone_len=distance_to_hitpoint/distance*50.0
  433.  
  434. new Float:scaled_bone_width=distance_to_hitpoint/distance*150.0
  435.  
  436. new Float:v_bone_start[3],Float:v_bone_end[3]
  437. new Float:offset_vector[3]
  438. // get the point 10.0 units away from wall
  439. normalize(v_middle,offset_vector,distance_to_hitpoint-10.0) // offset from wall
  440.  
  441. // set to eye level
  442. new Float:eye_level[3]
  443. copyVec(my_origin,eye_level)
  444.  
  445. if (ducking[spec_id]){
  446. eye_level[2]+=12.3
  447. }else{
  448. eye_level[2]+=17.5
  449. }
  450.  
  451.  
  452. addVec(offset_vector,eye_level)
  453.  
  454. // start and end of green box
  455. copyVec(offset_vector,v_bone_start)
  456. copyVec(offset_vector,v_bone_end)
  457. v_bone_end[2]-=scaled_bone_len
  458.  
  459. new Float:distance_target_hitpoint=distance-distance_to_hitpoint
  460.  
  461. new actual_bright=255
  462.  
  463. if (admin_options[i][ESP_BOX]){
  464. // this is to make green box darker if distance is larger
  465. if (distance_target_hitpoint<2040.0){
  466. actual_bright=(255-floatround(distance_target_hitpoint/12.0))
  467.  
  468. }else{
  469. actual_bright=85
  470. }
  471. new color
  472. if (distance_to_hitpoint!=distance){ // if no line of sight
  473. color=0
  474. }else{ // if line of sight
  475. color=target_team
  476. }
  477.  
  478. if (damage_done_to[spec_id]==s) {
  479. color=3
  480. damage_done_to[spec_id]=0
  481. }
  482. make_TE_BEAMPOINTS(i,color,v_bone_start,v_bone_end,floatround(scaled_bone_width),target_team,actual_bright)
  483. }
  484.  
  485.  
  486. if (admin_options[i][ESP_AIM_VEC] || admin_options[i][ESP_NAME] || admin_options[i][ESP_HEALTH_ARMOR] || admin_options[i][ESP_WEAPON] || admin_options[i][ESP_CLIP_AMMO] || admin_options[i][ESP_DISTANCE]){
  487.  
  488.  
  489. new Float:ret[2]
  490. new Float:x_angle=get_screen_pos(spec_id,v_middle,ret)
  491.  
  492. // find target with the smallest distance to crosshair (on x-axis)
  493. if (smallest_angle>floatabs(x_angle)){
  494. if (floatabs(x_angle)!=0.0){
  495. smallest_angle=floatabs(x_angle)
  496. view_target[spec_id]=s
  497. smallest_id=s // store nearest target id..
  498. xp=ret[0] // and x,y coordinates of hudmessage
  499. yp=ret[1]
  500. dist=distance
  501. }
  502. }
  503. }
  504. }
  505. }
  506. }
  507. }
  508. } // inner player loop end
  509. if (!is_user_alive(smallest_id)) {
  510. smallest_id=0
  511. xp=-1.0
  512. }
  513. if (smallest_id>0 && admin_options[i][ESP_AIM_VEC]){
  514. draw_aim_vector(i,smallest_id,2000)
  515. }
  516. if (xp>0.0 && xp<=1.0 && yp>0.0 && yp<=1.0){ // if in visible range
  517. // show the player info
  518. set_hudmessage(255, 255, 0, floatabs(xp), floatabs(yp), 0, 0.0, get_cvar_float("esp_timer"), 0.0, 0.0, 2)
  519.  
  520. new name[37]=""
  521. new tmp[33]
  522. get_user_name(smallest_id,tmp,32)
  523. if (admin_options[i][ESP_NAME]){
  524. format(name,36,"[%s]^n",tmp)
  525. }
  526.  
  527.  
  528. new health[25]=""
  529. if (admin_options[i][ESP_HEALTH_ARMOR]){
  530. new hp=get_user_health(smallest_id)
  531. new armor=get_user_armor(smallest_id)
  532. format(health,24,"health: %d armor: %d^n",hp,armor)
  533. }
  534.  
  535.  
  536. new clip_ammo[22]=""
  537. new clip,ammo
  538. new weapon_id=get_user_weapon(smallest_id,clip,ammo)
  539. if (admin_options[i][ESP_CLIP_AMMO]){
  540. format(clip_ammo,21,"clip: %d ammo: %d^n",clip,ammo)
  541. }
  542.  
  543. new weapon_name[21]=""
  544. if (admin_options[i][ESP_WEAPON]){
  545. if ((weapon_id-1)<0 || (weapon_id-1)>29) weapon_id=1
  546. format(weapon_name,20,"weapon: %s^n",weapons[weapon_id-1])
  547. //copy(weapon_name,9,weapons[weapon_id-1])
  548. }
  549.  
  550. new str_dist[19]
  551. if (admin_options[i][ESP_DISTANCE]){
  552. format(str_dist,18,"distance: %d^n",floatround(dist))
  553. }
  554.  
  555. show_hudmessage(i, "%s%s%s%s%s",name,health,weapon_name,clip_ammo,str_dist)
  556. }
  557. }
  558. }
  559. set_task(get_cvar_float("esp_timer"),"esp_timer") // keep it going
  560. return PLUGIN_CONTINUE
  561. }
  562.  
  563. public Float:get_screen_pos(id,Float:v_me_to_target[3],Float:Ret[2]){
  564. new Float:v_aim[3]
  565. VelocityByAim(id,1,v_aim) // get aim vector
  566. new Float:aim[3]
  567. copyVec(v_aim,aim) // make backup copy of v_aim
  568. v_aim[2]=0.0 // project aim vector vertically to x,y plane
  569. new Float:v_target[3]
  570. copyVec(v_me_to_target,v_target)
  571. v_target[2]=0.0 // project target vector vertically to x,y plane
  572. // both v_aim and v_target are in the x,y plane, so angle can be calculated..
  573. new Float:x_angle
  574. new Float:x_pos=get_screen_pos_x(v_target,v_aim,x_angle) // get the x coordinate of hudmessage..
  575. new Float:y_pos=get_screen_pos_y(v_me_to_target,aim) // get the y coordinate of hudmessage..
  576. Ret[0]=x_pos
  577. Ret[1]=y_pos
  578. return x_angle
  579. }
  580.  
  581. public Float:get_screen_pos_x(Float:target[3],Float:aim[3],&Float:xangle){
  582. new Float:x_angle=floatacos(vectorProduct(aim,target)/(getVecLen(aim)*getVecLen(target)),1) // get angle between vectors
  583. new Float:x_pos
  584. //this part is a bit tricky..
  585. //the problem is that the 'angle between vectors' formula returns always positive values
  586. //how can be determined if the target vector is on the left or right side of the aim vector? with only positive angles?
  587. //the solution:
  588. //the scalar triple product returns the volume of the parallelepiped that is created by three input vectors
  589. //
  590. //i used the aim and target vectors as the first two input parameters
  591. //and the third one is a vector pointing straight upwards [0,0,1]
  592. //if now the target is on the left side of spectator origin the created parallelepipeds volume is negative
  593. //and on the right side positive
  594. //now we can turn x_angle into a signed value..
  595. if (scalar_triple_product(aim,target)<0.0) x_angle*=-1 // make signed
  596. if (x_angle>=-45.0 && x_angle<=45.0){ // if in fov of 90
  597. x_pos=1.0-(floattan(x_angle,degrees)+1.0)/2.0 // calulate y_pos of hudmessage
  598. xangle=x_angle
  599. return x_pos
  600. }
  601. xangle=0.0
  602. return -2.0
  603. }
  604.  
  605. public Float:get_screen_pos_y(Float:v_target[3],Float:aim[3]){
  606. new Float:target[3]
  607.  
  608. // rotate vector about z-axis directly over the direction vector (to get height angle)
  609. rotateVectorZ(v_target,aim,target)
  610.  
  611. // get angle between aim vector and target vector
  612. new Float:y_angle=floatacos(vectorProduct(aim,target)/(getVecLen(aim)*getVecLen(target)),1) // get angle between vectors
  613.  
  614. new Float:y_pos
  615. new Float:norm_target[3],Float:norm_aim[3]
  616.  
  617. // get normalized target and aim vectors
  618. normalize(v_target,norm_target,1.0)
  619. normalize(aim,norm_aim,1.0)
  620.  
  621. //since the 'angle between vectors' formula returns always positive values
  622. if (norm_target[2]<norm_aim[2]) y_angle*=-1 //make signed
  623.  
  624. if (y_angle>=-45.0 && y_angle<=45.0){ // if in fov of 90
  625. y_pos=1.0-(floattan(y_angle,degrees)+1.0)/2.0 // calulate y_pos of hudmessage
  626. if (y_pos>=0.0 && y_pos<=1.0) return y_pos
  627. }
  628. return -2.0
  629. }
  630.  
  631. public get_team(id){
  632. new team[2]
  633. get_user_team(id,team,1)
  634. switch(team[0]){
  635. case 'T':{
  636. return 1
  637. }
  638. case 'C':{
  639. return 2
  640. }
  641. case 'S':{
  642. return 3
  643. }
  644. default:{}
  645. }
  646. return 0
  647. }
  648.  
  649. // Vector Operations -------------------------------------------------------------------------------
  650.  
  651. public Float:getVecLen(Float:Vec[3]){
  652. new Float:VecNull[3]={0.0,0.0,0.0}
  653. new Float:len=vector_distance(Vec,VecNull)
  654. return len
  655. }
  656.  
  657. public Float:scalar_triple_product(Float:a[3],Float:b[3]){
  658. new Float:up[3]={0.0,0.0,1.0}
  659. new Float:Ret[3]
  660. Ret[0]=a[1]*b[2]-a[2]*b[1]
  661. Ret[1]=a[2]*b[0]-a[0]*b[2]
  662. Ret[2]=a[0]*b[1]-a[1]*b[0]
  663. return vectorProduct(Ret,up)
  664. }
  665.  
  666. public normalize(Float:Vec[3],Float:Ret[3],Float:multiplier){
  667. new Float:len=getVecLen(Vec)
  668. copyVec(Vec,Ret)
  669. Ret[0]/=len
  670. Ret[1]/=len
  671. Ret[2]/=len
  672. Ret[0]*=multiplier
  673. Ret[1]*=multiplier
  674. Ret[2]*=multiplier
  675. }
  676.  
  677. public rotateVectorZ(Float:Vec[3],Float:direction[3],Float:Ret[3]){
  678. // rotates vector about z-axis
  679. new Float:tmp[3]
  680. copyVec(Vec,tmp)
  681. tmp[2]=0.0
  682. new Float:dest_len=getVecLen(tmp)
  683. copyVec(direction,tmp)
  684. tmp[2]=0.0
  685. new Float:tmp2[3]
  686. normalize(tmp,tmp2,dest_len)
  687. tmp2[2]=Vec[2]
  688. copyVec(tmp2,Ret)
  689. }
  690.  
  691. public Float:vectorProduct(Float:Vec1[3],Float:Vec2[3]){
  692. return Vec1[0]*Vec2[0]+Vec1[1]*Vec2[1]+Vec1[2]*Vec2[2]
  693. }
  694.  
  695. public copyVec(Float:Vec[3],Float:Ret[3]){
  696. Ret[0]=Vec[0]
  697. Ret[1]=Vec[1]
  698. Ret[2]=Vec[2]
  699. }
  700.  
  701. public subVec(Float:Vec1[3],Float:Vec2[3],Float:Ret[3]){
  702. Ret[0]=Vec1[0]-Vec2[0]
  703. Ret[1]=Vec1[1]-Vec2[1]
  704. Ret[2]=Vec1[2]-Vec2[2]
  705. }
  706.  
  707. public addVec(Float:Vec1[3],Float:Vec2[3]){
  708. Vec1[0]+=Vec2[0]
  709. Vec1[1]+=Vec2[1]
  710. Vec1[2]+=Vec2[2]
  711. }
  712.  
  713. // Temporary Entities ------------------------------------------------------------------------------
  714. // there is a list of much more temp entities at: http://djeyl.net/forum/index.php?s=80ec5b9163006b5cbd0a51dd198e563a&act=Attach&type=post&id=290870
  715. // all messages are sent with MSG_ONE_UNRELIABLE flag to avoid overflow in case of very low esp_timer setting and much targets
  716.  
  717. public make_TE_BEAMPOINTS(id,color,Float:Vec1[3],Float:Vec2[3],width,target_team,brightness){
  718. message_begin(MSG_ONE_UNRELIABLE ,SVC_TEMPENTITY,{0,0,0},id) //message begin
  719. write_byte(0)
  720. write_coord(floatround(Vec1[0])) // start position
  721. write_coord(floatround(Vec1[1]))
  722. write_coord(floatround(Vec1[2]))
  723. write_coord(floatround(Vec2[0])) // end position
  724. write_coord(floatround(Vec2[1]))
  725. write_coord(floatround(Vec2[2]))
  726. write_short(laser) // sprite index
  727. write_byte(3) // starting frame
  728. write_byte(0) // frame rate in 0.1's
  729. write_byte(floatround(get_cvar_float("esp_timer")*10)) // life in 0.1's
  730. write_byte(width) // line width in 0.1's
  731. write_byte(0) // noise amplitude in 0.01's
  732. write_byte(esp_colors[color][0])
  733. write_byte(esp_colors[color][1])
  734. write_byte(esp_colors[color][2])
  735. write_byte(brightness) // brightness)
  736. write_byte(0) // scroll speed in 0.1's
  737. message_end()
  738. }
  739.  
  740. public make_TE_BEAMENTPOINT(id,Float:target_origin[3],width,target_team){
  741. message_begin(MSG_ONE_UNRELIABLE,SVC_TEMPENTITY,{0,0,0},id)
  742. write_byte(1)
  743. write_short(id)
  744. write_coord(floatround(target_origin[0]))
  745. write_coord(floatround(target_origin[1]))
  746. write_coord(floatround(target_origin[2]))
  747. write_short(laser)
  748. write_byte(1)
  749. write_byte(1)
  750. write_byte(floatround(get_cvar_float("esp_timer")*10))
  751. write_byte(width)
  752. write_byte(0)
  753. write_byte(team_colors[target_team][0])
  754. write_byte(team_colors[target_team][1])
  755. write_byte(team_colors[target_team][2])
  756. write_byte(255)
  757. write_byte(0)
  758. message_end()
  759. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement