• Problems That Don't Need Their Own Thread v3.0
    5,003 replies, posted
[QUOTE=Tenrys;47665344]I don't get how to use that though, it doesn't seem to work.[/QUOTE] [lua] local vPositionInWorld = gui.ScreenToVector(gui.MousePos()) [/lua]
When I did that it didn't seem to work... I'll try it again some time later. Thanks!
[QUOTE=meowking1;47659378]Hey, I saw a job on scriptfodder where someone was asking how to limit commands for moderators to a certain DarkRP job like "Staff On Duty" so they wouldnt be able to use commands like noclip and godmode while they are roleplaying. How would I do this for my server?[/QUOTE] Anyone?
Can I hook GM:EntityTakeDamage( target, dmginfo ) ? Could I hook it as such: [code]hook.Add( "EntityTakeDamage", "Yo this be my hook son", function( targ, dmg ) -- My hook function end )[/code] [editline]5th May 2015[/editline] Also, I'd be hooking it in a SEnt, and I'll be trying to reduce the damage a player takes.
[QUOTE=WalkingZombie;47666262]Can I hook GM:EntityTakeDamage( target, dmginfo ) ? Could I hook it as such: [code]hook.Add( "EntityTakeDamage", "Yo this be my hook son", function( targ, dmg ) -- My hook function end )[/code] [editline]5th May 2015[/editline] Also, I'd be hooking it in a SEnt, and I'll be trying to reduce the damage a player takes.[/QUOTE] yes that's how it's done
Then again, I guess I could just hook it in an initialize script. [editline]5th May 2015[/editline] Thanks Busan1 !! [editline]5th May 2015[/editline] I suppose I have another question. Setting an Entity's collision group to [B]11[/B] (which is [B]COLLISION_GROUP_WEAPON[/B]) allows players to walk through them. However,[B] ENTITY:Touch( ent ) [/B]will not be called then. When you walk over a typical SWEP or Weapon, you pick it up automatically. Let's say I was making an Entity that I wanted to function similarly. How would I do that? What hook would run if a player walked through an Entity? I kinda want it to be performance light, which I believe rules out [B]ents.FindInBox(mins,maxs) [/B]
How would I use GM:CalcViewModelView to change the position of my SWEP's viewmodel? Just so you know, the name of the view model is models/weapons/c_shotgun.mdl, and the weapon name is simply "shotgun".
[QUOTE=A Fghtr Pilot;47667926]How would I use GM:CalcViewModelView to change the position of my SWEP's viewmodel? Just so you know, the name of the view model is models/weapons/c_shotgun.mdl, and the weapon name is simply "shotgun".[/QUOTE] return pos, ang [URL]http://wiki.garrysmod.com/page/GM/CalcViewModelView[/URL] [editline]5th May 2015[/editline] If you're running the code from the SWEP itself, however, then use this: [URL="http://wiki.garrysmod.com/page/WEAPON/GetViewModelPosition"]SWEP:GetViewModelPosition(pos, ang)[/URL] and again, return pos, ang
[QUOTE=James xX;47665424][lua] local vPositionInWorld = gui.ScreenToVector(gui.MousePos()) [/lua][/QUOTE] Returns this: 0.839305 0.200207 0.505455 I'm not even near the origin of the map.
[QUOTE=Tenrys;47668415]Returns this: 0.839305 0.200207 0.505455 I'm not even near the origin of the map.[/QUOTE] That gives you a direction, not a position. Shitty example: [lua] local vec = gui.ScreenToVector(gui.MousePos()) local tr = util.TraceLine({ start = ply:GetShootPos(), endpos = ply:GetShootPos() + vec*1e9, filter = ply }) [/lua]
[QUOTE=WalkingZombie;47668196]return pos, ang [URL]http://wiki.garrysmod.com/page/GM/CalcViewModelView[/URL] [editline]5th May 2015[/editline] If you're running the code from the SWEP itself, however, then use this: [URL="http://wiki.garrysmod.com/page/WEAPON/GetViewModelPosition"]SWEP:GetViewModelPosition(pos, ang)[/URL] and again, return pos, ang[/QUOTE] Like this? [CODE] function SWEP:GetViewModelPosition( pos, ang ) Vector(-2.161,0,0.519) return pos end [/CODE] Because, for some reason, this isn't working...
[QUOTE=A Fghtr Pilot;47669955]Like this? [CODE] function SWEP:GetViewModelPosition( pos, ang ) Vector(-2.161,0,0.519) return pos end [/CODE] Because, for some reason, this isn't working...[/QUOTE] You're not changing the pos variable.
[QUOTE=Willox;47669966]You're not changing the pos variable.[/QUOTE] I know what you mean but at the same time I don't... Can you show me what you mean?
You have two options 1) [code] pos = pos + Vector(-2.161,0,0.519) return pos [/code] 2) [code] pos:Add( Vector(-2.161,0,0.519) ) return pos [/code]
Thanks! Question, should the SWEP have their view model position changed upon me equipping it, or do I need to change something in SWEP:Think or SWEP:Initialize to get the function called?
[QUOTE=A Fghtr Pilot;47669955]Like this? [CODE] function SWEP:GetViewModelPosition( pos, ang ) Vector(-2.161,0,0.519) return pos end [/CODE] Because, for some reason, this isn't working...[/QUOTE] I might be late for this, I'm too lazy to read posts :downs: [CODE] function SWEP:GetViewModelPosition( pos, ang ) pos = Vector(-2.161,0,0.519) return pos end [/CODE] [editline]6th May 2015[/editline] You need to set pos before you return it, in order to change it. [editline]6th May 2015[/editline] Also, I myself have a question. halo.Add has it's first variable described as a "table of entities". I only have one entity I want to add a halo to, so I'm asking, can I just specify one entity and still have it work?
Literally two posts above. At the halo question, just do {myent}
[QUOTE=A Fghtr Pilot;47670745]Thanks! Question, should the SWEP have their view model position changed upon me equipping it, or do I need to change something in SWEP:Think or SWEP:Initialize to get the function called?[/QUOTE] The function you're hooking is called automatically. If the function is hooked when the SWEP is created, it should be fine. Also, thank you zerf, and yes... that post was literally two posts lol [editline]6th May 2015[/editline] I have another question, oh my. How can I find out how deep under water a player is, in units? I understand waterlevel is 0 = what water? 1 = feet, 2 = body, 3 = head, basically... but I want units, to see if maybe a player is 300 units below the top of the water volume.
[t]http://i.imgur.com/77YtgJT.png[/t] I've figured out how to color the background by doing [code]for k, v in pairs( DListView.Lines ) do[/code] etc, however even upon reading the [url="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/dlistview.lua"]DlistView[/url] I'm unable to work out how to color the line text? I gather it's something to-do with Columns?
[QUOTE=Mrkrabz;47674602][t]http://i.imgur.com/77YtgJT.png[/t] I've figured out how to color the background by doing [code]for k, v in pairs( DListView.Lines ) do[/code] etc, however even upon reading the [url="https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/vgui/dlistview.lua"]DlistView[/url] I'm unable to work out how to color the line text? I gather it's something to-do with Columns?[/QUOTE] It's all in the skin. skin.Colours.Label.*[Default|Bright|Dark|Highlight] This is performed in the DListView_Line's "DListViewLabel" panel: [lua] function PANEL:UpdateColours( skin ) if ( self:GetParent():IsLineSelected() ) then return self:SetTextStyleColor( skin.Colours.Label.Bright ) end return self:SetTextStyleColor( skin.Colours.Label.Dark ) end [/lua] Which, "SetTextStyleColor" comes from the DLabel panel.
are there any limitations regarding the PlayerDisconnected hook that I don't know about? im running a local SRCDs server to test/develop. im writing stuff to a database and want it to save a player's current data when they leave, like so: [code] function PlayerDisconnected( ply ) doStuff( ply ) end hook.Add( "PlayerDisconnected", "dostuff", doStuff )[/code] when i disconnect from my server it complains that ply is nil, not sure if its something to do with the server being local since i never had any problems doing it this way in the past. *edit* nevermind, i updated some functions and forgot to amend the extra ply argument to them all.
The code you provided seems to generate this error when someone tries to use the remover tool on anything, not just cars. It also seems to prevent the remover tool from working on cars altogether. This is the code that I am running in garrysmod/lua/autorun/server (the only things changed are the single equals to double equals, and the comments.) [lua] -- Code by Busan1 on facepunch local function canDoStuffWithCar( _e ) if( _e:GetDriver() && _e:GetDriver():IsPlayer() ) then return false; end return true; end hook.Add( "CanTool", "SomeUniqueHookName999", function( _p, _e, tool ) -- Remover restriction if( tool == "remover" && _e:IsVehicle() && !canDoStuffWithCar( _e ) ) then return false; end end ); hook.Add( "PhysgunPickup", "SomeUniqueHookName666", function( _p, _e ) -- Physgun restriction. if(_e:IsVehicle() && !canDoStuffWithCar( _e ) ) then return false; end end ); [/lua] Is there something simple I overlooked when testing?
[QUOTE=Deathbypwnage;47678690]The code you provided seems to generate this error when someone tries to use the remover tool on anything, not just cars. It also seems to prevent the remover tool from working on cars altogether. This is the code that I am running in garrysmod/lua/autorun/server (the only things changed are the single equals to double equals, and the comments.) [lua] -snip- [/lua] Is there something simple I overlooked when testing?[/QUOTE] what error are you getting? the only thing i would suspect from looking at it is that the '!canDoStuffWithCar ( _e )' function is being called on every entity that is shot, but GetDriver() will only work on vehicle entities. im not sure if lua tries to evaluate everything in an if statement or drops it at the first false, though, so i could be way off. [code] -- Code by Busan1 on facepunch local function canDoStuffWithCar( _e ) if( _e:GetDriver() && _e:GetDriver():IsPlayer() ) then return false; end return true; end hook.Add( "CanTool", "SomeUniqueHookName999", function( _p, _e, tool ) -- Remover restriction if( tool == "remover" && _e:IsVehicle()) then if (!canDoStuffWithCar( _e )) then return false; end end end ); hook.Add( "PhysgunPickup", "SomeUniqueHookName666", function( _p, _e ) -- Physgun restriction. if(_e:IsVehicle()) then if (!canDoStuffWithCar( _e )) then return false; end end end ); [/code] if the error is something along the lines of [b]attempt to call method 'GetDriver' (a nil value)[/b] then this should work. *edit* just read up that they do use short cut evaluation, so the above probably isnt the solution.
How would I, with GM:CalcView()(or SWEP:CalcView(), in this case), make a viewbob code?
[QUOTE=A Fghtr Pilot;47679640]How would I, with GM:CalcView()(or SWEP:CalcView(), in this case), make a viewbob code?[/QUOTE] [lua]ViewBobAng = 0 function ViewBob( ply, pos, angles, fov ) if IsValid(LocalPlayer()) then if( ply:GetVelocity():Length() > 0 ) then ViewBobAng = ViewBobAng + 1 * FrameTime() angles.pitch = angles.pitch + math.sin( ViewBobAng ) angles.yaw = angles.yaw + math.cos( ViewBobAng ) * 0.3 end end end hook.Add( "CalcView", "ViewBob", ViewBob )[/lua] Something along the lines of this, not tested it
[QUOTE=Mrkrabz;47680048][lua]ViewBobAng = 0 function ViewBob( ply, pos, angles, fov ) if IsValid(LocalPlayer()) then if( ply:GetVelocity():Length() > 0 ) then ViewBobAng = ViewBobAng + 1 * FrameTime() angles.pitch = angles.pitch + math.sin( ViewBobAng ) angles.yaw = angles.yaw + math.cos( ViewBobAng ) * 0.3 end end end hook.Add( "CalcView", "ViewBob", ViewBob )[/lua] Something along the lines of this, not tested it[/QUOTE] You sure calling CalcView would be better? Probably would be better to use SWEP:CalcView, I'm not trying to add viewbob to all weapons, I'm trying to add viewbob purely to my weapon. Also, it doesn't work when I change it to SWEP:CalcView and remove hook.Add.
[QUOTE=A Fghtr Pilot;47680193]You sure calling CalcView would be better? Probably would be better to use SWEP:CalcView, I'm not trying to add viewbob to all weapons, I'm trying to add viewbob purely to my weapon. Also, it doesn't work when I change it to SWEP:CalcView and remove hook.Add.[/QUOTE] [lua] local ViewBobAng = 0 function SWEP:CalcView(ply, pos, ang, fov) if ply != LocalPlayer() then return end if( ply:GetVelocity():Length() > 0 ) then ViewBobAng = ViewBobAng + 1 * FrameTime() ang.pitch = ang.pitch + math.sin( ViewBobAng ) ang.yaw = ang.yaw + math.cos( ViewBobAng ) * 0.3 end return pos, ang, fov end [/lua] You need to return the arguments for it to affect CalcView
How can I find out how deep under water a player is, in units? I understand waterlevel is 0 = what water? 1 = feet, 2 = body, 3 = head, basically... but I want units, for example, to see if maybe a player is 300 units below the surface.
[QUOTE=WalkingZombie;47681361]How can I find out how deep under water a player is, in units? I understand waterlevel is 0 = what water? 1 = feet, 2 = body, 3 = head, basically... but I want units, for example, to see if maybe a player is 300 units below the surface.[/QUOTE] I'd suggest saving the z pos of the player at waterlevel 1, then compare that to the player's z pos when they are waterlevel 3 that will give you units from the feet depth (basically surface). hope this helps
How do I convert a color table to player color? As far as I understand it, player color should be a vector with R, G, B values between 0 and 1, but a color table is a table with R G B A values between 0 and 255. So I think I need to take the first 3 values, divide them by 255, and turn it into a vector.. But how?
Sorry, you need to Log In to post a reply to this thread.