• Noob Lua Coder set eye angle concommand
    5 replies, posted
Ok so I want to make a console command where I can set my eye angle to a specific angle or if there is already one to do that I would really like to know what it is. This is mainly for setting my eye angle with expression 2, so if there is some command for setting eye angle in E2 I would appreciate that as well/instead.
for a concommand.. [lua] function SetEyesToAngle(ply, cmd, args) if !IsValid(ply) then return end local angle if #args > 0 then -- if they entered an angle into the concommand angle = args[1] else angle = Angle(0,0,0) end ply:SetEyeAngles(angle) end concommand.Add("seteyestoangle", SetEyesToAngle) --USAGE: (in console) seteyestoangle Angle(pitch,yaw,roll) [/lua]
[QUOTE=dr.dray_7;40543460] [lua] --USAGE: (in console) seteyestoangle Angle(pitch,yaw,roll) [/lua][/QUOTE] Won't [I]args[1][/I] be the [B]string[/B] "Angle(pitch,yaw,roll)" ? Or is there some concommand magic happening that actually makes that into an angle?
fix it by making the angle be Angle(args[1],args[2],args[3]), and 'seteyestoangle pitch yaw roll'
It should be something like this: [lua] local tn = function(n) return tonumber(n) or 0 end -- for example, if "1" is passed, return 1. if "yes" is passed, return 0. local function SetEyesToAngle(ply, cmd, args) -- It's only being used for a concommand, there's no reason to be global, so make it a local function. if !IsValid(ply) then return end local angle if #args > 2 then -- if they entered an angle into the concommand angle = Angle( tn(args[1]), tn(args[2]), tn(args[3]) ) else angle = Angle(0,0,0) end ply:SetEyeAngles(angle) end concommand.Add("seteyestoangle", SetEyesToAngle)[/lua]
Thanks very much! The reason I didn't do it myself (there are tutorials on it) is that I couldn't find anything which used multiple arguements, I thought the same thing was wh1t3rabbit and didn't know what do do about that.
Sorry, you need to Log In to post a reply to this thread.