Two Questions

I have two questions.

  1. How would I go about executing a con command through Lua?

  2. How can I check if what I’m aiming at is a player/NPC/Bot.

1. ply:ConCommand(“command_here”) or for the server, game.ConsoleCommand("command_here
")

1) Serverside:
**[Player.ConCommand

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Player.ConCommand)**(executes the command on a player)
**[Game.ConsoleCommand

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Game.ConsoleCommand)**(executes the command on the server)
Clientside:
RunConsoleCommand(“say”, “Hello, I didn’t type this.”)
2)
[lua]
if(ply:IsNPC()) then /* Do something / end
[/lua]
[lua]
if(ply:IsPlayer()) then /
Do something / end
[/lua]
[lua]
if(ply:IsBot()) then /
do something */ end
[/lua]

What you said for 2 doesn’t make sense to me. Wouldn’t that check if you are a bot/player/npc?

[lua]
local tr = ply:GetEyeTrace()
if( tr.HitNonWorld ) then
if( tr.Entity:IsPlayer() ) then
local e = tr.Entity
e:Kill()
end
end
[/lua]

Not an aim trace, but it’s close enough, unless you’re wanting it for a gun?

Basicly I want to have it so when my crosshairs are over a living thing it shoots automatically.

There’s not many ways you can explain to us that you’re not trying to create an aimbot or anything related to an aimbot.

This

He wants to make a gun that automatically shoots when it’s crosshairs are over an NPC/bot\player.
(Would probably be pretty useful in a gunfight :v:)

I am trying to make a triggerbot, NOT an aimbot. And it’s not like I’m planning on giving it out. That would ruin gun related game modes.


shoot = 0

function ShootON()
	shoot = 1
end

concommand.Add("+shoot", ShootON)

function ShootOFF()
	shoot = 0
end

concommand.Add("-shoot", ShootOFF)

function myMainFunc()
	local ply = LocalPlayer()
	local tr = ply:GetEyeTrace()  
	if tr.HitNonWorld then  
		if tr.Entity:IsPlayer() or tr.Entity:IsNPC() then
			if shoot == 1 then
				ply:ConCommand("+attack")
				ply:ConCommand("-attack")
			end
		end  
	end
end 

hook.Add("HUDPaint","Pingas1", myMainFunc)

What am I doing wrong?

[lua]
ply:ConCommand("+attack")
ply:ConCommand("-attack")
[/lua]

You can’t run them that fast, you need small intervals between them, I suggest using a Think hook instead of a HUDPaint hook.

[lua]
ply:ConCommand("+attack")
timer.Simple(0.0001, function() ply:ConCommand("-attack") end)
– blah blah
hook.Add(“Think”,“Pingas1”, myMainFunc)
[/lua]

Timer is just a wrapper using the Think hook, so it can only run every 0.006 seconds or so right?