• Problems That Don't Need Their Own Thread v2.0
    5,020 replies, posted
[QUOTE=PortalGod;47284503]if you're using the default fonts, you'll have to remake them (you can find the source for most of them [url=https://github.com/garrynewman/garrysmod/search?utf8=%E2%9C%93&q=createfont&type=Code]here[/url])[/QUOTE] I'm using a custom font :P
then just use ScrW()/ScrH()/ScreenScale() for the size argument like you would use them in a HUD or something
[QUOTE=GoldTrigger;47284260]Anyone know how to scale fonts according to screen size? ._. Left this out of my hud woops[/QUOTE] Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/ScreenScale]Global.ScreenScale[/url] when defining your font size. EDIT: Ninja'd
Is it possible to set the view and world models on a weapon on the fly? I've played around with the entity:SetModel() and switching the SWEP structure values to the new one as they seemed like obvious places to start. But now I'm totally stuck as to how to do this. Unless there's some function I've missed, because I expect the view and world models are tied to the player more than the weapon.
[QUOTE=wh1t3rabbit;47284702]Use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/ScreenScale]Global.ScreenScale[/url] when defining your font size. EDIT: Ninja'd[/QUOTE] Confused on how I would use that ._. Also, what does Ninja'd mean? ;-;
[QUOTE=GoldTrigger;47285013] Also, what does Ninja'd mean? ;-;[/QUOTE] I think it means someone told you the answer before he could.
[QUOTE=hexpunK;47284732]Is it possible to set the view and world models on a weapon on the fly? I've played around with the entity:SetModel() and switching the SWEP structure values to the new one as they seemed like obvious places to start. But now I'm totally stuck as to how to do this. Unless there's some function I've missed, because I expect the view and world models are tied to the player more than the weapon.[/QUOTE] Maybe this? [url]http://wiki.garrysmod.com/page/Player/GetViewModel[/url]
Is it possible to create animations in Lua? Things like adding a dance animation or prone animation to a player or even new weapon animations.
Why does IsOnGround not return true with any props touching the ground? There isn't a 'IfTouching', is there, or do I have to use some sort of trace? [CODE] concommand.Add("ongroundtest", function() for k, v in pairs( ents.GetAll() ) do if not ( v:GetModel() == nil ) then print("Model:",v:GetModel(),"On Ground?",v:IsOnGround() ) end end end) [/CODE]
IsOnGround has been broken for ages. You can do a hull trace.
Okay, thanks
[QUOTE=GoldTrigger;47285013]Confused on how I would use that ._. Also, what does Ninja'd mean? ;-;[/QUOTE] I've never used it myself but I know it's designed for use with fonts. It returns a number based on your screen size and the number you give it. Just play with the number you give it until you have it looking exactly as it currently does, then check it on a different resolution. And yeah people use "ninja'd" to mean someone posted the answer (fast like a ninja) while they were still typing. [editline]9th March 2015[/editline] [QUOTE=hexpunK;47284732]Is it possible to set the view and world models on a weapon on the fly? I've played around with the entity:SetModel() and switching the SWEP structure values to the new one as they seemed like obvious places to start. But now I'm totally stuck as to how to do this. Unless there's some function I've missed, because I expect the view and world models are tied to the player more than the weapon.[/QUOTE] I can't give a complete answer but when I played with having the player equip one actual weapon and then change its hold type and model through code, I had to use net messages to tell all clients to apply the same changes. Also need to network it to newly joined players otherwise they see whatever is the default for that swep (depending on your code I guess)
Is there a way to disable player spawning? [editline]9th March 2015[/editline] nvm, done with GM:PlayerDeathThink()
This code used to work perfectly fine before the update, it would show names, health etc above NPC's. Now it does nothing at all and give no errors. [lua] surface.CreateFont( "NPCDisp" , { font = "Arial Rounded MT", size = 15, weight = 1000, antialias = true, outline = false, shadow = true, } ); local function DrawNPCIcon(entNPC, posNPCPos) local strIcon = "icon16/emoticon_smile.png" surface.SetDrawColor(255, 255, 255, 255) surface.SetMaterial(Material(strIcon)) surface.DrawTexturedRect(posNPCPos.x, posNPCPos.y - 25, 16, 16) end local function DrawNameText(entNPC, posNPCPos, boolFriendly) local tblNPCTable = NPCTable(entNPC:GetNWInt("npc")) local intLevel = entNPC:GetNWInt("level") local plylevel = math.Clamp(LocalPlayer():GetLevel(),0,99999) local clrDrawColor = clrWhite if intLevel < plylevel then clrDrawColor = clrGreen end if intLevel > plylevel then clrDrawColor = clrRed end if boolFriendly then clrDrawColor = clrWhite end local strTitle = tblNPCTable.Title or "" if tblNPCTable.Shop then strTitle = ShopTable(tblNPCTable.Shop).PrintName end draw.SimpleTextOutlined(strTitle, "NPCDisp", posNPCPos.x, posNPCPos.y - 25, clrDrawColor, 1, 1, 1, clrDrakGray) local strDrawText = tblNPCTable.PrintName if !boolFriendly && !entNPC:IsBuilding() then strDrawText = strDrawText .. " lv. " .. intLevel end if tblNPCTable.Boss then draw.SimpleTextOutlined(strDrawText, "NPCDisp", posNPCPos.x, posNPCPos.y - 10, clrBrightRed, 1, 1, 1, clrDrakGray) elseif !tblNPCTable.Boss then draw.SimpleTextOutlined(strDrawText, "NPCDisp", posNPCPos.x, posNPCPos.y - 10, clrDrawColor, 1, 1, 1, clrDrakGray) end end local function DrawNPCHealthBar(entNPC, posNPCPos) local clrBarColor = clrGreen local intHealth = math.Clamp(entNPC:GetNWInt("Health"),0,99999) local intMaxHealth = entNPC:GetNWInt("MaxHealth") if intHealth <= (intMaxHealth * 0.2) then clrBarColor = clrRed end local NpcHealthBar = jdraw.NewProgressBar() NpcHealthBar:SetDemensions(posNPCPos.x - (80 / 2), posNPCPos.y, 80, 11) NpcHealthBar:SetStyle(4, clrBarColor) NpcHealthBar:SetBoarder(1, clrDrakGray) NpcHealthBar:SetText("UiBold", intHealth, clrDrakGray) NpcHealthBar:SetValue(intHealth, intMaxHealth) jdraw.DrawProgressBar(NpcHealthBar) end local function DrawNPCInfo() for _, ent in pairs(ents.GetAll()) do if IsValid(ent) && ( ent:IsNPC() || ent:IsBuilding() || ent:GetNWBool( "nextbot" ) ) && ent:GetNWInt("level") > 0 then if ent:GetPos():Distance(LocalPlayer():GetPos()) < 500 then local tblNPCTable = NPCTable(ent:GetNWInt("npc")) if !tblNPCTable then return end local boolFriendly = tblNPCTable.Race == "human" local posNPCPos = (ent:GetPos() + Vector(0, 0, 80)):ToScreen() DrawNameText(ent, posNPCPos, boolFriendly) if !boolFriendly then DrawNPCHealthBar(ent, posNPCPos) end end end end end hook.Add("HUDPaint", "DrawNPCInfo", DrawNPCInfo) [/lua]
I'm having problems setting and getting $nodecal on materials. I made a function to print the value of a field in each type: [lua] function printMatData(mat, field) print("Checking '$" .. field .. "' on " .. mat); local mat = Material(mat); print(mat:GetFloat("$" .. field)); print(mat:GetInt("$" .. field)); print(mat:GetMatrix("$" .. field)); print(mat:GetString("$" .. field)); print(mat:GetTexture("$" .. field)); print(mat:GetVector("$" .. field)); print(); end printMatData("models/tdmcars/shared/skin", "nodecal"); printMatData("models/tdmcars/shared/skin1", "nodecal"); [/lua] Here is the result: [t]http://i.imgur.com/8INqWXp.png[/t] And here is skin.vmt (skin1.vmt has "$nodecal" "1" as well): [code] "VertexlitGeneric" { "$basetexturetransform" "center .5 .5 scale 80 80 rotate 0 translate 0 0" "$basetexture" "models/tdmcars/shared/skin" "$bumpmap" "models/tdmcars/shared/skin_normal" "$nodecal" "1" "$phong" 1 "$phongexponent" 5 "$phongboost" 2 "$phongfresnelranges" "[1 1 1]" "$rimlight" 1 "$rimlightboost" 0.5 "$envmap" "env_cubemap" "$envmaptint" "[0.07 0.07 0.07]" "$normalmapalphaenvmapmask" 1 "$phongfix" "{1 1 1}" Proxies { Equals { srcVar1 $color resultVar $phongtint } Add { srcVar1 $phongfix srcVar2 $phongtint resultVar $phongtint } } } [/code] Any idea why its not printing? I cant mat:SetUndefined("$nodecal") either because it doesnt do anything.
[QUOTE=The Commander;47287990]This code used to work perfectly fine before the update, it would show names, health etc above NPC's. Now it does nothing at all and give no errors. -code- [/QUOTE] Add a bunch of print statements to see where the code stops running at.
Hey, I don't know if it's going to fit thread, but anyone knows where I can find well explained VGUI and Derma guides? I can do almost everything in serverside, but have no idea how to connect panels with serverside.
I really want to learn lua and I'm trying to use the gmod wiki to learn how. I did the intro, variable, and operator tutorials but I don't know where to go from there, anyone have any ideas on where to go next?
[QUOTE=wh1t3rabbit;47285537]I can't give a complete answer but when I played with having the player equip one actual weapon and then change its hold type and model through code, I had to use net messages to tell all clients to apply the same changes. Also need to network it to newly joined players otherwise they see whatever is the default for that swep (depending on your code I guess)[/QUOTE] I don't particularly have a problem networking one more thing haha, I'm already networking a few values as is, one more int can't hurt. Changing holdtypes was quite nice and straightforward, the model switching however is still totally stumping me. I suppose I could not draw the model as you normally would and render a replacement instead, assuming you can merge these things via bones, kinda how the GM13 hands work. [editline]9th March 2015[/editline] [QUOTE=Mike16112;47288061]I really want to learn lua and I'm trying to use the gmod wiki to learn how. I did the intro, variable, and operator tutorials but I don't know where to go from there, anyone have any ideas on where to go next?[/QUOTE] Think of a small script, something simple but one that doesn't have a tutorial on the wiki. Maybe a thing that counts your deaths and throws progressively worse insults at you through the chat? It should help you understand the applications of control structures, and you could work some data structure work into that to make it extend-able (like a table of insults to randomly choose from). [editline]10th March 2015[/editline] Fixed the model issue! The viewmodel just gets set in the PreDrawViewModel hook; [lua] hook.Add("PreDrawViewModel" , "LocalMorphLaser", function(viewM, ply, wep) ... viewM:SetModel(modes[curMode].v_model) ... end [/lua] The world model is just set in the SWEP:DrawWorldModel hook; [lua] function SWEP:DrawWorldModel() self:SetModel(modes[self:GetCurMode()].w_model) self:DrawModel() end [/lua] However the viewmodels don't agree with things like reload animations or anything actually useful like that. Interestingly firing animations will work fine.
[QUOTE=EnnX49;47288055]Hey, I don't know if it's going to fit thread, but anyone knows where I can find well explained VGUI and Derma guides? I can do almost everything in serverside, but have no idea how to connect panels with serverside.[/QUOTE] [url]http://wiki.garrysmod.com/page/Category:VGUI_Tutorials[/url] Old tutorials: [url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7a06.html#Panels[/url]
[QUOTE=Mike16112;47288061]I really want to learn lua and I'm trying to use the gmod wiki to learn how. I did the intro, variable, and operator tutorials but I don't know where to go from there, anyone have any ideas on where to go next?[/QUOTE] Is there anything you want to make in particular?
[QUOTE=Mike16112;47288061]I really want to learn lua and I'm trying to use the gmod wiki to learn how. I did the intro, variable, and operator tutorials but I don't know where to go from there, anyone have any ideas on where to go next?[/QUOTE] The Garry's Mod wiki is not for learning Lua, it is there to provide documentation for the API thats Garry's Mod provides. You should really consult [url=http://www.lua.org/manual/5.2/]this[/url].
I have a function that sometimes returns a nil. Can I test if an entity is "nil" in any way? And terminate the function in case the entity is nil?
[QUOTE=Fillipuster;47289474]I have a function that sometimes returns a nil. Can I test if an entity is "nil" in any way? And terminate the function in case the entity is nil?[/QUOTE] [lua]local ent = YourFunction() if ent == nil then --nil elseif IsValid(entity) then --valid entity else --invalid entity eg the world, disconnected player, etc end [/lua] Late edit: Can someone message me why this is dumb or incorrect?
[QUOTE=wh1t3rabbit;47289523][lua]local ent = YourFunction() if ent == nil then --nil elseif IsValid(entity) then --valid entity else --invalid entity eg the world, disconnected player, etc end [/lua][/QUOTE] Ty ;D
[lua]function ENT:StartTouch(ent) local meds=0 local iodine=0 local matches=0 local localEnts = ents.FindInSphere( self:GetPos(), 15 ) for k, v in pairs(localEnts) do if v:GetClass() == "m_meds" then meds = meds + 1 end if v:GetClass() == "m_matches" then matches = matches + 1 end if v:GetClass() == "m_iodine" then iodine = iodine + 1 end end if meds > 0 and iodine > 0 and matches > 1 then local meds_c=1 local iodine_c=1 local matches_c=2 for k, v in pairs(localEnts) do if v:GetClass() == "m_meds" and meds_c!=0 then print("Reduced meds") ent:Remove() meds=meds-1 end if v:GetClass() == "m_iodine" and iodine_c!=0 then print("Reduced iodine") ent:Remove() iodine=iodine-1 end if v:GetClass() == "m_matches" and matches_c!=0 then print("Reduced matches") ent:Remove() matches = matches - 1 end end self:Remove() end end[/lua] It should check on each touch if all the ingredients are around it, and if so, delete them all and itself. What is wrong here? It only deletes the one it touches, and itself.
[QUOTE=RedNinja;47289799]-code- It should check on each touch if all the ingredients are around it, and if so, delete them all and itself. What is wrong here? It only deletes the one it touches, and itself.[/QUOTE] You should try printing the results from FindInSphere(). Have you tried adjusting the radius?
[QUOTE=RedNinja;47289799][lua]function ENT:StartTouch(ent) local meds=0 local iodine=0 local matches=0 local localEnts = ents.FindInSphere( self:GetPos(), 15 ) for k, v in pairs(localEnts) do if v:GetClass() == "m_meds" then meds = meds + 1 end if v:GetClass() == "m_matches" then matches = matches + 1 end if v:GetClass() == "m_iodine" then iodine = iodine + 1 end end if meds > 0 and iodine > 0 and matches > 1 then local meds_c=1 local iodine_c=1 local matches_c=2 for k, v in pairs(localEnts) do if v:GetClass() == "m_meds" and meds_c!=0 then print("Reduced meds") ent:Remove() meds=meds-1 end if v:GetClass() == "m_iodine" and iodine_c!=0 then print("Reduced iodine") ent:Remove() iodine=iodine-1 end if v:GetClass() == "m_matches" and matches_c!=0 then print("Reduced matches") ent:Remove() matches = matches - 1 end end self:Remove() end end[/lua] It should check on each touch if all the ingredients are around it, and if so, delete them all and itself. What is wrong here? It only deletes the one it touches, and itself.[/QUOTE] [quote]if [B]v[/B]:GetClass() == "m_meds" and meds_c!=0 then print("Reduced meds") [B]ent[/B]:Remove() meds=meds-1 end[/quote] ent should be v
[QUOTE=wh1t3rabbit;47290121]ent should be v[/QUOTE] Thank you!
Does anyone know why entities that have never been in your line of sight are invalid? I send every players' entities using the net library and some are invalid when they are too far on the map.
Sorry, you need to Log In to post a reply to this thread.