actually ye that might be the cause
[lua]
local function ToggleMenu()
if (FrameOpen) then
gui.EnableScreenClicker(false)
Frame:SetVisible(false)
FrameOpen = false;
else
gui.EnableScreenClicker(true)
Frame:SetVisible(true)
FrameOpen = true;
end
[/lua]
Okay, thank you, it worked.
[QUOTE=Azaz3l;38274627]Okay, thank you, it worked.[/QUOTE]
I know you fixed it, but it'd probably be better to use Panel:GetVisible().
[b]Edit:[/b] Sorry, Panel:IsVisible(). *mutter*
//delete
im trying to count the time a player takes from spawning to press a button (or touch a trigger, whichever easier)
im not actually trying the code, just seeing if my idea for what im doing would work if i made it correctly
please help me understand how to do / a better way of approaching this? thanks
[lua]
function GM:PlayerSpawn( pl )
pl:timer = realtime()
// how do i get the value of this without it updating when called (and make it per player) (is this the best way to count time?)
end
function ENT:Use( activator, caller )
finaltime = realtime() - pl:timer
// im trying to take away the saved realtime value from the current realtime value to give the number of seconds it took to press the button
print (math.floor(finaltime * 10 + 0.5) / 10)
//im guessing that this would display it as xx.x
end
[/lua]
as you can see i have no idea what i am doing
[QUOTE=Kwaq;38275496]im trying to count the time a player takes from spawning to press a button (or touch a trigger, whichever easier)
im not actually trying the code, just seeing if my idea for what im doing would work if i made it correctly
please help me understand how to do / a better way of approaching this? thanks
[lua]
function GM:PlayerSpawn( pl )
pl:timer = realtime()
// how do i get the value of this without it updating when called (and make it per player) (is this the best way to count time?)
end
function ENT:Use( activator, caller )
finaltime = realtime() - pl:timer
// im trying to take away the saved realtime value from the current realtime value to give the number of seconds it took to press the button
print (math.floor(finaltime * 10 + 0.5) / 10)
//im guessing that this would display it as xx.x
end
[/lua]
as you can see i have no idea what i am doing[/QUOTE]
Using PlayerSpawn is fine, but if you want to reference a variable on an object use a period, not a colon. Colons are exclusively for object method calls, like "ply:Give()" or "ent:Remove()", where the method implicitly receives the object as the variable "self".
[lua]
local ply = player.GetByID(1)
ply.Function = function(text)
return "foo-" .. text
end
ply.Variable = "bar"
print(ply.Function(ply.Variable))
-- prints "foo-bar"[/lua]
Second, ENT:Use() receives as its first argument the player who used it ("caller" in your code). Using "pl", in that context, won't do anything, because "pl" is a local variable inside GM:PlayerSpawn() referring to the player who's spawning.
Try something like this instead:
[lua]
-- in gamemode/player_hooks.lua, or whatever you want to call it
function GM:PlayerSpawn(ply)
ply.StartTime = CurTime() -- note that variables are case-sensitive; CurTime() =/= curtime()
end
-- in entities/<ENT NAME HERE>/init.lua
function ENT:Use(activator, caller)
-- make sure it's a player and that SpawnTime is set
-- can't remember off the top of my head if non-players can use other entities
if activator:IsPlayer() and activator.SpawnTime then
activator.FinishTime = CurTime()
MsgN("Time taken for " .. activator:Nick() .. ": " .. (activator.FinishTime - activator.StartTime) .. " seconds.")
end
end
[/lua]
is there a command to spawn weapons for testing in TTT?
sv_cheats 1 then just use give
So, with the new setup for timer.simple, anyone mind explaining to me what the inclusion of "function()" does?
As it has been explained to me, but by someone who was making a guess, it specifies that the user defined function included is a function.
Scratch that, I know now, it's for declaring a new function within the timer.
[QUOTE=Jeffman12;38278524]So, with the new setup for timer.simple, anyone mind explaining to me what the inclusion of "function()" does?
As it has been explained to me, but by someone who was making a guess, it specifies that the user defined function included is a function.[/QUOTE]
function() isn't anything new, it's always been there. I think Garry just took out the option to throw in a custom function name with it's arguments and have the game find/run it. All function() end is doing is creating the function on hand. Someone else can probably explain it better but it acts just like how all there other functions do.
[lua]
concommand.add( "MyCommand", function( pl, cmd, arg )
print("Hi")
end)
hook.Add( "Think", function()
print("I can think!")
end)
usermessage.Hook( "SentToClient", function()
print("Hi Client.")
end)
timer.Simple( "MyTimer, 5, 0, function()
print("It's been 5 seconds!")
end)
[/lua]
[QUOTE=find me;38278704]function() isn't anything new, it's always been there. I think Garry just took out the option to throw in a custom function name with it's arguments and have the game find/run it. All function() end is doing is creating the function on hand. Someone else can probably explain it better but it acts just like how all there other functions do.
[lua]
concommand.add( "MyCommand", function( pl, cmd, arg )
print("Hi")
end)
hook.Add( "Think", function()
print("I can think!")
end)
usermessage.Hook( "SentToClient", function()
print("Hi Client.")
end)
timer.Simple( "MyTimer, 5, 0, function()
print("It's been 5 seconds!")
end)
[/lua][/QUOTE]
I guess what I should ask is if it's even necessary if you already have the custom function declared elsewhere. From what I can tell it's just there to allow you to create a local function if that happens to be more convenient, right? If not, I still don't understand how timer.Simple works.
[QUOTE=Jeffman12;38281002]I guess what I should ask is if it's even necessary if you already have the custom function declared elsewhere. From what I can tell it's just there to allow you to create a local function if that happens to be more convenient, right? If not, I still don't understand how timer.Simple works.[/QUOTE]
If the function is defined elsewhere you can make timer.Simple call it [b]with no arguments[/b] by passing the variable that represents it
[lua]
function myfunc()
print( "myfunc running" )
end
timer.Simple( 10, myfunc )
[/lua]
Hey guys, I'm trying to create a ULX Redeem script for Zombie Survival.
The code bellow is the redeem script from ZS (AFAIK)
[CODE]function GM:PlayerRedeemed(pl, silent, noequip)
if not silent then
umsg.Start("PlayerRedeemed")
umsg.Entity(pl)
umsg.End()
end
pl:RemoveStatus("overridemodel", false, true)
pl:ChangeTeam(TEAM_HUMAN)
pl:DoHulls()
if not noequip then pl.m_PreRedeem = true end
pl:UnSpectateAndSpawn()
pl.m_PreRedeem = nil
local frags = pl:Frags()
if frags < 0 then
pl:SetFrags(frags * 5)
else
pl:SetFrags(0)
end
pl:SetDeaths(0)
pl.DeathClass = nil
pl:SetZombieClass(self.DefaultZombieClass)
pl.SpawnedTime = CurTime()
end
Concommand.Add( "Redeem", PlayerRedeemed ) ---- I added this!
[/CODE]
Now this is the ULX addon i tried to use
[CODE]function ulx.slay( calling_ply, target_plys )
local affected_plys = {}
for i=1, #target_plys do
local v = target_plys[ i ]
if ulx.getExclusive( v, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
else
v:Redeem() -------------------------------- Problem is here!
table.insert( affected_plys, v )
end
end
ulx.fancyLogAdmin( calling_ply, "#A redeemed #T", affected_plys )
end
local redeem = ulx.command( CATEGORY_NAME, "ulx redeem", redeem, "!redeem" )
slay:addParam{ type=ULib.cmds.PlayersArg }
slay:defaultAccess( ULib.ACCESS_ADMIN )
slay:help( "Redeem target(s)." )[/CODE]
Obviously i need to give arguments as to what player i want to redeem but how do i go about doing so?
Hi,
I recently started lua coding with Gmod and was wondering if anyone could spare the time to explain how the self:DrawEntityOutline(1.0) method for entities works. Essentially I wanted to draw the outline when the player was looking at the entity. Here is my code so far:
cl_init.lua:
[CODE]include('shared.lua')
function ENT:Draw()
self:DrawModel()
self:DrawEntityOutline(1.0)
end[/CODE]
init.lua:
[CODE]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel( "models/Items/HealthKit.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
local phys = self.Entity:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
end
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local ent = ents.Create( "sent_health" )
ent:SetPos( tr.HitPos + tr.HitNormal * 16 )
ent:Spawn()
ent:Activate()
return ent
end
function ENT:Use( activator, caller )
self:Remove()
if ( activator:IsPlayer() ) then
local health = activator:Health()
activator:SetHealth( health + 20 )
end
end[/CODE]
shared.lua
[CODE]ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Health Kit"
ENT.Contact = "N/A"
ENT.Purpose = "Health kit to heal the player"
ENT.Instructions = "Heals the users health by 5 points"
ENT.Category = "Test Entity"
ENT.Spawnable = true
ENT.AdminSpawnable = true[/CODE]
The error occurs at the self:DrawEntityOutline(1.0) line in cl_init.lua
Error:
[CODE]
[ERROR] addons/joemod/lua/entities/sent_health/cl_init.lua:5: attempt to call method 'DrawEntityOutline' (a nil value)
1. unknown - addons/joemod/lua/entities/sent_health/cl_init.lua:5
[/CODE]
I used this tutorial to help with with my entity:
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexf251.html[/url]
If anyone could explain to me where I am going wrong and how to correct the issue it would be greatly appreciated
[url]http://www.garrysmod.org/downloads/?a=view&id=126346[/url]
Can someone help port it over to Garry's Mod 13 please? I could really use some help...
[QUOTE=Drakehawke;38281034]If the function is defined elsewhere you can make timer.Simple call it [b]with no arguments[/b] by passing the variable that represents it
[lua]
function myfunc()
print( "myfunc running" )
end
timer.Simple( 10, myfunc )
[/lua][/QUOTE]
Maybe this has changed in LuaJIT, but in the performance tests I've seen for Lua, creating a local function before you pass it to another function is [i]dramatically[/i] faster than creating an anonymous one in the function call, i.e. "timer.Simple(10, myfunc)" > "timer.Simple(10, function() --[[ stuff ]] end)".
[IMG]https://dl.dropbox.com/u/30778198/err.png[/IMG]
[code]
[ERROR] gamemode/init.lua:250: calling 'Query' on bad self ((null) expected, got userdata)
1. Query - [C]:-1
2. unknown - gamemodes/flood/gamemode/init.lua:250
[/code]
[lua]db:Query("SELECT * FROM db_table WHERE ID='STEAM_0_1_20914932'", function(tbl, sta, err)
end)[/lua]
After this update I started getting this error, never seen one like this before. The database is connected to and working as I did a check just before the query and it returns true. Update break tmysql4?
Also could anyone tell me what this means or what it was trying to error?
[code][C]:-1[/code]
The last update broke both mysqloo and tmysql4, wait for updates
Does anyone know why was Player.GetScriptedVehicle() removed and what to use now?
does anyone know why does this error popups and how to change it or make it work? "Couldn't include file 'includes\modules\tracex.lua' (File not found) (<nowhere>)"
Can anyone tell me as to why Gamemode names changed ? For example GM.Name = "String Here" no longer works ? Now it's displaying the -gamemode "gamemode" command, for example: Let's say I run a custom gamemode and I named it.. GM.Name = "Tickle My Pickle 1.3.5" and the gamemode.txt is named tickle.txt instead of displaying Tickle My Pickle 1.3.5 it displays tickle
Can anyone tell me why this is happening ? Can't wait to get my gamemodes fixed
Can anyone fix gmsv_teleport made by Spacetech?
[QUOTE=Persious;38292301]Can anyone fix gmsv_teleport made by Spacetech?[/QUOTE]
Link me and if it's not too complicated I'll try
[url]https://code.google.com/p/spacetechmodules/source/browse/#svn%2Ftrunk%2Fgmsv_teleport%253Fstate%253Dclosed[/url]
Thank you for trying! This is the only thing holding me back to start my own server!
I'm brand new to the world of LUA, and GLUA, this is my first project I'm trying to get my feet wet here. I have started to make my first gamemode the first thing I did was when you spawn you get a "pistol" it worked great!
The next step I did was regenerating ammo to players after x amount of time. I tried setting up a timer got some help on these forums, I tried to start up my gamemode and now I spawn with no weapon and get this error in the console:
[code]Couldn't include file 'shared.lua' (File not found) (@gamemodes/warfront/gamemode/cl_init.lua (line 1))[/code]
Here is my source its simple and short, maybe you guys can fill me in on whats going on?
[B]init.lua[/B]
[LUA]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )
// Serverside only stuff goes here
/*---------------------------------------------------------
Name: gamemode:PlayerLoadout( )
Desc: Give the player the default spawning weapons/ammo
---------------------------------------------------------*/
function GM:PlayerInitialSpawn( ply )
ply:SetGravity( 1 )
ply:SetWalkSpeed( 300 )
ply:SetRunSpeed( 500 )
end
function GM:PlayerSpawn ( ply )
ply:Give( "weapon_pistol" )
end
//Resupplying all players provided by: Luni
local function resupplyplayers()
for _, ply in pairs(player.GetHumans()) do
-- make sure he's alive
-- we're not interested in resupplying ghosts
if ply:Alive then
ply:GiveAmmo(60, "Pistol", true) -- feel free to change this value
ply:ChatPrint("Resupplied!")
end
end
timer.Create("Resupply", 60, 0, resupplyplayers)[/LUA]
[B]shared.lua[/B]
[LUA]GM.Name = "Warfront"
GM.Author = "Nazban"
GM.Email = "N/A"
GM.Website = "N/A"
function GM:Initialize()
self.BaseClass.Initialize( self )
end [/LUA]
[B]cl_init.lua[/B]
[LUA]include( 'shared.lua' )
// Clientside only stuff goes here
[/LUA]
Thanks for any help anyone can supply I'm still ridiculously new to all this so I'm sure I won't be a stranger around here in the LUA Scripting section!
[B]Replies:[/B]
[QUOTE=G4MB!T;38292898]try removing this
[lua]
function GM:Initialize()
self.BaseClass.Initialize( self )
end
[/lua][/QUOTE]
I tried this still no cigar,, I have placed the code back into the shared.lua. I'm going to look up some info on local functions.
try removing this
[lua]
function GM:Initialize()
self.BaseClass.Initialize( self )
end
[/lua]
Hiding the base scoreboard worked properly since today, any idea?
I need help with this. I am trying to fix the Parkour 1.5 lua. It is giving this error. And here are the lines:
[ERROR] lua/autorun/parkour_skill.lua:259: attempt to index local 'ply' (a nil value)
1. unknown - lua/autorun/parkour_skill.lua:259
Timer Failed! [Simple][@lua/autorun/parkour_skill.lua (line 258)]
[ERROR] lua/autorun/parkour_skill.lua:271: attempt to index local 'ply' (a nil value)
1. unknown - lua/autorun/parkour_skill.lua:271
Timer Failed! [Simple][@lua/autorun/parkour_skill.lua (line 270)]
function DoRoll( ply, vel )
local weapon = ply:GetActiveWeapon()
ply.lookangle = ply:GetUp() - ply:GetAimVector()
ply.lookingdown = false
if (ply.lookangle.z > 1.7) then
ply.lookingdown = true
end
if ply.lookingdown == true and ply:KeyDown(IN_DUCK) then
if weapon:IsValid() then
if weapon.Primary == nil then
weapon:SendWeaponAnim(ACT_VM_HOLSTER)
local AnimDuration = weapon:SequenceDuration()
local totime = 0
if AnimDuration != nil or AnimDuration > 0.1 then
totime = AnimDuration
end
[B]258: timer.Simple(totime, function(ply)
259: ply:DrawViewModel(false)[/B]
end, ply)
else
ply:DrawViewModel(false)
end
end
ply.Rolling = true
umsg.Start("ParkourRoll", ply)
umsg.End()
timer.Simple(0.6, function(ply)
[B]271: if ply:Alive() then[/B]
if weapon:IsValid() then
if weapon.Primary == nil then
weapon:SendWeaponAnim(ACT_VM_DRAW)
AnimDuration = weapon:SequenceDuration()
if weapon:IsValid() then
weapon:SetNextPrimaryFire(CurTime() + 0.3)
end
ply:DrawViewModel(true)
else
ply:DrawViewModel(true)
weapon:Deploy()
end
end
ply.Rolling = false
end
end, ply)
if vel > 1000 then
return vel / 20
else
return 0
end
end
end
hook.Add( "GetFallDamage", "DoRoll", DoRoll )
If you need the full thing, here is the link. [url]http://www.garrysmod.org/downloads/?a=view&id=126346[/url] Any help will be very thanked.
I can't seem to figure out whats wrong with this printer script, I'm sure you guys can help.
[lua]AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
local PrintMore
function ENT:Initialize()
self:SetModel("models/props_c17/consolebox01a.mdl")
self:SetColor( Color(125,80,30,255) )
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
self.sparking = false
self.damage = 100
self.IsMoneyPrinter = true
timer.Simple(10, self.CreateMoneybag)
self:SetPrice(0)
end
function ENT:OnTakeDamage(dmg)
if self.burningup then return end
self.damage = (self.damage or 100) - dmg:GetDamage()
if self.damage <= 0 then
local rnd = math.random(1, 10)
if rnd < 2 then
self:BurstIntoFlames()
else
self:Destruct()
self:Remove()
end
end
end
function ENT:Destruct()
local vPoint = self:GetPos()
local effectdata = EffectData()
effectdata:SetStart(vPoint)
effectdata:SetOrigin(vPoint)
effectdata:SetScale(1)
util.Effect("Explosion", effectdata)
GAMEMODE:Notify(self.dt.owning_ent, 1, 4, "Your money printer has exploded!")
end
function ENT:BurstIntoFlames()
GAMEMODE:Notify(self.dt.owning_ent, 1, 4, "Your money printer is overheating!")
self.burningup = true
local burntime = math.random(8, 18)
self:Ignite(burntime, 0)
timer.Simple(burntime, self.Fireball)
end
function ENT:Fireball()
if not self:IsOnFire() then self.burningup = false return end
local dist = math.random(20, 280) -- Explosion radius
self:Destruct()
for k, v in pairs(ents.FindInSphere(self:GetPos(), dist)) do
if not v:IsPlayer() and not v:IsWeapon() and v:GetClass() ~= "predicted_viewmodel" and not v.IsMoneyPrinter then
v:Ignite(math.random(5, 22), 0)
elseif v:IsPlayer() then
local distance = v:GetPos():Distance(self:GetPos())
v:TakeDamage(distance / dist * 100, self, self)
end
end
self:Remove()
end
function ENT:Use(activator)
if(activator:IsPlayer()) then
activator:AddMoney(self:GetPrice());
self:SetPrice(0)
end
end
function ENT:CreateMoneybag()
if not IsValid(self) then return end
if self:IsOnFire() then return end
local MoneyPos = self:GetPos()
local X = 22
local Y = 100
// ---Removed Code --- if math.random(1, 22) == 3 then self:BurstIntoFlames() end
//---------- Added code------
local count1 = 0
local mytable = ents.FindInSphere(self:GetPos(),100)
for key,value in ipairs(mytable) do
if string.find(value:GetClass(),"printer_cooler") then
count1 = count1 + 1
end
end
if(count1 >= 1) then
if math.random(1,24) == 3 then self:BurstIntoFlames() end
elseif(count1 == 0) then
if math.random(1,12) == 3 then self:BurstIntoFlames() end
end
//---------------------------
local amount = self:GetPrice() + Y
self:SetPrice(amount)
sound.Play( buttons/button6.wav, MoneyPos, 50, 100, 1)
self.sparking = false
timer.Simple(10, self.PrintMore)
end
function ENT:Think()
//--------------------------Added Code---------------------------------
local count2 = 0
local mytable = ents.FindInSphere(self:GetPos(),100)
for key,value in ipairs(mytable) do
if string.find(value:GetClass(),"printer_cooler") then
count2 = count2 + 1
end
end
if( count2 >= 1) then
self:SetIsCooling(true)
elseif( count2 == 0) then
self:SetIsCooling(false)
end
//-----------------------------------------------------------------------
if not self.sparking then return end
local effectdata = EffectData()
effectdata:SetOrigin(self:GetPos())
effectdata:SetMagnitude(1)
effectdata:SetScale(1)
effectdata:SetRadius(2)
util.Effect("Sparks", effectdata)
end[/lua]
[QUOTE=Halokiller38;38296880]I need help with this. I am trying to fix the Parkour 1.5 lua. It is giving this error. And here are the lines:
[ERROR] lua/autorun/parkour_skill.lua:259: attempt to index local 'ply' (a nil value)
1. unknown - lua/autorun/parkour_skill.lua:259
Timer Failed! [Simple][@lua/autorun/parkour_skill.lua (line 258)]
[ERROR] lua/autorun/parkour_skill.lua:271: attempt to index local 'ply' (a nil value)
1. unknown - lua/autorun/parkour_skill.lua:271
Timer Failed! [Simple][@lua/autorun/parkour_skill.lua (line 270)]
function DoRoll( ply, vel )
local weapon = ply:GetActiveWeapon()
ply.lookangle = ply:GetUp() - ply:GetAimVector()
ply.lookingdown = false
if (ply.lookangle.z > 1.7) then
ply.lookingdown = true
end
if ply.lookingdown == true and ply:KeyDown(IN_DUCK) then
if weapon:IsValid() then
if weapon.Primary == nil then
weapon:SendWeaponAnim(ACT_VM_HOLSTER)
local AnimDuration = weapon:SequenceDuration()
local totime = 0
if AnimDuration != nil or AnimDuration > 0.1 then
totime = AnimDuration
end
[B]258: timer.Simple(totime, function(ply)
259: ply:DrawViewModel(false)[/B]
end, ply)
else
ply:DrawViewModel(false)
end
end
ply.Rolling = true
umsg.Start("ParkourRoll", ply)
umsg.End()
timer.Simple(0.6, function(ply)
[B]271: if ply:Alive() then[/B]
if weapon:IsValid() then
if weapon.Primary == nil then
weapon:SendWeaponAnim(ACT_VM_DRAW)
AnimDuration = weapon:SequenceDuration()
if weapon:IsValid() then
weapon:SetNextPrimaryFire(CurTime() + 0.3)
end
ply:DrawViewModel(true)
else
ply:DrawViewModel(true)
weapon:Deploy()
end
end
ply.Rolling = false
end
end, ply)
if vel > 1000 then
return vel / 20
else
return 0
end
end
end
hook.Add( "GetFallDamage", "DoRoll", DoRoll )
If you need the full thing, here is the link. [url]http://www.garrysmod.org/downloads/?a=view&id=126346[/url] Any help will be very thanked.[/QUOTE]
you can't pass function() in timer ply anymore, remove it and it should work, but its gunna be a hard conversion for you if you don't understand some lua
Sorry, you need to Log In to post a reply to this thread.