I tried to send a json string and i can't understand how would i get how many bytes will i need
DComboBox allows you to store data along with a string, [LUA]DComboxBox:AddChoice( string , data )[/LUA] How do i get the data?
Screenshot chunk sender:
[code]
if SERVER then
util.AddNetworkString("Screenshot")
net.Receive("Screenshot" , function(len, ply)
if not ply.ScreenshotChunks then
ply.ScreenshotChunks = {}
end
local chunk = net.ReadData(( len - 1 ) / 8)
table.insert(ply.ScreenshotChunks, chunk)
local last_chunk = net.ReadBit() == 1
if last_chunk then
local data = table.concat(ply.ScreenshotChunks)
-- Do something else here, perhaps send to an admin using the same method?
file.Write("screenshot.txt", data)
ply.ScreenshotChunks = nil
end
end)
else
local MAX_CHUNK_SIZE = 16384
local CHUNK_RATE = 1 / 4 -- 4 chunk per second
local SENDING_DATA = false
local function SendScreenshot()
assert(not SENDING_DATA)
SENDING_DATA = true
local data = render.Capture {
x = 0,
y = 0,
w = ScrW(),
h = ScrH(),
quality = 50
}
local chunk_count = math.ceil(string.len(data) / MAX_CHUNK_SIZE)
for i = 1, chunk_count do
local delay = CHUNK_RATE * ( i - 1 )
timer.Simple(delay, function()
local chunk = string.sub(data, ( i - 1 ) * MAX_CHUNK_SIZE + 1, i * MAX_CHUNK_SIZE)
local chunk_len = string.len(chunk)
net.Start("Screenshot")
net.WriteData(chunk, chunk_len)
net.WriteBit(i == chunk_count)
net.SendToServer()
if i == chunk_count then
SENDING_DATA = false
end
end)
end
end
concommand.Add("send_data", SendScreenshot)
end
[/code]
Here it is. Hopefully it explains itself but if you don't understand any of it feel free to ask.
[QUOTE=Giraffen93;45582561]Can i resize a render.Capture() somehow? So it fits inside a net message.[/QUOTE]
One alternative to net messages is to send it via HTTP(). You could use [B]util.Base64Encode[/B] on the binary data before sending it, and (if using PHP) [URL="http://php.net/manual/en/function.base64-decode.php"]base64_decode[/URL] it on a webserver.
But if you actually need Lua to handle it, you can use a for-loop to send several net messages that are broken up in 64kB pieces of the binary data.
Here's something dumb you could do:
[CODE]
-- client code
local NET_TRANSFER_LIMIT = 64 * 1024 -- bytes per message
local SOURCE_TRANSFER_LIMIT = 20 * 1024 -- bytes per second
local UINT = 2 * 8 -- 2 bytes for the written binary data length
local BOOL = 1 * 8 -- 1 byte for the boolean that determines when the message is finished
local CHUNK_LENGTH = NET_TRANSFER_LIMIT - (UINT/8) - (BOOL/8) -- number of bytes left for the chunk
-- function for sending the >64kB message in 64kB chunks
function SendInChunks( strName, binData )
local binLen = #binData
local numChunks = math.ceil( binLen / CHUNK_LENGTH )
for i = 1, numChunks do
local START = ( i - 1 ) * ( CHUNK_LENGTH ) + 1
local END = i * CHUNK_LENGTH
local chunk = binData:sub( START, END )
net.Start( strName )
net.WriteUInt( #chunk, UINT )
net.WriteData( chunk, #chunk )
net.WriteBit( i == numChunks )
net.SendToServer()
end
end
-- test function with render.Capture
function RenderCapture()
local tbl = {
format = "jpeg",
h = ScrH(),
w = ScrW(),
quality = 70,
x = 0,
y = 0
}
local data = render.Capture( tbl )
print( #data ) -- verify you receive the same amount of bytes you sent
SendInChunks( "RenderCapture", data )
end
--[[-----------------------------------------------]]--
-- server code
local captures = {}
net.Receive( "RenderCapture", function( bits, ply )
local dataLength = net.ReadUInt( 16 )
local data = net.ReadData( dataLength )
local done = net.ReadBit() == 1
-- dumb
local capture = captures[ ply:SteamID() ]
capture = ( capture and capture .. data ) or data
captures[ ply:SteamID() ] = capture
if ( done ) then
print( #captures[ ply:SteamID() ] )
-- do what you want with the full catpure
captures[ ply:SteamID() ] = nil
end
end )
[/CODE]
It's lame but it does cut the message up unto sendable chunks. Since the source limit is apparently 20kB/s, this does take some time to send from client->server.
You could modify it so send the chunks based on a timer instead, and use SOURCE_TRANSFER_LIMIT as the max chunk length.
When using util.Compress, do i get binary data? How can i get the size of that
[QUOTE=gonzalolog;45583153]When using util.Compress, do i get binary data? How can i get the size of that[/QUOTE]
Lua strings are pretty much just binary data containers. Use string.len.
Ninja'd, of course.
Willox's way will be better in the end because of the delay. That way it doesn't choke up the client's end by sending huge messages very quickly (as my code will do).
[QUOTE=Mista Tea;45583201]Ninja'd, of course.
Willox's way will be better in the end because of the delay. That way it doesn't choke up the client's end by sending huge messages very quickly.[/QUOTE]
I'd actually suggest tuning it to only send a max of ~16KB/s rather than my script's 64KB/s to minimize any lag and still leave room for other networked stuff to fly about without hitting the cap.
that first sender works, takes about 15 seconds though
if i use clientside http posting it can be easily abused, i want to avoid that
DComboBox allows you to store data along with a string, [LUA]DComboxBox:AddChoice( string , data )[/LUA] How do i get the data?
-snip-
Um, how does that get the data attached to the specific string? [QUOTE=ShadowRanger;45583989]DComboBox.data or self.data if possible.[/QUOTE]
[QUOTE=HunterFP;45581658]Does anyone know a way to set the color of a player (SetColor) without defining the color of clientsidemodel that is linked to a bone of the player?[/QUOTE]
Anyone?
Anyone know of a good way to prevent attempts to crash a server using stacker and chairs?
A lot of people seem savvy and just come into my server and spawn a chair and stacker it and unfreeze it. Anyone have an ideas? I'm trying to eliminate having to blacklist the prop.
[QUOTE=TheBerryBeast;45584114]Um, how does that get the data attached to the specific string?[/QUOTE]Sorry, I think I misunderstood what you meant. I thought you meant once you've added a choice with data, how would you retrieve that data. Can you please elaborate a bit?
I'm having a small problem. Don't know if it's because I didn't put it in the right area, or if something is wrong with it.
[code]if ( game.GetMap() == "dm_chiron" ) then
for k, v in pairs( ents.FindByClass( "weapon_357" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_alyxgun" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_annabelle" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_ar2" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_brickbat" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_bugbait" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_crossbow" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_crowbar" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_frag" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_physcannon" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_pistol" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_rpg" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_shotgun" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_smg1" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_striderbuster" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_stunstick" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "weapon_slam" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_357" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_357_large" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_ar2" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_ar2_altfire" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_ar2_large" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_crate" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_crossbow" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_pistol" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_pistol_large" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_smg1" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_smg1_grenade" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_ammo_smg1_large" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_battery" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_box_buckshot" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_healthcharger" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_healthkit" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_healthvial" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_rpg_round" ) ) do
v:Remove()
end
for k, v in pairs( ents.FindByClass( "item_suitcharger" ) ) do
v:Remove()
end
end[/code]
Put in lua/autorun
[QUOTE=Vipes;45586800]I'm having a small problem. Don't know if it's because I didn't put it in the right area, or if something is wrong with it.
Put in lua/autorun[/QUOTE]
[lua]hook.Add( "InitPostEntity", "some_unique_name", function()
--your stuff here(not sure it will work but since I'm just awake I haven't a clear mind yet
end )[/lua]
Vipes, what gamemode is that for? If it is for TTT, the weaponplacer for TTT (search on workshop) has a handy feature where you can replace all HL2 entities by TTT variants with a single click of a button.
[QUOTE=TripsLetash;45587352]Vipes, what gamemode is that for? If it is for TTT, the weaponplacer for TTT (search on workshop) has a handy feature where you can replace all HL2 entities by TTT variants with a single click of a button.[/QUOTE]
It's for a DM gamemode, but I'm replacing all the weapons with different ones. So I'm pretty much trying to gut maps then use a Coderhire script I plan on buying.
You could look at how TTT handles its initializing (checks for a mapname.txt and uses those settings/positions) and look at the TTT weaponplacer (how to replace all your HL2 entities by your entities and how it creates the file), it would make it so that you could easily add any map you'd ever like to your DM gamemode without much work. I'm pretty sure redoing the code you posted above for every map will be tedious, and not very effecient. Just an idea :)
EDIT: I think I misunderstood what you wanted, my bad! My idea was more to get an external source to define your weapon replacements/spawns independant from the map while at the same time clearing whatever spawns are already present on the map :)
[QUOTE=Vipes;45587373]It's for a DM gamemode, but I'm replacing all the weapons with different ones. So I'm pretty much trying to gut maps then use a Coderhire script I plan on buying.[/QUOTE]
[lua]
hook.Add("InitPostEntity","RemoveWeapons",function()
if ( game.GetMap() == "dm_chiron" ) then
for k,v in pairs(ents.FindByClass("weapon_*")) do
v:Remove()
end
for k,v in pairs(ents.FindByClass("item_*")) do
v:Remove()
end
end
end)
[/lua]
put in a file inside of lua/autorun/server
[QUOTE=TripsLetash;45587394]You could look at how TTT handles its initializing (checks for a mapname.txt and uses those settings/positions) and look at the TTT weaponplacer (how to replace all your HL2 entities by your entities and how it creates the file), it would make it so that you could easily add any map you'd ever like to your DM gamemode without much work. I'm pretty sure redoing the code you posted above for every map will be tedious, and not very effecient. Just an idea :)[/QUOTE]
put every map in a table and put every item/gun in a table that will reduce the code alot
[QUOTE=Mitsudigi;45587400][lua]
hook.Add("InitPostEntity","RemoveWeapons",function()
if ( game.GetMap() == "dm_chiron" ) then
for k,v in pairs(ents.FindByClass("weapon_*")) do
v:Remove()
end
for k,v in pairs(ents.FindByClass("item_*")) do
v:Remove()
end
end
end)
[/lua]
put in a file inside of lua/autorun/server[/QUOTE]
I didn't wanna do that because I don't know how or if it'll conflict with weapons I'll place with [url=http://coderhire.com/scripts/view/600]this[/url].
[QUOTE=Vipes;45587529]I didn't wanna do that because I don't know how or if it'll conflict with weapons I'll place with [url=http://coderhire.com/scripts/view/600]this[/url].[/QUOTE]
Well you could either add a very slight delay to the script that places the weapons, which it may already have.. or simply have it set a variable on items it places that the removal code can use to ignore.
[lua]
for k,v in pairs(ents.FindByClass("item_*")) do
if not v.PlacedByScript then v:Remove() end
end
[/lua]
How do you make it so if you type a command, such as !addons, it will pop up a workshop collection?
[QUOTE=nightfield;45588225]How do you make it so if you type a command, such as !addons, it will pop up a workshop collection?[/QUOTE]You could try something like this:
[CODE]
concommand.Add( "addons", function( ply, cmd, args )
steamworks.ViewFile( workshopItemID )
end )
[/CODE]
Replace workshopItemID with the workshop collection id number. I'm not too sure whether steamworks.ViewFile supports collections though, but it's worth giving a try.
And where should I put that?
[QUOTE=nightfield;45588304]And where should I put that?[/QUOTE]Is this for a gamemode? If so is it your own custom one or one that's already made?
It's for Dark Roleplay.
[QUOTE=nightfield;45588312]It's for Dark Roleplay.[/QUOTE]Alright we'll your gonna want to put it in a shared file and made sure it's loaded properly. DarkRP recommends that you don't edit any core files so I don't want to say to put it in there and risk anything messing up. I'm pretty sure there's some sort of DarkRP modification system so I'm sure you could use that to implement it.
Sorry, you need to Log In to post a reply to this thread.