This is just the way source works. All maps are divided up into [url=https://developer.valvesoftware.com/wiki/Visleaf]visleaves[/url]. Clientside, only what is in your [url=https://developer.valvesoftware.com/wiki/PVS]potentially visual set (PVS)[/url] (which is all the visleaves that you can see any part of from the visleaf you are currently in) exists.
[QUOTE=MrManiak;47290961]Does anyone know why entities that have never been in your line of sight are invalid? I send every players' entities using the net library and some are invalid when they are too far on the map.[/QUOTE]
That's just the way Source works.
edit: ninja'd.
[QUOTE=Drakehawke;47291045]This is just the way source works. All maps are divided up into [url=https://developer.valvesoftware.com/wiki/Visleaf]visleaves[/url]. Clientside, only what is in your [url=https://developer.valvesoftware.com/wiki/PVS]potentially visual set (PVS)[/url] (which is all the visleaves that you can see any part of from the visleaf you are currently in) exists.[/QUOTE]
Thanks, that's very interesting stuff. I guess the only way would be to create a timer that stops once if the entity exists on the client. I should probably have a separate table for player vars instead of modifying the player metatable, then. That would be more efficient.
-snip-
[editline]10th March 2015[/editline]
[QUOTE=MrManiak;47291070]Thanks, that's very interesting stuff. I guess the only way would be to create a timer that stops once if the entity exists on the client. I should probably have a separate table for player vars instead of modifying the player metatable, then. That would be more efficient.[/QUOTE]
Actually now that I think about it I thought that player entities were immune to PVS. You should be able to safely store things on the player table clientside
Why does the # operator on tables return 0 when the table has string keys? I tested this in regular Lua so its an issue with Lua itself
[code]
local tbl1 = {
"T",
"F",
"S",
}
local tbl2 = {
["T"] = "D",
["F"] = "S",
["S"] = "A",
}
print(#tbl1, #tbl2)
[/code]
[quote]
3 0
[/quote]
[QUOTE=Exho;47291257]Why does the # operator on tables return 0 when the table has string keys? I tested this in regular Lua so its an issue with Lua itself
[code]
local tbl1 = {
"T",
"F",
"S",
}
local tbl2 = {
["T"] = "D",
["F"] = "S",
["S"] = "A",
}
print(#tbl1, #tbl2)
[/code][/QUOTE]
It's definitely a part of lua. The dictionaries you create by using a non-integer key create a hashtable, people have assumed that Lua inserts nil entries into the dictionary to save having to resize the table constantly when adding things, and the getn function/# operator always return zero if there's a nil entry because nil is kinda meaningless in a table.
[editline][/editline]
One caveat, if you use numeric dictionary indices, getn/# takes the largest numeric value it finds. It just can't handle non-numbers for the obvious reason, strings tell you nothing about how big a table is and nil entries are ignored either way.
[QUOTE=Drakehawke;47291078]-snip-
[editline]10th March 2015[/editline]
Actually now that I think about it I thought that player entities were immune to PVS. You should be able to safely store things on the player table clientside[/QUOTE]
I don't want to bring up old stupid drama again, but that's essentially why PERP3 would load for an infinite amount of time, and why everyone was named John Doe on "custom" servers. Players aren't immuned to that, I'm almost positive.
[QUOTE=hexpunK;47291285]
One caveat, if you use numeric dictionary indices, getn/# takes the largest numeric value it finds.[/QUOTE]
I think this should be clarified a bit. It will find such index N so t[N] is not nil and t[N+1] is nil.
That means it'll give you 3 for this table: {1,2,3,nil,4,5} so it's not always largest numeric index.
[QUOTE=mijyuoon;47291349]I think this should be clarified a bit. It will find such index N so t[N] is not nil and t[N+1] is nil.
That means it'll give you 3 for this table: {1,2,3,nil,4,5} so it's not always largest numeric index.[/QUOTE]
[lua]#{1,2,nil,4}
4
#{1,2,3,nil,5}
3
#{1,2,3,4,nil,6}
6
[/lua]
I haven't a clue either.
[QUOTE=!cake;47291396][lua]#{1,2,nil,4}
4
#{1,2,3,nil,5}
3
#{1,2,3,4,nil,6}
6
[/lua]
I haven't a clue either.[/QUOTE]
Did some testing, it's weird. If you actually type crap like print(#({1,2,3,nil,4})) into Lua REPL it'll print 5. In cases where such table is generated it usually prints 3. Weird.
Anyone have any input on the performance of the remade NWVars?
[QUOTE=MrManiak;47291298]I don't want to bring up old stupid drama again, but that's essentially why PERP3 would load for an infinite amount of time, and why everyone was named John Doe on "custom" servers. Players aren't immuned to that, I'm almost positive.[/QUOTE]
Definitely should be immune.. otherwise scoreboards wouldn't work.
I use John Doe on my server for players who haven't picked a name yet.
All player entities are valid and returned by player.GetAll clientside for me, regardless of what is and isn't in my PVS.
[editline]10th March 2015[/editline]
[QUOTE=Exho;47291257]Why does the # operator on tables return 0 when the table has string keys? I tested this in regular Lua so its an issue with Lua itself
[code]
local tbl1 = {
"T",
"F",
"S",
}
local tbl2 = {
["T"] = "D",
["F"] = "S",
["S"] = "A",
}
print(#tbl1, #tbl2)
[/code][/QUOTE]
GMod has table.Count for this FYI - essentially just loops through and counts.
[QUOTE=Drakehawke;47291555]Definitely should be immune.. otherwise scoreboards wouldn't work.
I use John Doe on my server for players who haven't picked a name yet.
All player entities are valid and returned by player.GetAll clientside for me, regardless of what is and isn't in my PVS.
[editline]10th March 2015[/editline]
GMod has table.Count for this FYI - essentially just loops through and counts.[/QUOTE]
I didn't use player.GetAll, the server sends an entity index and the client can't resolve it. The index returns to an invalid entity. I'll test it again later.
[QUOTE=MrManiak;47291653]I didn't use player.GetAll, the server sends an entity index and the client can't resolve it. The index returns to an invalid entity. I'll test it again later.[/QUOTE]
Then something is really going wrong. Players always occupy the first x entindexes.
[code]
] _lua for i=1,15,1 do print(Entity(i)) end
Player [1][Pwedmy]
Player [2][Matsumoto Yamaguchi]
Player [3][Ivef]
Player [4][[CG] kirbycrazy33]
Player [5][Hoopy]
Player [6][Drakehawke]
Player [7][Poltergeist]
Player [8][Kushy]
Player [9][Clutch]
Player [10][Smokey Bluntson]
Player [11][Ruastin]
Player [12][Mr. Breeze]
Player [13][TheGreatKhan]
Player [14][Kackalack]
Player [15][[NRG]Cyanide]
[/code]
See? The only thing I can think of is that a player has disconnected or something?
Been playing around with SNPC's and currently am mind boggled and confused myself.
I'm checking if there is a "sent_woodboard" entity within a range of 25 of the npc, if there is then attack it and give it 1 damage. The problem is, the npc attacks every sent_woodboard within his sphere and if one sent_woodboard's health gets to 1 and others are still at 2~ then he stops attacking and it doesn't break.
[lua]function ENT:CheckBreakable()
local breakable = ents.FindInSphere(self:GetPos(),25)
if breakable then
for i = 1, #breakable do
local v = breakable[i]
if ( v:GetClass() == "sent_woodboard" ) then
if v:Health() >= 1 then
print(v:Health())
self:StartActivity(ACT_MELEE_ATTACK1)
self.loco:FaceTowards( v:GetPos() )
v:TakeDamage(1,"zmb","zmb")
end
end
end
end
end[/lua]
This is a sample output of the entities health when attacking, notice it stops on 1 instead of breaking them
[lua]10
8
7
6
5
4
3
2
1[/lua]
My question basically is, how can I make him target one entity at a time rather than all of them at once?
If I'm understanding you correctly, break out of the loop.
Simply insert [lua]break[/lua] after you do your desired actions.
[QUOTE=Jeezy;47292272]If I'm understanding you correctly, break out of the loop.
Simply insert [lua]break[/lua] after you do your desired actions.[/QUOTE]
Thanks, that fixed the issue of it hitting multiple of them, however it still knocks the health to 1 then stop and doesn't get to 0 yet I'm checking if it's greater or equal than 1?
EDIT:
I fixed it, I'm going to bed now as I'm doing silly things! I learned staying up until 5:30am isn't the best >:)
[lua]if v:GetMaterial() ~= "models/wireframe" then[/lua]
works compared to
[lua]if !v:GetMaterial() == "models/wireframe" then[/lua]
I believed that was checking if that isn't that material, but apparently not! I should read up on the lua documentation a little more.
With the new update i cannot set fonts in ApplySchemeSettings anymore because SetFont now calls ApplySchemeSettings. Why was this done? Where can I set the font now? Since the Font is defined in the derma skin it's the only place that makes sense really.
Can anyone tell me more about what exactly does [url=http://wiki.garrysmod.com/page/CSoundPatch/SetDSP]CSoundPatch:SetDSP[/url] does?
I'm thinking it may be similar in function with:
[url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexb800.html[/url]
[QUOTE=Exho;47291257]Why does the # operator on tables return 0 when the table has string keys? I tested this in regular Lua so its an issue with Lua itself
[code]
local tbl1 = {
"T",
"F",
"S",
}
local tbl2 = {
["T"] = "D",
["F"] = "S",
["S"] = "A",
}
print(#tbl1, #tbl2)
[/code][/QUOTE]
[quote=http://www.lua.org/manual/5.1/manual.html#2.5.5]"For a regular array, with non-nil values from 1 to a given n, its length is exactly that n, the index of its last value. If the array has "holes" (that is, nil values between other non-nil values), then #t can be any of the indices that directly precedes a nil value (that is, it may consider any such nil value as the end of the array)."
[/quote]
Basically - unless you are using a sequential table - the length is undefined. This is because the length operator doesn't actually calculate the length, it just retrieves what Lua has already stored as its length.
I wanna create a little menu where you can run commands on a player, i.e press a button to kill etc but want it so players can easily add their own
Any suggestions on what sort of format I should use for this? Mainly concerned about the networking aspect
[QUOTE=NiandraLades;47293607]I wanna create a little menu where you can run commands on a player, i.e press a button to kill etc but want it so players can easily add their own
Any suggestions on what sort of format I should use for this? Mainly concerned about the networking aspect[/QUOTE]
This might not be as hands on as you'd like but maybe [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/properties/Add"]properties.Add[/URL] with some networking tricks to modify .... uhh actually looking at it it might be more trouble than its worth to dynamically edit/add properties.
[url]https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/includes/modules/properties.lua[/url]
How can I disable that ammo box on the Jeep?
In fact, I would like to replace what it does altogether.
is there like a command in console to close all derma menus?
[QUOTE=The Commander;47294471]How can I disable that ammo box on the Jeep?
In fact, I would like to replace what it does altogether.[/QUOTE]
See example 2
[url]http://wiki.garrysmod.com/page/GM/PlayerUse[/url]
[QUOTE=NiandraLades;47293607]I wanna create a little menu where you can run commands on a player, i.e press a button to kill etc but want it so players can easily add their own
Any suggestions on what sort of format I should use for this? Mainly concerned about the networking aspect[/QUOTE]
The way I do it is through DermaMenu( ) in a single list format. I'll be releasing my admin system soon and it generates menus in a nice format, and when you re-open the menu it'll automatically put the mouse at the last opened, even if nested. It supports unlimited nested too and will support my permissions system on release.
For networking, its quite simple... You can either use a SWEP, or create a console command on the server which handles the checks, or you can use net.SendToServer and do the checks in net.Receive.
[QUOTE=RedNinja;47294514]is there like a command in console to close all derma menus?[/QUOTE]
I wrote one: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_utilities/concommand_clearvgui.lua[/url]
Drop it into: addons/acecool/lua/autorun/client/concommand_clearvgui.lua
[QUOTE=Robotboy655;47294547]See example 2
[url]http://wiki.garrysmod.com/page/GM/PlayerUse[/url][/QUOTE]
There was a couple of things wrong in the example (hit box is 3 and not 5 etc)
I ended up using
[lua]
if IsValid( ent ) and ent:IsVehicle() then
if ply:GetEyeTrace().HitBox == 3 then
return false
end
end
[/lua]
[QUOTE=The Commander;47295766]There was a couple of things wrong in the example (hit box is 3 and not 5 etc)
I ended up using
[lua]
if IsValid( ent ) and ent:IsVehicle() then
if ply:GetEyeTrace().HitBox == 3 then
return false
end
end
[/lua][/QUOTE]
You should just shorten that to 1 if statement.
[QUOTE=The Commander;47295766]There was a couple of things wrong in the example (hit box is 3 and not 5 etc)
I ended up using
if IsValid( ent ) and ent:IsVehicle() then if ply:GetEyeTrace().HitBox == 3 then return false end end
[/QUOTE]
It is actually 5, I have tested it on the Jeep.
It is also 5 in the source code which gives you ammo, so..
I've made this freeze RTD script for deathrun, however it is having an issue unfreezing the player. It freezes them, and then shows the message, however it never unfreezes them. What's wrong in this script, is it something wrong with the timer?
[CODE]
RESULT.Name = "Freeze"
function RESULT:Trigger(target)
target:Freeze( true )
timer.Create("freeze", 10, 1, resetspeed )
end
function resetspeed()
target:Freeze( false )
end
function RESULT:ShowMessage(ply)
RTD:BroadcastMessageAboutPlayer(ply, "has been ", Color(0, 0, 255), "frozen", color_white, " for", color_black, " 10 ", color_white, "seconds.")
end
[/CODE]
I also seem to have an issue with the message in my 'Point Gain' RTD, where the player rolls the dice and gets any amount set between what I chose in the script, which in this case is 25-100. The message is displayed and the points are given of course, however the message is having a problem displaying the correct number. 'i' in this case is what is supposed to define and show the number given, however it is pretty much just saying "3" each time, or sometimes just blank. Here's the code:
[CODE]
RESULT.Name = "Point Gain"
function RESULT:Trigger(target)
local i = target:PS_GivePoints(math.random(25, 100))
end
function RESULT:ShowMessage(ply)
RTD:BroadcastMessageAboutPlayer(ply, "had their points ", Color(0, 255, 0), "increased", color_white, " by ", Color(0, 255, 0), i, color_white, ".")
end
[/CODE]
Sorry, you need to Log In to post a reply to this thread.