• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
Remove it in a timer in PlayerSpawn. It's probably from a default PlayerLoadout
Does anyone know a good way to blend 2 materials together through CreateMaterial? I have 2 textures that I want to be able to blend in real time however I simply can't get "$basetexture2" to work at all. This is what I'm using to test: [lua] local params = { ["$basetexture"] = "models/humans/male/group01/players_sheet", ["$basetexture2"] = "models/proximity/blah.png", ["$basetexturetransform"] = "center .5 .5 scale 1 1 rotate 0 translate 0 0", ["$basetexturetransform2"] = "center .5 .5 scale 1 1 rotate 0 translate 0 0", } local mat = CreateMaterial( "!test1", "UnlitGeneric", params ) hook.Add( "HUDPaint", "TEST", function( ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( mat ) surface.DrawTexturedRect( 0, 0, 512, 512 ) end)[/lua] Could this be because I'm using UnlitGeneric?
Yeah, blend uses it own shader
[QUOTE=RasmusG5;52193197]i meat that i have small list of weapons and randomizer picks one of them nd gives it to player but now it choses from every gun i have and picks some of them[/QUOTE] Take a look at [URL="https://www.lua.org/pil/2.5.html"]this relevant LUA wiki entry[/URL]. You can also use [URL="http://wiki.garrysmod.com/page/table/Random"]table.Random[/URL], like MPan1 had posted. Edit: If you're new to Lua/GLua in general, you could also check out [URL="https://facepunch.com/showthread.php?t=1337945"]this mildly aged thread[/URL].
[QUOTE=RasmusG5;52193197]i meat that i have small list of weapons and randomizer picks one of them nd gives it to player but now it choses from every gun i have and picks some of them[/QUOTE] If you're talking about hardcoding a list you can create a table of weapons then do [CODE] SomeWeaponList = { "classname_1", "classname_2", } ply:Give(SomeWeaponList[math.random(1, #SomeWeaponList)]) [/CODE]
Is there anyway to make this more optimized instead of creating hundreds upon thousands of table entries? It does work currently but I'm concerned of it's performance impact with alot of users. (The idea is to make a sort-of weighted randomization based on 2 or more values) [lua]players = {} players["STEAM_0:1:52355527"] = 33333 players["STEAM_0:1:52355528"] = 120000 function GetPercentage( _Table, _Key ) local int = 0 for k, v in pairs( _Table ) do int = int + v end return _Table[_Key] / int end function GetWinner( _Table ) local tab = {} for k, v in pairs( _Table ) do for i = 0, v do -- This is the shit i'm talking about table.insert( tab, k ) end end return table.Random( tab ) end local winner = GetWinner( players ) print( winner .. " won with a " .. math.Round( GetPercentage( players, winner ) * 100, 2 ) .. "% chance!" )[/lua]
Upon calling GetWinner, assign each SteamID to a numerical index, and add each of their powers to a total sum. Then call math.random from 1 to sum and reserve each SteamID a section of that total sum based off of their power. Ex. your first ID would get 1 to 33333 and you second ID would get 33334 to (33334 + 120000)
[QUOTE=Rocket;52203167]If I'm reading this right, couldn't you just generate a random number in the range 0...sum of all weights, and then choose the player by figuring out what player weight that number is between? For example, you'd generate a random number between 0 and 153333. If that random number is, for example, 54435, then the result would be the second player. To figure this out, you'd sum up the weights, and return the player where sum before < random number < sum with player. In this case, the second player would win because 33333 < 54435 < 153333.[/QUOTE] I hope I'm not just completely incompetent but how would something like this react to 2 people using the same value? My original thought process on this was that a bunch of numbers between any values could fuck this up. This was my test control (Always seemed to return the second index): [lua]players = {} players["STEAM_0:1:52355527"] = 4 players["STEAM_0:1:52355528"] = 3 players["STEAM_0:1:52355529"] = 2 players["STEAM_0:1:52355530"] = 2222222 function GetWinner( _Table ) local tab = {} local total = 0 for k, v in pairs( _Table ) do total = total + v end local num = math.random( 0, total ) for k, v in pairs( _Table ) do if v < num and num < total then print( "workdamnit: " .. k ) break end end return tab end[/lua] Regardless, I really do appreciate all the help!
[QUOTE=Moat;52203308]Well you're not storing the SteamID and what their portion of the sum is, which is what code_gs suggested. Here's a quick example of what he's trying to explain: (i think) [/QUOTE] For diverse amounts it works quite well, but for amounts closer to each other (or exactly the same) it often returns nil. I'll try playing around a bit more though.
[CODE] surface.CreateFont( "Title", { font = "CloseCaption_Bold", size = 30, weight = 500, blursize = 0, scanlines = 0, antialias = true, } ) surface.CreateFont( "Text", { font = "CloseCaption_Normal", size = 30, weight = 500, blursize = 0, scanlines = 0, antialias = true, } ) hook.Add("HUDPaint", "drawCAMenuAccept") local CAFrame = vgui.Create("DFrame") CAFrame:SetSize(400,350) CAFrame:SetPos(45,45) CAFrame:SetVisible(true) CAFrame:MakePopup() CAFrame:SetTitle("Chat Administrator Tool - by Meninist") local CAFrameAcceptButton = vgui.Create("DButton", CAFrame) CAFrameAcceptButton:SetPos(180,320) CAFrameAcceptButton:SetText("Apply") function CAFrameAcceptButton:DoClick() draw.SimpleText("Settings successfully saved!","Title",0,0,color=Color(255,255,255,255)) end [/CODE] My future chat filter/administrator system. I want it to have text in the middle of your screen that says "Settings Successfully Saved!" when the "Apply" button is clicked. I can't see the connection between the error and code. [CODE] [ERROR] lua/chatadministrator.lua:33: ')' expected near '=' 1. unknown - lua/chatadministrator.lua:0 [/CODE]
You can't do declarations in-line like that. I don't know why you're doing color= at all, but it should just be the colour object declared plainly into the draw.SimpleText function call.
[QUOTE=code_gs;52204186]You can't do declarations in-line like that. I don't know why you're doing color= at all, but it should just be the colour object declared plainly into the draw.SimpleText function call.[/QUOTE] I'm not sure either, thank you for the help. [editline]8th May 2017[/editline] Another simple question, I can't seem how to remove the text draw.SimpleText leaves behind... I want it to last for a couple seconds then disappear.
[QUOTE=kpjVideo;52203127]Is there anyway to make this more optimized instead of creating hundreds upon thousands of table entries? It does work currently but I'm concerned of it's performance impact with alot of users. (The idea is to make a sort-of weighted randomization based on 2 or more values)[/QUOTE] If I'm not too late, here is my solution to this (semi-common) problem: [url]http://stackoverflow.com/a/41166392/6778374[/url] [lua]local chancesTbl = { -- You can fill these with any non-negative integer you want -- No need to make sure they sum up to anything specific ["a"] = 2, ["b"] = 1, ["c"] = 3 } local function GetWeightedRandomKey() local sum = 0 for _, chance in pairs(chancesTbl) do sum = sum + chance end local rand = math.random(sum) local winningKey for key, chance in pairs(chancesTbl) do winningKey = key rand = rand - chance if rand <= 0 then break end end return winningKey end[/lua]
If I have set the skin of a panel using PANEL:SetSkin(), is there a way I can make one of its child panel exempt from changing the skin, or revert it back to the original derma?
[CODE][ERROR] addons/trade chat/lua/autorun/client/cl_tradechat.lua:44: unexpected symbol near ')' 1. unknown - addons/trade chat/lua/autorun/client/cl_tradechat.lua:0 [/CODE] I'm getting this error and I can't find where it's happening, any clue? [CODE]local rtbox = nil local isOpen = false local messages = "" net.Receive("receiveMessage" , function() local message = net.ReadString() local sender = net.ReadEntity() messages = messages.."\n"..sender:Name().." : "..message if isOpen then rtbox:SetText(messages) end end) function OpenChat() isOpen = true local frame = vgui.Create("DFrame") frame:SetTitle("Trade Chat - by Meninist") frame:SetSize(500,500) frame:Center() frame:MakePopup() end frame.OnClose = function(s) isOpen = false s:Remove() end local panel = vgui.Create("DPanel",frame) panel:SetPos(10,30) panel:SetSize(500 - 20 , 500 - 30 - 50) rtbox = vgui.Create("RichText",panel) rtbox:SetSize(500-20,500-30-50) rtbox:SetText(messages) function rtbox:PerformLayout() self:SetFontInternal("CloseCaption_Normal") self:SetFGColor(Color(255,255,255)) end) local entry = vgui.Create("DTextEntry",frame) entry:SetSize(500-20 , 40) entry:SetPos(10,30 + (500 - 30 - 50) + 5) entry.OnEnter = function(s) net.Start("sendMessage") net.WriteString(s:GetText) net.SendToServer() s:SetText("") s:RequestFocus() end end hook.Add("OnPlayerChat" , "OpenChatMenu" , function(ply,text) if ply == LocalPlayer() then if string.lower(text) == "!trade" then OpenChat() end end end) [/CODE]
Well, if you look at line 44, you'll see that there's a ')' symbol that shouldn't be there. Also, this is [B]literally[/B] what the error you posted said, did you even read it?
[QUOTE=JasonMan34;52207241]Well, if you look at line 44, you'll see that there's a ')' symbol that shouldn't be there. Also, this is [B]literally[/B] what the error you posted said, did you even read it?[/QUOTE] It was just one of those blind moments
How in the world do entities work? I'm trying to detour the :Use() function on an entity to still call it's parent entity. Ex: parent/init.lua [code] function ENT:Use(a,c,u,v) foo(a) end [/code] child/init.lua [code] local old_use = ENT.Use function ENT:Use(a,c,u,v) print("in child, old use is",old_use) local newa = bar(a) old_use(newa,c,u,v) end [/code] child/shared.lua [code] ENT.Base = "parent" [/code] The above print prints "in child, old use is nil"
[QUOTE=PigeonTroll;52206417]If I have set the skin of a panel using PANEL:SetSkin(), is there a way I can make one of its child panel exempt from changing the skin, or revert it back to the original derma?[/QUOTE] Did you try setting the exempt one to the default skin?
[QUOTE=Apickx;52207739]How in the world do entities work? I'm trying to detour the :Use() function on an entity to still call it's parent entity. Ex: parent/init.lua [code] function ENT:Use(a,c,u,v) foo(a) end [/code] child/init.lua [code] local old_use = ENT.Use function ENT:Use(a,c,u,v) print("in child, old use is",old_use) local newa = bar(a) old_use(newa,c,u,v) end [/code] child/shared.lua [code] ENT.Base = "parent" [/code] The above print prints "in child, old use is nil"[/QUOTE] Lua doesn't have true object-oriented programming and, especially, true inheritance. I'll spare you the details (I don't have a 100% grasp myself), but the correct solution is to use the baseclass library: [lua]-- child -- top of the file DEFINE_BASECLASS("parent") -- this defined a local variable called BaseClass -- anywhere else in the same file function ENT:Use(a, c, u, v) print("in child") local newa = bar(a) -- whatever code you want -- call the base (parent's "inherited") function Use: BaseClass.Use(self, newa, c, u, v) -- do not forget self, you did in your snippet end[/lua]
[QUOTE=NeatNit;52208612]Lua doesn't have true object-oriented programming and, especially, true inheritance. I'll spare you the details (I don't have a 100% grasp myself), but the correct solution is to use the baseclass library: :snip:[/QUOTE] What he did should have been correct, though if I had to guess why it failed, it'd be that his child loaded before his parent, thus there was no Use method to save for later use.
[QUOTE=bigdogmat;52208661]What he did should have been correct, though if I had to guess why it failed is because his child loaded before his parent, thus there was no Use method to save for later use.[/QUOTE] No. There is no opportunity for anything to set ENT.Use (based on ENT.Base) before the line "old_use = ENT.Use", even if they loaded in the intended order. This is [b]exactly[/b] the thing BaseClass is designed to do. It's also why baseclass.Get is guaranteed to work even if the child loads before the parent.
[QUOTE=NeatNit;52208682]No. There is no opportunity for anything to set ENT.Use (based on ENT.Base) before the line "old_use = ENT.Use", even if they loaded in the intended order. This is [b]exactly[/b] the thing BaseClass is designed to do. It's also why baseclass.Get is guaranteed to work even if the child loads before the parent.[/QUOTE] Ah yes I forgot the ENT table is actually never given a BaseClass, it's only used to setup the class. In that case you could also do "self.BaseClass.Use(self, ...)", though that leads of all kinds of possible infinite recursion.
If i set a network var on my entity using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/NetworkVar]Entity:NetworkVar[/url], can I retrieve it from another source using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetNWFloat]Entity:GetNWFloat[/url] and the other NWVar functions?
[QUOTE=Fillipuster;52214804]If i set a network var on my entity using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/NetworkVar]Entity:NetworkVar[/url], can I retrieve it from another source using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetNWFloat]Entity:GetNWFloat[/url] and the other NWVar functions?[/QUOTE] Only through the Setter/Getter functions it creates afaik
[QUOTE=Shenesis;52214188]Anyone knows why a prop_physics emits sound when touching the ground, while my custom entity doesn't emit sound?[/QUOTE] prop_physics has custom collision code that plays an impact sound on touch. You can replicate it using a PhysicsCollide or StartTouch callback
Client in possession and those around that person when they walk with a Physgun out causes them to all to crash. It seems to occur only when certain people walk with the gun. Without any changes to code, the problem seems to get worse and worse. I have no clue what could be causing it... Has anyone had issues like this before?
Does anyone know how to change the sky in rp_evocity_v33x? I searched everywhere and the only information I found was that there was an entity called sun_light but I can't find it when I parse through the ents in the map.
Anybody know of a method to spoof net messages serverside? As in, if I have a net.Receive hook on the server, is there a way for me to test it pretending that a bot sent it?
You can always make the net message call a function in SV so you can simulate it by yourself, although i though you could send net messages from bots to server, but well, there's no input from them so that just wouldn't work
Sorry, you need to Log In to post a reply to this thread.