[QUOTE=MCTeknic125;48271014]Updating some code to support Gmod 13+ Here is the error and the line.
[CODE][Pweld] lua/autorun/pw_positioning.lua:31: function arguments expected near ':'
1. unknown - lua/autorun/pw_positioning.lua:0[/CODE]
[CODE]ent:Angle:Set(ent:GetNetworkedVector("Rotation"))[/CODE][/QUOTE]
The problem is bad syntax. You can't have 2 juxtaposed colon calls without function arguments between them (eg, x:y():z() ). Following on from your previous post in another thread, you might want something like this:
[lua]
ent.OldAngles = ent:GetAngles( )
ent:SetAngles( ent:GetNetworkedAngle( "Rotation" ))
[/lua]
[QUOTE=James xX;48271040]The problem is bad syntax. You can't have 2 juxtaposed colon calls without function arguments between them (eg, x:y():z() ). Following on from your previous post in another thread, you might want something like this:
[lua]
ent.OldAngles = ent:GetAngles( )
ent:SetAngles( ent:GetNetworkedAngle( "Rotation" ))
[/lua][/QUOTE]
*sigh* That stopped the errors but it made even more problems that I can't track, I suck with lua, so I might have to ask someone to clean my code.
[QUOTE=MCTeknic125;48271168]*sigh* That stopped the errors but it made even more problems that I can't track, I suck with lua, so I might have to ask someone to clean my code.[/QUOTE]
Feel free to pm me the code with a description of what you intended it to do and I can see what I can do.
[QUOTE=James xX;48271216]Feel free to pm me the code with a description of what you intended it to do and I can see what I can do.[/QUOTE]
Done.
[LUA]local Equipment = nil
function GetEquipmentForRole(role)
-- need to build equipment cache?
if not Equipment then
-- start with all the non-weapon goodies
local tbl = table.Copy(EquipmentItems)
-- find buyable weapons to load info from
for k, v in pairs(weapons.GetList()) do
if v and v.CanBuy then
local data = v.EquipMenuData or {}
local base = {
id = WEPS.GetClass(v),
name = v.PrintName or "Unnamed",
limited = v.LimitedStock,
kind = v.Kind or WEAPON_NONE,
slot = (v.Slot or 0) + 1,
material = v.Icon or "vgui/ttt/icon_id",
-- the below should be specified in EquipMenuData, in which case
-- these values are overwritten
type = "Type not specified",
model = "models/weapons/w_bugbait.mdl",
desc = "No description specified."
};
-- Force material to nil so that model key is used when we are
-- explicitly told to do so (ie. material is false rather than nil).
if data.modelicon then
base.material = nil
end
table.Merge(base, data)
-- add this buyable weapon to all relevant equipment tables
for _, r in pairs(v.CanBuy) do
table.insert(tbl[r], base)
end
end
end
[/LUA]
PORTION OF CODE ^
[LUA][ERROR] gamemodes/terrortown/gamemode/cl_equip.lua:44: bad argument #1 to 'insert' (table expected, got nil)
1. insert - [C]:-1
2. GetEquipmentForRole - gamemodes/terrortown/gamemode/cl_equip.lua:44
3. unknown - gamemodes/terrortown/gamemode/cl_equip.lua:218
4. unknown - lua/includes/modules/concommand.lua:54[/LUA]
Heres my issue, Upon pressing C as a Traitor i get this error ^ and the T menu popups(but i cannot close it) and the menu has nothing in it. From what I THINK it seems, GetEquipmentForRole isn't defined(or it doesn't know what role i am and doesn't know what to grab). I have little to no experience in LUA and would appreciate some help! For those who are interested in seeing the full code([url]https://raw.githubusercontent.com/garrynewman/garrysmod/master/garrysmod/gamemodes/terrortown/gamemode/cl_equip.lua[/url])
Is there anyway of getting the next point in a PathFollower rather than just the current cursorpostion?
Got some more questions :( First, I have a UI that's mostly panels that are painted boxes. Whenever I click outside of them, they change color. How can I prevent this?
Additionally, in that same UI, DModelPanels aren't showing up, and I basically c+pd it from the GMod Wiki. How come?
Thanks in advance!
what's wrong with this code? I'm probably missing something really obvious
[lua]
[893] if trace.Entity:IsVehicle() && IsValid(trace.Entity:GetDriver()) then
[894] draw.SimpleTextOutlined('Driver: ' .. trace.Entity:GetDriver():Nick(), 'TargetIDLarge', Pos.x, Pos.y - 20, Color(255, 255, 255, 255), 1, 1, 2, Color(255, 100, 0, 255));
[895] end
[/lua]
the error I get:
[lua]
[ERROR] gamemodes/blah/gamemode/client/hud.lua:893: attempt to call method 'GetDriver' (a nil value)
1. HUDDrawTargetID - gamemodes/blah/gamemode/client/hud.lua:893
2. unknown - gamemodes/blah/gamemode/client/hud.lua:743
[/lua]
happens whenever I'm looking at an empty car, outside this is another if that checks and displays the owner of the car (works fine)
[QUOTE=Smt;48274800]...[/QUOTE]
It looks like [URL="http://wiki.garrysmod.com/page/Vehicle/GetDriver"]GetDriver is a server-side only function.[/URL]
[QUOTE=Sereni;48274881]It looks like [URL="http://wiki.garrysmod.com/page/Vehicle/GetDriver"]GetDriver is a server-side only function.[/URL][/QUOTE]
sigh, that's weird, i'm converting stuff over from gm12 but it was server side back then too, i wonder why this is even here in the first place, oh well thanks, I should really read the wiki properly
Could I use loops to make a menu like [url=http://puu.sh/j9Xn1/3cfe92fedb.jpg]this[/url]?
I'm thinking integers and tables. Or is there no other way than 135 lines of code?
And should I bother even trying to make a loop out of it?
[B]EDIT:[/B]
Couldn't really find any documentation of loops on the new wiki, and unsure how much of the old one works.
-snip i didnt see new page-
-snip-
I need a hint on how to proceed with re-sorting things on a table.
I have this nice table where each element has three keys, and there is a variable number of elements.
[code]{"1":{"url":"https://www.youtube.com/watch?v=ZqMqTB7RSjo","vidnumber":0, "vidtitle":"Cake recipe #1"},"2":{"url":"https://www.youtube.com/watch?v=2SbZYJwqnOo","vidnumber":1,"vidtitle":"Cake recipe #2"},"3":{"url":"https://www.youtube.com/watch?v=6Zx7dm0Y1sk","vidnumber":2,"vidtitle":"Cake recipe #3"},"4":{"url":"https://www.youtube.com/watch?v=d1PbHGtQaaE","vidnumber":3,"vidtitle":"Cake recipe #4"},..............}[/code]
I want to move (via functions, unless there's something better with Derma) Cake recipe #3 to its left, so the final result would be recipe #1, recipe #3, recipe #2, recipe #4. I can't think of how to do it though, should I move the element being moved to a temporary table and make each video at its left have vidnumber+1, should I ditch vidnumber and change the element's key (if so, how)...?
[QUOTE=Shenesis;48276077]Something like this?
[lua]
local tbl = {
[1] = "1",
[2] = "2",
[3] = "3",
[4] = "4",
}
local keytomove = 3
table.insert( tbl, 2, tbl[ keytomove ] )
tbl[ keytomove + 1 ] = nil
for _, v in pairs ( tbl ) do
print(v)
end
-- prints 1, 3, 2, 4
[/lua][/QUOTE]
That works perfectly! Thanks a ton.
(I also want it to go in the other order, but I understand enough to switch that by myself)
Hey guys, real quick, I'm creating buttons from a table with a for loop:
Table:
[CODE]MS_Categories = {
models = {
Name = "Player Models 2.0",
Guerilla = {
Name = "Guerilla",
Price = 1000,
Model = 'models/player/guerilla.mdl'
}
},
hats = {
Name = "Hats/Heads 2.0",
Melon = {
Name = "Melon",
Price = 1000,
Model = 'models/props_junk/watermelon01.mdl'
}
}
}[/CODE]
Loop:
[CODE] for k, v in pairs( MS_Categories ) do
local categorybutton = vgui.Create("DButton", dsidebar)
local bw, bh = 75, 75
categorybutton:Dock( TOP )
categorybutton:SetSize(bw, bh)
categorybutton:SetPos(ScrW() - bw, 0)
categorybutton:SetText( MS_Categories.k.Name ) -- Trouble line
categorybutton:SetFont( "MS_Button" )
end[/CODE]
How could I make MS_Categories.k.Name actually return the value I want?
v.Name
[editline]23rd July 2015[/editline]
Indexing a table with . means that the key is a string. In your case it's a number so it fails.
EG:
[lua]
local tab = {["hey"] = "man", [15] = "yo"}
tab.hey == "man" -- true
tab.15 == "yo" -- syntax error
tab[15] == "yo" -- true
[/lua]
[QUOTE=zerf;48280320]v.Name
[editline]23rd July 2015[/editline]
Indexing a table with . means that the key is a string. In your case it's a number so it fails.
EG:
[lua]
local tab = {["hey"] = "man", [15] = "yo"}
tab.hey == "man" -- true
tab.15 == "yo" -- syntax error
[/lua][/QUOTE]
Aaaand, now I feel stupid.
Deleted.
I'm working on a small test lua where you have to answer a question when you join the server. I've got this so far:
[CODE]function GM:PlayerInitialSpawn( ply )
if SERVER then
AddCSLuaFile("server_question.lua")
end
if CLIENT then
local frame = vgui.Create( "Answer this!?" )
frame:SetSize( 400, 200 )
frame:Center()
frame:MakePopup()
local DLabel = vgui.Create( "DLabel", Panel )
DLabel:SetPos( 40, 40 )
DLabel:SetText( question )
local TextEntry = vgui.Create( "DTextEntry", frame )
TextEntry:SetPos( 40, 60 )
TextEntry:SetSize( 75, 85 )
TextEntry:SetText( "Enter Answer Here!" )
TextEntry.OnEnter = function( self )
if self:GetValue() == answer then
frame:Close()
end
else
TextEntry:SetText("Incorrect!")
end
end
end[/CODE]
and then the questions/answers in the seperate Lua like this:
[CODE]function PickQuestion()
local q = math.random( 1, 100)
if q = 1 then
local question = "blah blah?"
local answer = "blah"
elseif q = 2 then
local question = "random text"
local answer = "just testing this"
else
local question = "blah blah"
local answer = "blah"
end
end[/CODE]
(obviously I'm gonna add a lot more questions than that)
So I'm gonna ask a probably noob question: what's the most efficient way of getting the local variables from one function to the other? Or should I set this up way differently?
EDIT: I think I'm being dumb and am just missing this:
[CODE]return question, answer[/CODE]
[QUOTE=Becomeimp;48282248]
So I'm gonna ask a probably noob question: what's the most efficient way of getting the local variables from one function to the other? Or should I set this up way differently?
[/QUOTE]
One problem is that you're defining the question/answer vars as local variables within the if-then statement, meaning they can't leave it.
As soon as you end that if statement, your question/answer vars go poof.
[CODE]function PickQuestion()
local q = math.random( 1, 100)
local question, answer
if q = 1 then
question = "blah blah?"
answer = "blah"
elseif q = 2 then
question = "random text"
answer = "just testing this"
else
question = "blah blah"
answer = "blah"
end
return question, answer
end[/CODE]
You'll also have to call the function at the start of your
[CODE]if CLIENT then[/CODE]
bit and append something like
[CODE]if CLIENT then
local question, answer = PickQuestion()[/CODE]
to it so that you can actually roll for your Q/A.
also move that [CODE]if SERVER then
AddCSLuaFile("server_question.lua")
end[/CODE] to the outside of the PlayerInitialSpawn function without the
[CODE]if SERVER then
end[/CODE]
bit.
I'm creating a client side panel with buttons that spawn an Npc. Everything seems setup correctly and there are no errors in console. Yet nothing happens when I try to spawn the Novnpc via the button. Ideas?
My server has some issues when a player changes jobs randomly. The server can stay up anywhere from 4 hours - 28 hours until a random player changes jobs to anything. I have been looking in every addon for functions that are called when the player changes jobs / teams such as PlayerSpawn, OnPlayerChangedTeam, PlayerCanJoinTeam, PlayerLoadout. What else should I look for? I already tried removing 80% of the addons and the issue still persist (I also tried a blank SQLite and MySQL DB with no luck). Server gets a segmentation fault when the player fully picks up their weapons.
[video=youtube;jGv17MjiDPU]https://www.youtube.com/watch?v=jGv17MjiDPU[/video]
to be honest i have no idea what i'm doing with this library, and i'm hoping i can get a pointer or two: when moving the camera ingame the meshes flicker from lit to black as seen in the video. the only way i've found to get it to stop is render.SetLightingMode(2), but that means that i won't be getting lighting which is why i'm using this library.
[lua]local temp = Vector()
local function vert(x, y, z, u, v, norm)
temp.x = x
temp.y = y
temp.z = z
mesh.Position(temp)
mesh.Color(255, 255, 255, 255)
mesh.Normal(norm)
mesh.TexCoord(0, u, v)
mesh.AdvanceVertex()
end
local function drawPanel(m, w, h, u, v, u2, v2, tex)
render.SetMaterial(Material(tex))
-- im either crazy or stupid, but after repeatedly doing the cross product both by hand as well as consulting google
-- im pretty sure that all of these vector normals are correct. could just be stupid though
cam.PushModelMatrix( m )
mesh.Begin(MATERIAL_QUADS, 1)
vert(-128, 64, 0, 0, 0, Vector(0, 0, -1))
vert(128, 64, 0, 1, 0, Vector(0, 0, -1))
vert(128, -64, 0, 1, 1, Vector(0, 0, -1))
vert(-128, -64, 0, 0, 1, Vector(0, 0, -1))
mesh.End()
--[[mesh.Begin(MATERIAL_TRIANGLES, 2)
--tri 1 (surface normal: V = (0, 128, 0) W = (256, 128, 0) VxW = N = (Vector(0, 0, -32768))
vert(-w/2, -h/2, 0, 0, 1, Vector(0, 0, -1)) -- neighbors: tri1, tri2
vert(-w/2, h/2, 0, 0, 0, Vector(0, 0, -1)) -- neighbors: tri1
vert(w/2, h/2, 0, 1, 0, Vector(0, 0, -1)) -- neighbors: tri1, tri2
--tri 2 surface normal: V = (0, -128, 0) W = (-256, -128, 0) VxW = N = (Vector(0, 0, -32768))
vert(w/2, h/2, 0, 1, 0, Vector(0,0,-1)) -- neighbors: tri1, tri2
vert(w/2, -h/2, 0, 1, 1, Vector(0,0,-1)) -- neighbors: tri2
vert(-w/2, -h/2, 0, 0, 1, Vector(0,0,-1)) -- neighbors: tri1, tri2
mesh.End()]]--
cam.PopModelMatrix()
end
local function drawMeshes(pos, ang)
local w = 256
local h = 128
local m = Matrix()
m:Translate(pos)
m:Rotate(ang)
m:Translate(Vector(0, 2*h, 0))
drawPanel(m, w, h, 0, 0, 1, 1, "phoenix_storms/MetalSet_1-2")
for i=0, 2 do
m:Translate(Vector(0, -h, 0))
drawPanel(m, w, h, 0, 0, 1, 1, "phoenix_storms/MetalSet_1-2")
end
m:Translate(Vector(0, -h, 0))
drawPanel(m, w, h, 0, 0, 1, 1, "phoenix_storms/MetalSet_1-2")
end[/lua]
appreciate anyone who can throw me a bone here
[QUOTE=Silv;48284908][video=youtube;jGv17MjiDPU]https://www.youtube.com/watch?v=jGv17MjiDPU[/video]
to be honest i have no idea what i'm doing with this library, and i'm hoping i can get a pointer or two: when moving the camera ingame the meshes flicker from lit to black as seen in the video. the only way i've found to get it to stop is render.SetLightingMode(2), but that means that i won't be getting lighting which is why i'm using this library.
[lua]local temp = Vector()
local function vert(x, y, z, u, v, norm)
temp.x = x
temp.y = y
temp.z = z
mesh.Position(temp)
mesh.Color(255, 255, 255, 255)
mesh.Normal(norm)
mesh.TexCoord(0, u, v)
mesh.AdvanceVertex()
end
local function drawPanel(m, w, h, u, v, u2, v2, tex)
render.SetMaterial(Material(tex))
-- im either crazy or stupid, but after repeatedly doing the cross product both by hand as well as consulting google
-- im pretty sure that all of these vector normals are correct. could just be stupid though
cam.PushModelMatrix( m )
render.SuppressEngineLighting(true)
mesh.Begin(MATERIAL_QUADS, 1)
vert(-128, 64, 0, 0, 0, Vector(0, 0, -1))
vert(128, 64, 0, 1, 0, Vector(0, 0, -1))
vert(128, -64, 0, 1, 1, Vector(0, 0, -1))
vert(-128, -64, 0, 0, 1, Vector(0, 0, -1))
mesh.End()
--[[mesh.Begin(MATERIAL_TRIANGLES, 2)
--tri 1 (surface normal: V = (0, 128, 0) W = (256, 128, 0) VxW = N = (Vector(0, 0, -32768))
vert(-w/2, -h/2, 0, 0, 1, Vector(0, 0, -1)) -- neighbors: tri1, tri2
vert(-w/2, h/2, 0, 0, 0, Vector(0, 0, -1)) -- neighbors: tri1
vert(w/2, h/2, 0, 1, 0, Vector(0, 0, -1)) -- neighbors: tri1, tri2
--tri 2 surface normal: V = (0, -128, 0) W = (-256, -128, 0) VxW = N = (Vector(0, 0, -32768))
vert(w/2, h/2, 0, 1, 0, Vector(0,0,-1)) -- neighbors: tri1, tri2
vert(w/2, -h/2, 0, 1, 1, Vector(0,0,-1)) -- neighbors: tri2
vert(-w/2, -h/2, 0, 0, 1, Vector(0,0,-1)) -- neighbors: tri1, tri2
mesh.End()]]--
render.SuppressEngineLighting(false)
cam.PopModelMatrix()
end
local function drawReelMesh(pos, ang, reel, visIndex)
local w = 256
local h = 128
local m = Matrix()
m:Translate(pos)
m:Rotate(ang)
m:Translate(Vector(0, 2*h, 0))
drawPanel(m, w, h, 0, 0, 1, 1, "phoenix_storms/MetalSet_1-2")
for i=0, 2 do
m:Translate(Vector(0, -h, 0))
drawPanel(m, w, h, 0, 0, 1, 1, "phoenix_storms/MetalSet_1-2")
end
m:Translate(Vector(0, -h, 0))
drawPanel(m, w, h, 0, 0, 1, 1, "phoenix_storms/MetalSet_1-2")
end[/lua]
appreciate anyone who can throw me a bone here[/QUOTE]
I don't know anything about the Mesh library, but I know that for IMesh objects, what you need to do is [i]render a model first[/i] with Entity:DrawModel() or something so that its lighting information carries over to the mesh:
[code]function ENT:Draw()
//Render the entity's model so that its lighting gets applied to the mesh,
//but use a completely invisible texture so it doesn't actually show up
render.ModelMaterialOverride( Material("some_invisible_texture_vmt_that_you_made") )
self:DrawModel()
render.ModelMaterialOverride()
//Now render the imesh
render.SetMaterial(mat)
local matrix = Matrix()
matrix:SetTranslation(self:GetPos())
matrix:SetAngles(self:GetAngles())
cam.PushModelMatrix( matrix )
self.MeshObject:Draw()
cam.PopModelMatrix()
end[/code]
Maybe you can adapt something like that to however you're using the mesh library.
My question is on the last page, so I figured I'd just bump it
[quote=HELP;444444]I already made a thread for this problem but noone is really helping so I figured I'd just ask it here. I don't want to make this post extra lengthy by posting a video here so I'll link the video: [url]https://youtu.be/XH6QIdAeARE[/url] So, I want to achieve a recoil system as seen at 4:02 in the video. You'll notice that the player's view is pushed up then pushed slowly back down(I don't want to use ViewPunch for this). Could I achieve this by using math.Clamp, CurTime(), and self.Owner:EyeAngles()? Thanks. Link to the original thread:
[url]http://facepunch.com/showthread.php?t=1477089&p=48262458#post48262458[/url]
[/quote]
[QUOTE=TwoYearLurker;48284994]Maybe you can adapt something like that to however you're using the mesh library.[/QUOTE]
I was considering using IMesh, but at first glance it felt more restricted than Mesh.
This is what I've got right now in the ENT:Draw() function. I'll see if that invisible bit makes a difference though!
[lua]function ENT:Draw()
self:DrawModel()
local ang = Angle()
local pos = self:GetPos()
ang = self:LocalToWorldAngles(ang)
drawMeshes(pos, ang)
end[/lua]
[QUOTE=Silv;48285045]I was considering using IMesh, but at first glance it felt more restricted than Mesh.
This is what I've got right now in the ENT:Draw() function. I'll see if that invisible bit makes a difference though!
[lua]function ENT:Draw()
self:DrawModel()
local ang = Angle()
local pos = self:GetPos()
ang = self:LocalToWorldAngles(ang)
drawMeshes(pos, ang)
end[/lua][/QUOTE]
IMesh should be faster than mesh.* stuff because with mesh.* you need to call ton of functions in a draw hook instead of one. And I don't believe IMesh is more restricted, they have same capabilities.
[QUOTE=DeathWard;48283406]-snip-[/QUOTE]
thanks this was a lot of help! i've got everything set up now (all the prints are working), the only thing not happening is the Derma won't open. I'm assuming its a tiny formatting error I'm mising somewhere (there's no errors though). Here's what I have now:
[CODE]--First File
AddCSLuaFile()
include("nonstuck_checker_questions.lua")
print("Menu loaded!" )
local function spawn( ply )
print( "Menu Open!" )
if SERVER then
end
if CLIENT then
local question, answer = PickQuestion()
print("Here's your question!")
print(question)
print(answer)
local frame = vgui.Create( "DFrame" )
frame:SetSize( 400, 200 )
frame:SetPos( 100, 100 )
frame:MakePopup()
frame:SetTitle("You're a Homestuck, right?")
frame:SetDraggable( false )
local DLabel = vgui.Create( "DLabel", frame )
DLabel:SetPos( 40, 40 )
DLabel:SetText( question )
local TextEntry = vgui.Create( "DTextEntry", frame )
TextEntry:SetPos( 40, 60 )
TextEntry:SetSize( 75, 85 )
TextEntry:SetText( "Enter Answer Here!" )
TextEntry.OnEnter = function( self )
if self:GetValue() == answer then
frame:Close()
else
TextEntry:SetText("Incorrect!")
end
end
end
end
hook.Add( "PlayerInitialSpawn", "nonstuck_checker", spawn )
--Second File
AddCSLuaFile()
print( "Questions loaded!")
local function PickQuestion()
local q = math.random( 1, 100)
local question, answer
print(q)
if q == 1 then
question = "What is the name of the game the kids play?"
answer = "SBURB"
elseif q == 2 then
question = "What day does the SBURB Beta arrive?"
answer = "April 13, 2009"
else
question = "What is Zahhak's first name?"
answer = "Equius"
end
return question, answer
end
--yeah its for a friend's homestuck server. some real nerd stuff happening here.[/CODE]
EDIT: Did some more testing and it seems that PickQuestion() isn't running at all. How come?
Also should PickQuestion() be localized? I've tried it both ways and neither work
EDIT 2: Got it working! I needed to send a net message from Server => Client and then have the PickQuestion() non-localized
Does running hook.Call() on a server-only block of call only run that hook on the server and doesn't fire on the client?
Sorry, you need to Log In to post a reply to this thread.