Ulysses

General => Developers Corner => Topic started by: sir snifflebutt on April 21, 2017, 01:25:40 AM

Title: !up
Post by: sir snifflebutt on April 21, 2017, 01:25:40 AM
so i would like if anyone could help me with making a !up command for those who play darkrp and you get weed pots and you drop it on its side and you know its a pain to make it face up i would like a command when you look at the entite and you do !up makes it face up.
Title: Re: !up
Post by: MrPresident on April 21, 2017, 09:50:17 AM
That sounds like fun.. give me a few minutes and I'll see what I can do for you.
Title: Re: !up
Post by: MrPresident on April 21, 2017, 10:10:43 AM
Code: Lua
  1. local CATEGORY_NAME = "Custom Commands"
  2.  
  3. ------------------------------ Up ------------------------------
  4. function ulx.up( calling_ply )
  5.    local ent = calling_ply:GetEyeTrace().Entity
  6.    if not IsValid( ent ) then return end
  7.    local y = ent:GetAngles().y
  8.    local pos = ent:GetPos()
  9.    ent:SetAngles( Angle(0, y, 0) )
  10.    ent:PhysWake()
  11. end
  12.  
  13. local up = ulx.command( CATEGORY_NAME, "ulx up", ulx.up, "!up" )
  14. up:defaultAccess( ULib.ACCESS_ADMIN )
  15. up:help( "Sets the looked at entity upright." )
  16.  

Here is a short video of it in action!
https://gfycat.com/WindingObedientAnhinga (https://gfycat.com/WindingObedientAnhinga)
Title: Re: !up
Post by: Bytewave on April 21, 2017, 02:05:33 PM
-snip-

You could use Entity.PhysWake() (https://wiki.garrysmod.com/page/Entity/PhysWake) to clean up the code a little. Does pretty much exactly what you do at the end.
Title: Re: !up
Post by: MrPresident on April 21, 2017, 07:51:20 PM
I wonder if this function is new(ish) because I've only ever done it the other way.
Thanks for the info.