Hey guys I had having problems with ValidEntity
Heres the code, I have been playing with this for days but i did not found a solution yet. (FOR GM13)
[CODE]function GM.CruiseControlTimer()
local t = player.GetAll()
for k=1, #t do
local v = t[k]
if(ValidEntity(v:GetVehicle())) then -- <---THIS IS LINE 75!
local car = v:GetVehicle()
if(v:GetVehicle().CruiseControl) then
local iSpeed = car:GetVelocity():Length() / 17.6
local iMaxSpeed = math.abs(car.CruiseControlSpeed)
if(iMaxSpeed > 0) then
if(iSpeed >= iMaxSpeed) then
car:GetPhysicsObject():SetDamping(math.ceil(iSpeed - iMaxSpeed + 4), 0)
else
car:GetPhysicsObject():SetDamping(0, 0)
end
end
else
car:GetPhysicsObject():SetDamping(0, 0)
end
else
if(v.IsInCruiseControl) then
v:ConCommand("-forward")
v:ConCommand("-back")
v:ConCommand("-jump")
v.IsInCruiseControl = false
end
end
end
end
timer.Create("CruiseControlTimer", 0.075, 0, GM.CruiseControlTimer)[/CODE]
Result in console when adding a bot to the server:
[CODE]Timer 'CruiseControlTimer" Error: [THEPATH/system_vehicle_cruisecontrol.lua:75] attempt to call global "ValidEntity" [a nil value]
1. lua/includes/modules/timer.lua:172 (unknown)
2.[C]:-1 (pcall)
3. lua/includes/modules/hook.lua:80 (unknown)[/CODE]
Thank you in advance
[QUOTE=andre_bule;37937237]Hey guys I had having problems with ValidEntity
Heres the code, I have been playing with this for days but i did not found a solution yet. (FOR GM13)
[CODE]function GM.CruiseControlTimer()
local t = player.GetAll()
for k=1, #t do
local v = t[k]
if(ValidEntity(v:GetVehicle())) then -- <---THIS IS LINE 75!
local car = v:GetVehicle()
if(v:GetVehicle().CruiseControl) then
local iSpeed = car:GetVelocity():Length() / 17.6
local iMaxSpeed = math.abs(car.CruiseControlSpeed)
if(iMaxSpeed > 0) then
if(iSpeed >= iMaxSpeed) then
car:GetPhysicsObject():SetDamping(math.ceil(iSpeed - iMaxSpeed + 4), 0)
else
car:GetPhysicsObject():SetDamping(0, 0)
end
end
else
car:GetPhysicsObject():SetDamping(0, 0)
end
else
if(v.IsInCruiseControl) then
v:ConCommand("-forward")
v:ConCommand("-back")
v:ConCommand("-jump")
v.IsInCruiseControl = false
end
end
end
end
timer.Create("CruiseControlTimer", 0.075, 0, GM.CruiseControlTimer)[/CODE]
Result in console when adding a bot to the server:
[CODE]Timer 'CruiseControlTimer" Error: [THEPATH/system_vehicle_cruisecontrol.lua:75] attempt to call global "ValidEntity" [a nil value]
1. lua/includes/modules/timer.lua:172 (unknown)
2.[C]:-1 (pcall)
3. lua/includes/modules/hook.lua:80 (unknown)[/CODE]
Thank you in advance[/QUOTE]
ValidEntity was removed and replaced with IsValid()
ValidEntity was removed from GMOD13 in update 34
use [url]http://wiki.garrysmod.com/page/Global/IsValid[/url] instead
oh come on, I was 20 seconds late, we posted in the same minute.
Is there any way in LUA to group thousands together using a function of some sort? (Eg. Formatting 1000000 to 1 000 000) like the number_format function in PHP.
Or if not, does anybody reading this have the code to do so?
Thanks
[url]https://github.com/FPtje/DarkRP/blob/master/gamemode/client/hud.lua#L46[/url]
committed that a long time ago, I'm not sure who made it (raBBish?) and there are more efficient ways, but that's what you're after
[QUOTE=Banana Lord.;37938501][url]https://github.com/FPtje/DarkRP/blob/master/gamemode/client/hud.lua#L46[/url]
committed that a long time ago, I'm not sure who made it (raBBish?) and there are more efficient ways, but that's what you're after[/QUOTE]
Exactly what I needed, thanks!
[QUOTE=Banana Lord.;37938501][url]https://github.com/FPtje/DarkRP/blob/master/gamemode/client/hud.lua#L46[/url]
committed that a long time ago, I'm not sure who made it (raBBish?) and there are more efficient ways, but that's what you're after[/QUOTE]
I remember this: [url]http://www.facepunch.com/showthread.php?t=1202167&p=37331620&viewfull=1#post37331620[/url]
:V
(scroll down for comma inserting contest)
How do I make a particle spawn below my playermodel's feet?
If I have panel1 = vgui.Create("DFrame") and then all that other stuff, making it a fully-customized panel with buttons etc., is there any way to clone the panel exactly the way it is without having to copy-paste the code? Like, say, panel2 = panel1:Copy()
I'm trying to return a list of teams in a DListView, how ever I can only manage to return the table of teams in a string. I am only after the teams name, how would I go about doing this?
Current code;
[lua]
dlist = vgui.Create("DListView", dpropertysheet)
dlist:SetPos()
dlist:SetSize()
dlist:SetMultiSelect(false)
dlist:AddColumn("Faction Name")
--dlist:AddColumn("Total Members")
for k,v in pairs(team.GetAllTeams(team.GetName())) do
dlist:AddLine(table.ToString(v))
end
[/lua]
Any help is appreciated.
[QUOTE=NintendoEKS;37941944]I'm trying to return a list of teams in a DListView, how ever I can only manage to return the table of teams in a string. I am only after the teams name, how would I go about doing this?
Current code;
[lua]
dlist = vgui.Create("DListView", dpropertysheet)
dlist:SetPos()
dlist:SetSize()
dlist:SetMultiSelect(false)
dlist:AddColumn("Faction Name")
--dlist:AddColumn("Total Members")
for k,v in pairs(team.GetAllTeams(team.GetName())) do
dlist:AddLine(table.ToString(v))
end
[/lua]
Any help is appreciated.[/QUOTE]
you're using team.GetAllTeams(STRING DUMBASS), just use team.GetAllTeams() and then grab the string
Lets say i have a skybox material. How can i make it black and white, or at the very least, super bright, using Lua?
I'm not too familiar with VMTs, there are lots of things you can set on them... $color doesn't accomplish what i want, or at least not on its own.
I'm guessing SetShader might be what i'm looking for.
Alright I've managed to make a list of teams how ever, I'm using the player.GetAll() method so it's making a repeated list of teams. What 'check' can I run to return false if it already exists?
Current code;
[lua]
dlist = vgui.Create("DListView", dpropertysheet)
dlist:SetPos()
dlist:SetSize()
dlist:SetMultiSelect(false)
dlist:AddColumn("Faction Name")
--dlist:AddColumn("Total Members")
for k,v in pairs(player.GetAll()) do
dlist:AddLine(team.GetName(v:Team()))
end
[/lua]
[QUOTE=NintendoEKS;37944376]Alright I've managed to make a list of teams how ever, I'm using the player.GetAll() method so it's making a repeated list of teams. What 'check' can I run to return false if it already exists?
Current code;
[lua]
dlist = vgui.Create("DListView", dpropertysheet)
dlist:SetPos()
dlist:SetSize()
dlist:SetMultiSelect(false)
dlist:AddColumn("Faction Name")
--dlist:AddColumn("Total Members")
for k,v in pairs(player.GetAll()) do
dlist:AddLine(team.GetName(v:Team()))
end
[/lua][/QUOTE]
there might be a better way of doing this, but it works
[lua]
local teams = {}
for k, ply in pairs(player.GetAll()) do
local teamName = team.GetName(ply:Team())
teams[teamName] = 1 --the value can be anything other than nil, its just the key that matters
end
for teamName, v in pairs(teams) do
dlist:AddLine(teamName)
end
[/lua]
it does mean two loops, though.
Maybe someone can help me out, I'm trying to create a DFrame but it's not working
Warning: vgui.Create failed to create the VGUI component (DFrame)
[lua]
--lua/autorun/client
local DermaPanel = vgui.Create("DFrame")
DermaPanel:SetPos(ScrW / 2, ScrH / 2)
DermaPanel:SetSize(300, 200)
DermaPanel:SetTitle("Test")
DermaPanel:SetVisible(true)
DermaPanel:SetDraggable(true)
DermaPanel:ShowCloseButton(true)
DermaPanel:MakePopup()
[/lua]
DFrame is in [url]http://wiki.garrysmod.com/page/Libraries/vgui/List_of_VGUI_elements[/url] so I don't understand why it failed to create it? I didn't see anything about DFrames in the GMOD13 docs
Edit: Okay, so the old wiki says its "Frame", and it is, which is odd considering the new wiki doesn't mention this. also some functions seem to have been removed.. but anyway, figured it out.
I'm unable to work out how to get a players nickname or steam id from a console command argument.
Here's some context, although this might not be the best way to go about it:
Serverside/init.lua:
[lua]function ProbationAdd(ply, cmd, args)
local probate = args[1]
print("Admin has put " .. probate .. " under probation")
hook.Add("ProbationAdd", "Player Probation", function(ply)
for k,v in pairs(ply:GetAll()) do
--Not sure what to do here. Need to get the players nickname or steamid not as a string.
end
end
end )
end
concommand.Add( "ProbAdd", ProbationAdd, nil, "Player Probation Name Adding")[/lua]
[QUOTE=Zyler;37944953]I'm unable to work out how to get a players nickname or steam id from a console command argument.
Here's some context, although this might not be the best way to go about it:
Serverside/init.lua:
[lua]function ProbationAdd(ply, cmd, args)
local probate = args[1]
print("Admin has put " .. probate .. " under probation")
hook.Add("ProbationAdd", "Player Probation", function(ply)
for k,v in pairs(ply:GetAll()) do
--Not sure what to do here. Need to get the players nickname or steamid not as a string.
end
end
end )
end
concommand.Add( "ProbAdd", ProbationAdd, nil, "Player Probation Name Adding")[/lua][/QUOTE]
player:Nick
player:Steamid - I think
How can I fix this error: [gamemodes/perp3/gamemode/cl_scoreboards.lua:50] attempt to index upvalue 'pScoreBoard' (a nil value)(Hook: ScoreboardShow)
[CODE]include( "scoreboards/scoreboard.lua" )
local pScoreBoard = nil
/*---------------------------------------------------------
Name: gamemode:CreateScoreboard( )
Desc: Creates/Recreates the scoreboard
---------------------------------------------------------*/
function GM:CreateScoreboard()
if ( pScoreBoard ) then
pScoreBoard:Remove()
pScoreBoard = nil
end
pScoreBoard = vgui.Create( "ScoreBoard" )
end
/*---------------------------------------------------------
Name: gamemode:ScoreboardShow( )
Desc: Sets the scoreboard to visible
---------------------------------------------------------*/
function GM:ScoreboardShow()
GAMEMODE.ShowScoreboard = true
gui.EnableScreenClicker( true )
if ( !pScoreBoard ) then
self:CreateScoreboard()
end
pScoreBoard:SetVisible( true ) -- <----- LINE 50
pScoreBoard:UpdateScoreboard( true )
end
/*---------------------------------------------------------
Name: gamemode:ScoreboardHide( )
Desc: Hides the scoreboard
---------------------------------------------------------*/
function GM:ScoreboardHide()
GAMEMODE.ShowScoreboard = false
gui.EnableScreenClicker( false )
if ( pScoreBoard ) then pScoreBoard:SetVisible( false ) end
end
function GM:HUDDrawScoreBoard()
// Do nothing (We're vgui'd up)
end
[/CODE]
Thank you in advance
[QUOTE=andre_bule;37945020]player:Nick
player:Steamid - I think [/QUOTE]
Here's what I've got so far:
[lua]function ProbationAdd(ply, cmd, args)
probate = args[1]
hook.Add("ProbationAdd", "Player Probation", function(ply)
for k,v in pairs(ply:GetAll()) do
if ply:Nick() == probate then
ply:RemoveAllItems()
print("Admin has put " .. probate .. " under probation")
end
end
end )
end
concommand.Add( "ProbAdd", ProbationAdd, nil, "Player Probation Name Adding")[/lua]
Unfortunately it doesn't work and I can't work out how to fix it. Can anyone help with this?
i dont know what you are trying to accomplish my making a hook inside a function, but there is a much better way to do this.
give me a minute to write the code up
[editline]7th October 2012[/editline]
[lua]
function ProbationAdd(ply, cmd, args)
if (!args[1] || args[1]:Trim() == "") then
// we didnt even type an argument
return;
end
// trim and lower the arg!
local probate = args[1]:Trim():lower();
// GetHumans will return only players, if you want bots change to GetAll
for _, p in pairs(player.GetHumans()) do
// trim and lower the name because we trimmed the arg, and throw in steamid support :D
if (p:Nick():Trim():lower() == probate || p:SteamID():lower()) then // steamids contain no white space so no need to trim
// ply is the player calling the console command
// p is the player we have chosen
p:RemoveAllItems()
print(ply:GetName() .. " has put " .. p:GetName() .. " under probation");
end
end
end
concommand.Add( "ProbAdd", ProbationAdd, nil, "Player Probation Name Adding")
[/lua]
guys i need help my error is: ERROR: GAMEMODE:'PlayerSetModel' Failed: [gamemodes\darkrpsvn\gamemode\sv_gamemode_functions.lua:415] attempt to index local 'TEAM' (a nil value)
and here is my code for the line 415: [QUOTE]if type(TEAM.model) == "table" then
local ChosenModel = ply.rpChosenModel or ply:GetInfo("rp_playermodel")
ChosenModel = string.lower(ChosenModel)
local found
for _,Models in pairs(TEAM.model) do
if ChosenModel == string.lower(Models) then
EndModel = Models
found = true
break
end
end[/QUOTE]
what is TEAM?
what do you think
[editline]7th October 2012[/editline]
e.g. TEAM_GUN
How can I fix this error: [gamemodes/perp3/gamemode/cl_scoreboards.lua:50] attempt to index upvalue 'pScoreBoard' (a nil value)(Hook: ScoreboardShow)
[CODE]include( "scoreboards/scoreboard.lua" )
local pScoreBoard = nil
/*---------------------------------------------------------
Name: gamemode:CreateScoreboard( )
Desc: Creates/Recreates the scoreboard
---------------------------------------------------------*/
function GM:CreateScoreboard()
if ( pScoreBoard ) then
pScoreBoard:Remove()
pScoreBoard = nil
end
pScoreBoard = vgui.Create( "ScoreBoard" )
end
/*---------------------------------------------------------
Name: gamemode:ScoreboardShow( )
Desc: Sets the scoreboard to visible
---------------------------------------------------------*/
function GM:ScoreboardShow()
GAMEMODE.ShowScoreboard = true
gui.EnableScreenClicker( true )
if ( !pScoreBoard ) then
self:CreateScoreboard()
end
pScoreBoard:SetVisible( true ) -- <----- LINE 50
pScoreBoard:UpdateScoreboard( true )
end
/*---------------------------------------------------------
Name: gamemode:ScoreboardHide( )
Desc: Hides the scoreboard
---------------------------------------------------------*/
function GM:ScoreboardHide()
GAMEMODE.ShowScoreboard = false
gui.EnableScreenClicker( false )
if ( pScoreBoard ) then pScoreBoard:SetVisible( false ) end
end
function GM:HUDDrawScoreBoard()
// Do nothing (We're vgui'd up)
end[/CODE]
Thank you in advance
it is a nil value but where is set TEAM
[editline]7th October 2012[/editline]
[QUOTE=thejjokerr;37945627]I bet you it's a nil value
[editline]7th October 2012[/editline]
Show the part where you set TEAM[/QUOTE]
yes its a nil value but what u mean show were i set TEAM say like shared.lua or something
Okay, started coding a little something in GM13 and stumbled across this weird error (and I could bet this question was asked thousands of times already, but I'm too lazy to look for a solution myself):
[gamemodes/mos/gamemode/shared.lua:9] chunk has too many syntax levels
[gamemodes/mos/gamemode/cl_stats.lua:14] chunk has too many syntax levels
[gamemodes/mos/gamemode/cl_stats.lua:20] chunk has too many syntax levels
This is my shared.lua:
[lua]MOS = GM
for k, v in pairs(file.Find("mos/gamemode/*", "LUA")) do
local prefix = string.sub(v, 1, 3)
if prefix == "sh_" then
if SERVER then
AddCSLuaFile(v)
include(v)
else
include(v)
end
elseif prefix == "cl_" then
if SERVER then
AddCSLuaFile(v)
else
include(v)
end
elseif prefix == "sv_" then
if SERVER then
include(v)
end
end
end[/lua]
And this is my cl_stats.lua:
[lua]MOS.hunger = 0
MOS.thirst = 0
MOS.stamina = 100
MOS.fatigue = 0
net.Receive("mosStatsUpdate", function()
MOS.hunger = net.ReadFloat()
MOS.thirst = net.ReadFloat()
MOS.stamina = net.ReadFloat()
MOS.fatigue = net.ReadFloat()
end)
hook.Add("HUDPaint", "StatsDebug", function()
local x = ScrW()/12
local y = ScrH()/12
surface.SetFont("DefaultSmall")
local _, h = surface.GetTextSize("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
draw.DrawText("hunger: " .. string.sub(tostring(MOS.hunger), 1, 4), DefaultSmall, x, y, Color(255, 255, 255), 0)
draw.DrawText("thirst: " .. string.sub(tostring(MOS.thirst), 1, 4), DefaultSmall, x, y+h, Color(255, 255, 255), 0)
draw.DrawText("stamina: " .. string.sub(tostring(MOS.stamina), 1, 4), DefaultSmall, x, y+2*h, Color(255, 255, 255), 0)
draw.DrawText("fatigue: " .. string.sub(tostring(MOS.fatigue), 1, 4), DefaultSmall, x, y+3*h, Color(255, 255, 255), 0)
end)[/lua]
It doesn't halt the execution of the script, nor does it interfere with the script in any other way. But it makes me confused, since from the first glance everything looks fine, at least to me, and I've never come across this error in GM12.
i googled "lua chunk has too many syntax levels"
this is the first link
[url]http://facepunch.com/showthread.php?t=1080557[/url]
helps to look around first
I remember a while back I could use a console command to turn on debugging, and make it so my traces became visible, but I forgot how, and I can't find any info on it. How can I do that?
[B]edit:[/B]
Nevermind, I found it! It was [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2364.html]Debugoverlay[/url] and the console command 'developer'.
[QUOTE=Insomnia Array;37947543]Okay, started coding a little something in GM13 and stumbled across this weird error (and I could bet this question was asked thousands of times already, but I'm too lazy to look for a solution myself):
[gamemodes/mos/gamemode/shared.lua:9] chunk has too many syntax levels
[gamemodes/mos/gamemode/cl_stats.lua:14] chunk has too many syntax levels
[gamemodes/mos/gamemode/cl_stats.lua:20] chunk has too many syntax levels
This is my shared.lua:
[lua]MOS = GM
for k, v in pairs(file.Find("mos/gamemode/*", "LUA")) do
local prefix = string.sub(v, 1, 3)
if prefix == "sh_" then
if SERVER then
AddCSLuaFile(v)
include(v)
else
include(v)
end
elseif prefix == "cl_" then
if SERVER then
AddCSLuaFile(v)
else
include(v)
end
elseif prefix == "sv_" then
if SERVER then
include(v)
end
end
end[/lua]
And this is my cl_stats.lua:
[lua]MOS.hunger = 0
MOS.thirst = 0
MOS.stamina = 100
MOS.fatigue = 0
net.Receive("mosStatsUpdate", function()
MOS.hunger = net.ReadFloat()
MOS.thirst = net.ReadFloat()
MOS.stamina = net.ReadFloat()
MOS.fatigue = net.ReadFloat()
end)
hook.Add("HUDPaint", "StatsDebug", function()
local x = ScrW()/12
local y = ScrH()/12
surface.SetFont("DefaultSmall")
local _, h = surface.GetTextSize("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
draw.DrawText("hunger: " .. string.sub(tostring(MOS.hunger), 1, 4), DefaultSmall, x, y, Color(255, 255, 255), 0)
draw.DrawText("thirst: " .. string.sub(tostring(MOS.thirst), 1, 4), DefaultSmall, x, y+h, Color(255, 255, 255), 0)
draw.DrawText("stamina: " .. string.sub(tostring(MOS.stamina), 1, 4), DefaultSmall, x, y+2*h, Color(255, 255, 255), 0)
draw.DrawText("fatigue: " .. string.sub(tostring(MOS.fatigue), 1, 4), DefaultSmall, x, y+3*h, Color(255, 255, 255), 0)
end)[/lua]
It doesn't halt the execution of the script, nor does it interfere with the script in any other way. But it makes me confused, since from the first glance everything looks fine, at least to me, and I've never come across this error in GM12.[/QUOTE]
You're including already included files.
[QUOTE=G4MB!T;37947788]i googled "lua chunk has too many syntax levels"
this is the first link
[url]http://facepunch.com/showthread.php?t=1080557[/url]
helps to look around first[/QUOTE]
From my previous experience googling lua errors never yielded proper results. My bad.
But hey, isn't this the thread to ask stupid irrelevant questions in?
[QUOTE=skullorz;37947975]You're including already included files.[/QUOTE]
Thanks.
edit:
There should be a 'lazy' rating.
HEY CAN YOU HELP ME WITH MY ERROR: GAMEMODE:'PlayerSetModel' Failed: [gamemodes\darkrpsvn\gamemode\sv_gamemode_functions .lua:415] attempt to index local 'TEAM' (a nil value)
and here is my code for the line 415:
if type(TEAM.model) == "table" then
local ChosenModel = ply.rpChosenModel or ply:GetInfo("rp_playermodel")
ChosenModel = string.lower(ChosenModel)
local found
for _,Models in pairs(TEAM.model) do
if ChosenModel == string.lower(Models) then
EndModel = Models
found = true
break
end
end
[editline]7th October 2012[/editline]
[QUOTE=Insomnia Array;37948111]From my previous experience googling lua errors never yielded proper results. My bad.
But hey, isn't this the thread to ask stupid irrelevant questions in?
Thanks.
edit:
There should be a 'lazy' rating.[/QUOTE]
HEY CAN YOU HELP ME WITH MY ERROR: GAMEMODE:'PlayerSetModel' Failed: [gamemodes\darkrpsvn\gamemode\sv_gamemode_functions .lua:415] attempt to index local 'TEAM' (a nil value)
and here is my code for the line 415:
if type(TEAM.model) == "table" then
local ChosenModel = ply.rpChosenModel or ply:GetInfo("rp_playermodel")
ChosenModel = string.lower(ChosenModel)
local found
for _,Models in pairs(TEAM.model) do
if ChosenModel == string.lower(Models) then
EndModel = Models
found = true
break
end
end
Hey did garry changed something with SetVisible and IsVisible? because I am getting an error with this:
[gamemodes/somegamemode/gamemode/cl_networking.lua:191] attempt to index field 'InventoryPanel' (a nil value)
1. gamemodes/somegamemode/gamemode/cl_networking.lua:191 (Function)
2. lua/includes/modules/usermessage.lua:87 (unknown)
Sorry, you need to Log In to post a reply to this thread.