• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
[QUOTE=AnonTakesOver;46021824]What's better; Writing a table directly through net or Converting table to JSON, sending string, rebuilding on other side. The table is a table of tables.[/QUOTE] What are the contents of the tables?
[QUOTE=rejax;46021837]What are the contents of the tables?[/QUOTE] It's an inventory table. So it's a table, filled with a bunch of items, the item tables contain values such as the entity class, print name, print model, if it's stack-able and the amount. I'm probably going to be adding some other variables to it, but most and if not all the values shouldn't be tables. Tables are indexed just by iteration.
[QUOTE=Tomelyr;46020367] [lua]function ITEM:OnEquip(ply) ply.currenthat = "tophat" -- Need to add the filename by hand, since ITEM.ID is returning an error. every. freakin. time... end [/lua][/QUOTE] I believe it causes you an error because ITEM always points to the same (meta)table. Try putting a print(ITEM) statement somewhere in the function and you'll notice it prints the same address. Should work just fine if you use 'self.ID' instead of 'ITEM.ID'.
[QUOTE=mcd1992;46018197]You need to remove it before the context menu gets created. [url=https://github.com/garrynewman/garrysmod/blob/4eb9bb19dcfac06007691376ecaf2dbc56efa6b2/garrysmod/gamemodes/sandbox/gamemode/editor_player.lua]editor_player.lua[/url] see also [url=https://github.com/garrynewman/garrysmod/blob/08b9b77c9fcc1d9e11424d653c20c0c3c1a559e2/garrysmod/gamemodes/sandbox/gamemode/spawnmenu/contextmenu.lua]contextmenu.lua[/url][/QUOTE]Do not edit those files. Just add a this function to a clientside file. [CODE]hook.Add("ContextMenuOpen", "removecontextmenu", function( ) return false end)[/CODE]
[QUOTE=AnonTakesOver;46021824]What's better; Writing a table directly through net or Converting table to JSON, sending string, rebuilding on other side. The table is a table of tables.[/QUOTE] It's not really something that matters that much. These things only start to matter as you sender larger sets of information. Also, why not share the information of items via lua includes rather than making it serverside and networking it anyway?
[QUOTE=PaellaPablo;46022296]Also, why not share the information of items via lua includes rather than making it serverside and networking it anyway?[/QUOTE] I could be wrong, but I think he's talking about sending the contents of someones inventory. If he is trying to send the whole table of items, I'd definitely suggest just using a shared lua file. As to sending it, it's simply enough to just use net.WriteTable Why convert and unconvert where you don't need to? This way it's already setup and good to go?
[QUOTE=CoreBase;46022282]Do not edit those files. Just add a this function to a clientside file. [CODE]hook.Add("ContextMenuOpen", "removecontextmenu", function( ) return false end)[/CODE][/QUOTE] i don't want to remove the whole context menu though
[QUOTE=Luni;46019293][code]net.WriteInt(ply:GetFOV(), 2)[/code] should be [code]net.WriteUInt(ply:GetFOV(), 8)[/code] you're sending it as a 2-bit signed int, which only allows values from -2 to 1[/QUOTE] I had no clue what a bit is. I assumed that 2 bits was a double digit int
[QUOTE=ROFLBURGER;46027762]I had no clue what a bit is. I assumed that 2 bits was a double digit int[/QUOTE] 1 bit = 4 binary numbers ( 0110 ) 8 bits = 1 byte ( 0100 0110 0100 0110 0101 1111 0000 01010 ) [B]In Bytes ( Multiply by 8 ):[/B] SIZE_OF_CHAR = 1 SIZE_OF_SHORT = 2 SIZE_OF_INT = 4 SIZE_OF_LONG = 4 SIZE_OF_FLOAT = 4 SIZE_OF_DOUBLE = 8 SIZE_OF_BOOL = 1 bit EX: "HAI" is a string. 1x8 = 8. 8x3 (3 chars) = 24 bits. 3 is a short. 2x8 = 16bits. 3000 is a int. 4x8 = 32bits These are the data types. Since they're unsigned, Ints are 1 byte.
wow nerd
[QUOTE=EthanTheGreat;46027799]1 bit = 4 binary numbers ( 0110 ) 8 bits = 1 byte ( 0100 0110 0100 0110 0101 1111 0000 01010 ) [B]In Bytes ( Multiply by 8 ):[/B] SIZE_OF_CHAR = 1 SIZE_OF_SHORT = 2 SIZE_OF_INT = 4 SIZE_OF_LONG = 4 SIZE_OF_FLOAT = 4 SIZE_OF_DOUBLE = 8 SIZE_OF_BOOL = 1 bit EX: "HAI" is a string. 1x8 = 8. 8x3 (3 chars) = 24 bits. 3 is a short. 2x8 = 16bits. 3000 is a int. 4x8 = 32bits These are the data types. Since they're unsigned, Ints are 1 byte.[/QUOTE] if we're talking just about the net library, unsigned ints are different from normal ints, and each data type uses a header which I think is 1 byte [editline]a[/editline] missed the top of your post, that's wrong, 1 bit is 1 binary int and 1 byte is 8 bits [editline]a[/editline] [QUOTE=bran92don;46028243]Can you not slowly increase the size of a flex using a loop? I am trying to make this flex slowly increase in size , but anytime I throw it into a loop my game crashes. [/QUOTE] while loops are run in the same frame, you'd have to use a hook like think for that
Can you not slowly increase the size of a flex using a loop? I am trying to make this flex slowly increase in size , but anytime I throw it into a loop my game crashes. code: [lua] local time = CurTime() + 1 while( ent:GetFlexWeight( 1 ) != swell and CurTime() < time ) do if ent:GetFlexWeight( 1 ) != swell then ent:SetFlexScale( 1 ) ent:SetFlexWeight( 0, ent:GetFlexWeight( 0)+.1 ) ent:SetFlexWeight( 1, ent:GetFlexWeight( 1)+.1 ) ent:SetFlexWeight( 2, ent:GetFlexWeight( 2)+.1 ) end end [/lua] [editline]20th September 2014[/editline] [QUOTE=PortalGod;46028232] while loops are run in the same frame, you'd have to use a hook like think for that[/QUOTE] I have always tried to avoid using think hooks as much as possible, because I read somewhere that to many of them hinders performance majorly.
[QUOTE=bran92don;46028243]Can you not slowly increase the size of a flex using a loop? I am trying to make this flex slowly increase in size , but anytime I throw it into a loop my game crashes. code: [lua] local time = CurTime() + 1 while( ent:GetFlexWeight( 1 ) != swell and CurTime() < time ) do if ent:GetFlexWeight( 1 ) != swell then ent:SetFlexScale( 1 ) ent:SetFlexWeight( 0, ent:GetFlexWeight( 0)+.1 ) ent:SetFlexWeight( 1, ent:GetFlexWeight( 1)+.1 ) ent:SetFlexWeight( 2, ent:GetFlexWeight( 2)+.1 ) end end [/lua] [editline]20th September 2014[/editline] I have always tried to avoid using think hooks as much as possible, because I read somewhere that to many of them hinders performance majorly.[/QUOTE] You cant do that, it'll still be in the same frame by the time it checks for curtime again... and again... and again... and the value is always the same because you're recursively calling it an infinite amount of times in a tick To use a while like that you need a coroutine
I am trying to play with sequences that some vehicle models have. Can anyone give me some pointers on how to actually manipulate those sequences? I got up to about LookupSeqence and that was it. Not sure on how SetSequence and the such work.
[QUOTE=AnonTakesOver;46012199]With an inventory system, I assume the SQL that comes local with gmod is better than a MySQL server? My inventory is a table of all shit, obviously. How do I save a players table to the local SQL server on GMod? Best to have it get the table from using their Community ID. Anyway, so how do I save a table to the local SQL and retrieve it.[/QUOTE] I'd highly recommend using MySQL instead of the built in SQLLite... If you use the built in, create your own tables, queries etc... If you use PlayerPData, it stores data like this: column1: <uniqueid>[<column_id>] column2: <value> Converting from pdata to SQL takes some work if you ever decide to switch: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/database/converting_sv_db_to_mysql.lua.html[/url] If you do end up writing your own queries, you should have no trouble getting around that.. So, I'd recommend either use MySQL, or write your own queries in such a way that converting won't cause any headaches.
[QUOTE=EthanTheGreat;46027799]1 bit = 4 binary numbers ( 0110 ) 8 bits = 1 byte ( 0100 0110 0100 0110 0101 1111 0000 01010 ) [B]In Bytes ( Multiply by 8 ):[/B] SIZE_OF_CHAR = 1 SIZE_OF_SHORT = 2 SIZE_OF_INT = 4 SIZE_OF_LONG = 4 SIZE_OF_FLOAT = 4 SIZE_OF_DOUBLE = 8 SIZE_OF_BOOL = 1 bit EX: "HAI" is a string. 1x8 = 8. 8x3 (3 chars) = 24 bits. 3 is a short. 2x8 = 16bits. 3000 is a int. 4x8 = 32bits These are the data types. Since they're unsigned, Ints are 1 byte.[/QUOTE] Glad you have done your research. 1 bit can either be 0 or 1, so I don't see how you can get a combination of 4 0s and 1s to be called a bit. 4 bits together are called a nibble. Whatever you say, here's the correct table: char - 8 bits (1 byte) - 0-255 when unsigned, -128-127 when signed short - 16 bits (2 bytes) - 0-65535 when unsigned, -32768 to 32767 when signed int - 32 bits (4 bytes) In the past, a long was actually 32 bit, and an int was 16 bit, but since 32-bit systems became more common, this changed to be the same. A boolean, even though it can only have 0-1, is stored in 8 bits, aka a byte. You can not store a single byte unless you compose multiple booleans using bitshifting. The string HAI will also have a null terminator so it won't just be 3 bytes. In C++, you need to allocate a char array which has 3 elements, 3 for the characters and an extra element will be "added" for the null terminator, so it'll be 4 bytes (4 chars, 1 byte each) If you have the number 3000, that doesn't automatically mean it's an int. You can store the number in a short, which is only 2 bytes if you want. It doesn't have to do with the amount of digits, but with the value that you can store using a set amount of bytes (2^n). The last thing what you said, the "1 byte ints", they don't exist. (unless you are talking about C++, __int8 does exist). If you want to have all data types, just read this: [url]http://msdn.microsoft.com/en-us/library/s3f49ktz.aspx[/url]
It's also useful to know how to work out how many bits you'd need to store a value. If x is the amount of bits you have, here is how to work out the boundaries. [code] -- Unsigned min = 0 max = 2^x - 1 -- Signed min = -2^(x - 1) + 1 max = 2^(x - 1) - 1 [/code]
I really want to get this reload function in a swep to work. The timer is causing it, basically. [code] function SWEP:Reload() if not IsFirstTimePredicted( ) then return end if self:Clip1() >= self.Primary.ClipSize then return end if not self.ReloadDelay then self.ReloadDelay = 0 end if self.ReloadDelay >= CurTime() then return end self.ReloadDelay = CurTime() + self.Owner:GetViewModel():SequenceDuration() + 0.25 self.Owner:SetAnimation(PLAYER_RELOAD) self:SendWeaponAnim( ACT_VM_RELOAD ) self:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration() + 0.1) self.Weapon:EmitSound("weapons/smg1/smg1_reload.wav",100,100) self:SetClip1(self.Primary.ClipSize) --[[ timer.Simple(self.Owner:GetViewModel():SequenceDuration()*0.75,function() if IsValid(self) then self:SetClip1(self.Primary.ClipSize) end end) --]] end [/code] It's basically doing a "double reload" if you hold down the reload button if I include the timer function and remove the non-timed setClip.
What do you mean "Double reload"?
[QUOTE=ROFLBURGER;46032819]I really want to get this reload function in a swep to work. The timer is causing it, basically. [code] function SWEP:Reload() if not IsFirstTimePredicted( ) then return end if self:Clip1() >= self.Primary.ClipSize then return end if not self.ReloadDelay then self.ReloadDelay = 0 end if self.ReloadDelay >= CurTime() then return end self.ReloadDelay = CurTime() + self.Owner:GetViewModel():SequenceDuration() + 0.25 self.Owner:SetAnimation(PLAYER_RELOAD) self:SendWeaponAnim( ACT_VM_RELOAD ) self:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration() + 0.1) self.Weapon:EmitSound("weapons/smg1/smg1_reload.wav",100,100) self:SetClip1(self.Primary.ClipSize) --[[ timer.Simple(self.Owner:GetViewModel():SequenceDuration()*0.75,function() if IsValid(self) then self:SetClip1(self.Primary.ClipSize) end end) --]] end [/code] It's basically doing a "double reload" if you hold down the reload button if I include the timer function and remove the non-timed setClip.[/QUOTE] Don't use the timer library in a swep, sent, etc. The object already has a think function, you can use that so it's safe.
[QUOTE=Robotboy655;46032873]What do you mean "Double reload"?[/QUOTE] I'm guessing he means reload is called twice?
[QUOTE=Robotboy655;46032873]What do you mean "Double reload"?[/QUOTE] Reload is called twice, sorry I was using the wording people reported :v:
[QUOTE=ROFLBURGER;46033364]Reload is called twice, sorry I was using the wording people reported :v:[/QUOTE] I guess it is called once on client and once on server ( only on a server, in singleplayer it should be called only once serverside ), take that into account. [editline]20th September 2014[/editline] Or rather, you are setting "self.ReloadDelay = CurTime() + self.Owner:GetViewModel():SequenceDuration() + 0.25" this BEFORE you play the animation.
I am trying to get DarkRP jobs, but seemingly fine code comes out with completely asinine code [lua]/*--------------------------------------------------------------------------- DarkRP custom jobs --------------------------------------------------------------------------- This file contains your custom jobs. This file should also contain jobs from DarkRP that you edited. Note: If you want to edit a default DarkRP job, first disable it in darkrp_config/disabled_defaults.lua Once you've done that, copy and paste the job to this file and edit it. The default jobs can be found here: [url]https://github.com/FPtje/DarkRP/blob/master/gamemode/config/jobrelated.lua[/url] For examples and explanation please visit this wiki page: [url]http://wiki.darkrp.com/index.php/DarkRP:CustomJobFields[/url] Add jobs under the following line: ---------------------------------------------------------------------------*/ TEAM_Example = DarkRP.createJob("S.W.A.T.", { color = Color(255, 255, 255, 255), model = { "models/player/ct_urban.mdl" }, description = [[The S.W.A.T. team takes care of those pesky terrorists! Those fucking basterds will get it now! This is a V.I.P. only job! Job specific rules: 1. The S.W.A.T. may not base. 2. The S.W.A.T. may not act as a normal police.]], weapons = {"weapon_deagle", "weapon_m4a1"}, command = "swat", max = 2, salary = 45 * 2, admin = 0, vote = false, hasLicense = true, customCheck = function(ply) return ply:GetUserGroup() == "VIP" or ply:IsSuperAdmin end, CustomCheckFailMsg = "This job is only for VIP users.", modelScale = 1, maxpocket = 10, candemote = false, mayor = false, chief = false, medic = false, cook = false, hobo = false, ammo = { ["pistol"] = 60, }, }) /*--------------------------------------------------------------------------- Define which team joining players spawn into and what team you change to if demoted ---------------------------------------------------------------------------*/ GAMEMODE.DefaultTeam = TEAM_CITIZEN /*--------------------------------------------------------------------------- Define which teams belong to civil protection Civil protection can set warrants, make people wanted and do some other police related things ---------------------------------------------------------------------------*/ GAMEMODE.CivilProtection = { [TEAM_POLICE] = true, [TEAM_CHIEF] = true, [TEAM_MAYOR] = true, } /*--------------------------------------------------------------------------- Jobs that are hitmen (enables the hitman menu) ---------------------------------------------------------------------------*/ DarkRP.addHitmanTeam(TEAM_MOB) [/lua] Comes up as: [ERROR] addons/darkrpmodification-master/lua/darkrp_customthings/jobs.lua:36: function arguments expected near 'end' 1. unknown - addons/darkrpmodification-master/lua/darkrp_customthings/jobs.lua:0 Hint: line 36 is: max = 2,
I'm using SetColor to change the color of a player model in one function. I need to disable this color in another function; how do i do it?
replace [code] customCheck = function(ply) return ply:GetUserGroup() == "VIP" or ply:IsSuperAdmin end, [/code] with [code] customCheck = function(ply) return ply:GetUserGroup() == "VIP" or ply:IsSuperAdmin() end, [/code]
DarkRP job files report the wrong line number in errors due to a bug with multi-line C comments and blank lines.
Is there a possible way to remove the player's ability to control movement in mid flight or at least minimize it? Like I don't know if there are any commands but I was thinking of like if ply:IsOnGround() == false then --DISABLE W A S D keys end [QUOTE=Robotboy655;46033442]I guess it is called once on client and once on server ( only on a server, in singleplayer it should be called only once serverside ), take that into account. [editline]20th September 2014[/editline] Or rather, you are setting "self.ReloadDelay = CurTime() + self.Owner:GetViewModel():SequenceDuration() + 0.25" this BEFORE you play the animation.[/QUOTE] I changed it to self.IsReloading and made everything run on CurTime instead of timers. This helped a lot
[QUOTE=ROFLBURGER;46034926]Is there a possible way to remove the player's ability to control movement in mid flight or at least minimize it? Like I don't know if there are any commands but I was thinking of like if ply:IsOnGround() == false then --DISABLE W A S D keys end I changed it to self.IsReloading and made everything run on CurTime instead of timers. This helped a lot[/QUOTE] sv_airacceleration or something like that has a play in it. However, you can use a Move hook to disable movement keys in the air. Just be aware that CurTime() isn't always real time. It's based on host_timescale.
Basically I made an aimbot gun so bots can use it. It works fine but for regular bots, SetEyeAngles doesn't seem to work. Does anyone know how to prevent this? [editline]20th September 2014[/editline] Acutally I sorta got it working. I just keep getting spammed error messages [code]function SWEP:BotThink() local FindPlayers = ents.FindByClass("player") if self.Bot.SearchDelay <= CurTime() then Result = {} for k,v in pairs(FindPlayers) do if v ~= self.Owner and v:Alive() then --if CLIENT then RealDistance = v:GetPos():Distance(self.Owner:GetPos()) --end Distance = v:GetPos():Distance(self.Owner:GetPos()) - 10000000 Result[v] = math.abs(Distance) if SERVER then --PrintTable(Result) end end end Winner = table.GetWinningKey( Result ) or Entity(1) --print(Winner:Nick()) --print(Winner) self.Bot.SearchDelay = CurTime() + 1 end if SERVER then Main = (Winner:GetPos() - self:GetPos() ):Angle() P = math.Clamp(Main.p,0,360) Y = math.Clamp(Main.y,0,360) R = 0 Tots = Angle(P,Y,R) if RealDistance < 2000 then self.Owner:SetEyeAngles(Tots) end end --if CLIENT then if self.Owner:GetEyeTrace().Entity:Health() > 0 then if self.Bot.ShootDelay <= CurTime() then self:Shoot() self.Weapon:EmitSound(self.Primary.Sound,100,100) self.Bot.ShootDelay = CurTime() + 0.25 end end --end if self:Clip1() < 0 then self:SetClip1(30) end if not DebugTime then DebugTime = 0 end if DebugTime <= CurTime() then DebugTime = CurTime() + 2 if SERVER then print(Tots) end end end[/code] Even when I round the numbers I get this error [code] DataTable warning: player: Out-of-range value (355.000000) in SendPropFloat 'm_angEyeAngles[0]', clamping. [/code] [editline]20th September 2014[/editline] I did a google search and I'm getting mixed results
Sorry, you need to Log In to post a reply to this thread.