Every now and then one of my servers freezes and then when I interact with the SRCDS window it does this:
[t]http://p.sup.sx/i/1421469337.png[/t]
Anyone know what causes it?
[QUOTE=Phoenixf129;46946869][lua]
function ENT:OnLimbHit( hitgroup, dmginfo )
if not IsValid( self ) then return end
if hitgroup == HITGROUP_HEAD then
dmginfo:ScaleDamage( 2.75 )
elseif hitgroup == HITGROUP_CHEST then
dmginfo:ScaleDamage( 1.25 )
elseif hitgroup == HITGROUP_STOMACH then
dmginfo:ScaleDamage( 0.75 )
else
dmginfo:ScaleDamage( 0.50 )
end
end
[/lua]
If I remember correctly. I use these in my zombie nextbots. It looks like it's undocumented too.[/QUOTE]
That's fantastic, where did you even find that?
Does anyone know how to use the autocomplete features that the DTextEntry element seems to have functionality for?
[QUOTE=StonedPenguin;46951532]Every now and then one of my servers freezes and then when I interact with the SRCDS window it does this:
[t]http://p.sup.sx/i/1421469337.png[/t]
Anyone know what causes it?[/QUOTE]
If you happen to click inside of the SRCDS console, like trying to copy some text, but don't remember to 'break' out of it by entering some text or something, the next time any text would try to print to the console, you'll cause the whole server to hang until the next time you interact with it.
I'm not explaining it very well, but you can replicate it by just clicking anywhere in SRCDS and then saying something in-game via chat. The server will hang indefinitely until you type something in console.
[QUOTE=Mista Tea;46951748]If you happen to click inside of the SRCDS console, like trying to copy some text, but don't remember to 'break' out of it by entering some text or something, the next time any text would try to print to the console, you'll cause the whole server to hang until the next time you interact with it.
I'm not explaining it very well, but you can replicate it by just clicking anywhere in SRCDS and then saying something in-game via chat. The server will hang indefinitely until you type something in console.[/QUOTE]
I've accidentally done that before however this happens with no interaction with the SRCDS window and only on 1 of 4 servers on the same box.
Okay, so hopefuly this is easy to solve, I've made an SMG SWEP that fires oranges and uses clips, but my 2 problems are: 1. In third person I can see the SMG being held as a pistol, the reload animation also is the reload animation of a pistol, and 2. In first person, there is no reload animation, I do get the SMG reload sound though, and it does reload the clip. This is my first SWEP I'm actualy trying to make (I made the Chair-Thrower work properly and am trying to edit it to be an orange-firing SMG that uses clips), so I'm very new to this :P. Now I'll try and properly paste the relevant code in using the boxes I'm supposed to use:
[LUA] SWEP.HoldType = "smg" [/LUA]
[LUA] local ReloadSound = Sound("Weapon_SMG1.Reload") [/LUA]
[LUA] function SWEP:Reload( )
if ( self.Owner:GetAmmoCount( self.Weapon:GetPrimaryAmmoType() ) > 0 ) then
self.Weapon:EmitSound( ReloadSound )
self.Weapon:DefaultReload( ACT_GESTURE_RELOAD_SMG1 )
end
end [/LUA]
Thanks, Sorry I'm new :P.
EDIT: And no there are no console errors.
[lua]local function PlayerSay(ply, text, teamChat)
if ( string.sub( text, 1, 4 ) == "/attack" ) then
ply:AnimRestartGesture( GESTURE_SLOT_CUSTOM, ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE, true )
return false
end
end
hook.Add("PlayerSay","PlayerSay",PlayerSay)
[/lua]
Why won't this work? It doesn't have any errors it just doesn't do anything.
[QUOTE=Garrison;46954613][lua]local function PlayerSay(ply, text, teamChat)
if ( string.sub( text, 1, 4 ) == "/attack" ) then
ply:AnimRestartGesture( GESTURE_SLOT_CUSTOM, ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE, true )
return false
end
end
hook.Add("PlayerSay","PlayerSay",PlayerSay)
[/lua]
Why won't this work? It doesn't have any errors it just doesn't do anything.[/QUOTE]
Because string.sub( text, 1, 4 ) would == /att
I don't see why people use string.sub, seems like a bad method. I suggest using string.find instead,
[lua]if string.find(text, "/attack", 0, true) then ... end[/lua]
[QUOTE=StonedPenguin;46954656]Because string.sub( text, 1, 4 ) would == /att[/QUOTE]
Acttually I had it at /att when I was testing, my mistake for posting the wrong code.
You could also do this:
[code]
hook.Add("PlayerSay", "da.commands.chat", function(ply, text, public)
local chatWords = string.Explode(" ", text)
if string.sub(text, 1, 1) == "!" or string.sub(text, 1, 1) == "/" then
local cmd = string.sub(string.lower(chatWords[1]), 2)
if cmd == "attack" then
-- do shit
elseif cmd == "kill" then
ply:Kill()
end
end
end)
[/code]
I use this method in my admin mod, but it's a bit more complex. I store commands in tables with their functions and check cmd against the table, but that's unnecessarily complicated if you just want to easily add commands.
I really just want to know why this line in particular won't show any signs of doing something.
[lua]
ply:AnimRestartGesture( GESTURE_SLOT_CUSTOM, ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE, true )
[/lua]
[QUOTE=Phoenixf129;46946869][lua]
function ENT:OnLimbHit( hitgroup, dmginfo )
if not IsValid( self ) then return end
if hitgroup == HITGROUP_HEAD then
dmginfo:ScaleDamage( 2.75 )
elseif hitgroup == HITGROUP_CHEST then
dmginfo:ScaleDamage( 1.25 )
elseif hitgroup == HITGROUP_STOMACH then
dmginfo:ScaleDamage( 0.75 )
else
dmginfo:ScaleDamage( 0.50 )
end
end
[/lua]
If I remember correctly. I use these in my zombie nextbots. It looks like it's undocumented too.[/QUOTE]
[QUOTE=Ericson666;46951660]That's fantastic, where did you even find that?[/QUOTE]
I take it back, that function doesn't actually do anything :p
[code]surface.SetMaterial( GetRenderTarget( "ExistingRenderTarget", Dimension, Dimension, true ) )[/code]
returns userdata
[quote=Developer Console]lua:302: bad argument #1 to 'SetMaterial' (IMaterial expected, got userdata)[/quote]
[editline]17th January 2015[/editline]
note "ExistingRenderTarget" is not what I really typed, I typed the actual name of the rendertarget...
[QUOTE=Garrison;46954844]I really just want to know why this line in particular won't show any signs of doing something.
[lua]
ply:AnimRestartGesture( GESTURE_SLOT_CUSTOM, ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE, true )
[/lua][/QUOTE]
Because all the gestures are being overridden by the player animation system. Exactly SLOT_CUSTOM here:
[url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/gamemode/animations.lua#L84[/url]
[QUOTE=Author.;46954700]I don't see why people use string.sub, seems like a bad method. I suggest using string.find instead,
[lua]if string.find(text, "/attack", 0, true) then ... end[/lua][/QUOTE]
I'd advise against using string.find as it would be triggered even if players are typing normal text and not a command. E.g.,
[CODE]
lua_run_cl print( ("I sure hope I don't get killed/slayed"):find( "/slay", 1, true ) )
31 35
[/CODE]
Clearly the player has no intention of running the /slay command, but string.find would believe otherwise.
I feel really dumb but, how do I make a local table inside a function that keeps its state? Right now I'm declaring it outside the function.
[lua]local abc = {}
function doStuff()
-- expect abc to retain its data from previous execution of this function
-- manipulate abc
end[/lua]
I want to declare abc inside the function (to be local to the function instead of the whole file), how do I do this?
I think I saw in several places that it can be done like so:
[lua]function doStuff()
local abc = abc or {}
-- expect abc to retain its data from previous execution of this function
-- manipulate abc
end[/lua]
But my memory must be misleading me, because this doesn't work at all - it resets abc to {} every time. What's the correct way to do this?
[QUOTE=Neat-Nit;46955446]I feel really dumb but, how do I make a local table inside a function that keeps its state? Right now I'm declaring it outside the function.
local abc = {}function doStuff() -- expect abc to retain its data from previous execution of this function -- manipulate abcend
I want to declare abc inside the function (to be local to the function instead of the whole file), how do I do this?
I think I saw in several places that it can be done like so:
function doStuff() local abc = abc or {} -- expect abc to retain its data from previous execution of this function -- manipulate abcend
But my memory must be misleading me, because this doesn't work at all - it resets abc to {} every time. What's the correct way to do this?[/QUOTE]
[lua]
//Some table that has stuff in the global scope
local table1 = {'dick','penis','weiner'}
//function
function doStuff()
local table2 = table1 or {}
return table2[3]
end
[/lua]
[QUOTE=Revenge282;46955536][lua]
//Some table that has stuff in the global scope
local table1 = {'dick','penis','weiner'}
//function
function doStuff()
local table2 = table1 or {}
return table2[3]
end
[/lua][/QUOTE]
So then... it isn't possible?
[QUOTE=Neat-Nit;46955446][CODE]function doStuff()
local abc = abc or {}
-- expect abc to retain its data from previous execution of this function
-- manipulate abc
end[/CODE][/QUOTE]
The method that you are trying to use would not work because of the local scope on abc.
Trying to assign a local variable to itself will always be nil, meaning [B]local abc = abc or {}[/B] will translate to [B]local abc = nil or {}[/B], or just [B]local abc = {}[/B], every time.
By the time the doStuff() function returns, abc will go out of scope and be garbage collected. The next time you run doStuff(), the data you set on it during the last call will no longer be assigned to abc.
The method [B]something = something or somethingElse[/B] works for variables with a [B]global [/B]scope, not local variables. The first time it is executed, it equates to [B]something = nil or somethingElse[/B], meaning something = somethingElse. But if the file were to be refreshed, it would then be [B]something = (table already stored in something) or somethingElse[/B], which would be something = something, allowing it to retain data that had already been entered inside of it.
I've probably butchered that explanation.
[QUOTE=Neat-Nit;46955564]So then... it isn't possible?[/QUOTE]
I don't know why you need it, but...
[lua]
local doStuff
do
local abc = {}
function doStuff()
-- do stuff
end
end
[/lua]
[QUOTE=Mista Tea;46955582]The method that you are trying to use would not work.
Trying to assign a local variable to itself will always be nil, meaning [B]local abc = abc or {}[/B] will translate to [B]local abc = nil or {}[/B], or just [B]local abc = {}[/B], every time.
By the time the doStuff() function returns, abc will go out of scope and be garbage collected. The next time you run doStuff(), the data you set on it during the last call will no longer be assigned to abc.
The method [B]something = something or somethingElse[/B] only works for variables with a global scope, not local variables. The first time it is executed, it equates to [B]something = nil or somethingElse[/B], meaning something = somethingElse. But if the file were to be refreshed, it would then be [B]something = (table already stored in something) or somethingElse[/B], which would be something = something, allowing it to retain data that had already been entered inside of it.
I've probably butchered that explanation.[/QUOTE]
Actually you explained it perfectly, thanks!
[QUOTE=EvacX;46955596]I don't know why you need it, but...
[lua]
local doStuff
do
local abc = {}
function doStuff()
-- do stuff
end
end
[/lua][/QUOTE]
Thanks, I'm probably gonna keep it local to the file rather than the function since it's a really small thing. Mind if I ask, though, why you need to declare local doStuff at the top?
You could use string.StartWith, etc... Here are some examples:
These look the "cleanest" because it converts ! to public command meaning it is echoed and turned into console command, / is private; example once uses concommand.Add while example 2 lets you add salt and pepper ( pre/postfix ) using chatcommand.Add
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands_examples.lua.html[/url]
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands_other.lua.html[/url]
[QUOTE=Neat-Nit;46955630]Thanks, I'm probably gonna keep it local to the file rather than the function since it's a really small thing. Mind if I ask, though, why you need to declare local doStuff at the top?[/QUOTE]
How else would the code that comes after the do-end block know about it?
does anyone have any examples for the drive system?
[QUOTE=EvacX;46955671]How else would the code that comes after the do-end block know about it?[/QUOTE]
Hmm... I think I understand. Still very new to lua (and programming in general - unless oldschool-style BASIC or visual languages count :P), so I don't have the whole 'scope' thing [i]quite[/i] figured out yet...
Thanks!
I get a strange compile error called "Node without a volume" whenever I attempt to use a lua_run entity . I've asked some mapper friends of mine and there have never experienced it so I figured I would ask it here since it is a Garry entity... The compile error completely stops the compile of the map and gives no coordinates or anything
Is it preventing the compile or showing as a warning?
[quote=Interlopers]Warning: node without a volume
Description:
Your map has a node without a volume. (a node is what a clipnode was in hl1, in other words a volume denoting where the player can get to and where not.)
Solution:
Unless you just did some vertex-manipulation or placed static props in a wall, or added a funky new displacement, you shouldn't hunt this error down, as it may take you ages to find, unless you get strange effects in your map. Just fix (simplify) the awkward gemetry if you find it. May also be the sign of an invalid brush, or simply vertices offgrid (unlikely?).
See also:
Reference: Finding the unfindable
Generally, this error may be ignored
Last contribution: Anonymous[/quote]
If removing a point entity fixes the issue, it might be the code you are running - does it contain any strings? It could be breaking the vmf format.
[CODE]TEAM_TACRESTEAMCO = AddExtraTeam("Tactical Response Team Commander", {
color = Color(0, 102, 204, 255),
model = {
"models/player/gasmask.mdl",
"models/player/riot.mdl",
"models/player/urban.mdl",
"models/player/swat.mdl" },
description = [[ Tactical Response Team Commander it is your
job to command your team in raids.]],
weapons = {"arrest_stick", "unarrest_stick", "stunstick", "door_ram", "weaponchecker", "weapon_fists", "m9k_glock", "m9k_l85", "m9k_usas", },
command = "trtco",
max = 1,
salary = 90,
admin = 0,
vote = true,
hasLicense = true,
NeedToChangeFrom = TEAM_TACRESTEAM,
customCheck = function(ply) return CLIENT or table.HasValue({"tier1", "tier2", "tier3", "tier4", "tier5",
"mod1", "mod2", "mod3", "mod4", "mod5",
"admin1", "admin2", "admin3", "admin4", "admin5",
"superadmin", "owner" },
ply:GetNWString("usergroup")) end
CustomCheckFailMsg = "This job is Tier 1+ only!",
vip = true
})[/CODE]
Is putting off this error:
[CODE][ERROR] addons/darkrpmodification/lua/darkrp_customthings/jobs.lua:395: '}' expected (to close '{' at line 373) near 'CustomCheckFailMsg'
1. unknown - addons/darkrpmodification/lua/darkrp_customthings/jobs.lua:0[/CODE]
Any ideas? I look at the braces locations and stuff but I can't seem to find the issue.
[QUOTE=Yumaglo;46958142]Is putting off this error:
[CODE][ERROR] addons/darkrpmodification/lua/darkrp_customthings/jobs.lua:395: '}' expected (to close '{' at line 373) near 'CustomCheckFailMsg'
1. unknown - addons/darkrpmodification/lua/darkrp_customthings/jobs.lua:0[/CODE]
Any ideas? I look at the braces locations and stuff but I can't seem to find the issue.[/QUOTE]
The error can sound a bit misleading. Add a comma after [B]ply:GetNWString("usergroup")) end[/B]
Sorry, you need to Log In to post a reply to this thread.