Swep that lets you pick everything up and move it around
8 replies, posted
So I know you can use the Physics Gun, but I'd like to make a swep that allows you to pick up players, npcs and any objects. A bit like holding E on something in garrys mod. I'm not sure how to do this. Can someone point me in the right direction(s) for this? Or if there is already one, that would be good too ^_^ Thanks!
[url]https://wiki.garrysmod.com/page/Player/GetEyeTrace[/url]
[url]https://wiki.garrysmod.com/page/Entity/GetForward[/url]
If you can math, you can do this.
[QUOTE=RedXVIII;50613162][url]https://wiki.garrysmod.com/page/Player/GetEyeTrace[/url]
[url]https://wiki.garrysmod.com/page/Entity/GetForward[/url]
If you can math, you can do this.[/QUOTE]
That's great thanks. Is it possible for you to give me an example to get me started? Thank you :)
[QUOTE=tcmaxwell2;50630360]That's great thanks. Is it possible for you to give me an example to get me started? Thank you :)[/QUOTE]
Do you know lua?
[QUOTE=overki11;50632393]Do you know lua?[/QUOTE]
Cmon :P
If you want to have every entity pick-upable then use KEYDOWN.
[url]https://wiki.garrysmod.com/page/Player/KeyDown[/url]
In it's hook, trace the player's whats-hes-lookin'on (aka 'eye'), with GetEyeTrace, and get the Entity from there.
[url]https://wiki.garrysmod.com/page/Structures/TraceResult[/url]
From there, you just need to apply force on or set the position of the given entity, however you expect the swep to work.
[QUOTE=Kiro The Pro;50633055]Cmon :P
If you want to have every entity pick-upable then use KEYDOWN.
[url]https://wiki.garrysmod.com/page/Player/KeyDown[/url]
In it's hook, trace the player's whats-hes-lookin'on (aka 'eye'), with GetEyeTrace, and get the Entity from there.
[url]https://wiki.garrysmod.com/page/Structures/TraceResult[/url]
From there, you just need to apply force on or set the position of the given entity, however you expect the swep to work.[/QUOTE]
Thanks! It's my first time at lua. I read articles and such.
[CODE]
for v,k in pairs(player.GetAll()) then
if k:KeyDown( IN_USE ) then
local ent = k:GetEyeTrace().Entity
ent:SetPos( k:GetForward()*70 )
end
end
[/CODE]
take that with a grain of salt, im at work and cannot test this but that is the basic idea of it to get players see what key they are holding and do the set pos, you can also use apply force but meh.
if you want to make it happen on a weapon either add it to the weapon swep or just add a weapon check [url]https://wiki.garrysmod.com/page/Player/GetActiveWeapon[/url]
[QUOTE=shipstreet;50685726][CODE]
for v,k in pairs(player.GetAll()) then
if k:KeyDown( IN_USE ) then
local ent = k:GetEyeTrace().Entity
ent:SetPos( k:GetForward()*70 )
end
end
[/CODE]
take that with a grain of salt, im at work and cannot test this but that is the basic idea of it to get players see what key they are holding and do the set pos, you can also use apply force but meh.
if you want to make it happen on a weapon either add it to the weapon swep or just add a weapon check [url]https://wiki.garrysmod.com/page/Player/GetActiveWeapon[/url][/QUOTE]
Make sure you add some checks to the class name with GetClass so you don't for example change the position of the world (dunno if thats possible but you can never be too safe)
physgun works
Sorry, you need to Log In to post a reply to this thread.