Shoot Through ConCommand.Add SWEP?

Hey people.

I made already a post like this a while back ago but i still couldnt find a solution for this problem.
Basicly what I’m trying to do is Shoot a Ent? (If thats the correct word for it) through concommand.add (so you type that command and it shoots the monitor) Its for admins only.

[lua]
function SWEP:throw_attack()

local player = players.GetAll()[1]
if player:IsUserGroup(“superadmin”) then

if (SERVER) then
self.Weapon:EmitSound (ShootSound2);
self.Owner:SetAnimation(PLAYER_ATTACK1)
self.Monitor = ents.Create(“monitor”)
self.Monitor:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
self.Monitor:SetAngles( self.Owner:EyeAngles() )
self.Monitor:SetPhysicsAttacker(self.Owner)
self.Monitor:SetOwner(self.Owner)
self.Monitor:Spawn()

	local phys = self.Monitor:GetPhysicsObject(); 
	local tr = self.Owner:GetEyeTrace();
	local PlayerPos = self.Owner:GetShootPos()
 
local shot_length = tr.HitPos:Length(); 
phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() *  math.pow(shot_length, 3));
phys:ApplyForceOffset(VectorRand()*math.Rand(10000,30000),PlayerPos + VectorRand()*math.Rand(0.5,1.5))

end

end
end
concommand.Add(“Shoothax”,SWEP:throw_attack)
[/lua]

Hope this is clear,

Nearly everything in the posted code is undefined. Fixed version:[LUA]concommand.Add(“Shoothax”, function(ply)
if ply:Alive() and ply:IsUserGroup(“superadmin”) then
local Mntr = ents.Create(“monitor”)
Mntr:SetPos(ply:EyePos()+ ply:GetAimVector()* 16)
Mntr:SetAngles(ply:EyeAngles())
Mntr:SetPhysicsAttacker(ply)
Mntr:SetOwner(ply)
Mntr:Spawn()
Mntr:GetPhysicsObject():ApplyForceCenter(ply:GetAimVector():GetNormalized()* math.pow(ply:GetEyeTrace().HitPos:Length(), 3))
Mntr:GetPhysicsObject():ApplyForceOffset(VectorRand()* math.Rand(10000,30000), ply:GetShootPos()+ VectorRand()* math.Rand(0.5,1.5))
ply:SetAnimation(PLAYER_ATTACK1)
ply:EmitSound(ShootSound2) – I can see that you’re a begginer in LUA so, you probably also havent defined the shoot sound.
end
end)[/LUA]

Thank you very much, but do i have to overwrite function SWEP_Throw or something like that, with this code?

Edit: The code dont work, it sees the “Shoothax” in console, but it doesnt shoot the monitor im superadmin, This is the error:

] Shoothax
Can’t find factory for entity: monitor
[@weapons\weapon_ttt_hax\shared.lua:60] Tried to use a NULL entity!

The map called “monitor” is in “gamemodes errortown\entities\entities”
Do you need the files what is in the inside of the map?

Dont put this code in a swep, put the code in an autorun, which line is line60?

And never did created anything for TTT, but this is basic code which should work for it.

Line 60:

[lua]
Mntr:SetPos(ply:EyePos()+ ply:GetAimVector()* 16)
[/lua]

Ent (line 59) :
[lua]
local Mntr = ents.Create(“monitor”)
[/lua]

Do you mean i have to put that code into a different file and then place into lua/autorun?

Yeah, console commands created on server start.

Are you sure the “monitor” is a valid Entity? Try to create it VIA console cmd “ents_create monitor” and see if it creates or not.

Well I did rcon ent_create monitor then the server crashed, it says too that i had to enable sv_cheats 1 i did that too but it still dint worked.

This is what is into the “monitor” map

shared.lua :

[lua]
ENT.Type = “anim”
ENT.PrintName = “monitor”
ENT.Author = “me”

ENT.Spawnable = false
ENT.AdminSpawnable = false
[/lua]

Init.lua

[lua]
AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)

include(‘shared.lua’)

function ENT:Initialize()
self.DieTime = CurTime() + 9

