• Portal 2 like "pointers"
    5 replies, posted
Hey, On my servers, I recently got requested to make Portal 2 like pointers for our gamemode. For those who don't know, these allow you to point anywhere in the world and "mark" it onscreen for your team mates (or partner, in Portal 2). I've done the basics (using crude NWVectors, but this is just a base and will be improved upon), but I was wondering if anyone had any further ideas to make it more Portal 2-esque. Particle effects perhaps, or entity highlighting? [lua] AddCSLuaFile("pointers.lua") if SERVER then local entities = {"prop", "func", "player", "sent", "heal" } concommand.Add("pointer", function(ply, command, args) if ply.Pointed and ply.Pointed + 10 > CurTime() then return end ply.Pointed = CurTime() ply:SetNWVector("pointer", ply:GetEyeTrace().HitPos) ply:EmitSound("buttons/button15.wav", 500, 100) if ply:GetEyeTrace().Entity then local datent = ply:GetEyeTrace.Entity for k,v in pairs(entities) do if string.find(datent:GetClass(), v) then hook.Add("Think", "DatPointer"..ply:EntIndex(), function() ply:SetNWVector("pointer", datent:GetPos()) end) end end timer.Simple(10, function() if !ply:IsValid() then return end ply:SetNWVector("pointer", Vector(0,0,0)) hook.Remove("Think", "DatPointer"..ply:EntIndex()) end) end) else hook.Add("HUDPaint", "Pointers", function() if !LocalPlayer or !LocalPlayer():IsValid() then return end for k,v in pairs(player.GetAll()) do local pos = Vector(0,0,0) if v:Team() == LocalPlayer():Team() and !(v:Team() == 50 and LocalPlayer():Team() == 50) then pos = v:GetNWVector("pointer") or Vector(0,0,0) if pos != Vector(0,0,0) then local toscreen = pos:ToScreen() if !toscreen.visible then return end local teamc = team.GetColor(v:Team()) or Color(255,255,255,255) surface.DrawCircle(toscreen.x, toscreen.y, 20, team.GetColor(v:Team()) or Color(255,255,255,155)) surface.DrawCircle(toscreen.x, toscreen.y, 21, team.GetColor(v:Team()) or Color(255,255,255,155)) surface.DrawCircle(toscreen.x, toscreen.y, 22, team.GetColor(v:Team()) or Color(255,255,255,155)) local x = toscreen.x local y = toscreen.y local gap = 4 local length = gap + 10 surface.DrawLine( x - length, y, x - gap, y ) surface.DrawLine( x + length, y, x + gap, y ) surface.DrawLine( x, y - length, x, y - gap ) surface.DrawLine( x, y + length, x, y + gap ) end end end end) local down = false hook.Add("Think", "Pointeryus", function() if input.IsKeyDown(KEY_G) then down = true else down = false end if down then LocalPlayer():ConCommand("pointer") end end) end [/lua]
Instead of checking the key press on the Think hook, can't you just use GAMEMODE:KeyPress(key)?
Does nobody read the wiki anymore? [b][url=wiki.garrysmod.com/?title=Gamemode.KeyPress]Gamemode.KeyPress [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] is only for IN_ keys, not KEY_ keys.
How are these pointers...?
[QUOTE=_NewBee;33268769]How are these pointers...?[/QUOTE] They work in the same way Portal 2 ones do, or near enough. You point at a place in the world, and it marks that location on the HUD for both you and your team mates. This is a more crude way to do it, but it was requested by someone on my server, and I liked the idea.
Looks nice... Could you make this to be used in Sandbox too? It would be awesome.
Sorry, you need to Log In to post a reply to this thread.