[QUOTE=syl0r;46090979]Move the net.Receive and the util.AddNetworkedString out of the hook[/QUOTE]
Where would I put the util.AddNetworkString at then? It tosses an error if I place it outside anywhere. I also get [CODE][ERROR] lua_run:1: attempt to call global 'DeathMsgPly' (a nil value)
1. unknown - lua_run:1
[/CODE]
EDIT: That fixed it.
[QUOTE=NiandraLades;46089229]Yeah, I've heard it's bad to use that, but if I recall, I've tried doing just RunConsoleCommand but connect is blocked or something[/QUOTE]Use ConCommand
-snip- Figured it out
Hello,
I have a little question about game.IsDedicated().
Suppose I create a server with srcds, on my own computer (with sv_lan 0), and then I join this server with the same computer. If I call this function from my client game, it is returning false.
But will it return true for other players who are connecting from other computers ?
Also, this may sound dumb, but when I type "ip" in server console, it outputs "localhost", even with sv_lan = 0. Is it normal? :/
call game.IsDedicated( ) on the SERVER side of things; it'll return true. Your CLIENT will return false.
[QUOTE=syl0r;46084686]Yup.
You could write a recursive script that adds all files for you though.[/QUOTE]
Any tips on how I would do that?
Something like this?
[lua]
function AddDirLua(dir)
local list = file.FindDir("../"..dir.."/*")
for _, fdir in pairs(list) do
if fdir != ".svn" then
AddDir(dir.."/"..fdir)
end
end
for k,v in pairs(file.Find(dir.."/*", true)) do
resource.AddCSLuaFile(dir.."/"..v)
end
end
[/lua]
I'm having a problem with my SWEP base.
Basically (har har) I have two issues.
First one is the fact that once in a blue moon someone is stuck at a "double zoom" aka their FOV is half of what it should be. The only thing that controls that the first few functions starting at lines 77 and 91. They are called when the gun is deployed and initialized.
Second problem is that sometimes the guns shoot 3 bullets clientside when they're supposed to be shooting 1 bullet. This may have something to do with the functions at lines 60 and 280.
The base file can be found below
[url]https://github.com/BurgerLUA/CSSWeapons/blob/master/lua/weapons/weapon_cs_base.lua[/url]
you can download my weapons in it's entirety in the link below if you want
[url]https://github.com/BurgerLUA/CSSWeapons[/url]
[editline]4[/editline]
Why is this funny
[QUOTE=bluebull107;46093444]Any tips on how I would do that?
Something like this?
[lua]
function AddDirLua(dir)
local list = file.FindDir("../"..dir.."/*")
for _, fdir in pairs(list) do
if fdir != ".svn" then
AddDir(dir.."/"..fdir)
end
end
for k,v in pairs(file.Find(dir.."/*", true)) do
resource.AddCSLuaFile(dir.."/"..v)
end
end
[/lua][/QUOTE]
I use this function:
[lua]
local function addResourceFolder( dir )
local f, d = file.Find( dir .. "/*", "GAME" )
for _, v in pairs( f ) do
resource.AddFile( dir .. "/" .. v )
end
for _, v in pairs( d ) do
addResourceFolder( dir .. "/" .. v )
end
end
[/lua]
[QUOTE=DEFCON1;46093752]I use this function:
[lua]
local function addResourceFolder( dir )
local f, d = file.Find( dir .. "/*", "GAME" )
for _, v in pairs( f ) do
resource.AddFile( dir .. "/" .. v )
end
for _, v in pairs( d ) do
addResourceFolder( dir .. "/" .. v )
end
end
[/lua][/QUOTE]
[quote]dir .. "/" .. v[/quote]
Unless you don't care about garbage, I recommend you read up on string concatenation in Lua.
How would I spawn an entity ingame. Im trying to use !spawn ent npc_shop but it doesnt work like I would like it to. I know this is a simple thing to do but I just cant figure it out.
[QUOTE=bluebull107;46097621]How would I spawn an entity ingame. Im trying to use !spawn ent npc_shop but it doesnt work like I would like it to. I know this is a simple thing to do but I just cant figure it out.[/QUOTE]
For debugging purposes, in single player or in multiplayer with sv_cheats 1, [B]ent_create npc_shop[/B].
How can I override the surface property of a model, or group of models with the same texture? Because I'm tired of Sprops plates with the annoying sounds it makes when you walk on them.
I tried:
[code]
local m1 = Material( "sprops/sprops_grid" )
local m2 = Material( "nature/snowfloor003a" )
m1:SetTexture( "$basetexture" , m2:GetTexture( "$basetexture" ) )
m1:SetString( "$surfaceprop", "sand" )
m1:Recompute()
[/code]
The texture changed as planned (it was just a test), but the surfaceprop did not change... I tried the same thing with the ground texture of gm_flatgrass, and both the texture and the sound changed as planned.
I also tried messing with "PlayerFootstep" and "EntityEmitSound" hooks, got something semi-working but it's far from being perfect.. So his there a working way to change the surfaceprop of a model ?
[QUOTE=vexx21322;46094406]Unless you don't care about garbage, I recommend you read up on string concatenation in Lua.[/QUOTE]
What's wrong with using .. for string concatenation in Lua?
[IMG]http://i.imgur.com/5zUm354.png[/IMG]
is this because of size constraints? trying to avoid chunk sending
it should be well below 64kb
[QUOTE=Giraffen93;46100891][IMG]http://i.imgur.com/5zUm354.png[/IMG]
is this because of size constraints? trying to avoid chunk sending
it should be well below 64kb[/QUOTE]
There is no 215 type, show your code.
[QUOTE=Willox;46100934]There is no 215 type, show your code.[/QUOTE]
Serverside:
[lua]
http.Fetch("https://braxnet.org/rp/furniture.php", function(body)
FPROPS = util.JSONToTable(body)
if not FPROPS then return end
net.Start("FurnitureNet")
net.WriteTable(FPROPS)
net.Broadcast()
end)
[/lua]
Clientside:
[lua]
net.Receive("FurnitureNet", function(len)
FPROPS = net.ReadTable()
print("Received furniture, "..#FPROPS.." props")
end)
[/lua]
there isn't really anything more to it
[editline]29th September 2014[/editline]
seems that it quadruples the size when sent, oh well back to chunk sending i guess
[QUOTE=Giraffen93;46100990]Serverside:
[lua]
http.Fetch("https://braxnet.org/rp/furniture.php", function(body)
FPROPS = util.JSONToTable(body)
if not FPROPS then return end
net.Start("FurnitureNet")
net.WriteTable(FPROPS)
net.Broadcast()
end)
[/lua]
Clientside:
[lua]
net.Receive("FurnitureNet", function(len)
FPROPS = net.ReadTable()
print("Received furniture, "..#FPROPS.." props")
end)
[/lua]
there isn't really anything more to it
[editline]29th September 2014[/editline]
seems that it quadruples the size when sent, oh well back to chunk sending i guess[/QUOTE]
Did you try just sending it as a string instead and converting it client side?
It would appear there is something in your table that's acting weird. Try using PrintTable( TABLE ) to check that all is working correctly.
[QUOTE=sacred1337;46102409]Did you try just sending it as a string instead and converting it client side?
It would appear there is something in your table that's acting weird. Try using PrintTable( TABLE ) to check that all is working correctly.[/QUOTE]
the json string is too big too
the returned html page is 8kb, shouldn't be a problem, but it exceeds 64kb while in gmod
Line 4 is spewing [U]attempt to index local 'ply' (a nil value)[/U]?
[LUA]if SERVER then
hook.Add( "PlayerSpawn", "ShittyHook", function( ply )
local stuff = file.Read( "zeaga/somedata.txt", "DATA" )
if not string.match( stuff, ply:SteamID( ) ) then -- Errors
-- do some shit
end
end )
end[/LUA]
That's the gist of the part of the code that's causing the problem, anyway. It's actually supposed to be hooked to PlayerInitialSpawn but I have it set to PlayerSpawn for debugging purposes.
Am I doing it right?
[lua]
function meta:IsRoomFor(uniq)
local roomfor = true
local itmdata = PlexInv.GetItemTable(uniq)
for i = 1, InventoryConfig.Width do
for i2 = 1, InventoryConfig.Height do
if !ply.PlexInv[i][i2].Item and !ply.PlexInv[i][i2].MasterPos then
for i3 = 1, itmdata.w do
for i4 = 1, itmdata.w do
if ply.PlexInv[i+i3-1][i2+i4-1] and !ply.PlexInv[i+i3-1][i2+i4-1].Item and !ply.PlexInv[i+i3-1][i2+i4-1].MasterPos then
continue
else
roomfor = false
end
end
end
if roomfor then
return i, i2
end
end
end
end
return false, false
end
[/lua]
[editline]29th September 2014[/editline]
AnonTakesOver, if I'm doing it wrong then correct me, please.
[QUOTE=AirBlack;46104168]Am I doing it right?
[lua]
function meta:IsRoomFor(uniq)
local roomfor = true
local itmdata = PlexInv.GetItemTable(uniq)
for i = 1, InventoryConfig.Width do
for i2 = 1, InventoryConfig.Height do
if !ply.PlexInv[i][i2].Item and !ply.PlexInv[i][i2].MasterPos then
for i3 = 1, itmdata.w do
for i4 = 1, itmdata.w do
if ply.PlexInv[i+i3-1][i2+i4-1] and !ply.PlexInv[i+i3-1][i2+i4-1].Item and !ply.PlexInv[i+i3-1][i2+i4-1].MasterPos then
continue
else
roomfor = false
end
end
end
if roomfor then
return i, i2
end
end
end
end
return false, false
end
[/lua]
[editline]29th September 2014[/editline]
AnonTakesOver, if I'm doing it wrong then correct me, please.[/QUOTE]
Why do you have 4 nested for loops?
[QUOTE=syl0r;46104287]Why do you have 4 nested for loops?[/QUOTE]
First two loops are checking x and y and other two loops are checking x+width and y+height. If you didn't understand then it's grid based inventory system.
[QUOTE=AirBlack;46104306]First two loops are checking x and y and other two loops are checking x+width and y+height. If you didn't understand then it's grid based inventory system.[/QUOTE]
Is it a 4 dimensional inventory system or what?
[QUOTE=syl0r;46104344]Is it a 4 dimensional inventory system or what?[/QUOTE]
It's 2 dimensional inventory system with item size(M4 from CS:S is 6/2 for example(6 in width and 2 in height))
[QUOTE=AirBlack;46104409]It's 2 dimensional inventory system with item size(M4 from CS:S is 6/2 for example(6 in width and 2 in height))[/QUOTE]
I see, I guess you are doing it right then.
I am sure there are (much) better algorithms to find a free spot but I guess it doesn't really matter that much.
One thing you should do though is put the inner 2 for loops into a seperate method (doesFit(x,y) or something like that). It increases readability and maintainability by a lot.
[QUOTE=syl0r;46104586]I see, I guess you are doing it right then.
I am sure there are (much) better algorithms to find a free spot but I guess it doesn't really matter that much.
One thing you should do though is put the inner 2 for loops into a seperate method (doesFit(x,y) or something like that). It increases readability and maintainability by a lot.[/QUOTE]
My inventory system is based by X and Y coordinates. I need to check every coordinate for free place. So, if I'll do doesFit function it will contain loops too.
[QUOTE=AirBlack;46104809]My inventory system is based by X and Y coordinates. I need to check every coordinate for free place. So, if I'll do doesFit function it will contain loops too.[/QUOTE]
Yeah, I know.
The only reason to do it is that people can understand it easier. This is especially useful when you want someone else to understand your code or you come back 3 months after you coded it and want to make changes yourself.
It can also be used in other functions and thus can reduce code duplicates.
[QUOTE=syl0r;46104969]Yeah, I know.
The only reason to do it is that people can understand it easier. This is especially useful when you want someone else to understand your code or you come back 3 months after you coded it and want to make changes yourself.
It can also be used in other functions and thus can reduce code duplicates.[/QUOTE]
Made more readable version
[lua]
local function inbox(ply,x,y,w,h)//ply is needed for inventory table
local cox = true
for i = 1, w do//looping x
if !cox then break end//if not in box then break x loop
for i2 = 1, h do//looping y
local item = ply.PlexInv[x+i-1][y+i2-1]
if !item or item.Item or item.MasterPos then//check if that slot exists and doesn't have item on it
cox = true
break//break y loop
end
end
end
return cox//return is in box
end
function meta:IsRoomFor(uniq)
local itmdata = PlexInv.GetItemTable(uniq)//gets item data from global stored table of items
for i = 1, InventoryConfig.Width do//looping x on whole inventory
for i2 = 1, InventoryConfig.Height do//looping y on whole inventory
if i + itmdata.w - 1 <= InventoryConfig.Width and i2 + itmdata.h - 1 <= InventoryConfig.Height then//check if position fits to item(to pervent table key invalid)
if inbox(self,i, i2, itmdata.w, itmdata.h) then//checking if item fits in box
return i, i2//if fits then return master position(left upper coordinates)
end
end
end
end
return false//if doesn't fit then return false
end
[/lua]
What's the character limit for lua files and folders in our lua directory?
Hi, I have a small issue with my script that i cant figure out, and i also have a question:
I have a DTextEntry in my frame, then when i press my dbutton it sends the DTextEntry text to the server, and heres my issue, how would i go on about sending the text back to all clients from the server?
[QUOTE=BFG9000;46105518]What's the character limit for lua files and folders in our lua directory?[/QUOTE]
You'll probably get limited by a few things (on Windows at least) at 260 characters total path length. Each file/dir name shouldn't be greater than 255 characters either.
why?
Sorry, you need to Log In to post a reply to this thread.