local pl = self.Entity:GetOwner()
local aimvec = pl:GetAimVector()
self.Entity.Team = pl:Team()
self.Entity:SetPos(pl:GetShootPos() + pl:GetAimVector() * 30)
self.Entity:SetAngles(pl:GetAimVector():Angle()* math.random(1,45))
self.Entity:SetModel("models/props_lab/monitor01a.mdl")
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE)
local phys = self.Entity:GetPhysicsObject()
if phys:IsValid() then
	phys:SetMass(200)
end
self.Touched = {}
self.OriginalAngles = self.Entity:GetAngles()

end

function ENT:Think()
if CurTime() > self.DieTime then
self.Entity:Remove()
end
end

function ENT:PhysicsCollide(data, phys)
local hitEnt = data.HitEntity
if (self.Entity.Hit) then return end
self.Entity.Hit = true

self.HitTime = CurTime()

	hitEnt:TakeDamage(9999, self:GetOwner(), self)

self.Entity:EmitSound(“physics/metal/metal_box_break”…math.random(1,2)…".wav")

	function self:PhysicsCollide() end

end

[/lua]

cl_init.lua

[lua]
include(“shared.lua”)

function ENT:Draw()
self.Entity:DrawModel()
end
[/lua]

Did you make the entity in the first place? And why the hell is there Ent:PhysicsCollide() being called inside a physics collide? Owner does not exist in Ent:Initialize(). It doesn’t really need the cl_init file. Allot of thing are wrong with it, like why are you setting the entity’s angles on initialize? But its not crucial for the entity to work, so irrelevant to this thread. Probably should start by not calling the physicsCollide, thats a bit out of the ordinary, so might be whats causing the ent to be blocked.

No i dint make this, its a SWEP from garrysmod.org

So yeah I personally dont know what to change over there,

Any ideas how to fix this? :expressionless:

bump

Any help? Its still unresloved :l

Warning: This may be wrong, but I am just trying to help
If you want to make the HAXX weapon shoot through a console command can’t you just add
[lua]
concommand.Add(“shoothax”, SWEP:Primary)
[/lua]

If the weapon hasn’t been pulled out yet the cmd wont even exist and once its holstered it’ll most likely brake.

So far I know it haves to do something with Ent’s right? Freemaan gave me a idea what to do with the Init.lua file but that dint worked :l

Make my code launch some other entity, like prop_physics to see if it works, the problem is that the monitor entity gets blocked for some reason…

Well im not home at the moment but will do that when im home in about… 4 hours then ill post if that worked or not, Thanks for the advice :slight_smile:

Doesnt work this is the error:

] Shoothax
[weapons\weapon_ttt_hax\shared.lua:62] attempt to call method ‘SetPhysicsAttacker’ (a nil value)

Full code:

[lua]
resource.AddFile( “sound/weapons/hacks01.wav” )

SWEP.Author = “Kwigg, updated by NECROSSIN”;
SWEP.Contact = “”;
SWEP.Purpose = “Cheaters?”;
SWEP.Instructions = “Remember to turn on sv_cheats.”;

SWEP.Base = “weapon_tttbase”

SWEP.Spawnable = false;
SWEP.AdminSpawnable = true;

SWEP.ViewModel = “models/Weapons/v_pfinger.mdl”;
SWEP.WorldModel = “models/props_lab/monitor01a.mdl”;
SWEP.ViewModelFOV = 95

SWEP.Primary.ClipSize = -1;
SWEP.Primary.DefaultClip = -1;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = “none”;

local ShootSound = Sound (“weapons/hacks01.wav”);
local ShootSound2 = Sound (“weapons/iceaxe/iceaxe_swing1.wav”);
local ScoutSound = Sound (“vo/scout_jeers04.wav”);

function SWEP:Deploy()
self.Owner:DrawViewModel(false)
self.Owner:DrawWorldModel(false)
end

function SWEP:Reload()

end

