[QUOTE=YoutoYokodera;51708888]There is a thread for the wiki btw[/QUOTE]
Did not see it.
But I also have another issue. The wiki says [url]http://wiki.garrysmod.com/page/DListView/AddLine[/url] returns the panel but it returns nothing. Any reason for this?
[QUOTE=0V3RR1D3;51708938]Did not see it.
But I also have another issue. The wiki says [url]http://wiki.garrysmod.com/page/DListView/AddLine[/url] returns the panel but it returns nothing. Any reason for this?[/QUOTE]
Can't help with that but here [Url]https://facepunch.com/showthread.php?t=1250533&page=13[/url]
[QUOTE=YoutoYokodera;51709148]Can't help with that but here [Url]https://facepunch.com/showthread.php?t=1250533&page=13[/url][/QUOTE]
That question was not really related to the wiki, it was a question about why it does not return a line, but instead the parent panel itself.
[QUOTE=0V3RR1D3;51708872]Probably the wrong place but not sure where to post it, the wiki page for [url]https://wiki.garrysmod.com/page/DListView/OnRowSelected[/url] has its arguments inverted.[/QUOTE]
How are its arguments inverted? You can take a look at the [URL="https://github.com/garrynewman/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/lua/vgui/dlistview.lua#L377"]source[/URL] if you'd like, looks fine to me.
[QUOTE=0V3RR1D3;51708938]Did not see it.
But I also have another issue. The wiki says [url]http://wiki.garrysmod.com/page/DListView/AddLine[/url] returns the panel but it returns nothing. Any reason for this?[/QUOTE]
This works fine for me, and [URL="https://github.com/garrynewman/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/lua/vgui/dlistview.lua#L305"]source[/URL] looks fine as well, is it possible you have an addon overwriting default functions?
[editline]22nd January 2017[/editline]
[QUOTE=YoutoYokodera;51708738]I'm finding the best way to do this, any specific idea?
SetNW is obviously not ok
I've search and found a way of adding var to the player metatable but then after that the guy say I could try to change the var by SetNW so I think that is bad as the first idea[/QUOTE]
I already told you two ways to do this,
Using a table
[code]
local data = {}
-- Within a function to store stuff on a player
data[ply] = data[ply] or {}
data[ply][key] = value
[/code]
Or, storing it in the players table
[code]
ply.network_data = ply.network_data or {}
ply.network_data[key] = value
[/code]
What's the cleanest way to get a shared random value between the client and the server? Basically, I need to get the CurTime but 100% the same between server and client; not predicted
[QUOTE=TFA;51709644]What's the cleanest way to get a shared random value between the client and the server? Basically, I need to get the CurTime but 100% the same between server and client; not predicted[/QUOTE]
Get the curtime on the server and send it to the player?
I was looking at [url]https://wiki.garrysmod.com/page/GM/PlayerSpawn[/url]
and tried to use the example
function GM:PlayerSpawn( ply )
MsgN( ply:Nick() .. " has spawned!" )
end
and when I try to run it I recieve an error about "attempt to index global 'GM' (a nil value)"
I feel really dumb for not getting this but can someone explain why it's not working to me please?
[QUOTE=Sweet Berries;51709888]I was looking at [url]https://wiki.garrysmod.com/page/GM/PlayerSpawn[/url]
and tried to use the example
function GM:PlayerSpawn( ply )
MsgN( ply:Nick() .. " has spawned!" )
end
and when I try to run it I recieve an error about "attempt to index global 'GM' (a nil value)"
I feel really dumb for not getting this but can someone explain why it's not working to me please?[/QUOTE]
Call it in a hook, like so:
[code]
hook.Add("PlayerSpawn", "AnyIdentifierHere", function(ply)
-- code here
end )
[/code]
I believe that should work.
[QUOTE=Sweet Berries;51709888]I was looking at [url]https://wiki.garrysmod.com/page/GM/PlayerSpawn[/url]
and tried to use the example
function GM:PlayerSpawn( ply )
MsgN( ply:Nick() .. " has spawned!" )
end
and when I try to run it I recieve an error about "attempt to index global 'GM' (a nil value)"
I feel really dumb for not getting this but can someone explain why it's not working to me please?[/QUOTE]
Because of when it is run. Vaguely, your code is run after the gamemode has loaded, so you should use GAMEMODE instead [url]http://wiki.garrysmod.com/page/Global_Variables[/url]. (or, even better, use the hook)
[code]
hook.Add("PlayerSpawn","say_players_name",function(ply)
MsgN(ply:Nick() .. " has spawned!")
end)
[/code]
Edit: Sniped
Thanks guys, I saw that using the hook worked, but I was just curious why the other example, which uses a function would not work.
[editline]22nd January 2017[/editline]
As it says on
[url]https://wiki.garrysmod.com/page/Hook_Library_Usage[/url]
"Functions under the GM (or GAMEMODE) table are also treated as hooks. When an event is being ran, all hooks defined using hook.Add are called before the Gamemode function.
This means that the following code within a gamemode will also print to the console whenever a player spawns:
function GM:PlayerSpawn( ply )
print( ply:Name() .. " has spawned!" )
end
"
Which is confusing why it wont work
[QUOTE=Apickx;51709859]Get the curtime on the server and send it to the player?[/QUOTE]
This doesn't work, as the process of actually sending the time is delayed with network latency
[QUOTE=TFA;51709644]What's the cleanest way to get a shared random value between the client and the server? Basically, I need to get the CurTime but 100% the same between server and client; not predicted[/QUOTE]
There is no way for this to happen unless you can wait for a net message or you wait for CurTime (or any nwvar) to be updated clientside before running whatever code needs it.
[editline]22nd January 2017[/editline]
Or maybe you can do some clever stuff with http.Fetch, you'd still have to wait for it to get a result though. There is no instant way.
[QUOTE=TFA;51709644]What's the cleanest way to get a shared random value between the client and the server? Basically, I need to get the CurTime but 100% the same between server and client; not predicted[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/util/SharedRandom]util.SharedRandom[/url]
Says it's best used in a predicted hook, though.
[QUOTE=0V3RR1D3;51708938]Did not see it.
But I also have another issue. The wiki says [url]http://wiki.garrysmod.com/page/DListView/AddLine[/url] returns the panel but it returns nothing. Any reason for this?[/QUOTE]
It seems to return the line?
[lua]function PANEL:AddLine( ... )
self:SetDirty( true )
self:InvalidateLayout()
local Line = vgui.Create( "DListView_Line", self.pnlCanvas )
local ID = table.insert( self.Lines, Line )
Line:SetListView( self )
Line:SetID( ID )
-- This assures that there will be an entry for every column
for k, v in pairs( self.Columns ) do
Line:SetColumnText( k, "" )
end
for k, v in pairs( {...} ) do
Line:SetColumnText( k, v )
end
-- Make appear at the bottom of the sorted list
local SortID = table.insert( self.Sorted, Line )
if ( SortID % 2 == 1 ) then
Line:SetAltLine( true )
end
return Line
end[/lua]
[editline]22nd January 2017[/editline]
[QUOTE=TFA;51710163]This doesn't work, as the process of actually sending the time is delayed with network latency[/QUOTE]
This might work, not 100% sure.
[lua]local RCurTime = 0
hook.Add( "Move", "GetRealCurTime", function()
if !IsFirstTimePredicted() then return end
RCurTime = CurTime() + engine.TickInterval()
end)[/lua]
What's the best way to edit a func_tracktrain's velocity?
Also, whenever attempting to utilize the Entity's ID it's an issue since it's incremented each time the map is loaded.
[QUOTE=Aeternal;51710828]What's the best way to edit a func_tracktrain's velocity?
Also, whenever attempting to utilize the Entity's ID it's an issue since it's incremented each time the map is loaded.[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/MapCreationID]Entity:MapCreationID[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ents/GetMapCreatedEntity]ents.GetMapCreatedEntity[/url]. If I'm understanding the valve wiki page for it you can use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetKeyValue]Entity:SetKeyValue[/url] to change the velocity.
[QUOTE=bigdogmat;51709525]-snip-[/QUOTE]
Oh I was thinking in a box, thanks
Again a sleep helped :| ._.
[QUOTE=bigdogmat;51709525]How are its arguments inverted? You can take a look at the [URL="https://github.com/garrynewman/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/lua/vgui/dlistview.lua#L377"]source[/URL] if you'd like, looks fine to me.
This works fine for me, and [URL="https://github.com/garrynewman/garrysmod/blob/784cd57576d85712fa13a7cea3a9523b4df966b0/garrysmod/lua/vgui/dlistview.lua#L305"]source[/URL] looks fine as well, is it possible you have an addon overwriting default functions?
[editline]22nd January 2017[/editline]
I already told you two ways to do this,
Using a table
[code]
local data = {}
-- Within a function to store stuff on a player
data[ply] = data[ply] or {}
data[ply][key] = value
[/code]
Or, storing it in the players table
[code]
ply.network_data = ply.network_data or {}
ply.network_data[key] = value
[/code][/QUOTE]
So i've gone with this
[code]data = {}
function StoreValue(ply, key, value)
data[ply] = data[ply] or {}
data[ply][key] = value
end
function TakeValue(ply, key)
return data[ply][key]
end[/code]
But when i do in server and client
[code] --SERVER
function GM:PlayerSpawn( ply )
ply:StoreValue("money", 100)
end
--CLIENT
LocalPlayer():TakeValue("key")
-- it say
[ERROR] gamemodes/revorp/gamemode/cl_hud.lua:30: attempt to call method 'TakeValue' (a nil value)
1. v - gamemodes/revorp/gamemode/cl_hud.lua:30
2. unknown - lua/includes/modules/hook.lua:84
-- or i do this
TakeValue(LocalPlayer(), "money")
-- it say
[ERROR] gamemodes/revorp/gamemode/shared.lua:25: attempt to index a nil value
1. TakeValue - gamemodes/revorp/gamemode/shared.lua:25
2. v - gamemodes/revorp/gamemode/cl_hud.lua:30
3. unknown - lua/includes/modules/hook.lua:84
[/code]
[QUOTE=YoutoYokodera;51712502]
:snip[/QUOTE]
First error is because you either haven't defined TakeValue as a player method, or haven't defined it client side.
Second error is because you're attempting to index that players data field, but because that player doesn't have any values set on him, that field is non existent.
It doesn't look like you're networking the values anywhere, so I can only assume you aren't.
[QUOTE=bigdogmat;51712523]First error is because you either haven't defined TakeValue as a player method, or haven't defined it client side.
Second error is because you're attempting to index that players data field, but because that player doesn't have any values set on him, that field is non existent.
It doesn't look like you're networking the values anywhere, so I can only assume you aren't.[/QUOTE]
bruh i though if i put those func in shared.lua it will be avail to both sv and cl
[QUOTE=YoutoYokodera;51712547]bruh i though if i put those func in shared.lua it will be avail to both sv and cl[/QUOTE]
The functions will be, the data is separate. Think of a shared file as being 2 separate files, one loaded on the server, one loaded on the client.
Is it more efficient (or better practice) to use string.format to add variables into text, or is it better to just use .. to connect the variables?
[QUOTE=PigeonTroll;51712803]Is it more efficient (or better practice) to use string.format to add variables into text, or is it better to just use .. to connect the variables?[/QUOTE]
I use string.format when there needs to be two+ concatenations, but I actually haven't measured the efficiency difference. I do know for sure a single concat is faster than string.format, though, but it's minimal enough where it's up to personal preference.
[QUOTE=code_gs;51712875]I use string.format when there needs to be two+ concatenations, but I actually haven't measured the efficiency difference. I do know for sure a single concat is faster than string.format, though, but it's minimal enough where it's up to personal preference.[/QUOTE]
99% of the time concatenating multiple values at the same time is faster than string.format, but of course string.format is vastly different than concatenation.
The reason it will be faster is because calling a function created unneeded function calls, whereas concatenation of x things will be directly encoded into 1 opcode
[QUOTE=Rocket;51713043]only optimize when you need to[/QUOTE]
Or get in the habit of optimisation, to where it's second nature; then, it takes less work, and it's less likely you'll have to scrawl over thousands of lines of code in a second pass to try and make it run better.
[QUOTE=Rocket;51713043]Focus on clean code, only optimize when you need to - and I doubt string concatenation is going to be where you need to cut.[/QUOTE]
Depends on the strings he's working with and how he is concatenating them. Doing it wrong can be a memory killer. I don't know how or if JIT optimizes this, but in vanilla lua it's important to remember that when you are concatenating a string, you are creating a new string of the same size. Good read in PIL.
[url]https://www.lua.org/pil/11.6.html[/url]
[QUOTE=Promptitude;51710713]It seems to return the line?
[lua]function PANEL:AddLine( ... )
self:SetDirty( true )
self:InvalidateLayout()
local Line = vgui.Create( "DListView_Line", self.pnlCanvas )
local ID = table.insert( self.Lines, Line )
Line:SetListView( self )
Line:SetID( ID )
-- This assures that there will be an entry for every column
for k, v in pairs( self.Columns ) do
Line:SetColumnText( k, "" )
end
for k, v in pairs( {...} ) do
Line:SetColumnText( k, v )
end
-- Make appear at the bottom of the sorted list
local SortID = table.insert( self.Sorted, Line )
if ( SortID % 2 == 1 ) then
Line:SetAltLine( true )
end
return Line
end[/lua]
[editline]22nd January 2017[/editline]
This might work, not 100% sure.
[lua]local RCurTime = 0
hook.Add( "Move", "GetRealCurTime", function()
if !IsFirstTimePredicted() then return end
RCurTime = CurTime() + engine.TickInterval()
end)[/lua][/QUOTE]
Must be something messing with it then as everything is fine its just that, for me the arguments are backwards as in the first one is the actually panel and then the second is the index. I'll go take a look to see if its something my end, sorry for the post.
Does anyone know what the worldmodel for the physgun is? I've always used models/weapons/v_superphyscannon.mdl for viewmodel and models/weapons/w_superphyscannon.mdl for world, but apparently this has changed through times.
Any help is appreciated!
is there a way to lock focus onto a specific frame? I have a main DFrame, with a button that pops up a smaller one, and I want the user to only be able to interact with the small one until they close it
How can I stop the console saying this whenever I shoot the swep :)
[CODE]Changing collision rules within a callback is likely to cause crashes![/CODE]
Sorry, you need to Log In to post a reply to this thread.