• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
I'm making a small addon to just play around and explore new fields in Lua. Right now I have it to where the client saves the image in the data folder but have been painfully trying to make it so I can use the image(s) that are in the data folder to set it as a material on an entity. I can't seem to find a solution. local _M = {   ["1"] = {folder = '', name = 'gametracker', src = 'https://pbs.twimg.com/profile_images/788853490621812737/cdWhilh0.jpg', saved = false} } for i=1,table.Count(_M) do   local loc = tostring(i)   http.Fetch( _M[loc]['src'], function( body, len, headers, code )      file.Write(_M[loc]['folder'] .. _M[loc]['name'] .. '.jpg', body)      _M[loc]['saved'] = true   end, function( error )       print('hi')   end) end
Hello, I'm really new to LUA and trying to make my own money printer for darkRP. I wrote the basic printing algorithm so it would constantly generate 2 dollars with a small delay. So Here's the init.lua (without some unnessecary things): AddCSLuaFile("cl_init.lua") AddCSLuaFile("Shared.lua") include("shared.lua") local function PrintMore(ent)     if not IsValid(ent) then return end     timer.Simple(1, function()         if not IsValid(ent) then return end         ent:CreateMoneybag()     end) end function ENT:Initialize() self:initVars() self:SetModel("models/props_c17/consolebox01a.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:SetMaterial ("phoenix_storms/gear") local phys = self:GetPhysicsObject()     phys:Wake() timer.Simple(1, function() PrintMore(self) end) self:SetStoredA(1) end function ENT:CreateMoneybag() if not IsValid(self) or self:IsOnFire() then return end if not self:GetStoredA() >= self.MaxStoredA then amount = self:GetStoredA() + 2 if amount > self.MaxStoredA then amount = self.MaxStoredA end self:SetStoredA(amount) end timer.Simple(math.random(1,20), function() PrintMore(self) end) end and shared.lua: ENT.Type = "anim" ENT.Base = "base_gmodentity" ENT.PrintName = "ShitPrint inc. MARK I" ENT.Author = "Atziri" ENT.Spawnable = true ENT.IsMoneyPrinter = true function ENT:initVars() self.MaxStoredA = 300 end function ENT:SetupDataTables()     self:NetworkVar("Int", 0, "price")     self:NetworkVar("Entity", 1, "owning_ent") self:NetworkVar("Int", 1, "StoredA") end But when i spawn it, it gives me this error after a couple of seconds: [ERROR] lua/entities/customprinter/init.lua:39: attempt to compare number with boolean   1. CreateMoneybag - lua/entities/customprinter/init.lua:39    2. unknown - lua/entities/customprinter/init.lua:9 Timer Failed! [Simple][@lua/entities/customprinter/init.lua (line 7)] The 39th line is in the ENT:CreateMoneybag() function and here it is: if not self:GetStoredA() >= self.MaxStoredA then Apparently it can't compare both values because one of them is a boolean? If so, I don't understand how's the self.MaxStoredA is a boolean? I set it as a variable in shared.lua and gave a number value to it. I can't figure out why it doesn't pass through?
use brackets if not (self:GetStoredA() >= self.MaxStoredA) then
To elaborate the last response: the 'not' keyword is higher in the Lua order of operations so when you don't use parenthesis it equates to this if (not self:GetStoredA()) >= self.MaxStoredA then
Hmm. I used this function in an Effect, a tracer effect, but I don't see it on the Wiki. self.Position = self:GetTracerShootPos(data:GetOrigin(), self.WeaponEnt, self.Attachment) GetTracerShootPos render.DrawBeam(self.Position, self.EndPos, rad, ctime*-10, ctime*-10 + .1, Color(R, G, B, self.Alpha)) No errors, works wonderfully... So I wonder... everything about this function lol. self refers to the effect, so effect:GetTracerShootPos exists... Does it exist for other things such as ENT or SWEP? or PLAYER? Any information I can get about GetTracerShootPos would be gladly accepted
garrysmod/base.lua at master · Facepunch/garrysmod · GitHub
Thank you very much! Why is this not on the wiki? And... is there a way I could put it on the wiki? (I don't have an account for the wiki)
I will make a page for it.
Uhm... so I've been making a laser sight, and all looks fine until... this: Imgur which started happening when I added the beam. Imgur Here's my code. If you can make sense of it please let me know how I can fix this skybox glitch. It also affects water. [lua]hook.Add( "PreDrawEffects", "draw.VectorSprite", function() local ply = LocalPlayer() local wep = ply:GetActiveWeapon() if IsValid(ply) && IsValid(wep) && wep:GetClass() == "weapon_eagle" then local isAiming = math.Clamp( (CurTime() - wep.fIronTime) / IRONSIGHT_TIME, 0, 1 ) if wep:GetMode() && !wep:GetModeing() && (!wep:GetAiming() or isAiming >= 1) then local tr = util.GetPlayerTrace( ply ) local punchMult = 4.20 tr.mask = MASK_SHOT_PORTAL tr.endpos = ply:GetShootPos()+(ply:GetAimVector():Angle()+ply:GetViewPunchAngles()*punchMult):Forward()*32768 local trace = util.TraceLine( tr ) if !trace.HitSky then local dist = (trace.HitPos-ply:GetShootPos()):Length() local distp = math.Clamp(dist-15, 0, 16 )/16 local dotpos = trace.HitPos-trace.Normal*16*distp if dist > 960 then dotpos = ply:GetShootPos()+(ply:GetAimVector():Angle()+ply:GetViewPunchAngles()*punchMult):Forward()*960 end render.SetMaterial( ourMat ) render.DrawSprite( dotpos, 16, 16, Color(255,0,0) ) local Attach = ply:GetViewModel():GetAttachment( 1 ) local AttachPos = Attach.Pos+Attach.Ang:Right()*2+Attach.Ang:Forward()*2 render.DrawSprite( AttachPos, 4, 4, Color(255,0,0) ) render.SetMaterial( ourBem ) local BeamDir = (dotpos-AttachPos):GetNormal() local TrcDist = (dotpos-AttachPos):Length() render.StartBeam( 2 ) render.AddBeam( AttachPos, 1, 0, Color(255,0,0) ) render.AddBeam( AttachPos+BeamDir*math.min(80,TrcDist), 0, 1, Color(0,0,0) ) render.EndBeam() end end end end )[/lua]
How would I go about grabbing a specific part of a table? What I currently have works, but it seem's like there should be a better way to do this. My table actually contains 77 indexes (which is why I'm hoping there is an easier way) but for example purposes, I have lowered it to 9. bParts = {}     bParts[1] = "Head"     bParts[2] = "Neck"     bParts[3] = "Upper Torso"     bParts[4] = "Lower Torso"     bParts[5] = "Left Arm"     bParts[6] = "Right Arm"     bParts[7] = "Left Leg"     bParts[8] = "Right Leg"     bParts[9] = "Groin" local damage = "" local damagemod = 1 local part = bParts[math.random(1, 9)] if part == bParts[1] || part == bParts[2] || part == bParts[3] then damage = " (epic!)" damagemod = 2 else damage = "" damagemod = 1 end I tried something like this but it seemed to work randomly for k, v in pairs(bParts) do if k <= 3 then damage = " (epic!)" damagemod = 2 else damage = "" damagemod = 1 end end
So since im not getting any luck at finding it myself still, I'll attempt to ask here as well if anyone has an idea. So I am working on a server using custom content i am making. Somewhere later on items stopped saving/loading which is a problem that i don't want. No lua errors are shown at all either. My pointshop has custom items in it as well that. The pointshop, whether its the one ive been tweaking or a vanilla unmodified reinstall, still has this problem. (Meaning reinstalling pointshop doesn't fix this) No, the only addons outside of pointshop is ULX/ULib and a group check addon that gives points when you join it. Anything else is weapon models from the workshop and stuff I'm putting in. (Ive removed the group check as well which did not fix it either) I'm asking because Im not quite sure where the issue is. I am an amateur at lua and once i couldnt fix it by reinstalling the pointshop, I am at a loss, what is a possibly stopping pointshop from loading items? (Points load just fine, and my own xp system loads as well so i am also confused about this) At a point, all of this was working, custom items including, it just stopped at a unknown time. I even removed moved sv.db so the server could make a new fresh start, but to no success. I already have looked through google for these issues but the threads didnt get me any farther, considering they didnt have much of an answer either. I am also putting this into a gamemode I am making, so pointshop is being used by it. I tried pointshop in the sandbox gamemode which saves and loads the items correctly, so I don't understand what to do to get my gamemode to load pointshop stuff. function GM:PlayerDisconnected( ply )     ply:statssave()     ply:PS_Save() end function GM:PlayerInitialSpawn( ply )     ply:PS_GiveItem("crowbar")     ply:PS_EquipItem("crowbar")     scream = 0 --ignore     pain = 0 --ignore     taunt = 0 --ignore     footstep = 0 --ignore     voicepitch = 1.0 --ignore     ply:SetModel( "models/player/Group03/Male_0" .. math.random(1,9) .. ".mdl")     ply:SetupTeam( autobalance() )     ply:Give( "weapon_physcannon" )     ply:statsload()     ply:PS_LoadData() end is what i use to load my level system but also in attempt to load pointshop. (which does not work) There must be a step I am missing to get pointshop to load my stuff. (removing ps_loaddata and ps_save from the two does not help either)
Best way I guess would be to either store the random number and check if it's less than 3, or restructure your table's values into a string and bool for telling if it's epic or not.
bParts = {} bParts["Head"] = true bParts["Neck"] = true bParts["Upper Torso"] = true bParts["Lower Torso"] = false bParts["Left Arm"] = false bParts["Right Arm"] = false bParts["Left Leg"] = false bParts["Right Leg"] = false bParts["Groin"] = false function IsEpic(part) return bParts[part] end function GetDamageMod(part) return IsEpic(part) and 2 or 1 end
Can someone please help me get the glua highlighter for note++, I've been trying for 3 hours to find it but all I can find is 32 bit versions and note++ keeps saying no. Thanks guys.
Notepad++ GLua Highlighter ?
Im trying to find a command that will let me search for a specific player's specific SEnt. I.e I want to find user "Jack Mehoff" 's spawned in SEnt(S) named "custom_printer". thx
Little reccomendation sublimes GLua syntax is excellent, definitely a good starting point
Very simple one here, I think. I've done something where I'd be using ply:ViewPunch or ply:SetViewPunchAngles in a SWEP. One of them needs to be called very often to smoothly do what I want it to do, otherwise it'll be very unusual. So I am calling :ViewPunch in the think function. Simply put, using :SetViewPunchAngles would be VERY difficult for me, as I'd have to calculate a LOT of things to do it this way... I just want to know what's worse, :ViewPunch or :SetViewPunchAngles in a think function?
How to fire a button from LUA? Example: local time = 5 timer.Create("timerexample", 1, 0, function() time = time - 1 if time == 5 then for k,v in pairs(ents.FindByClass("func_button")) do v:Fire("Use") end end end)
If you want to fire every button every 5 seconds you do: timer.Create("Fire every button every 5 seconds", 5, 0, function() for k,v in pairs(ents.FindByClass("func_button")) do v:Fire("Use") end end)
If you want to delay the button being fired by 5 seconds but only run once, you can do v:Fire("Use",5)
No, to find out how many money printers one person owns.
One more question, trying to use GetVehicleClass to seperate different HUDs between different types of vehicles (airboats and jeeps), keeps coming back with this while getting in the car: [ERROR] .../gamemode/cl_init.lua:171: attempt to call method 'GetVehicleClass' (a nil value)   1. unknown - .../gamemode/cl_init.lua:171 LINE 171: local car = ply:GetVehicle() local variable = car:GetVehicleClass() print(variable) anyone have an idea on how to get the VehicleClass to print?
Make sure "car" is valid before trying to access its class.
Is there any way to get a key based on where it is on the keyboard? For example, if I want to get the key in position Q in QWERTY layout on an AZERTY keyboard, it would give me KEY_A. Or at the very least, is there any way to detect a player's keyboard layout?
There is not - you'll have to request it.
I'm hoping a conversion can be added to the library for such.
One could be made in Lua, but the user would have to manually select the layout. I'll give it a shot.
I'd appreciate such. If you don't feel like doing such, I'll do it tomorrow for our users.
Anyone have an idea on how to stop sound.PlayURL?
Sorry, you need to Log In to post a reply to this thread.