What can i do then ?
Using it outside of a coroutine make gmod crash ye
[T]http://puu.sh/g7WxC/90a68c2108.png[/T]
How would I access a weapons variables without it being spawned as in, I want to check SWEP.Wave in the weapon directly
[QUOTE=ForrestMarkX;47190964]How would I access a weapons variables without it being spawned as in, I want to check SWEP.Wave in the weapon directly[/QUOTE]
[lua]list.Get( "Weapon" )[/lua]
do PrintTable on that to see its structure, hope this helps :)
That's for weapons you can spawn.
weapons.GetStored( "class" ) will return the weapon table.
I've used weapons.GetList for all weapons and their variables.
[QUOTE=Kogitsune;47191100]That's for weapons you can spawn.
weapons.GetStored( "class" ) will return the weapon table.[/QUOTE]
So use something like local weapon = weapons.GetStored( tab.SWEP ) then weapon.Wave?
Yes.
[QUOTE=Kogitsune;47191147]Yes.[/QUOTE]
Hmm this does not work, I have the default wave set to 0 eg SWEP.Wave = 0 in shared when I do print(weapon.Wave) in a if weapon then statment it returns nil for every weapon
[code] s:AddHook( "PlayerSwitchWeapon", function( this, pl, old, new )
local base, mul
base = weapons.GetStored( new:GetClass( ) )
if not base or RPG:GetSkill( pl, this.Name ) < 1 then
return
end
mul = 1 + RPG:GetSkill( pl, this.Name ) * .05
if base.Primary.ClipSize and base.Primary.ClipSize >= 1 then
new.Primary.ClipSize = math.Round( base.Primary.ClipSize * mul )
end
if base.Secondary.ClipSize and base.Secondary.ClipSize >= 1 then
new.Secondary.ClipSize = math.Round( base.Secondary.ClipSize * mul )
end
end )[/code]
If it is nil, it means that Wave isn't defined on the weapon class you are feeding it, or at least is nil in the state you are calling it from.
[QUOTE=Kogitsune;47191488][code] s:AddHook( "PlayerSwitchWeapon", function( this, pl, old, new )
local base, mul
base = weapons.GetStored( new:GetClass( ) )
if not base or RPG:GetSkill( pl, this.Name ) < 1 then
return
end
mul = 1 + RPG:GetSkill( pl, this.Name ) * .05
if base.Primary.ClipSize and base.Primary.ClipSize >= 1 then
new.Primary.ClipSize = math.Round( base.Primary.ClipSize * mul )
end
if base.Secondary.ClipSize and base.Secondary.ClipSize >= 1 then
new.Secondary.ClipSize = math.Round( base.Secondary.ClipSize * mul )
end
end )[/code]
If it is nil, it means that Wave isn't defined on the weapon class you are feeding it, or at least is nil in the state you are calling it from.[/QUOTE]
It shouldn't be as Wave is defined within the base class of every weapon used, it's used from AddItem in ZS which is called sometime after Initialize
Edit: Ahh I see the table does not get base class variables the var needs to be defined in each class that uses it
Someone to help me with?
I got this error:
[CODE]
[ERROR] addons/strange sweps/lua/entities/ent_killer/init.lua:43: Tried to use a NULL entity!
1. GetPhysicsObject - [C]:-1
2. unknown - addons/strange sweps/lua/entities/ent_killer/init.lua:43
[/CODE]
The entity code is:
[CODE]AddCSLuaFile()
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.Spawnable = false
function ENT:Draw()
if SERVER then return end
self:DrawModel()
end
function ENT:Initialize()
self:SetModel( "models/props_combine/headcrabcannister01a.mdl" )
self:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics,
self:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics
self:SetSolid( SOLID_VPHYSICS ) -- Toolbox
end
function ENT:Use( activator, caller )
end
function ENT:Think()
local phys = self.GetPhysicsObject()
local velocity = self.Owner:GetPos()
velocity = velocity * 1000000
velocity = velocity + (VectorRand() * 10)
phys:ApplyForceCenter( velocity )
end
[/CODE]
This is the problem here:
[code]
self.GetPhysicsObject()[/code]
You must call entity methods like this:
[code]self:GetPhysicsObject()[/code]
Im trying to create an item system but it keeps erroring addons/server_shop/lua/items/1.lua:8: attempt to call field 'registerItem' (a nil value)
[B]sh_init.lua (inside autorun/)[/B]
[code] ServerShop = {}
local files = file.Find( "items/*.lua", "LUA" )
for k, v in pairs(files) do
include("items/"..v)
if SERVER then
AddCSLuaFile("items/"..v)
return end
end
function ServerShop.registerItem(tbl)
table.insert(ServerShop, {test=tbl.Name})
end
for k , v in pairs (ServerShop) do
print(v.test)
end [/code]
[B]My test item[/B]:
[code]
local item = {}
item.Name = "Pistol"
item.Description = "HL2 Pistol"
item.PrintCheck = "This is a test"
ServerShop.registerItem(item)
[/code]
I Haven't been able to fix this problem? If anyone could help it'd be really appreciated?
-snip-
You're defining the function after including the files. Move ServerShop.registerItem above your loop.
Now i got this:
[CODE][ERROR] addons/strange sweps/lua/entities/ent_killer/init.lua:43: Tried to use a NULL entity!
1. GetPos - [C]:-1
2. unknown - addons/strange sweps/lua/entities/ent_killer/init.lua:43
[/CODE]
[CODE]AddCSLuaFile()
AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init")
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.Spawnable = false
function ENT:Draw()
if SERVER then return end
self:DrawModel()
end
function ENT:Initialize()
self:SetModel( "models/props_combine/headcrabcannister01a.mdl" )
self:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics,
self:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics
self:SetSolid( SOLID_VPHYSICS ) -- Toolbox
end
function ENT:Use( activator, caller )
end
function ENT:Think()
local phys = self:GetPhysicsObject()
local velocity = self.Owner:GetPos()
velocity = velocity * 1000000
velocity = velocity + (VectorRand() * 10)
local angle = self:GetAngles()
phys:ApplyForceCenter( velocity )
end
[/CODE]
So i need help offsetting the rendering position of a 3D2D camera. The hook this is running in is HUDPaint
so it is required that i do cam.Start3D()
[lua]
cam.Start3D(EyePos(),EyeAngles()+Angle(0,0,-90))
cam.Start3D2D(EyePos()+(EyeAngles():Forward()*15),EyeAngles()+Angle(-130,3,-30),0.02)
[/lua]
Can someone explain to me how i would offset the position to be on the left side of the screen? 3D2D objects dont render if they are out of their bounds.
Here is a screenshot with the current valid rendering bounds highlighted in green:
[quote][img]http://i.imgur.com/B0nvlHK.jpg[/img][/quote]
I'm trying to impliment prop rotation in my prop hunt server on gmod, but I can't seem to get it working, anyone know why?
[LUA]hook.Add( "SetupMove", "PH_PropRotation", function( _p, mv, cmd )
if ( _p:KeyDown( IN_ATTACK2 ) and _p:Team() == TEAM_PROPS) then
local _ang = _p:EyeAngles( )
local _last_ang = ( _p.LastAng && _p.LastAng || _ang )
local _difference_y = math.AngleDifference( _ang.y, _last_ang.y )
local _difference_x = math.AngleDifference( _ang.x, _last_ang.x )
_p.LastAng = _ang
_p:SetAngles(Angle(_difference_x, _difference_y, 90))
end
end )[/LUA]
[QUOTE=Garr;47192469]Now i got this:
[CODE][ERROR] addons/strange sweps/lua/entities/ent_killer/init.lua:43: Tried to use a NULL entity!
1. GetPos - [C]:-1
2. unknown - addons/strange sweps/lua/entities/ent_killer/init.lua:43
[/CODE]
[CODE]AddCSLuaFile()
AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init")
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.Spawnable = false
function ENT:Draw()
if SERVER then return end
self:DrawModel()
end
function ENT:Initialize()
self:SetModel( "models/props_combine/headcrabcannister01a.mdl" )
self:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics,
self:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics
self:SetSolid( SOLID_VPHYSICS ) -- Toolbox
end
function ENT:Use( activator, caller )
end
function ENT:Think()
local phys = self:GetPhysicsObject()
local velocity = self.Owner:GetPos()
velocity = velocity * 1000000
velocity = velocity + (VectorRand() * 10)
local angle = self:GetAngles()
phys:ApplyForceCenter( velocity )
end
[/CODE][/QUOTE]
self.Owner is not defined in your code.
[QUOTE=Robotboy655;47192595]self.Owner is not defined in your code.[/QUOTE]
So what should i do?
[QUOTE=AJ10017;47192527]So i need help offsetting the rendering position of a 3D2D camera. The hook this is running in is HUDPaint
so it is required that i do cam.Start3D()
[lua]
cam.Start3D(EyePos(),EyeAngles()+Angle(0,0,-90))
cam.Start3D2D(EyePos()+(EyeAngles():Forward()*15),EyeAngles()+Angle(-130,3,-30),0.02)
[/lua]
Can someone explain to me how i would offset the position to be on the left side of the screen? 3D2D objects dont render if they are out of their bounds.
Here is a screenshot with the current valid rendering bounds highlighted in green:[/QUOTE]
HUDPaint is a very small viewport - switch to a hook that is in a 3d context like PostDrawTranslucentRenderables and ditch starting the 3d camera.
Then, it'd be pretty simple - you just move it by EyeAngles( ):Right( ) * -distance.
[QUOTE=Garr;47192622]So what should i do?[/QUOTE]
Define it ( Make the variable exist, self.Owner = SomeEntityVariable ) or don't use it.
[QUOTE=Robotboy655;47192674]Define it ( Make the variable exist, self.Owner = SomeEntityVariable ) or don't use it.[/QUOTE]
Wup :l
After a of time trying to do this define shit i am pretty sure i don't know how to define something...
If someone want to help me in this do so... Because i don't know how to define
[QUOTE=Kogitsune;47192635]HUDPaint is a very small viewport - switch to a hook that is in a 3d context like PostDrawTranslucentRenderables and ditch starting the 3d camera.
Then, it'd be pretty simple - you just move it by EyeAngles( ):Right( ) * -distance.[/QUOTE]
Thanks! im using EyeAngles():Up()*-distance to offset it now, thanks so much for explaining that to me
[QUOTE=Garr;47192742]Wup :l
After a of time trying to do this define shit i am pretty sure i don't know how to define something...
If someone want to help me in this do so... Because i don't know how to define[/QUOTE]
I am confused about these replies. You posted the same error as the first one (referencing to self:GetPhysicsObject() ). However Robotboy is saying that the issue is self.Owner.
[B]Edit:[/B] Also I thought you don't have to define self.Owner Example - ([url]http://wiki.garrysmod.com/page/WEAPON/PrimaryAttack[/url])
[QUOTE=MCiLuZiioNz;47193678]I am confused about these replies. You posted the same error as the first one (referencing to self:GetPhysicsObject() ). However Robotboy is saying that the issue is self.Owner.
[B]Edit:[/B] Also I thought you don't have to define self.Owner Example - ([url]http://wiki.garrysmod.com/page/WEAPON/PrimaryAttack[/url])[/QUOTE]
The issue of self:GetPhysicsObject() is alredy fixed,the problem is the define thing, since in not capable of usin self.Owner:GetPos() it in my entity. Could you please tell me how to define something?
[QUOTE=Garr;47193857]The issue of self:GetPhysicsObject() is alredy fixed,the problem is the define thing, since in not capable of usin self.Owner:GetPos() it in my entity. Could you please tell me how to define something?[/QUOTE]
What I am saying is that the error is unrelated to the code posted as that was fixed in your previous post. So my question is, what error do you get now?
What's the difference between DeriveGamemode(name) and GM.Base = name?
Also: If I set mygamemode's base to "base" and I set mygamemodetwo's base to "mygamemode", will I have access to methods from base? Would I if I had used DeriveGamemode somehow?
[QUOTE=MCiLuZiioNz;47193899]What I am saying is that the error is unrelated to the code posted as that was fixed in your previous post. So my question is, what error do you get now?[/QUOTE]
[ERROR] addons/strange sweps/lua/entities/ent_killer/init.lua:43: Tried to use a NULL entity!
1. GetPos - [C]:-1
2. unknown - addons/strange sweps/lua/entities/ent_killer/init.lua:43
this error. Robotboy said me to define the self.Owner thing. And i have no idea how i should define it
Anybody got the stencil code for drawing one thing through another thing (but not everything else)?
Sorry, you need to Log In to post a reply to this thread.