[QUOTE=Keosan;48271592][LUA]local Equipment = nil
function GetEquipmentForRole(role)
-- need to build equipment cache?
if not Equipment then
-- start with all the non-weapon goodies
local tbl = table.Copy(EquipmentItems)
-- find buyable weapons to load info from
for k, v in pairs(weapons.GetList()) do
if v and v.CanBuy then
local data = v.EquipMenuData or {}
local base = {
id = WEPS.GetClass(v),
name = v.PrintName or "Unnamed",
limited = v.LimitedStock,
kind = v.Kind or WEAPON_NONE,
slot = (v.Slot or 0) + 1,
material = v.Icon or "vgui/ttt/icon_id",
-- the below should be specified in EquipMenuData, in which case
-- these values are overwritten
type = "Type not specified",
model = "models/weapons/w_bugbait.mdl",
desc = "No description specified."
};
-- Force material to nil so that model key is used when we are
-- explicitly told to do so (ie. material is false rather than nil).
if data.modelicon then
base.material = nil
end
table.Merge(base, data)
-- add this buyable weapon to all relevant equipment tables
for _, r in pairs(v.CanBuy) do
table.insert(tbl[r], base)
end
end
end
[/LUA]
PORTION OF CODE ^
[LUA][ERROR] gamemodes/terrortown/gamemode/cl_equip.lua:44: bad argument #1 to 'insert' (table expected, got nil)
1. insert - [C]:-1
2. GetEquipmentForRole - gamemodes/terrortown/gamemode/cl_equip.lua:44
3. unknown - gamemodes/terrortown/gamemode/cl_equip.lua:218
4. unknown - lua/includes/modules/concommand.lua:54[/LUA]
Heres my issue, Upon pressing C as a Traitor i get this error ^ and the T menu popups(but i cannot close it) and the menu has nothing in it. From what I THINK it seems, GetEquipmentForRole isn't defined(or it doesn't know what role i am and doesn't know what to grab). I have little to no experience in LUA and would appreciate some help! For those who are interested in seeing the full code([url]https://raw.githubusercontent.com/garrynewman/garrysmod/master/garrysmod/gamemodes/terrortown/gamemode/cl_equip.lua[/url])[/QUOTE]
I still need help. I added Pointshop 2 and Prometheus donations and it started giving me this error.
Can someone please explain to me the difference between a gamemode/contents for model paths versus the root model folder (garrysmod/garrysmod/models). I had an entity (npc) that would spawn invisible because it used the root path instead of the path I directed in my init.lua file when I called it.
[QUOTE=Becomeimp;48257070]Whenever I spawn an object as an entity, it doesn't have it's multiple skins or animations. If I spawn the model itself from the spawn menu then it does. Is there something needed in the Lua to effectively "load in" its resources?[/QUOTE]
this is almost 2 pages back now so i'm gonna bump it.
Basically if I SetSkin to anything other than 0, let's say 2, it still shows up as the first skin. But if I right-click it, I can see that Skin 2 is checked!
Is it possible to define a custom click-bounds function for a Derma element? I want to create a circular DButton (not just visually).
how can i clamping vectors?
i making projectile (need to limiting pos)
[lua]
function PROJ:onSpawn()
-- ...
self.minPos = self:getPos()
self.maxPos = self:getPos() + self:getOwner():GetAimVector() * self.range
-- ...
end
function PROJ:onUpdate()
-- ...
self.clamp = self.clamp + (self:getVelocity() * self.speed) * dt
self.clamp.x = math.Clamp(self.clamp.x, self.minPos.x, self.maxPos.x)
self.clamp.y = math.Clamp(self.clamp.y, self.minPos.y, self.maxPos.y)
self.clamp.z = math.Clamp(self.clamp.z, self.minPos.z, self.maxPos.z)
self:setPos(self.clamp)
-- ...
end
[/lua]
this code half work but subtracted vectors not working..(x, y, z)
result image
[url]http://images.akamai.steamusercontent.com/ugc/445079817133070350/EE3C5969032A7EE1B83019A14E67C7D0AED72977/[/url]
How exactly do you use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/InputMouseApply]GM/InputMouseApply[/url]?
I wanted to invert the X and Y when the mouse moves.
Hey guys, I have a question. How do I allow scrolling of a DPaneList without showing a scrollbar?
[QUOTE=liqob;48294682]Hey guys, I have a question. How do I allow scrolling of a DPaneList without showing a scrollbar?[/QUOTE]
Hide the scrollbar. You should be able to do something like:
[lua]
local list = vgui.Create("DPanelList")
list:EnableVerticalScrollbar()
local bar = list.VBar
bar:SetVisible(false)
[/lua]
Hey there. I recently got advice as to how I'd make a laser sight for a weapon.
[quote]
[quote=MegaTronJohn;44444]
Hey there. I want to create a laser sight that will go on my weapon. There are a few questions I have before, though:
1. What entity/effect could I use to create the laser sight?
2. Would I set it's position on the weapon with SetPos()?
3. Should I do this clientside or serverside?
Thanks in advance.
[/quote]
[b]What entity/effect could I use to create the laser sight?[/b]
[url]http://wiki.garrysmod.com/page/render/DrawBeam[/url]
Use starting position of laser sight's attachment point because anything different will result in dodgy laser sight.
[url]http://wiki.garrysmod.com/page/Entity/GetAttachment[/url]
and ending position of LocalPlayer():GetEyeTrace().HitPos
[b]Would I set it's position on the weapon with SetPos()?[/b]
No. You must set it's position via render.DrawBeam
[b]Should I do this clientside or serverside?[/b]
Clientside
[/quote]
I have one question. Where would I call render.DrawBeam in a SWEP code? HUDPaint? ViewModelDrawn?
[editline]26th July 2015[/editline]
Okay, ViewModelDrawn is just crashing my game when I try to use render.DrawBeam in it. I really want to add laser sights, please help...
I have an entity which does nothing atm but is a filing cabinent - if I jump against it, the model will fall over though
How do I make it spawn frozen and unmoveable?
I tried this in initialize but it did nothing
[code]
self:Sleep()
self:EnableMotion(false)
[/code]
[QUOTE=NiandraLades;48295624]I have an entity which does nothing atm but is a filing cabinent - if I jump against it, the model will fall over though
How do I make it spawn frozen and unmoveable?
I tried this in initialize but it did nothing
[code]
self:Sleep()
self:EnableMotion(false)
[/code][/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/PhysicsDestroy]Entity:PhysicsDestroy[/url]
So I'm shit at vector math (and math in general tbh :v:)
I'm trying to get a decent camera position for DModelPanel which hopefuly will work with a range of size of models. It's currently used for a vehicle customization panel and when there is a gokart it will be small, then a larger SUV will be too big etc.
[lua]
icon:SetCamPos( Vector( -250, 40, 100) )
icon:SetLookAt(Vector(0,-40,0))
[/lua]
I'm aware I need to use something along the lines of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/OBBCenter]Entity:OBBCenter[/url] etc, but I'm pretty stuck.
[QUOTE=Sereni;48295118]Hide the scrollbar. You should be able to do something like:
[lua]
local list = vgui.Create("DPanelList")
list:EnableVerticalScrollbar()
local bar = list.VBar
bar:SetVisible(false)
[/lua][/QUOTE]
It's creating a scrollbar but it's not making it disappear. I also tried bar:SetSize(0, 0).
[QUOTE=liqob;48296336]It's creating a scrollbar but it's not making it disappear. I also tried bar:SetSize(0, 0).[/QUOTE]
Try overriding the paint function with a blank function maybe.
[code]bar.Paint = function(panel, w, h)
end[/code]
I've been learning LUA scripting for the past week, and for four days I haven't been able to fix a certain problem with my first SWEP. I've tried everything but ask for help.
So, my weapon is supposed to fire these plasma ball entities that damage and ignite whatever they hit (I haven't actually coded that part yet). The problem is that the plasma balls don't move when they're spawned. The only time they'll move is if a prop or another plasma ball touches the very edge of its collisions. It's almost as if the entity's physics doesn't wake, but it does when something touches it.
Here's a webm of it in action:
[vid]http://webm.host/9f718/vid.webm[/vid]
Notice how I'm not getting any errors.
Here is the code for the entity:
[CODE]AddCSLuaFile ()
DEFINE_BASECLASS ( "base_anim" )
ENT.PrintName = "Energy Ball"
ENT.Author = "Me"
ENT.Information = "A ball of energy that does moderate damage and ignites things (including people) on impact."
ENT.Category = "Coding Stuff"
ENT.Editable = false
ENT.Spawnable = false
ENT.AdminOnly = false
ENT.RenderGroup = RENDERGROUP_TRANSLUCENT //I still don't know exactly what this does, but it's set up just fine. Don't mess with it.
local Size = 16
local CollisionSize = 8
function ENT:Initialize()
if ( SERVER ) then
self:SetModel ( "models/weapons/w_bugbait.mdl" ) //This model won't actually be rendered in ENT:Draw, so it's just going to be used as a shadow.
self:PhysicsInitSphere ( CollisionSize, "glass" ) //This creates new collisions to use instead of the Bugbait model's default one. We can set its bounds with variables.
local phys = self:GetPhysicsObject()
if ( IsValid ( phys ) ) then //This wakes up the model's physics if it's allowed.
phys:Wake()
end
phys:EnableGravity ( false ) //We don't want the plasma to just fall to the ground!
self:SetCollisionBounds ( Vector (-CollisionSize, -CollisionSize, -CollisionSize), Vector (CollisionSize, CollisionSize, CollisionSize) )
timer.Simple ( 5, function() self:Remove() end )
end
end
function ENT:PhysicsCollide ( data, physobj ) //We're going to need this later to ignite and deal damage to things our plasma balls hit.
return
end
if ( CLIENT ) then
function ENT:Draw () //This draws a sprite at the entity's position, colors it, and stretches it to a set size in the variable at th etop of the script.
local Plasma = Material ( "sprites/strider_blackball" )
local SelfPos = self:GetPos()
render.SetMaterial ( Plasma )
render.DrawSprite ( SelfPos, Size, Size, Color ( 119, 0, 255 ) )
end
end
[/CODE]
Here is the code for the weapon, if it's any help:
[CODE]AddCSLuaFile()
SWEP.PrintName = "Plasma Rifle"
SWEP.Author = "Me"
SWEP.Purpose = "Fires plasma that hurts enemies. Point it at something nasty and pull the trigger."
SWEP.AdminOnly = false
SWEP.Spawnable = true
SWEP.Category = "Coding Stuff"
SWEP.Slot = 2
SWEP.SlotPos = 3
SWEP.DrawAmmo = true
local WeaponFire = Sound ( "Weapon_IRifle.Single" )
local DryFire = Sound ( "Weapon_Pistol.Empty" )
SWEP.Primary.ClipSize = 50
SWEP.Primary.DefaultClip = 50
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "AR2"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = -1
SWEP.UseHands = true
function SWEP:Initialize()
self:SetHoldType( "ar2" )
end
function SWEP:PrimaryAttack()
if( self:Clip1() != 0 ) then
self:SetNextPrimaryFire ( CurTime() + 0.1 )
self:EmitSound ( WeaponFire )
self:ShootEffects ( self )
util.ScreenShake ( Vector( 0, 0, 0 ), 2, 2, 0.48, 3000 )
if ( CLIENT ) then return end
self:SetClip1 ( math.min ( self:Clip1 () - 1 ) )
self:FireProjectile ( "sent_plasmaball" )
else
self:SetNextPrimaryFire ( CurTime() + 0.125 )
self:DefaultReload ( ACT_VM_RELOAD );
end
end
function SWEP:SecondaryAttack ()
self:SetNextSecondaryFire ( CurTime() + 1 )
self:EmitSound ( DryFire )
end
function SWEP:Reload ()
self:DefaultReload ( ACT_VM_RELOAD );
end
function SWEP:FireProjectile ( ent_name )
local Forward = self.Owner:EyeAngles():Forward()
local EntSpeed = 1700
local EntSpread = 90
local ent = ents.Create( ent_name )
if ( IsValid( ent ) ) then
ent:SetPos ( self.Owner:GetShootPos() + Forward * 32 )
ent:SetAngles ( self.Owner:EyeAngles() )
ent:Spawn()
ent:SetOwner ( self.Owner )
ent:SetVelocity ( Forward * EntSpeed + ( VectorRand() * EntSpread ) )
end
end
function SWEP:ShouldDropOnDie ()
return false
end
[/CODE]
[QUOTE=Renegade Master;48296761]I've been learning LUA scripting for the past week, and for four days I haven't been able to fix a certain problem with my first SWEP. I've tried everything but ask for help.
So, my weapon is supposed to fire these plasma ball entities that damage and ignite whatever they hit (I haven't actually coded that part yet). The problem is that the plasma balls don't move when they're spawned. The only time they'll move is if a prop or another plasma ball touches the very edge of its collisions. It's almost as if the entity's physics doesn't wake, but it does when something touches it.
Here is the code for the weapon, if it's any help:
[/QUOTE]
You should probably try, under the SWEP:FireProjectile function, changing [code]ent:SetVelocity( vector )[/code]
to
[code]ent:GetPhysicsObject():SetVelocity( vector )[/code]
[QUOTE=Z0mb1n3;48296889]You should probably try, under the SWEP:FireProjectile function, changing [code]ent:SetVelocity( vector )[/code]
to
[code]ent:GetPhysicsObject():SetVelocity( vector )[/code][/QUOTE]
It works just fine now, thanks!
[QUOTE=Z0mb1n3;48296475]Try overriding the paint function with a blank function maybe.
[code]bar.Paint = function(panel, w, h)
end[/code][/QUOTE]
That's not working either.
How do i create an unique timer?
I found something like that...
[CODE]
timer.Create(player:UniqueID(), 60, 0, function() end, player)
[/CODE], but is that correct? Or what do i else need to add?
[QUOTE=liqob;48297111]That's not working either.[/QUOTE]
Try hiding the child elements of the scrollbar:
[lua]
local list = vgui.Create("DPanelList")
list:EnableVerticalScrollbar()
local bar = list.VBar
bar.btnUp:SetVisible(false)
bar.btnDown:SetVisible(false)
bar.btnGrip:SetVisible(false)
[/lua]
This isn't really a lua question but, what causes a model to be invisible? both singleplayer and multiplayer, windows and linux?
whenever I load the model's icon or the ragdoll for the first time in a game, I get this:
MDLCache: Failed load of .VVD data for Humans\Group01\Male_01.mdl
That's not the path of the model it's self (normal hl2/gmod models are fine) but I guess a model it uses for the face and whatever else, are these models just broke or is there a way to fix them? (they worked in gm12)
[QUOTE=Infineox;48297194]How do i create an unique timer?
I found something like that...
[CODE]
timer.Create(player:UniqueID(), 60, 0, function() end, player)
[/CODE], but is that correct? Or what do i else need to add?[/QUOTE]
[lua]timer.Create(player:UniqueID().."_timerThing", 60, 0, function() end)[/lua]
You're being a bit vague though, I don't know what you mean.
[QUOTE=Infineox;48297194]How do i create an unique timer?
I found something like that...
[CODE]
timer.Create(player:UniqueID(), 60, 0, function() end, player)
[/CODE], but is that correct? Or what do i else need to add?[/QUOTE]
What exactly do you mean by an unique timer?
So I've been working on some custom entities that have a few wire inputs/outputs. Unfortunately, when I save and spawn the contraption with Adv Dupe 2, the entity spawns in unwired. Does anyone have experience with this? I'm not sure where to even begin, so any help is appreciated.
Not a problem as much as a recommendation:
If I have multiple things that need to be ran on different times at different paces, should I create multiple timers, or a single one running every 0,05 or something small and then use RepsLeft + math to indicate when stuff happens?
[QUOTE=Coment;48306496]Not a problem as much as a recommendation:
If I have multiple things that need to be ran on different times at different paces, should I create multiple timers, or a single one running every 0,05 or something small and then use RepsLeft + math to indicate when stuff happens?[/QUOTE]
can you please show us an example of both cases? i didn't quite get that.
[QUOTE=tzahush;48306708]can you please show us an example of both cases? i didn't quite get that.[/QUOTE]
basically doing multiple timers that execute themselves one after another, or have a single one where the repetitions left * time between repetitions mandates what gets executed.
something like
[code]timer.Create("ShowThings",1,1,function()
DoThisThing(1)
DoThisSecondThing(1)
end)
timer.Simple(3, function()
ShowThisPopup()
end)
timer.Simple(4, function() timer.Start("ShowThings") end)
[/code]
vs
[code]
timer.Create("DoAll",1,5,function()
local repsLeft = timer.RepsLeft("DoAll")
if repsLeft == 4 then
DoThisThing(1)
DoThisSecondThing(1)
end
if repsLeft == 2 then
ShowThisPopup()
end
if repsLeft == 1 then
DoThisThing(2)
DoThisSecondThing(2)
end
end)
[/code]
Anyone know how I'd check if a door is locked?
[QUOTE=MegaTronJohn;48307486]Anyone know how I'd check if a door is locked?[/QUOTE]
Try this (serverside only):
[lua]
DoorEntity:GetSaveTable( ).m_bLocked
[/lua]
That should return whether it's locked or not.
I'm using render.RenderView() to render to a render target, but for some reason it draws some things (pictured below) to the screen.
[img_thumb]http://images.akamai.steamusercontent.com/ugc/450709426680523823/4D6B74B5EAD0E515374BF93DD2A6BDB3B90A79E9/[/img_thumb]
[lua]
local oldw, oldh = ScrW(), ScrH()
local oldrt = render.GetRenderTarget( )
render.SetRenderTarget( self.RenderTarget )
render.SetViewPort( 0, 0, ScrW(), ScrH() )
render.Clear( 255, 255, 255, 0 )
cam.Start2D()
self.drawingrenderables = true
render.RenderView({
origin = LocalPlayer( ):EyePos( ),
angles = LocalPlayer( ):EyeAngles( ),
x = 0,
y = 0,
w = ScrW( ),
h = ScrH( ),
dopostprocess = false,
drawhud = false,
drawmonitors = false,
drawviewmodel = false,
ortho = false
})
self.drawingrenderables = false
cam.End2D()
render.SetRenderTarget( oldrt )
render.SetViewPort( 0, 0, oldw, oldh )
[/lua]
That code is only called when self.drawingrenderables is false. Any ides?
Sorry, you need to Log In to post a reply to this thread.