• Problems That Don't Need Their Own Thread v3.0
    5,003 replies, posted
what is the thing to make a string into a number?
[QUOTE=The Fire;49286767]what is the thing to make a string into a number?[/QUOTE] tonumber [url]https://wiki.garrysmod.com/page/Global/tonumber[/url]
ok [editline]10th December 2015[/editline] tonumber( string "my string", number base=6 ) so that should do?
[QUOTE=The Fire;49286798]ok [editline]10th December 2015[/editline] tonumber( string "my string", number base=6 ) so that should do?[/QUOTE] Dont use the base argument. The other one has to be for example "8"
what do you mean?
[QUOTE=The Fire;49286860]what do you mean?[/QUOTE] tonumber( "my string", 6 )
Can someone please explain how to fix the clicking noise on a SWEP, I'm trying to create a melee weapon and on every swing it makes a clicking noise as if the clip is empty. Can someone help? [lua] AddCSLuaFile("shared.lua") AddCSLuaFile("cl_init.lua") include("shared.lua") SWEP.ViewModel = "models/weapons/c_crowbar.mdl" SWEP.WorldModel = "models/weapons/w_crowbar.mdl" SWEP.ViewModelFOV = 90 SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.HoldType = "knife" SWEP.DrawAmmo = false SWEP.WeaponType = "Tool" SWEP.SwingSound = "npc/vort/claw_swing1.wav" SWEP.HitSound = "physics/flesh/flesh_impact_bullet1.wav" SWEP.SwingDelay = 0.1 SWEP.Range = 50 SWEP.CanHitTree = true SWEP.CanHitOre = true function SWEP:Initialize() self:SetClip1(-1) // Putting this in stopped my weapon from turning into a gun and right back to the original weapon model self:SetClip2(-1) self:SetHoldType( self.HoldType ) self.NextSwing = CurTime() self.Stats = {} for k,v in pairs(BUFF_TYPES[self.WeaponType]) do self.Stats[k] = 0 end end function SWEP:SetStats(tbl) for k,v in pairs(tbl) do if v[1] then if self.Stats[v[1]] then self.Stats[v[1]] = self.Stats[v[1]] + v[2] else self.Stats[v[1]] = v[2] end end end if self.Stats[BUFF_SWINGSPEED] then self.SwingDelay = self.SwingDelay - tonumber("." .. self.Stats[BUFF_SWINGSPEED]) end end function SWEP:PrimaryAttack() self:OnSwing() end function SWEP:SecondaryAttack() return true end function SWEP:OnSwing() local tr = self.Owner:GetEyeTrace() self:EmitSound(self.SwingSound) self.Owner:SetAnimation( PLAYER_ATTACK1 ) self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER ) if tr.Entity then local ent = tr.Entity if ent:GetPos():Distance(self:GetPos()) <= self.Range then if ent:IsPlayer() || ent:IsNPC() then else if string.find(string.lower(ent:GetModel()), "tree") && self.CanHitTree then self.Owner:Notify("Hit tree") end if string.find(string.lower(ent:GetModel()), "rock") && self.CanHitOre then end end end end self.NextSwing = CurTime() + self.SwingDelay end function SWEP:OnDrop() self:Remove() end function SWEP:Deploy() end function SWEP:Think() end [/lua][
Does anyone know what I would do to create c_model hands and then parent/bonemerge them to a viewmodel?
[QUOTE=The Fire;49286860]what do you mean?[/QUOTE] Just use he function tonumber like this: [CODE]local numberOnString = "15" local number = tonumber( numberOnString ) -- Change the string with numbers to a number local YayMaths = (number / 2 + 5) ^ 2[/CODE]
How would I determine if a vector is behind a player - specifically that they are not viewing towards that vector? [url=https://wiki.garrysmod.com/page/Entity/IsLineOfSightClear]Found it.[/url]
I'm trying to clamp a health value for a health bar on a HUD, but I can't seem to clamp it. When the value goes over 100, the bar is still drawn and extended off the HUD. Heres the code, any help is appreciated :) [lua] local w = ScrW() local h = ScrH() local hudhealth = LocalPlayer():Health() / 100 local hudhealthclamped = math.Clamp(hudhealth, 0, 100) draw.RoundedBox(4, 20, h - 55, 370 * hudhealthclamped, 20, Color(255, 50, 50, 255)) [/lua]
[QUOTE=Shenesis;49295997]Because you are clamping between 0 and 100, instead of 0 to 1: by doing say 150/100 you get 1.5 and that is lower than 100 so the value isn't really clamped[/QUOTE] Thanks a lot, completely forgot about that.
Which functions would I need to do the following: Creating an entity, which will do something when a player is in a radius of x source units.
[QUOTE=P4sca1;49296391]Which functions would I need to do the following: Creating an entity, which will do something when a player is in a radius of x source units.[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ents/FindInSphere]ents.FindInSphere[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/Think]ENTITY/Think[/url]
what is my problem? [ERROR] gamemodes/fbase2/gamemode/client/modules/cl_hud.lua:699: attempt to index a nil value 1. v - gamemodes/fbase2/gamemode/client/modules/cl_hud.lua:699 2. unknown - lua/includes/modules/hook.lua:84 Line 699: [CODE] local newSize = strCurrentSize + DrawString("Font_HUDSmall", TEXT_ALIGN_LEFT, MMapX + 5 + 40 + 5, MMapY - 10 + i * 10 - 20 - 55 * k + rv.flAlpha / 255 * 20 + 5, Color(v[i].r, v[i].g, v[i].b, 0), strString); [/CODE]
:snip:
[QUOTE=The Fire;49298088]what is my problem? [ERROR] gamemodes/fbase2/gamemode/client/modules/cl_hud.lua:699: attempt to index a nil value 1. v - gamemodes/fbase2/gamemode/client/modules/cl_hud.lua:699 2. unknown - lua/includes/modules/hook.lua:84 Line 699: [CODE] local newSize = strCurrentSize + DrawString("Font_HUDSmall", TEXT_ALIGN_LEFT, MMapX + 5 + 40 + 5, MMapY - 10 + i * 10 - 20 - 55 * k + rv.flAlpha / 255 * 20 + 5, Color(v[i].r, v[i].g, v[i].b, 0), strString); [/CODE][/QUOTE] v it's nil or it's not a table, you're trying to index an invalid value, check the code around this
Why are hudhealth = LocalPlayer():Health() / 100. What are the / 100s purpose?
[QUOTE=Klaes4Zaugen;49299879]Why are hudhealth = LocalPlayer():Health() / 100. What are the / 100s purpose?[/QUOTE] Thats on default the max health.
[QUOTE=Leyserr;49295915]I'm trying to clamp a health value for a health bar on a HUD, but I can't seem to clamp it. When the value goes over 100, the bar is still drawn and extended off the HUD. Heres the code, any help is appreciated :) [lua] local w = ScrW() local h = ScrH() local hudhealth = LocalPlayer():Health() / 100 local hudhealthclamped = math.Clamp(hudhealth, 0, 100) draw.RoundedBox(4, 20, h - 55, 370 * hudhealthclamped, 20, Color(255, 50, 50, 255)) [/lua][/QUOTE] Wouldnt it be better to divide it by ply:GetMaxHealth() instead of 100?
I am trying to make a script where every 10 secs the script will check if the client has a certain weapon and if he has it send a signal to the server which would do something about it like killing them or banning with ULX (Will implement if I get it to work first). No Lua errors but the script does not seem to be executing. Client side Code: [code] if CLIENT then ply=LocalPlayer() timer.Create( "CheckTimer", 10, 0, function() if ply:HasWeapon("m9k_orbital_srike") then net.Start("ExploitedWeapon") net.SendToServer() end end) end [/code] Server Side Code: [code] if SERVER then util.AddNetworkString("ExploitedWeapon") net.Receive("ExploitedWeapon", function(len, ply) print(ply:Nick().." Spawned a restricted weapon") ply:Kill() end) end [/code]
snip
[QUOTE=Tatsumi-Chan;49302336]I am trying to make a script where every 10 secs the script will check if the client has a certain weapon and if he has it send a signal to the server which would do something about it like killing them or banning with ULX (Will implement if I get it to work first). No Lua errors but the script does not seem to be executing. Client side Code: [code] if CLIENT then ply=LocalPlayer() timer.Create( "CheckTimer", 10, 0, function() if ply:HasWeapon("m9k_orbital_srike") then net.Start("ExploitedWeapon") net.SendToServer() end end) end [/code] Server Side Code: [code] if SERVER then util.AddNetworkString("ExploitedWeapon") net.Receive("ExploitedWeapon", function(len, ply) print(ply:Nick().." Spawned a restricted weapon") ply:Kill() end) end [/code][/QUOTE] You misspelled "m9k_orbital_strike" as "m9k_orbital_srike" Also, if you are looking to prevent spawning restricted weapons, then I would suggest doing that in your weapon spawning VGUI's code, not like how you're doing it.
-snip-
How would I go about checking if a player is in a certain distance to an entity/npc?
[QUOTE=Leyserr;49309940]How would I go about checking if a player is in a certain distance to an entity/npc?[/QUOTE] [CODE]if (ply:GetPos():Distance(npc:GetPos()) <= 500) then[/CODE]
[QUOTE=BillyOnWiiU;49309957][CODE]if (ply:GetPos():Distance(npc:GetPos()) <= 500) then[/CODE][/QUOTE] Thanks man!
I'm currently trying to scale the collision mesh of a prop so that it can block a section I wish to have inaccesable but currently no matter what I try the collision angles do not match the props and is forced to a constant angle. This have become frustrating and I can't figure out how to rotate the collision Here is the code I currently use [code] local ent = ents.Create("prop_dynamic_override") if ent:IsValid() then ent:SetPos(Vector(-2982.032471, -3562.071777, 1026.395752)) ent:SetAngles(Angle(-89.981, 61.203, 180.000)) ent:SetModel("models/props_lab/blastdoor001c.mdl") ent:SetSolid(SOLID_VPHYSICS) local scale = Vector(0.1, 3, 5) local ang = Angle(-89.981, 61.203, 180.000) local mins = ent:OBBMins() local min_x = mins.x * scale.x local min_y = mins.y * scale.y local min_z = mins.z * scale.z local maxs = ent:OBBMaxs() local max_x = maxs.x * scale.x local max_y = maxs.y * scale.y local max_z = maxs.z * scale.z local mins2 = Vector(min_x, min_y, min_z) local maxs2 = Vector(max_x, max_y, max_z) mins2:Rotate(ang) maxs2:Rotate(ang) ent:PhysicsInitBox(mins2,maxs2) ent:SetCollisionBounds(mins2,maxs2) ent:Spawn() end[/code]
I'm trying to make a 3d2d hud. I'm had some success with putting 3d2d on props and shit but I can't seem to get the positioning quite right for a HUD. Here is what I got. [video=youtube;_Agwcri7KsE]https://www.youtube.com/watch?v=_Agwcri7KsE[/video] As you can see it's not aligned to the player properly. Somehow. ;_; Here is my code. [CODE] hook.Add( "PostDrawOpaqueRenderables", "SCHHealth", function() local angle = ply:GetEyeTraceNoCursor().Normal:Angle() -- comes from a derma slider thing so I could fiddle with it extra. angle:RotateAroundAxis( angle:Forward(), SlForward ) angle:RotateAroundAxis( angle:Right(), SlRight ) angle:RotateAroundAxis( angle:Up(), SlUp ) local forward = LocalPlayer():GetEyeTraceNoCursor().Normal * mult -- local forward = mult cam.Start3D2D( ply:EyePos() * forward , angle, 0.2 ) -- cam.Start3D2D( Vector(0, 0, 0) * 20 , Angle(0, 400, 0 ), 1.2 ) render.PushFilterMin( TEXFILTER.ANISOTROPIC ) render.PushFilterMag( TEXFILTER.ANISOTROPIC ) surface.SetDrawColor( 5, 5, 8, 255 ) surface.DrawRect( 0, 0, 500, 500 ) draw.SimpleText( "You have ".. hp .." health." , "DermaDefault", 24, 0, Color( 255, 255, 255, 255 ) ) -- drawBlur( 60, ScrH() - 35, HPmath, 50, 4, 5, 255 ) -- draw.RoundedBox( 0, 60, ScrH() - 35, HPmath, 50, Color( 255, 30, 10, 230 ) ) render.PopFilterMin() render.PopFilterMag() cam.End3D2D()[/CODE]
I'm having a bit of a brain aneurysm and cannot figure out how to calculate the degree of rotation difference between the player's forward direction and a nearby entity. Essentially, if this was a top-down view... [t]http://puu.sh/lW9Y2.jpg[/t] I've been using :Dot like this... [code] local norm = LocalPlayer():GetForward() local pos = LocalPlayer():GetPos() local dot for a, b in pairs(ents.FindByClass("npc_*")) do local vpos = b:GetPos() local slope = (Vector(vpos.x, vpos.y, 0) - Vector(pos.x, pos.y, 0)):GetNormalized() dot = norm:Dot(slope) end [/code] but unfortunately, the way this is working out is it only does from 1 - 50 degrees, 50 being if the player is looking straight at the entity, and 1 if the entity is directly to their left or right. I want a way to have a degree that is not mirrored, meaning something like: they are to my left if the dot is 180, to my right if 0 or 360, in front of me if 90, and behind me if 270, etc. EDIT: Nevermind, I got it. Subtracted the y of the player's angle from the angle of the normal between the player and the entity. EDIT2: Well that's providing fucky results, too, so maybe if someone else has a better idea?
Sorry, you need to Log In to post a reply to this thread.