• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
@Rory I made an inventory system a while ago and I think I had an issue like this and I couldn't figure out why until I decided to copy the table. Try copying the table before you edit it like this [code]net.Receive("ChestDeposit", function(len, ply) local iName = net.ReadString() -- In my test case, this is coming in as "Soda Can" local iCount = net.ReadInt(32) -- In test case, this is coming in as 16 (the amount I have in my inventory) -- Retrieve the indicies where these items exist local index_from = GetTableIndex(ply.Inventory, iName) -- In the test case, this is returning "2" (which is correct) local index_to = GetTableIndex(ply.ChestInventory, ply.Inventory[index_from]["name"]) -- In the test case, returning "1" (which is correct) -- If the TO index exists, we need to add to what's there, not make a new one. local exists = false if index_to ~= nil then exists = true end if exists then -- In the test case, this returns TRUE, as it should be. print(iCount) -- Verify the count coming in local copyInv = table.Copy(ply.Inventory[index_from]) local copyChest = table.Copy(ply.ChestInventory[index_to]) ply.Inventory[index_from]["amount"] = copyInv["amount"] - iCount -- The math portion of this is ZERO, but is staying 16 ply.ChestInventory[index_to]["amount"] = copyChest["amount"] + iCount -- Math is 32, but is staying 16 print("[DEBUG] Depositing into Chest") else table.insert(ply.ChestInventory, ply.Inventory[index_from]) -- This also works but the test case isn't hitting this end -- Anytime an inventory changes, update it with the client(s) (These work, too) net.Start("InvUpdate") net.WriteTable(ply.Inventory) net.Send(ply) net.Start("ChestUpdate") net.WriteTable(ply.ChestInventory) net.Send(ply) end)[/code] Forget why this works. Also you should only network the changes to the inventory and bank, not the whole thing since that can be a lot of extra data that isn't changing (unless you want to)
[QUOTE=dence47;52429770]@Rory I had an issue like this [/QUOTE] Sweet baby Jesus it worked. For now at least. lol. Thank you so much. I guess passing tables around so much was confusing the system so it was mixing up it's numbers. Making copies of the tables, and only screwing with the actual table itself when I'm done calculating seems to have worked.
Question: has anyone made some sort of quest/mission system for gmod? Especially where multiple players can accept a quest/mission and when it's complete they each get some sort of reward?
snip
so i got this error on my f4 menu[lua][ERROR] gamemodes/metro_online/gamemode/f4_menu.lua:79: attempt to index global 'entsArr' (a nil value) 1. DoClick - gamemodes/metro_online/gamemode/f4_menu.lua:79 2. unknown - lua/vgui/dlabel.lua:232 [/lua] in this i wont see anything weird [lua]local Menu net.Receive("FMenu",function() if(Menu==nil) then Menu = vgui.Create("DFrame") Menu:SetSize(750, 500) Menu:SetPos(ScrW()/2-325, ScrH()/2-250) Menu:SetTitle("Metro Online") Menu:SetDraggable(true) Menu:ShowCloseButton(false) Menu:SetDeleteOnClose(false) Menu.Paint = function() surface.SetDrawColor(60,60,60,255) surface.DrawRect(0,0,Menu:GetWide(),Menu:GetTall()) surface.SetDrawColor(40,40,40,255) surface.DrawRect(0,24,Menu:GetWide(),1) end end addButtons(Menu) if(net.ReadBit()==0)then Menu:Hide() gui.EnableScreenClicker(false) else Menu:Show() gui:EnableScreenClicker(true) end end) function addButtons(Menu) local playerButton = vgui.Create("DButton") playerButton:SetParent(Menu) playerButton:SetText("") playerButton:SetSize(100,50) playerButton:SetPos(0,25) playerButton.Paint = function() surface.SetDrawColor(50,50,50,255) surface.DrawRect(0,0,playerButton:GetWide(),playerButton:GetTall()) surface.SetDrawColor(40,40,40,255) surface.DrawRect(0,49,playerButton:GetWide(),1) surface.DrawRect(99,0,1,playerButton:GetTall()) draw.DrawText("Player","DermaDefaultBold",playerButton:GetWide()/2,17,Color(255,255,255,255),1) end playerButton.DoClick = function(playerButton) local playerPanel = Menu:Add("PlayerPanel") end local shopButton = vgui.Create("DButton") shopButton:SetParent(Menu) shopButton:SetText("") shopButton:SetSize(100,50) shopButton:SetPos(100,25) shopButton.Paint = function() surface.SetDrawColor(50,50,50,255) surface.DrawRect(0,0,playerButton:GetWide(),shopButton:GetTall()) surface.SetDrawColor(40,40,40,255) surface.DrawRect(0,49,shopButton:GetWide(),1) surface.DrawRect(99,0,1,shopButton:GetTall()) draw.DrawText("Shop","DermaDefaultBold",shopButton:GetWide()/2,17,Color(255,255,255,255),1) end shopButton.DoClick = function(shopButton) local shopPanel = Menu:Add("ShopPanel") local iconList = vgui.Create("DIconLayout",shopPanel) iconList:SetPos(0,0) iconList:SetSize(shopPanel:GetWide(),shopPanel:GetTall()) iconList:SetSpaceY(5) iconList:SetSpaceX(5) local entsARR = {} entsArr[1] = scripted_ents.Get("weapon_357") for k,v in pairs(entsArr) do local icon = vgui.Create("SpawnIcon",iconList) icon:SetModel(v["Model"]) icon:SetToolTip(v["PrintName"]) iconList:Add(icon) icon.DoClick = function(icon) LocalPlayer():ConCommand("buy_entity "..v["ClassName"]) end end end end PANEL = {} function PANEL:Init() self:SetSize(750,525) self:SetPos(100,75) end function PANEL:Paint(w,h) draw.RoundedBox(0,0,0,w,h,Color(0,0,0,255)) end vgui.Register("PlayerPanel",PANEL,"Panel") PANEL = {} function PANEL:Init() self:SetSize(750,525) self:SetPos(100,75) end function PANEL:Paint(w,h) draw.RoundedBox(0,0,0,w,h,Color(255,255,255,255)) end vgui.Register("ShopPanel",PANEL,"Panel")[/lua]
@Rasmus You have entsARR instead of entsArr
[QUOTE=dence47;52431070]@Rasmus You have entsARR instead of entsArr[/QUOTE] what line?
[QUOTE=RasmusG5;52431105]what line?[/QUOTE] Ctrl + F dude. Where you define it at [lua]local entsARR = {}[/lua] [QUOTE=Banana Lord.;52431123][ERROR] gamemodes/metro_online/gamemode/f4_menu.lua:[B]79[/B]: attempt to index global 'entsArr' (a nil value)[/QUOTE] Except that's not the line where entsARR is, which is what he asked about...
[QUOTE=RasmusG5;52431105]what line?[/QUOTE] [quote][ERROR] gamemodes/metro_online/gamemode/f4_menu.lua:[B]79[/B]: attempt to index global 'entsArr' (a nil value)[/quote] [editline]4th July 2017[/editline] It's the line above it. Looking at the error should make it easy to find the mistake...
What's the difference between [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/debug/Trace]debug.Trace[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/debug/traceback]debug.traceback[/url]? Is there anything one function can do that the other can't?
[QUOTE=JasonMan34;52431201]What's the difference between [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/debug/Trace]debug.Trace[/url] and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/debug/traceback]debug.traceback[/url]? Is there anything one function can do that the other can't?[/QUOTE] debug.Trace is [URL="https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/includes/extensions/debug.lua#L24-L51"]written in Lua[/URL] and is just formatted differently to include the file in the trace. debug.traceback allows you to select the level and thread -- though the ladder doesn't matter in GMod, while debug.Trace will always start from the immediate level and main thread.
[QUOTE=code_gs;52431228]debug.Trace is [URL="https://github.com/Facepunch/garrysmod/blob/master/garrysmod/lua/includes/extensions/debug.lua#L24-L51"]written in Lua[/URL] and is just formatted differently to include the file in the trace. debug.traceback allows you to select the level and thread -- though the ladder doesn't matter in GMod, while debug.Trace will always start from the immediate level and main thread.[/QUOTE] Thread does matter if you're using coroutines, which are admittedly pretty rare
I don't know if this is suitable to ask here, but if I uploaded server content that replaces already existent content in gmod (let's say the HL2 hands), will the people who download that server content automatically through resource.addworkshop have that content loaded when they go on other servers and/or singleplayer?
[QUOTE=ROFLBURGER;52434054]I don't know if this is suitable to ask here, but if I uploaded server content that replaces already existent content in gmod (let's say the HL2 hands), will the people who download that server content automatically through resource.addworkshop have that content loaded when they go on other servers and/or singleplayer?[/QUOTE] I believe it has to be mounted on the server for it to be used on the client, but I could be wrong.
I'm having some trouble using the player_manager Class system So basically i have created a folder inside my gamemode name player_class and create a file name player_tank [code]DEFINE_BASECLASS( "player_default" ) local PLAYER = {} -- -- See gamemodes/base/player_class/player_default.lua for all overridable variables -- PLAYER.WalkSpeed = 190 PLAYER.RunSpeed = 190 function PLAYER:Loadout() self.Player:RemoveAllAmmo() self.Player:GiveAmmo( 256, "Pistol", true ) self.Player:Give( "swat_shield" ) self.Player:Give("mwr_colt45") end player_manager.RegisterClass( "player_tank", PLAYER, "player_default" )[/code] Then i include it in shared.lua and AddCSLuaFile Then i set the player class in Spawn hook [code]function GM:PlayerSpawn(ply) if (ply:Unassigned()) then ply:StripAmmo() ply:StripWeapons() ply:Spectate(OBS_MODE_ROAMING) net.Start("send") net.Send(ply) return false else ply:UnSpectate() player_manager.SetPlayerClass(ply, "player_tank") print(player_manager.GetPlayerClass(ply)) end end[/code] But it does like nothing, the print show that my class is tank but i still have no loadout, default run speed and stuffs [editline]5th July 2017[/editline] oh and i did return true on Spawn hook, just cut off some unnecessary code [editline]5th July 2017[/editline] I also heard making class with this is a bad idea. Is that true?
[lua] submenu3.Paint = function() draw.SimpleText("REQUIRES", "Trebuchet24", submenu3:GetWide()/2, 282, Color(180,180,180), TEXT_ALIGN_CENTER) draw.RoundedBox(8, 8, 304, 256, 128, Color(0,0,0)) if selection ~= nil then draw.SimpleText(selection["name"], "BudgetLabel", submenu3:GetWide()/2, 52, Color(0,255,0), TEXT_ALIGN_CENTER) draw.SimpleText(selection["desc"], "BudgetLabel", submenu3:GetWide()/2, 116, Color(0,255,0), TEXT_ALIGN_CENTER) if sel_type == "inv" then draw.SimpleText(selection["amount"], "BudgetLabel", submenu3:GetWide()/2, 180, Color(0,255,0), TEXT_ALIGN_CENTER) draw.SimpleText(selection["weight"], "BudgetLabel", submenu3:GetWide()/2, 244, Color(0,255,0), TEXT_ALIGN_CENTER) else draw.SimpleText(selection["amount"], "BudgetLabel", submenu3:GetWide()/2, 244, Color(255,255,0), TEXT_ALIGN_CENTER) draw.SimpleText(selection["trivial"], "BudgetLabel", submenu3:GetWide()/2, 180, Color(255,255,0), TEXT_ALIGN_CENTER) local spacer = 304 -- k = item name, v = how many they have to have for k,v in pairs(selection["requirements"]) do local has_item = false for a,b in pairs(inventory) do -- a is the inventory slot #, b is useless if inventory[a]["name"] == v and inventory[a]["amount"] >= v then has_item = true end end if has_item then draw.SimpleText(v.." "..k, "BudgetLabel", submenu3:GetWide()/2, spacer, Color(80,255,80), TEXT_ALIGN_CENTER) else draw.SimpleText(v.." "..k, "BudgetLabel", submenu3:GetWide()/2, spacer, Color(255,80,80), TEXT_ALIGN_CENTER) end spacer = spacer + 12 end end end end [/lua] What is an efficient way to handle this? This code is client side. Basically, it's looping twice within the draw function of the submenu. That is a big no-no for efficiency, but I cannot figure out how else to handle it. SimpleText needs to be green if they have the item, red if they do not (it's a list to show what's required in order to submit the mission). If all the items required are listed green, the player can click the button (this already works and is irrelevant). If the items are red, then the player knows which items they are missing by seeing what is not green. [b]Update[/b] I just put my real code into the Lua example above so as to not beat around the bush and just get the problem solved.
Is bullet damage handled separately from any other kind of damage? I'm trying to make the TTT grenades explode when shot, and have the following code and the following results: [code] function SWEP:CreateGrenade(src, ang, vel, angimp, ply) local gren = ents.Create(self:GetGrenadeName()) if not IsValid(gren) then return end gren:SetPos(src) gren:SetAngles(ang) -- gren:SetVelocity(vel) gren:SetOwner(ply) gren:SetThrower(ply) gren:SetGravity(0.4) gren:SetFriction(0.2) gren:SetElasticity(0.45) gren:Spawn() gren:PhysWake() -- This is the part I added in, -- that I have a question regarding function gren:OnTakeDamage(dmg) -- 2: Bullet damage -- 128: Crowbar damage -- 64: Explosion damage if dmg:GetDamageType() == 2 then print("bang") end damType = dmg:GetDamageType() print("OMG IT WORKS: " .. dmg:GetDamage() .. ":" .. damType ) end -- End modifications local phys = gren:GetPhysicsObject() if IsValid(phys) then phys:SetVelocity(vel) phys:AddAngleVelocity(angimp) end -- This has to happen AFTER Spawn() calls gren's Initialize() gren:SetDetonateExact(self:GetDetTime()) return gren end [/code] Tossing the grenade and hitting it with a crowbar gets a response (128), and when it explodes it gets a response (64), but shooting it returns nothing. The function's not even called at all, it seems.
How i can stop render player on distance and will it help incrase Client fps?
[QUOTE=Shadari;52436563]Is bullet damage handled separately from any other kind of damage? I'm trying to make the TTT grenades explode when shot, and have the following code and the following results: [code] function SWEP:CreateGrenade(src, ang, vel, angimp, ply) local gren = ents.Create(self:GetGrenadeName()) if not IsValid(gren) then return end gren:SetPos(src) gren:SetAngles(ang) -- gren:SetVelocity(vel) gren:SetOwner(ply) gren:SetThrower(ply) gren:SetGravity(0.4) gren:SetFriction(0.2) gren:SetElasticity(0.45) gren:Spawn() gren:PhysWake() -- This is the part I added in, -- that I have a question regarding function gren:OnTakeDamage(dmg) -- 2: Bullet damage -- 128: Crowbar damage -- 64: Explosion damage if dmg:GetDamageType() == 2 then print("bang") end damType = dmg:GetDamageType() print("OMG IT WORKS: " .. dmg:GetDamage() .. ":" .. damType ) end -- End modifications local phys = gren:GetPhysicsObject() if IsValid(phys) then phys:SetVelocity(vel) phys:AddAngleVelocity(angimp) end -- This has to happen AFTER Spawn() calls gren's Initialize() gren:SetDetonateExact(self:GetDetTime()) return gren end [/code] Tossing the grenade and hitting it with a crowbar gets a response (128), and when it explodes it gets a response (64), but shooting it returns nothing. The function's not even called at all, it seems.[/QUOTE] I believe TTT grenades have the DEBRIS collision group, so they won't collide with bullets. BTW, its not optimal and probably a bad idea to define a function in a function like that, you should edit the base entity of the grenade instead.
[QUOTE=Shakes Wilder;52436889]I believe TTT grenades have the DEBRIS collision group, so they won't collide with bullets. BTW, its not optimal and probably a bad idea to define a function in a function like that, you should edit the base entity of the grenade instead.[/QUOTE] So setting the collision group to something else should let it work? As for the code being optimal, I'm just trying to get a working base before I clean up and actually make it something I would share. That said, lua isn't exactly my comfort zone. Thank you!
[QUOTE=Shadari;52436960]So setting the collision group to something else should let it work? As for the code being optimal, I'm just trying to get a working base before I clean up and actually make it something I would share. That said, lua isn't exactly my comfort zone. Thank you![/QUOTE] Yepperoo, use :SetCollisionGroup and set it to COLLISION_GROUP_DEBRIS_TRIGGER or COLLISION_GROUP_NONE
Sorry, should have OP'd this here but already started a thread. Saving/Loading vectors with file.Write/Read()? [url]https://facepunch.com/showthread.php?t=1570395[/url]
[QUOTE=Shakes Wilder;52436979]Yepperoo, use :SetCollisionGroup and set it to COLLISION_GROUP_DEBRIS_TRIGGER or COLLISION_GROUP_NONE[/QUOTE] The explosions don't happen when its shot, but the grenades have bullet holes in them now so I'm gonna assume that means I'm on the right track! Why they're not taking damage with those bullet holes is where I'm at now. Maybe I shouldn't be using ENT:OnTakeDamage(dmg) for this one, if there's some other kind of function that would just detect the collision. Though that might be overthinking things.
How can i retrieve the weapon entity dropped by [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/ShouldDropWeapon]Player:ShouldDropWeapon[/url] ? I want to remove it after 10s
[QUOTE=YoutoYokodera;52437272]How can i retrieve the weapon entity dropped by [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/ShouldDropWeapon]Player:ShouldDropWeapon[/url] ? I want to remove it after 10s[/QUOTE] I think it would be better to set up your own custom system where you run through the player's weapon inventory [URL="http://wiki.garrysmod.com/page/GM/DoPlayerDeath"]before the death[/URL] and spawn each weapon while running SafeRemoveEntityDelayed( Entity entity, number delay )
[QUOTE=Shakes Wilder;52436889]I believe TTT grenades have the DEBRIS collision group, so they won't collide with bullets. [B]BTW, its not optimal and probably a bad idea to define a function in a function like that[/B], you should edit the base entity of the grenade instead.[/QUOTE] To be fair, you would choke on draw calls or physics interaction ever before you would notice an impact on lua GC. It's not a big deal. [editline]6th July 2017[/editline] [QUOTE=Shadari;52437088]The explosions don't happen when its shot, but the grenades have bullet holes in them now so I'm gonna assume that means I'm on the right track! Why they're not taking damage with those bullet holes is where I'm at now. Maybe I shouldn't be using ENT:OnTakeDamage(dmg) for this one, if there's some other kind of function that would just detect the collision. Though that might be overthinking things.[/QUOTE] ENT.OnTakeDamage is only triggered for physics damage. Try [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/EntityTakeDamage]GM:EntityTakeDamage[/url]
Is there a clientside equivalent of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerCanSeePlayersChat]GM:PlayerCanSeePlayersChat[/url]? If not how could I hide the chat of specific players clientside?
[QUOTE=Sean Bean;52437830]Is there a clientside equivalent of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerCanSeePlayersChat]GM:PlayerCanSeePlayersChat[/url]? If not how could I hide the chat of specific players clientside?[/QUOTE] Tried [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/OnPlayerChat]GM:OnPlayerChat[/url]?
[QUOTE=ROFLBURGER;52437291]I think it would be better to set up your own custom system where you run through the player's weapon inventory [URL="http://wiki.garrysmod.com/page/GM/DoPlayerDeath"]before the death[/URL] and spawn each weapon while running SafeRemoveEntityDelayed( Entity entity, number delay )[/QUOTE] It is hard for me to positioning the gun to the player arm, any better way?
[QUOTE=YoutoYokodera;52437863]It is hard for me to positioning the gun to the player arm, any better way?[/QUOTE] Just use ply:GetPost() + ply:OBBCenter() + ply:GetForward()*10 + ply:GetUp()*3 (Player's Position) + (Center Offset) + (10 units in front of the player) +(3 units above the player)
Sorry, you need to Log In to post a reply to this thread.