function SWEP:Initialize()
self.ActivityTranslate = {}
self.ActivityTranslate[ACT_HL2MP_IDLE] = ACT_HL2MP_IDLE_MELEE
self.ActivityTranslate[ACT_HL2MP_WALK] = ACT_HL2MP_WALK_MELEE
self.ActivityTranslate[ACT_HL2MP_RUN] = ACT_HL2MP_RUN_MELEE
self.ActivityTranslate[ACT_HL2MP_IDLE_CROUCH] = ACT_HL2MP_IDLE_MELEE
self.ActivityTranslate[ACT_HL2MP_WALK_CROUCH] = ACT_HL2MP_WALK_CROUCH_MELEE
self.ActivityTranslate[ACT_HL2MP_GESTURE_RANGE_ATTACK] = ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE
self.ActivityTranslate[ACT_HL2MP_GESTURE_RELOAD] = ACT_HL2MP_GESTURE_RELOAD_MELEE
self.ActivityTranslate[ACT_HL2MP_JUMP] = ACT_HL2MP_JUMP_MELEE
self.ActivityTranslate[ACT_RANGE_ATTACK1] = ACT_RANGE_ATTACK_MELEE
end

function SWEP:Think()
end

concommand.Add(“Shoothax”, function(ply)
if ply:Alive() and ply:IsUserGroup(“superadmin”) then
local Mntr = ents.Create(“prop_physics”)
Mntr:SetPos(ply:EyePos()+ ply:GetAimVector()* 16)
Mntr:SetAngles(ply:EyeAngles())
Mntr:SetPhysicsAttacker(ply)
Mntr:SetOwner(ply)
Mntr:Spawn()
Mntr:GetPhysicsObject():ApplyForceCenter(ply:GetAimVector():GetNormalized()* math.pow(ply:GetEyeTrace().HitPos:Length(), 3))
Mntr:GetPhysicsObject():ApplyForceOffset(VectorRand()* math.Rand(10000,30000), ply:GetShootPos()+ VectorRand()* math.Rand(0.5,1.5))
ply:SetAnimation(PLAYER_ATTACK1)
ply:EmitSound(ShootSound) – I can see that you’re a begginer in LUA so, you probably also havent defined the shoot sound.
end
end)

function SWEP:PrimaryAttack()

self.Weapon:EmitSound (ShootSound);
self.Owner:DrawViewModel(true)
self.Weapon:SetNextPrimaryFire( CurTime() + 5 )
timer.Create("HAX", 1.01, 1, function()
self.Owner:DrawViewModel(false)
self:throw_attack() 
end )
timer.Simple(1.02, game.ConsoleCommand, "host_timescale 0.03

")
timer.Simple(1.03, game.ConsoleCommand, "pp_motionblur 1
")
timer.Simple(1.3, game.ConsoleCommand, "pp_motionblur 0
")
timer.Simple(1.3, game.ConsoleCommand, "host_timescale 1
")
end

function SWEP:SecondaryAttack()
self.Weapon:SetNextSecondaryFire( CurTime() + 4 )
local tr = self.Owner:GetEyeTrace();
if tr.Entity:IsNPC() or tr.Entity:IsPlayer() then
tr.Entity:EmitSound (ScoutSound)
end
end
[/lua]

You have to give prop_physics a model before spawning.

So it would be :

[lua]
concommand.Add(“Shoothax”, function(ply)
if ply:Alive() and ply:IsUserGroup(“superadmin”) then
local Mntr = ents.Create(“prop_physics”)
Mntr:SetPos(ply:EyePos()+ ply:GetAimVector()* 16)
Mntr:SetAngles(ply:EyeAngles())
Mntr:SetPhysicsAttacker(ply)
Mntr:SetOwner(ply)
Mntr:SetModel(“models/props_c17/oildrum001.mdl”)
Mntr:Spawn()
Mntr:GetPhysicsObject():ApplyForceCenter(ply:GetAimVector():GetNormalized()* math.pow(ply:GetEyeTrace().HitPos:Length(), 3))
Mntr:GetPhysicsObject():ApplyForceOffset(VectorRand()* math.Rand(10000,30000), ply:GetShootPos()+ VectorRand()* math.Rand(0.5,1.5))
ply:SetAnimation(PLAYER_ATTACK1)
ply:EmitSound(ShootSound) – I can see that you’re a begginer in LUA so, you probably also havent defined the shoot sound.
end
end)
[/lua]

?

Edit: Tried the code above, still same error:

] Shoothax
[weapons\weapon_ttt_hax\shared.lua:62] attempt to call method ‘SetPhysicsAttacker’ (a nil value)