Advertisement
errur

ui.nut

Mar 15th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. ScriptPrintMessageChatAll("Registered game_ui");
  2.  
  3. self.ConnectOutput("PressedAttack", "PressedAttack");
  4. self.ConnectOutput("UnpressedAttack", "UnpressedAttack");
  5.  
  6. player <- null;
  7. tracker <- null;
  8.  
  9. DoIncludeScript("VUtil", null);
  10.  
  11. function OnPostSpawn()
  12. {
  13.    
  14. }
  15.  
  16. class TraceInfo
  17. {
  18.     constructor(h,d)
  19.     {
  20.         Hit = h;
  21.         Dist = d;
  22.     }
  23.  
  24.     Hit = null;
  25.     Dist = null;
  26. }
  27.  
  28. //Returns the hit position of a trace along a normalized direction vector.
  29. function TraceDir(orig, dir, maxd, filter)
  30. {
  31.     local frac = TraceLine(orig,orig+dir*maxd,filter);
  32.     if(frac == 1.0) { return TraceInfo(orig+(dir*maxd),0.0);}
  33.     return TraceInfo(orig+(dir*(maxd*frac)),maxd*frac);
  34. }
  35.  
  36. function PressedAttack()
  37. {      
  38.     if((player == null) || (tracker == null))
  39.     {
  40.         player <- activator;       
  41.         tracker <- VUtil.Player.CreateEye(player);     
  42.     }
  43.     printl("+attack called by " + player); 
  44.    
  45.     local trace = TraceDir(player.EyePosition()-Vector(0,0,10),tracker.GetForwardVector(),46341.0,player); //Cast a ray from the player's eyes in the direction they are looking   
  46.     /*exp <- Entities.CreateByClassname("env_explosion");
  47.     exp.__KeyValueFromInt("iMagnitude", 1000);
  48.     exp.__KeyValueFromInt("iRadiusOverride", 100);
  49.     exp.__KeyValueFromInt("SpawnFlags", 16);
  50.     exp.SetOrigin(trace.Hit);
  51.     exp.SetOwner(player);
  52.     EntFireByHandle(exp, "Explode", "", 0, player, player);*/
  53.     ent <- null;
  54.     if((ent = Entities.FindByClassnameNearest("player", trace.Hit, 100)) != null)
  55.     {
  56.         if(ent == player)
  57.         {
  58.             player.SetOrigin(player.GetOrigin() + Vector(0,0,2));
  59.             player.SetVelocity(player.GetVelocity() + Vector(0,0,200));
  60.         }
  61.         else
  62.         {
  63.             EntFireByHandle(ent, "SetHealth", "0", 0, player, player);
  64.         }
  65.     }
  66.     DispatchParticleEffect("weapon_muzzle_flash_taser", trace.Hit, trace.Hit);
  67.     DebugDrawLine(player.EyePosition(), trace.Hit, 255, 10, 10, false, 5);
  68.    
  69. }
  70. function UnpressedAttack()
  71. {  
  72.     printl("-attack called by " + player);
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement