Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ScriptPrintMessageChatAll("Registered game_ui");
- self.ConnectOutput("PressedAttack", "PressedAttack");
- self.ConnectOutput("UnpressedAttack", "UnpressedAttack");
- player <- null;
- tracker <- null;
- DoIncludeScript("VUtil", null);
- function OnPostSpawn()
- {
- }
- class TraceInfo
- {
- constructor(h,d)
- {
- Hit = h;
- Dist = d;
- }
- Hit = null;
- Dist = null;
- }
- //Returns the hit position of a trace along a normalized direction vector.
- function TraceDir(orig, dir, maxd, filter)
- {
- local frac = TraceLine(orig,orig+dir*maxd,filter);
- if(frac == 1.0) { return TraceInfo(orig+(dir*maxd),0.0);}
- return TraceInfo(orig+(dir*(maxd*frac)),maxd*frac);
- }
- function PressedAttack()
- {
- if((player == null) || (tracker == null))
- {
- player <- activator;
- tracker <- VUtil.Player.CreateEye(player);
- }
- printl("+attack called by " + player);
- 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
- /*exp <- Entities.CreateByClassname("env_explosion");
- exp.__KeyValueFromInt("iMagnitude", 1000);
- exp.__KeyValueFromInt("iRadiusOverride", 100);
- exp.__KeyValueFromInt("SpawnFlags", 16);
- exp.SetOrigin(trace.Hit);
- exp.SetOwner(player);
- EntFireByHandle(exp, "Explode", "", 0, player, player);*/
- ent <- null;
- if((ent = Entities.FindByClassnameNearest("player", trace.Hit, 100)) != null)
- {
- if(ent == player)
- {
- player.SetOrigin(player.GetOrigin() + Vector(0,0,2));
- player.SetVelocity(player.GetVelocity() + Vector(0,0,200));
- }
- else
- {
- EntFireByHandle(ent, "SetHealth", "0", 0, player, player);
- }
- }
- DispatchParticleEffect("weapon_muzzle_flash_taser", trace.Hit, trace.Hit);
- DebugDrawLine(player.EyePosition(), trace.Hit, 255, 10, 10, false, 5);
- }
- function UnpressedAttack()
- {
- printl("-attack called by " + player);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement