[lua]true and 1 or 0[/lua]
This will always be 1. Your first eleven prints are impossible.
Edit: you just fixed that now
[QUOTE=Bo98;45566541][lua]true and 1 or 0[/lua]
This will always be 1. Your first eleven prints are impossible.
Edit: you just fixed that now[/QUOTE]
Ya sorry I was literally just removing the actual table lookup (which always returned false)
[QUOTE=Willox;45566523]net.WriteBit takes a boolean, not a number. When giving it a number your input will be turned in to a boolean and will always be treated as true due to numbers being truthy in Lua.[/QUOTE]
The function name is misleading :S (bool is a byte not a bit, I expected it to turn everything except the number zero into true)
-snip- too slow :(
[QUOTE=OzymandiasJ;45566563]Ya sorry I was literally just removing the actual table lookup (which always returned false)
The function name is misleading :S (bool is a byte not a bit, I expected it to turn everything except the number zero into true)[/QUOTE]
The next gmod update introduces net.WriteBool and net.ReadBool, but until then you have to either implement them yourself or deal with the shittily named functions.
[QUOTE=Willox;45566618]The next gmod update introduces net.WriteBool and net.ReadBool, but until then you have to either implement them yourself or deal with the shittily named functions.[/QUOTE]
actually it makes it better:
net.WriteBit(ply.OwnedWeapons[i])
I was doing
net.WriteBit(ply.OwnedWeapons[i] and 1 or 0)
Hey, how would I modify a SWEP that is on the ground? For example changing it's material/colour
So I want to get all of the data that is in a DList but I am a bit confused on the out put of [b][url=http://wiki.garrysmod.com/?title=DListView.GetLines]DListView.GetLines [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].
It outputs something like this.
[img]http://puu.sh/aAUhB/26e9eae22d.png[/img]
I am not really sure what to do with this. Is there even a way to get all of the entered data from a dlist?
Is there a way to slow down player walk animation in gamemode?
[QUOTE=TheMostUpset;45567559]Is there a way to slow down player walk animation in gamemode?[/QUOTE]
Just lower their walkspeed. Source takes care of the animation.
Is there a hook for when a Derma Panel is closed?
[QUOTE=Ott;45567844]Just lower their walkspeed. Source takes care of the animation.[/QUOTE]
I need to keep my walkspeed, but slow down the animation
[QUOTE=TheMostUpset;45568250]I need to keep my walkspeed, but slow down the animation[/QUOTE]
If that happened, their feet wouldn't sync up with the ground.
[QUOTE=residualgrub;45567537]So I want to get all of the data that is in a DList but I am a bit confused on the out put of [B][URL="http://wiki.garrysmod.com/?title=DListView.GetLines"]DListView.GetLines [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B].
It outputs something like this.
[IMG]http://puu.sh/aAUhB/26e9eae22d.png[/IMG]
I am not really sure what to do with this. Is there even a way to get all of the entered data from a dlist?[/QUOTE]
Just an example of how to view the contents of each line, tab separated.
[CODE]for _, line in pairs( DListView:GetLines() ) do
for _, column in pairs( line.Columns ) do
Msg( column:GetText() .. "\t" )
end
print()
end[/CODE]
For my given DListView, it prints the contents out like this:
[CODE]19 A Beautiful Lie Unknown 30 Seconds to Mars 04:05
20 Attack Unknown 30 Seconds to Mars 03:09
21 End of the Beginning Unknown 30 Seconds to Mars 04:39
22 From Yesterday Unknown 30 Seconds to Mars 04:08
23 The Kill Unknown 30 Seconds to Mars 03:51
24 All Mixed Up 311 311 02:59
25 Down 311 311 02:53
26 Love Song Greatest Hits '93-'03 311 03:28
27 Beautiful Disaster Transistor 311 03:58
28 What's Up (He-Man Version) Unknown 4 Non Blondes 02:06
29 Ship the Artists Four's Fall Down 5Copy 04:36
30 Peacock Unknown 7 Minutes Dead 05:16
31 3 Libras Mer de Noms A Perfect Circle 03:39
[/CODE]
Each DListView_Line has a [B].Columns[/B] field that holds each panel that was created/added when DListView:AddLine() was called. So all you have to do is loop through those columns and call [B]:GetText()[/B] to retrieve the string value.
I just viewed the source for the DListView_Line to do this. You can find it here: [URL]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/dlistview_line.lua[/URL]
I hope this helps.
[B]
--Edit--[/B]
Looks like there is DListView_Line:GetColumnText( i ) as well, so you could change the 2nd for-loop to
[CODE]for k, _ in pairs( self.Columns ) do
Msg( line:GetColumnText( k ) .. "\t" )
end[/CODE]
but it's not any more convenient than column:GetText().
Is it possible to get the size of the chat box?
[QUOTE=tommy228;45570838]Is it possible to get the size of the chat box?[/QUOTE]
Not at the moment. You could try figuring out it's exact size at a specific resolution and then finding what it scales it by when changing resolution, but that's really lame.
I started a GitHub request for more chatbox functionality, and getting the width/height of the chatbox was one of the suggestions: [URL="https://github.com/Facepunch/garrysmod-requests/issues/266"]https://github.com/Facepunch/garrysmod-requests/issues/266
[/URL]
It's been 2 months since the last reply though :/
How do I get a position of a vgui element if I've placed it using Dock ? Element.GetPos seems to return 0
This is happening with my swep and I have no idea why :
[code]
[ERROR] lua/weapons/wavebeam.lua:237: attempt to perform arithmetic on field 'FireMode' (a nil value)
1. unknown - lua/weapons/wavebeam.lua:237
[/code]
It's in blue so I'm assuming it's clientside lua, but i'm stopping anything being done on the client
Now, what i'm doing here is trying to change the weapon's firemode value when I press secondary fire; the code at fault is this :
[code]
function SWEP:SecondaryAttack()
if CLIENT then return end
if self.FireMode == 4 then
self.FireMode = 1
else
self.FireMode = self.FireMode + 1
end
self:UpdateFireMode(2)
print("Firemode Updated to "..self.FireMode)
self:CallOnClient("UpdateFireMode",2)
self:EmitSound( "weapons/armcannon/changebeam.wav" )
self:SetNextSecondaryFire( CurTime() + 0.2)
end
[/code]
I've got code at the beginning of the swep AND in Intialize setting firemode to 1.
What's the issue?
[code]if self.FireMode == 4 then
self.FireMode = 1
else
self.FireMode = self.FireMode + 1
end[/code]
This piece of code.
[code]if nil == 4 then //self.FireMode is nil because you have not defined it anywhere
//blah
else
var = nil + 1 // nil + 1 throws an error.
end[/code]
Solution:
[code]self.FireMode = self.FireMode or 1[/code]
in SWEP:Initialize.
[QUOTE=Robotboy655;45572195][code]if self.FireMode == 4 then
self.FireMode = 1
else
self.FireMode = self.FireMode + 1
end[/code]
This piece of code.
[code]if nil == 4 then //self.FireMode is nil because you have not defined it anywhere
//blah
else
var = nil + 1 // nil + 1 throws an error.
end[/code]
Solution:
[code]self.FireMode = self.FireMode or 1[/code]
in SWEP:Initialize.[/QUOTE]
Still spewing the exact same errors with that new code added in.
Post the new code, with marking the erroring line.
I have a table structured like a filepath for example this one:
[LUA]
tabl = {
someFolderNameHere = { someFolderNameHere11 = {someFileNameHere21 = "Hello"}, someFolderNameHere12 = {someFileNameHere23 = "Hello22"}},
someFolderNameHere2 = { someFolderNameHere211 = {someFolderNameHere21 = { someFileNameHereidk = "yay"}}},
etc...
}
[/LUA]
How would I go about adding the full thing to a DTree/DFileBrowser (note that the files aren't something I got from files.Find or similar so their default methods won't work)
(It also could be another nested list of anything else)
[QUOTE=LennyPenny;45573825]I have a table structured like a filepath for example this one:
[LUA]
tabl = {
someFolderNameHere = { someFolderNameHere11 = {someFileNameHere21 = "Hello"}, someFolderNameHere12 = {someFileNameHere23 = "Hello22"}},
someFolderNameHere2 = { someFolderNameHere211 = {someFolderNameHere21 = { someFileNameHereidk = "yay"}}},
etc...
}
[/LUA]
How would I go about adding the full thing to a DTree/DFileBrowser (note that the files aren't something I got from files.Find or similar so their default methods won't work)
(It also could be another nested list of anything else)[/QUOTE]
[url]https://github.com/garrynewman/garrysmod/blob/7eaa3cbca609e572ff296c6aeaad491696f61111/garrysmod/lua/includes/util.lua#L38[/url]
How do I get an NPC's health?
[QUOTE=IntenseBarney;45574382]How do I get an NPC's health?[/QUOTE]
NPC:Health(). Health is not networked to client for NPCs.
[QUOTE=Robotboy655;45574456]NPC:Health(). Health is not networked to client for NPCs.[/QUOTE]
Thanks, thought it would have been NPC:GetHealth() >.<
[QUOTE=IntenseBarney;45574483]Thanks, thought it would have been NPC:GetHealth() >.<[/QUOTE]
Yeah, some function names are counter intuitive. It should be GetHealth().
[QUOTE=PortalGod;45549383]Material and surface.GetTextureID should only be called once and stored, outside of any drawing functions[/QUOTE]
I don't know how to do this though. I tried the below but it seems like it doesn't work
[code]surface.CreateFont( "BurgerFont", {
font = "Roboto-Black",
size = 50,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
function HUDHide( myhud )
if SERVER then return end
for k, v in pairs{"CHudHealth","CHudBattery","CHudAmmo","CHudSecondaryAmmo"} do
if myhud == v then return false end
end
end
hook.Add( "HUDShouldDraw", "HUDHide", HUDHide )
print("Updated")
if CLIENT then
for i=1, 400 do
surface.SetMaterial( Material("BurgerHUD/WhiteCircle.png") )
end
end
local function BurgerBulletHUD()
if SERVER then return end
local ply = LocalPlayer()
if ply:Alive() then
HP = ply:Health()
ARM = ply:Armor()
ammo = ply:GetActiveWeapon():Clip1() or 69
if ply:GetActiveWeapon():IsScripted() then
maxammo=ply:GetActiveWeapon():GetTable().Primary.ClipSize
else
maxammo=ply:GetActiveWeapon():Clip1()
end
extraammo = ply:GetAmmoCount(ply:GetActiveWeapon():GetPrimaryAmmoType())
secondaryammo = ply:GetAmmoCount(ply:GetActiveWeapon():GetSecondaryAmmoType())
wep = ply:GetActiveWeapon()
end
if ScrW() == 640 then Scale = 0.5
elseif ScrW() == 800 then Scale = 0.75
elseif ScrW() == 1024 then Scale = 1
elseif ScrW() == 1280 then Scale = 1
else Scale = 1 end
Basefade = 255
BaseTrig = 2
ConVert = math.pi/180
Size = (ScrH()/8)*Scale
BarWidth=25*Scale
BarHeight=25*Scale
CenterX = ScrW()*0 + BarWidth*7
CenterX2 = ScrW() - BarWidth*7
CenterY = ScrH() - BarHeight*7
surface.SetFont( "BurgerFont" )
surface.SetTextColor( 255 - 2.25*HP,2.25*HP,(HP-100)*3,Basefade )
surface.SetTextPos( CenterX-(1/3)*100, CenterY-25)
surface.DrawText( HP )
if ARM >= 1 then
surface.SetFont( "BurgerFont" )
surface.SetTextColor( ARM-100,100,ARM*2.55,Basefade )
surface.SetTextPos( CenterX-(1/3)*100, CenterY+25)
surface.DrawText( ARM )
end
if extraammo >= 1 then
surface.SetFont( "BurgerFont" )
surface.SetTextColor( 255, 255, 0, 255 )
surface.SetTextPos( CenterX2-25 , CenterY-25)
surface.DrawText( extraammo )
end
for i = 1, math.min(HP,100) do
healthmod = 0.3
if ARM==0 then
PosSet= 0 ; SizeMul=1 ; fixer= 0
else
PosSet= 0 ; SizeMul=1; fixer = 0
end
local RingX = math.sin(-(PosSet+i+fixer)*BaseTrig*ConVert*healthmod*2)*Size + CenterX - BarWidth/2
local RingY = math.cos(-(PosSet+i+fixer)*BaseTrig*ConVert*healthmod*2)*Size + CenterY
--surface.SetMaterial( Material("BurgerHUD/WhiteSquare.png") )
surface.SetDrawColor(255 - 2.25*HP,2.25*HP,(HP-100)*3,Basefade)
surface.DrawTexturedRectRotated(RingX,RingY,BarWidth,(BarHeight+(i*SizeMul))*(Size/500), -(fixer+i+PosSet)*1.2)
end
if ARM >=1 then
for i = 1, math.min(ARM,100) do
local healthmod = 0.3
local RingX = math.sin(i*BaseTrig*ConVert*healthmod*2)*Size + CenterX + BarWidth/2
local RingY = math.cos(i*BaseTrig*ConVert*healthmod*2)*Size + CenterY
--surface.SetMaterial( Material("BurgerHUD/WhiteSquare.png") )
surface.SetDrawColor((ARM-100),100,ARM*2.55,Basefade)
surface.DrawTexturedRectRotated(RingX,RingY,BarWidth,(BarHeight+(i*SizeMul))*(Size/500),i*1.2)
end
end
if ammo >= 1 then
for i = 1, ammo do
local clipmod = 180/maxammo
local RingX = math.sin(-i*BaseTrig*ConVert*clipmod)*Size + CenterX2
local RingY = math.cos(-i*BaseTrig*ConVert*clipmod)*Size + CenterY
--surface.SetMaterial( Material("BurgerHUD/WhiteCircle.png") )
surface.SetDrawColor(255,255,0,Basefade)
surface.DrawTexturedRectRotated(RingX,RingY,BarWidth*math.Clamp(clipmod/2,1,10)/4,BarHeight*math.Clamp(clipmod/2,1,10)/4,0)
--surface.DrawTexturedRectRotated(RingX,RingY,BarWidth,BarHeight,i*1.2)
end
end
end
hook.Add("HUDPaint", "BB_HUDPAINT", BurgerBulletHUD)
[/code]
I mean it shows up and everything but the shapes are all squares and it conflicts with another mod. Even without that silly for i=300 line it has the same result.
[QUOTE=smithy285;45567441]Hey, how would I modify a SWEP that is on the ground? For example changing it's material/colour[/QUOTE]
So, my question wasn't answered on the previous page, i'm not sure if I have to wait a certain time to bump it but it has been nearly 24 hours and I am still looking for an answer, thanks.
[QUOTE=Robotboy655;45572564]Post the new code, with marking the erroring line.[/QUOTE]
offending code is still
[code]
function SWEP:SecondaryAttack()
if !SERVER then return end
if self.FireMode == 4 then
self.FireMode = 1
else
self.FireMode = self.FireMode + 1 -- ERROR HERE M8 CAN YOU SEE ME AM I MARKED CLEAR
end
self:UpdateFireMode(2)
print("Firemode Updated to "..self.FireMode)
self:CallOnClient("UpdateFireMode",self.FireMode)
self:CallOnClient("UpdateModeValues")
self:EmitSound( "weapons/armcannon/changebeam.wav" )
self:SetNextSecondaryFire( CurTime() + 0.2)
end
[/code]
the changed code is :
[code]
function SWEP:Initialize()
self.FireMode = self.Firemode or 1
self:SetHoldType("shotgun")
self.ChargePowerSound = CreateSound( self , "weapons/armcannon/powerbeam_charge.wav" )
self.ChargeWaveSound = CreateSound( self , "weapons/armcannon/wavebeam_charge.wav" )
self.ChargeIceSound = CreateSound( self , "weapons/armcannon/icebeam_charge.wav" )
self.ChargePlasmaSound = CreateSound( self , "weapons/armcannon/plasmabeam_charge.wav" )
self:UpdateModeValues()
if SERVER then
self.FireMode = self.Firemode or 1
self:UpdateModeValues()
end
if CLIENT then
self.Owner:GetViewModel():SetPlaybackRate(1)
// Create a new table for every weapon instance
self.VElements = table.FullCopy( self.VElements )
self.WElements = table.FullCopy( self.WElements )
self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
self:CreateModels(self.VElements) // create viewmodels
self:CreateModels(self.WElements)......
[/code]
i can send you the full code if you wish via PM
[QUOTE=Robotboy655;45572564]Post the new code, [b]with marking the erroring line.[/b][/QUOTE]
Sorry, you need to Log In to post a reply to this thread.