[QUOTE=BFG9000;46185784]No, this doesn't work because the point of rotation cannot be changed. I'm looking to rotate an object's angle and position around a determined point.[/QUOTE]
You don't need to know trigonometry or even advanced vector math for that, you only need to understand how transformations work and how to accumulate them to get what you need.
It might be easier if you understand the fact that angles can be represented as three normalized basis vectors which are perpendicular to each other (Forward, Right and Up). Just picture that in your head and imagine yourself moving them around or rotating them and you should be able to handle transformations just fine.
Here's a way to achieve the effect you are looking for. If you use CurTime to determine the amount of rotation you should apply around the Up axis, you effectively get your object to orbit around the reference point. Of course the reference requires an angle as well, otherwise there would be an infinite number of possible Up vectors and you wouldn't be able to determine which one to use.
[img]http://i.imgur.com/EEhJKbE.png[/img]
Which results in this code.
[lua]local function calcPosAng(pos0, ang0, distance, rotation)
-- Copy the reference position and angle
local pos, ang = Vector(), Angle()
pos:Set(pos0)
ang:Set(ang0)
-- Rotate the angle around its axis of revolution
ang:RotateAroundAxis(ang:Up(), rotation)
-- Move the position away from the center in the direction the new angle is facing
pos:Add(distance * ang:Forward())
return pos, ang
end[/lua]
You can also do it with matrices, which is more readable in my opinion, and also a lot more versatile.
[lua]local function calcPosAng(pos0, ang0, distance, rotation)
-- Build the initial matrix
local m = Matrix()
m:Translate(pos0)
m:Rotate(ang0)
-- Rotate around the Z axis
m:Rotate(Angle(0, rotation, 0))
-- Translate along the X axis
m:Translate(Vector(distance, 0, 0))
-- Extract the position and angle from the matrix
return m:GetTranslation(), m:GetAngles()
end[/lua]
For instance, if you want to rotate the object around itself after computing its position, all you have to do is add a rotation after the last translation.
It helps if you picture a matrix as a noclipping player who can rotate in all directions. The player starts at Vector(0, 0, 0) and Angle(0, 0, 0) and all transformations are relative to his current view angles. Therefore a translation around X, Y and Z will cause him to move respectively forward/back, right/left and up/down. Similarly, a pitch rotation will cause him to look up or down, a yaw rotation will make him look to the right or to the left, and a roll rotation will tilt his view. Since transformations can be chained, the order in which they occur matters, if you take a few steps forward and then turn right, you won't end up in the same place as if you turned right before stepping forward.
Of course this is very informal, matrices have a lot more to them, but if you know how to manipulate them for basic transformations, they can make your life so much easier.
I'm making a short freeze all props script, and ive tried doing Freeze(true), EnableMotion(false), Lock()
I'm getting attempt to call method 'freeze, enablemotion, lock' (a nil value) everytime.
[code]
for _, ent in pairs(ents.FindByClass("prop_physics") ) do
ent:EnableMotion(false)
end
[/code]
Any suggestions on what i can use?
[QUOTE=Invule;46190185]I'm making a short freeze all props script, and ive tried doing Freeze(true), EnableMotion(false), Lock()
I'm getting attempt to call method 'freeze, enablemotion, lock' (a nil value) everytime.
[code]
for _, ent in pairs(ents.FindByClass("prop_physics") ) do
ent:EnableMotion(false)
end
[/code]
Any suggestions on what i can use?[/QUOTE]
The way the physgun does freezing is by setting the entity's movetype to MOVETYPE_NONE and disabling motion for the [B]physobject[/B] of the entity.
[QUOTE=Invule;46190185]I'm making a short freeze all props script, and ive tried doing Freeze(true), EnableMotion(false), Lock()
I'm getting attempt to call method 'freeze, enablemotion, lock' (a nil value) everytime.
[code]
for _, ent in pairs(ents.FindByClass("prop_physics") ) do
ent:EnableMotion(false)
end
[/code]
Any suggestions on what i can use?[/QUOTE]
EnableMotion only works on the Entity's Physics Object, not the Entity itself. Grab the PhysObj and disable motion there, then it will work
[QUOTE=Exho;46185410]Okay, I think this might help... I want to find the player's current facing Angle Roll, round it to some variant of 90 (0, 90, 180, -90), and then clamping the view from that point. If someone could tell me how to do that, i would be thankful.
This is my project I am working on: [url]https://github.com/Exho1/TTT_Spy_Cable/[/url][/QUOTE]
Anyone?
@Exho and Atebite
I got it working thanks :D
how can i make the text in my jobinfo label to stop going off the side? i want the text to go down and everything i try makes it go off the side [IMG]http://i.imgur.com/l88iaGJ.png[/IMG] [CODE]local jobinfo = vgui.Create( "DLabel", jobinfoB )
jobinfo:SetPos( 10, 40 )
jobinfo:SetText( "lots of text here" )
jobinfo:SetAutoStretchVertical( true )
jobinfo:SetDark(true)
[/CODE]
[QUOTE=TrippleT;46195409]how can i make the text in my jobinfo label to stop going off the side? i want the text to go down and everything i try makes it go off the side [IMG]http://i.imgur.com/l88iaGJ.png[/IMG] [CODE]local jobinfo = vgui.Create( "DLabel", jobinfoB )
jobinfo:SetPos( 10, 40 )
jobinfo:SetText( "lots of text here" )
jobinfo:SetAutoStretchVertical( true )
jobinfo:SetDark(true)
[/CODE][/QUOTE]
You want the text to wrap, this is also something I am interested in for a different purpose
[QUOTE=Exho;46195534]You want the text to wrap, this is also something I am interested in for a different purpose[/QUOTE] i did try that and it still goes out
[editline]10th October 2014[/editline]
it wraps but most of it still goes out
[QUOTE=TrippleT;46195552]i did try that and it still goes out
[editline]10th October 2014[/editline]
it wraps but most of it still goes out[/QUOTE]
Have you set the width of the label?
[QUOTE=wh1t3rabbit;46195668]Have you set the width of the label?[/QUOTE]
In my experience, that only cuts off the letter
[editline]9th October 2014[/editline]
I give up on my attempt at cloning Loure's Spy Cable, fuck angles and everything about them.
For anyone who is interested (not likely since I didnt get help here), [url]https://github.com/Exho1/TTT_Spy_Cable/[/url]
With a brief look over the wiki page and the dlabel.lua script I don't really see any way to word-wrap it.
You could possibly use a multi-line dtextentry and make it so it cannot be edited.
I have a small issue. I want to check which player out of all of them has the most frags.
[lua]for _,v in pairs(player.GetAll()) do
if v:Frags() > -- what do I do here... crap
end
end
[/lua]
At this point I genuinely don't know what to do... I'm completely stuck here.
[QUOTE=RonanZer0;46196051]I have a small issue. I want to check which player out of all of them has the most frags.
[lua]for _,v in pairs(player.GetAll()) do
if v:Frags() > -- what do I do here... crap
end
end
[/lua]
At this point I genuinely don't know what to do... I'm completely stuck here.[/QUOTE]
I could think of 2 ways currently.
First off: The Fretta way.
[lua]
local winningply
local winningfrags = 0
for k,v in pairs(player.GetAll()) do
if v:Frags() > winningfrags then
winningply = v
winningfrags = v:Frags()
end
end
[/lua]
or with an Table:
[lua]local winner = {}
for k,v in pairs(player.GetAll()) do
winner[v:Frags()] = v
end
table.SortbyKey(winner)
print(table.GetLastKey(winner))
[/lua]
all pseudocode.
Silly questions, but I want to save player data in GM:ShutDown and save it in the database. My first call in my save function to ply:Nick() works fine, but ply:SteamID64() is returning nil. What the hell's going on? Before I copied the data into another table, but I need to save quite a few fields and keeping them updated somewhere else will be obnoxious.
[QUOTE=Agent766;46196346]Silly questions, but I want to save player data in GM:ShutDown and save it in the database. My first call in my save function to ply:Nick() works fine, but ply:SteamID64() is returning nil. What the hell's going on? Before I copied the data into another table, but I need to save quite a few fields and keeping them updated somewhere else will be obnoxious.[/QUOTE]
I've found that hook to be unreliable at best, it seems to shut down before functions complete :/
how would I make hud elements such as SimpleText move around on the screen? i want it to move in a random direction and fade out but the only way i can accomplish this is by updating the postion and opacity of the element every frame which seems ridiculous.
[QUOTE=Lizart;46198165]how would I make hud elements such as SimpleText move around on the screen? i want it to move in a random direction and fade out but the only way i can accomplish this is by updating the postion and opacity of the element every frame which seems ridiculous.[/QUOTE]
It might seem ridiculous but that's how you do it.
Is there a way to save png image into data folder?
[QUOTE=TrippleT;46195409]how can i make the text in my jobinfo label to stop going off the side? i want the text to go down and everything i try makes it go off the side [IMG]http://i.imgur.com/l88iaGJ.png[/IMG] [CODE]local jobinfo = vgui.Create( "DLabel", jobinfoB )
jobinfo:SetPos( 10, 40 )
jobinfo:SetText( "lots of text here" )
jobinfo:SetAutoStretchVertical( true )
jobinfo:SetDark(true)
[/CODE][/QUOTE]
If you're running darkrp you can do this:
draw.DrawText( DarkRP.textWrap( "ur message", "ur font", width), "ur font", width, height, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT );
example: draw.DrawText( DarkRP.textWrap( msg, "info", 300 ), "info", 20 * x, 70 * y, Color(255, 255, 255, 255), TEXT_ALIGN_LEFT );
If that dosent work you need to draw.roundedbox where your description is and draw in that.
[QUOTE=rebel1324;46198336]Is there a way to save png image into data folder?[/QUOTE]
You can only save .txt files no matter what, unless you got a module. And as far as I know, render.Capture doesn't support .png.
Anyone know how to attach a certain prop to all players on the server?
For example to make everyone on the server wear a helmet?
I though about using code like in the SWEP construction kit
[code]
SWEP.WElements = { ["element_name"] = { type = "Model", model = "", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(0, 0, 0), angle = Angle(0, 0, 0), size = Vector(0.5, 0.5, 0.5),
color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } } [/code]
but I don't know how to implement it the way I want
The text order is reversed when its displayed over the player's head. I want the most recent message at the bottom for reading purposes.
[t]http://i.imgur.com/M3sO513.jpg[/t]
[code]
if SERVER then
AddCSLuaFile()
util.AddNetworkString( "PlayerSaidSomethin" )
hook.Add( "PlayerSay", "PlayerSayExample", function( ply, text, team )
--if not ply:Alive() or ply:IsSpec() then return end
local SayData = {}
SayData.ply = ply
SayData.txt = text
net.Start("PlayerSaidSomethin")
net.WriteTable(SayData)
net.Broadcast() -- Tell erryone
end)
end
if CLIENT then
surface.CreateFont( "Overhead_Msg", {
font = "Arial",
size = 30,
weight = 500,
antialias = true,
} )
surface.CreateFont( "Overhead_Name", {
font = "Arial",
size = 32,
weight = 650,
antialias = true,
} )
local MsgTable = {}
net.Receive( "PlayerSaidSomethin", function( len, ply )
local Data = net.ReadTable()
local ply = Data.ply
local msg = string.Trim(Data.txt) -- Trimming whitespace is a good idea
table.insert(MsgTable, msg)
if #MsgTable > 8 then -- To prevent the Leaning Tower of Chat
table.remove( MsgTable, 1 ) -- Remove the first key
end
if timer.Exists(ply:UniqueID().."_ChatMessage") then -- If chat is already displaying
local tleft = timer.TimeLeft(ply:UniqueID().."_ChatMessage")
timer.Adjust( ply:UniqueID().."_ChatMessage", tleft + 3, 1, function() -- Adjust it
hook.Remove("PostDrawOpaqueRenderables", ply:UniqueID().."_ChatMessage")
table.Empty(MsgTable)
end)
end
hook.Add( "PostDrawOpaqueRenderables", ply:UniqueID().."_ChatMessage", function()
--if ply == LocalPlayer() then return end
if #MsgTable < 1 then -- No messages
timer.Simple(0.5, function() -- Delay for effect
hook.Remove("PostDrawOpaqueRenderables", ply:UniqueID().."_ChatMessage")
table.Empty(MsgTable)
end)
end
local BoneIndx = ply:LookupBone("ValveBiped.Bip01_Head1")
local BonePos, BoneAng = ply:GetBonePosition( BoneIndx )
local pos = BonePos + Vector(0,0,80) -- Place above head bone
local eyeang = LocalPlayer():EyeAngles().y - 90 -- Face upwards
local ang = Angle( 0, eyeang, 90 )
-- Start drawing
cam.Start3D2D(pos, ang, 0.1)
local Height = 255
local Width = 2
local Buffer = 30
-- Background
surface.SetDrawColor( 255, 255, 255, 100 )
surface.DrawRect(0-(Width/2), 600, Width, Height )
surface.DrawRect(0-(Height/2), 600, Height, Width )
--table.SortByKey( MsgTable, false ) -- Doesnt affect it
for k, v in pairs(MsgTable) do
if string.len(v) > 80 then
-- Make it either not show the message or try again to get word wrap working
print("too big")
print(string.len(v))
end
-- Draw the message
draw.DrawText( v, "Overhead_Msg", 0, 600-Buffer, Color(255,255,255,255), TEXT_ALIGN_CENTER )
Buffer = Buffer + 30
end
draw.DrawText( ply:Nick()..":", "Overhead_Name", 0, 600-Buffer, Color(25, 200, 25, 255), TEXT_ALIGN_CENTER )
cam.End3D2D()
end)
timer.Create(ply:UniqueID().."_ChatOneBy", 5, #MsgTable, function()
-- Removes the oldest message, one element at a time.
table.remove( MsgTable, 1 )
end)
timer.Create(ply:UniqueID().."_ChatTimer", (#MsgTable*5)+6, 1, function()
-- The actual table remover
hook.Remove("PostDrawOpaqueRenderables", ply:UniqueID().."_ChatMessage")
table.Empty(MsgTable)
end)
end)
end
[/code]
[QUOTE=Exho;46199457]The text order is reversed when its displayed over the player's head. I want the most recent message at the bottom for reading purposes.
[/QUOTE]
table.insert(MsgTable, msg)
>
table.insert(MsgTable, 1, msg)
???
[QUOTE=rebel1324;46198336]Is there a way to save png image into data folder?[/QUOTE]
[lua]
local f = file.Open('path/to/file.txt', 'wb', 'DATA')
f:Write(binaryData)
f:Close()
[/lua]
You have to change the .txt file extension outside of Garry's Mod to .png or .jpg depending on what you passed to render.Capture()
[QUOTE=Author.;46199079]You can only save .txt files no matter what, unless you got a module. And as far as I know, render.Capture doesn't support .png.[/QUOTE]
[url]http://wiki.garrysmod.com/page/Structures/RenderCaptureData[/url]
It does support png. Although, if I remember the png quality terrible compared to jpg.
[QUOTE=OzymandiasJ;46199707]table.insert(MsgTable, msg)
>
table.insert(MsgTable, 1, msg)
???[/QUOTE]
If I insert the new message to the first key in the table, will that overwrite the original first key? Or will it push all the keys/messages up one value?
Like if I have this:
[I][1] "Hey"
[2] "Hello"
[3] "Howdy"[/I]
And do this:
[I]table.insert(MsgTable, 1, Msg)[/I]
It will do this?
[I]
[1] "NewMessage"
[2] "Hey"
[3] "Hello"
[4] "Howdy"
[/I]
[QUOTE=Exho;46200356]If I insert the new message to the first key in the table, will that overwrite the original first key? Or will it push all the keys/messages up one value?
Like if I have this:
[I][1] "Hey"
[2] "Hello"
[3] "Howdy"[/I]
And do this:
[I]table.insert(MsgTable, 1, Msg)[/I]
It will do this?
[I]
[1] "NewMessage"
[2] "Hey"
[3] "Hello"
[4] "Howdy"
[/I][/QUOTE]
[img]http://puu.sh/c6Zuq.png[/img]
[QUOTE=Blasteh;46197424]I've found that hook to be unreliable at best, it seems to shut down before functions complete :/[/QUOTE]
any recommendations for working around this then?
hey i have a text screen above my npc but it seems to far to the right and idk how to change the y all i can change is the x [CODE]cam.Start3D2D(ent:GetPos() + ent:GetAngles:Right() * -75, TextAng, 0.2)
draw.WordBox(2, -TextWidth*0.5 + 5, -30, text, "HUDNumber5", Color(50, 0, 0, 50), Color(255,255,255,255))
cam.End3D2D()[/CODE]
Hey, I've looked into render.DrawBeam(), and i basically want to draw a beam from my gun but I have no idea where to start, if someone could point me in the right direction that'd be great, Also i've looked at the maurits page about it, but I didn't get far :(
Sorry, you need to Log In to post a reply to this thread.