• ConCommand Question?
    22 replies, posted
Hey guys, I founded this code at toybox in Gmod, [lua] if CLIENT then SWEP.PrintName = "Haax!" SWEP.Author = "Otger" SWEP.Contact = "" SWEP.Purpose = "Throw monitors at your enemies! Based on the 'The Gmod Idiot Box' YouTube series by DasBoSchitt." SWEP.Instructions = "Left click to shoot a monitor. Right click to attack with the spawned monitors. Reload to open the menu." SWEP.Slot = 1 SWEP.SlotPos = 3 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true end SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.ViewModel = "models/weapons/V_hands.mdl" SWEP.WorldModel = "models/props_junk/PopCan01a.mdl" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.SndSpawn = Sound("vo/npc/male01/herecomehacks01.wav") SWEP.SndHaax = Sound("vo/npc/male01/hacks01.wav") util.PrecacheModel("models/props_lab/monitor01a.mdl") util.PrecacheModel("models/props_lab/monitor02.mdl") if SERVER then if !HaaxSettings then HaaxSettings = {} HaaxSettings.Grav = false HaaxSettings.DmgSelf = true HaaxSettings.RndMdl = false end concommand.Add("HaaxConfig", function(ply,cmd,args) local wep = Entity(tonumber(args[1])) if ValidEntity(wep) && wep.IsHaaxSWEP then if (ply == wep.Owner) && ply:IsAdmin() then wep:HaaxUpdateGravity(tobool(args[2])) HaaxSettings.DmgSelf = tobool(args[3]) wep:HaaxUpdateModels(tobool(args[4])) end end end) concommand.Add("HaaxClear", function(ply,cmd,args) local wep = Entity(tonumber(args[1])) if ValidEntity(wep) && wep.IsHaaxSWEP then if (ply == wep.Owner) && ply:IsAdmin() then wep:HaaxClear() end end end) local function HaaxOverrideDamage(ent,inflictor,attacker,amount,dmginfo) if inflictor:GetClass() == "prop_haax" && ValidEntity(inflictor.SWEP) then if ent:IsPlayer() then if (inflictor.HaaxOwner == ent) && !HaaxSettings.DmgSelf then dmginfo:SetDamage(0) end end end end hook.Add("EntityTakeDamage", "HaaxOverrideDamage", HaaxOverrideDamage) function SWEP:HaaxClear() local props = ents.FindByClass("prop_haax") if table.Count(props) > 0 then SendUserMessage("HaaxClear", self.Owner) for _,ent in pairs(props) do if ValidEntity(ent) && ValidEntity(ent.HaaxOwner) && (ent.HaaxOwner == self.Owner) then ent:Remove() end end end end function SWEP:HaaxUpdateGravity(bGrav) if HaaxSettings.Grav ~= bGrav then local props = ents.FindByClass("prop_haax") if table.Count(props) > 0 then for _,ent in pairs(props) do if ValidEntity(ent) && ValidEntity(ent.HaaxOwner) && (ent.HaaxOwner == self.Owner) then ent:GetPhysicsObject():EnableGravity(bGrav) end end end end HaaxSettings.Grav = bGrav end function SWEP:HaaxUpdateModels(bNotRandom) if HaaxSettings.RndMdl ~= bNotRandom then local props = ents.FindByClass("prop_haax") if table.Count(props) > 0 then for _,ent in pairs(props) do if ValidEntity(ent) && ValidEntity(ent.HaaxOwner) && (ent.HaaxOwner == self.Owner) then if bNotRandom then if ent:GetModel() ~= "models/props_lab/monitor01a.mdl" then ent:SetModel("models/props_lab/monitor01a.mdl") end else if math.random(3) == 1 then ent:SetModel("models/props_lab/monitor01a.mdl") else ent:SetModel("models/props_lab/monitor02.mdl") ent:SetSkin(math.random(3)) end end end end end end HaaxSettings.RndMdl = bNotRandom end end if CLIENT then local HaaxSndRemove = Sound("buttons/button15.wav") killicon.AddFont("prop_haax", "HL2MPTypeDeath", "9", Color(160,160,128,255)) language.Add("prop_haax", "Haax!") usermessage.Hook("HaaxClear",function(um) GAMEMODE:AddNotify("Removed Haax Monitors", NOTIFY_UNDO, 4) LocalPlayer():EmitSound(HaaxSndRemove) end) usermessage.Hook("HaaxMenu",function(um) local wep = LocalPlayer():GetActiveWeapon() if wep && wep.IsHaaxSWEP then local tData = string.Explode(",",um:ReadString()) wep:MenuOpen(tData) end end) function SWEP:MenuCreate() if self.Menu then self.Menu:SetVisible(false) self.Menu:Remove() end self.Menu = vgui.Create("DFrame") self.Menu:SetName("HaaxMenu") self.Menu:SetTitle("Haax! - Settings") self.Menu:SetDraggable(true) self.Menu:ShowCloseButton(true) self.Menu:SetDeleteOnClose(false) self.Menu:SetSize(256,192) self.Menu:SetVisible(false) self.Menu.ChkGrav = vgui.Create("DCheckBoxLabel", self.Menu) self.Menu.ChkGrav:SetPos(16,32) self.Menu.ChkGrav:SetText("Enable gravity") self.Menu.ChkGrav:SetTooltip("If checked, the monitors will be affected by the gravity.") self.Menu.ChkGrav:SizeToContents() self.Menu.ChkDmgSelf = vgui.Create("DCheckBoxLabel", self.Menu) self.Menu.ChkDmgSelf:SetPos(16,64) self.Menu.ChkDmgSelf:SetText("Damage owner") self.Menu.ChkDmgSelf:SetTooltip("If checked, the monitors will inflict damage to their owner.") self.Menu.ChkDmgSelf:SizeToContents() self.Menu.ChkRndMdl = vgui.Create("DCheckBoxLabel", self.Menu) self.Menu.ChkRndMdl:SetPos(16,96) self.Menu.ChkRndMdl:SetText("Disable random models") self.Menu.ChkRndMdl:SetTooltip("If checked, all the monitors will have the default model. (Use it in case you see missing textures)") self.Menu.ChkRndMdl:SizeToContents() self.Menu.BtnClear = vgui.Create("DButton", self.Menu) self.Menu.BtnClear:SetText("Remove monitors") self.Menu.BtnClear:SetPos(16,128) self.Menu.BtnClear:SetSize(224,24) self.Menu.BtnClear.SWEP = self self.Menu.BtnClear.DoClick = function(button) RunConsoleCommand("HaaxClear", button.SWEP:EntIndex()) button.SWEP.Menu:SetVisible(false) end self.Menu.BtnSave = vgui.Create("DButton", self.Menu) self.Menu.BtnSave:SetText("Apply settings") self.Menu.BtnSave:SetPos(16,160) self.Menu.BtnSave:SetSize(224,24) self.Menu.BtnSave.SWEP = self self.Menu.BtnSave.DoClick = function(button) RunConsoleCommand("HaaxConfig", button.SWEP:EntIndex(), tostring(button.SWEP.Menu.ChkGrav:GetChecked()), tostring(button.SWEP.Menu.ChkDmgSelf:Get
Yep, look at line 41 of that code you pasted. Same idea.
[QUOTE=MisterTickles;28541931]Yep, look at line 41 of that code you pasted. Same idea.[/QUOTE] But that dont trigger to shoot a monitor right? What i exacly mean is that it shoots a monitor when u enter a command but you need to be admin to use it. Sorry, quite new with this command.
Anybody?
You have to code it.
Yeah but where? I mean the code of shooting something though command, never made something like that before
Too busy right now to do it myself. But this is what you would do.. [lua] concommand.Add("HaxShoot", function(ply,cmd,args) //code for spawning a monitor and shooting it? end) [/lua] The code for it is in the swep. Just find it. Code doesn't go in a clientside file.
[QUOTE=Brandan;28550667]Too busy right now to do it myself. But this is what you would do.. [lua] concommand.Add("HaxShoot", function(ply,cmd,args) //code for spawning a monitor and shooting it? end) [/lua] The code for it is in the swep. Just find it. Code doesn't go in a clientside file.[/QUOTE] So it would be: [lua] concommand.Add("HaxShoot", function(ply,cmd,args) if (!SERVER) then return end if ply:IsAdmin then self:EmitSound(self.SndHaax) local tr = self.Owner:GetEyeTrace() local ent = ents.Create("prop_haax") ent:SetPos(self.Owner:EyePos()+self.Owner:GetAimVector()*(16+self.Owner:GetVelocity():Length()/64)) ent:SetAngles(self.Owner:EyeAngles()) ent.HaaxOwner = self.Owner ent.SWEP = self ent:Spawn() local phys = ent:GetPhysicsObject() if phys:IsValid() then local dist = tr.HitPos:Distance(self.Owner:GetPos()) phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized()*math.pow(dist,3)) end cleanup.Add(self.Owner, "props", ent) undo.Create("HaaxMonitor") undo.AddEntity(ent) undo.SetPlayer(self.Owner) undo.SetCustomUndoText("Undone Haax Monitor") undo.Finish() self.Owner:DoAttackEvent() self.Weapon:SetNextPrimaryFire(CurTime()+0.2) end) [/lua] Maybe a stupid question but where am i suppose to put this shared.lua, Just in lua/weapons ?
The code your using is a console command. Not a swep. Unless you put the code there. It would go in lua/autorun or something of the sorts. Oh, and at the top of the code you should put [lua] self=ply self.Owner=ply [/lua] and remove line 32 and 31. edit: [lua] concommand.Add("HaxShoot", function(ply,cmd,args) if (!SERVER) then return end self=ply self.Owner=ply if ply:IsAdmin then self:EmitSound(self.SndHaax) local tr = self.Owner:GetEyeTrace() local ent = ents.Create("prop_haax") ent:SetPos(self.Owner:EyePos()+self.Owner:GetAimVector()*(16+self.Owner:GetVelocity():Length()/64)) ent:SetAngles(self.Owner:EyeAngles()) ent.HaaxOwner = ply ent.SWEP = self ent:Spawn() local phys = ent:GetPhysicsObject() if phys:IsValid() then local dist = tr.HitPos:Distance(self.Owner:GetPos()) phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized()*math.pow(dist,3)) end cleanup.Add(self.Owner, "props", ent) undo.Create("HaaxMonitor") undo.AddEntity(ent) undo.SetPlayer(self.Owner) undo.SetCustomUndoText("Undone Haax Monitor") undo.Finish() end) [/lua]
[QUOTE=Brandan;28552078]The code your using is a console command. Not a swep. Unless you put the code there. It would go in lua/autorun or something of the sorts. Oh, and at the top of the code you should put [lua] self=ply self.Owner=ply [/lua] and remove line 32 and 31. edit: [lua] concommand.Add("HaxShoot", function(ply,cmd,args) if (!SERVER) then return end self=ply self.Owner=ply if ply:IsAdmin then self:EmitSound(self.SndHaax) local tr = self.Owner:GetEyeTrace() local ent = ents.Create("prop_haax") ent:SetPos(self.Owner:EyePos()+self.Owner:GetAimVector()*(16+self.Owner:GetVelocity():Length()/64)) ent:SetAngles(self.Owner:EyeAngles()) ent.HaaxOwner = ply ent.SWEP = self ent:Spawn() local phys = ent:GetPhysicsObject() if phys:IsValid() then local dist = tr.HitPos:Distance(self.Owner:GetPos()) phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized()*math.pow(dist,3)) end cleanup.Add(self.Owner, "props", ent) undo.Create("HaaxMonitor") undo.AddEntity(ent) undo.SetPlayer(self.Owner) undo.SetCustomUndoText("Undone Haax Monitor") undo.Finish() end) [/lua][/QUOTE] I have placed the LUA in lua\autorun\server and there it seemed like to see the LUA file, In autorun it dint worked. But it gave this error: [lua/autorun/server/hax.lua:132] function arguments expected near "then" This is final code: [lua] if CLIENT then SWEP.PrintName = "Haax!" SWEP.Author = "Otger" SWEP.Contact = "" SWEP.Purpose = "Throw monitors at your enemies! Based on the 'The Gmod Idiot Box' YouTube series by DasBoSchitt." SWEP.Instructions = "Left click to shoot a monitor. Right click to attack with the spawned monitors. Reload to open the menu." SWEP.Slot = 1 SWEP.SlotPos = 3 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true end SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.ViewModel = "models/weapons/V_hands.mdl" SWEP.WorldModel = "models/props_junk/PopCan01a.mdl" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.SndSpawn = Sound("vo/npc/male01/herecomehacks01.wav") SWEP.SndHaax = Sound("vo/npc/male01/hacks01.wav") util.PrecacheModel("models/props_lab/monitor01a.mdl") util.PrecacheModel("models/props_lab/monitor02.mdl") if SERVER then if !HaaxSettings then HaaxSettings = {} HaaxSettings.Grav = false HaaxSettings.DmgSelf = true HaaxSettings.RndMdl = false end concommand.Add("HaaxConfig", function(ply,cmd,args) local wep = Entity(tonumber(args[1])) if ValidEntity(wep) && wep.IsHaaxSWEP then if (ply == wep.Owner) && ply:IsAdmin() then wep:HaaxUpdateGravity(tobool(args[2])) HaaxSettings.DmgSelf = tobool(args[3]) wep:HaaxUpdateModels(tobool(args[4])) end end end) concommand.Add("HaaxClear", function(ply,cmd,args) local wep = Entity(tonumber(args[1])) if ValidEntity(wep) && wep.IsHaaxSWEP then if (ply == wep.Owner) && ply:IsAdmin() then wep:HaaxClear() end end end) local function HaaxOverrideDamage(ent,inflictor,attacker,amount,dmginfo) if inflictor:GetClass() == "prop_haax" && ValidEntity(inflictor.SWEP) then if ent:IsPlayer() then if (inflictor.HaaxOwner == ent) && !HaaxSettings.DmgSelf then dmginfo:SetDamage(0) end end end end hook.Add("EntityTakeDamage", "HaaxOverrideDamage", HaaxOverrideDamage) function SWEP:HaaxClear() local props = ents.FindByClass("prop_haax") if table.Count(props) > 0 then SendUserMessage("HaaxClear", self.Owner) for _,ent in pairs(props) do if ValidEntity(ent) && ValidEntity(ent.HaaxOwner) && (ent.HaaxOwner == self.Owner) then ent:Remove() end end end end function SWEP:HaaxUpdateGravity(bGrav) if HaaxSettings.Grav ~= bGrav then local props = ents.FindByClass("prop_haax") if table.Count(props) > 0 then for _,ent in pairs(props) do if ValidEntity(ent) && ValidEntity(ent.HaaxOwner) && (ent.HaaxOwner == self.Owner) then ent:GetPhysicsObject():EnableGravity(bGrav) end end end end HaaxSettings.Grav = bGrav end function SWEP:HaaxUpdateModels(bNotRandom) if HaaxSettings.RndMdl ~= bNotRandom then local props = ents.FindByClass("prop_haax") if table.Count(props) > 0 then for _,ent in pairs(props) do if ValidEntity(ent) && ValidEntity(ent.HaaxOwner) && (ent.HaaxOwner == self.Owner) then if bNotRandom then if ent:GetModel() ~= "models/props_lab/monitor01a.mdl" then ent:SetModel("models/props_lab/monitor01a.mdl") end else if math.random(3) == 1 then ent:SetModel("models/props_lab/monitor01a.mdl") else ent:SetModel("models/props_lab/monitor02.mdl") ent:SetSkin(math.random(3)) end end end end end end HaaxSettings.RndMdl = bNotRandom end end concommand.Add("ttt_hax", function(ply,cmd,args) if (!SERVER) then return end self=ply self.Owner=ply if ply:IsAdmin then self:EmitSound(self.SndHaax) local tr = self.Owner:GetEyeTrace() local ent = ents.Create("prop_haax") ent:SetPos(self.Owner:EyePos()+self.Owner:GetAimVector()*(16+self.Owner:GetVelocity():Length()/64)) ent:SetAngles(self.Owner:EyeAngles()) ent.HaaxOwner = ply ent.SWEP = self ent:Spawn() local phys = ent:GetPhysicsObject() if phys:IsValid() then local dist = tr.HitPos:Distance(self.Owner:GetPos()) phys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized()*math.pow(dist,3)) end cleanup.Add(self.Owner, "props", ent) undo.Create("HaaxMonitor") undo.AddEntity(ent) undo.SetPlayer(self.Owner) undo.SetCustomUndoText("Undone Haax Monitor") undo.Finish() end) if CLIENT then local HaaxSndRemove = Sound("buttons/button15.wav") killicon.AddFont("prop_haax", "HL2MPTypeDeath", "9", Color(160,160,128,255)) language.Add("prop_haax", "Haax!") usermessage.Hook("HaaxClear",function(um) GAMEMODE:AddNotify("Removed Haax Monitors", NOTIFY_UNDO, 4) LocalPlayer():EmitSound(HaaxSndRemove) end) usermessage.Hook("HaaxMenu",function(um) local wep = LocalPlayer():GetActiveWeapon() if wep && wep.IsHaaxSWEP then local tData = string.Explode(",",um:ReadString()) wep:MenuOpen(tData) end end) function SWEP:MenuCreate() if self.Menu then self.Menu:SetVisible(false) self.Menu:Remove() end self.Menu = vgui.Create("DFrame") self.Menu:SetName("HaaxMenu") self.Menu:SetTitle("Haax! - Settings") self.Menu:SetDraggable(true) self.Menu:ShowCloseButton(true) self.Menu:SetDeleteOnClose(false) self.Menu:SetSize(256,192) self.Menu:SetVisible(false) self.
It's IsAdmin()
-snip-
[QUOTE=Persious;28553643]It's IsAdmin()[/QUOTE] That dint work either [editline]12th March 2011[/editline] Anybody know how i can fix this? :l
Try reading the errors, fixing them. You have a lot of errors in that code.
[QUOTE=Drew P. Richard;28567564]Try reading the errors, fixing them. You have a lot of errors in that code.[/QUOTE] But it doesnt give a LUA error only the one i showed a few posts above?
Are you running this locally or on a server?
Locally for test, it goes on my server when its completely optimized and finished etc.
You should be seeing errors then.
[QUOTE=Drew P. Richard;28571447]You should be seeing errors then.[/QUOTE] Nope only the error what i had above, but i dont want it as SWEP i want it as that it shoots the monitor through command eg. ttt_hax or shoothax
You have a lot of errors in the code you posted.
[QUOTE=Drew P. Richard;28575232]You have a lot of errors in the code you posted.[/QUOTE] how about this? [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.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 function SWEP:throw_attack() 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 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\n") timer.Simple(1.03, game.ConsoleCommand, "pp_motionblur 1\n") timer.Simple(1.3, game.ConsoleCommand, "pp_motionblur 0\n") timer.Simple(1.3, game.ConsoleCommand, "host_timescale 1\n") 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]
I thought you didn't want a SWEP...
[QUOTE=Drew P. Richard;28583609]I thought you didn't want a SWEP...[/QUOTE] Yeah but i need this base for the command to work right?
Sorry, you need to Log In to post a reply to this thread.