Alright, i'm trying to do a super simple script to set a target on fire if it's not on fire, and extinguish it if it is on fire, nothing spectacular, however i'm getting syntax errors and i'd appreciate it if someone could help me determine exactly what i'm doing wrong here.
[code]lua_run if (target:IsOnFire()) then (Ignite()) else (Extinguish()) end[/code]
This is the error if you need it.
[code][ERROR] lua_run:1: syntax error near 'else'
1. unknown - lua_run:0
[/code]
[QUOTE=elowin;39573072]Alright, i'm trying to do a super simple script to set a target on fire if it's not on fire, and extinguish it if it is on fire, nothing spectacular, however i'm getting syntax errors and i'd appreciate it if someone could help me determine exactly what i'm doing wrong here.
[code]lua_run if (target:IsOnFire()) then (Ignite()) else (Extinguish()) end[/code]
This is the error if you need it.
[code][ERROR] lua_run:1: syntax error near 'else'
1. unknown - lua_run:0
[/code][/QUOTE]
[lua]
lua_run if (target:IsOnFire()) then (target:Ignite(10,0)) else (target:Extinguish()) end
[/lua]
Also make sure you define what target is before hand, ie
[lua]
local target -- equal this to some entity
if (target:IsOnFire()) then
(target:Ignite(10,0))
else
(target:Extinguish())
end
[/lua]
[QUOTE=theVendetta;39573187][lua]
lua_run if (target:IsOnFire()) then (target:Ignite(10,0)) else (target:Extinguish()) end
[/lua]
Also make sure you define what target is before hand, ie
[lua]
local target -- equal this to some entity
if (target:IsOnFire()) then
(target:Ignite(10,0))
else
(target:Extinguish())
end
[/lua][/QUOTE]
Thanks, can't believe I forgot to tell it what to put on fire/extinguish.
I'm still getting the same error though.
And yeah, I already defined what the target is.
[QUOTE=Alex_Lee;39572708]I made my MW2 ACR Swep using Mad Cows weapon base and there are no error with codes. but sounds are missing....
These are the damn part bugging me.[/QUOTE]
Try making sounds by using [URL="http://wiki.garrysmod.com/page/Libraries/sound/Add"]sound.Add[/URL]
If your ACR came with a soundscript you can copy that and be pretty much done, just change the "wave" index to "sound"
How do I make my SWEP work in SinglePlayer? it works ONLY in multiplayer..
Things Not Working::
[CODE] if ( CLIENT ) then
chat.AddText( Color( 255,0,0 ), ply, "Text" )
end
if ( CLIENT ) then
surface.SetFont( "ProduceSupport" )
surface.SetTextPos( ScrW() /2 - 190, ScrH() -140 )
surface.SetTextColor( 255, 255, 255 )
surface.DrawText( "Text" )
end
timer.Simple( 0.16, function() hook.Add("HUDPaint", "ProduceSupportFunc", ProduceSupportFunc ) end )[/CODE]
[QUOTE=monadko;39574043]How do I make my SWEP work in SinglePlayer? it works ONLY in multiplayer..
Things Not Working::
[CODE] if ( CLIENT ) then
chat.AddText( Color( 255,0,0 ), ply, "Text" )
end
if ( CLIENT ) then
surface.SetFont( "ProduceSupport" )
surface.SetTextPos( ScrW() /2 - 190, ScrH() -140 )
surface.SetTextColor( 255, 255, 255 )
surface.DrawText( "Text" )
end
timer.Simple( 0.16, function() hook.Add("HUDPaint", "ProduceSupportFunc", ProduceSupportFunc ) end )[/CODE][/QUOTE]
I'm no expert and I have no idea why it only works in multiplayer, but to me it's pretty strange that you've done "if client" twice, instead of just adding all the functions under the same header.
Maybe i'm missing something though.
[QUOTE=elowin;39574176]I'm no expert and I have no idea why it only works in multiplayer, but to me it's pretty strange that you've done "if client" twice, instead of just adding all the functions under the same header.
Maybe i'm missing something though.[/QUOTE]
Actually, first "if CLIENT" one is [CODE]function SWEP:Deploy()
if ( CLIENT ) then
chat.AddText( Color( 255,0,0 ), ply, "Text" )
end
end[/CODE] and the next "if CLIENT" one is [CODE]function SWEP:PrimaryAttack()
function ProduceSupportFunc()
if ( CLIENT ) then
surface.SetFont( "ProduceSupport" )
surface.SetTextPos( ScrW() /2 - 190, ScrH() -140 )
surface.SetTextColor( 255, 255, 255 )
surface.DrawText( "Text" )
end
end
...
timer.Simple( 0.16, function() hook.Add("HUDPaint", "ProduceSupportFunc", ProduceSupportFunc ) end )
timer.Simple( 1.36, function() hook.Remove("HUDPaint", "ProduceSupportFunc" ) end )
end[/CODE]
umm.. do you get it?
[QUOTE=monadko;39574252]
-Snip-
umm.. do you get it?[/QUOTE]
You don't need two same ifs .. its like asking for your friends name twice.
and I think you need "return true" inside "SWEP:Deploy()" and a bit cleaner version:
[lua]
if CLIENT then
function ProduceSupportFunc()
surface.SetFont( "ProduceSupport" )
surface.SetTextPos( ScrW() /2 - 190, ScrH() -140 )
surface.SetTextColor( 255, 255, 255 )
surface.DrawText( "Text" )
end
end
function SWEP:PrimaryAttack()
if CLIENT then
timer.Simple( 0.16, function() hook.Add("HUDPaint", "ProduceSupportFunc", ProduceSupportFunc ) end )
timer.Simple( 1.36, function() hook.Remove("HUDPaint", "ProduceSupportFunc" ) end )
end
end
[/lua]
Note: don't hook HUDPaint on the serverside.
I need to run +attack2 command, but it won't work wit ConCommand nor RunConsoleCommand.
How can I emulate that ?
[QUOTE=Netheous;39575143]I need to run +attack2 command, but it won't work wit ConCommand nor RunConsoleCommand.
How can I emulate that ?[/QUOTE]
RunConsoleCommand("+attack2") should work.
.. are you sure you did RunConsoleCommand("-attack2") to reset it after?
Some of the errors I get from [url]http://errors.garrysmod.com[/url] doesn't make any sense to me.
Maybe I just don't understand why they happen or maybe the client broke GMod by themselves.
I'm not sure.
Here is one example.
"lua/autorun/client/scarracemessages.lua:45: attempt to call method 'Alive' (a nil value)"
And here is line.
[lua]
if !LocalPlayer():Alive() then return end
[/lua]
LocalPlayer is a player. All players should have the Alive() function. The alive function is shared
so it shouldn't matter if it's called on server or client. The code is running on the client in a HUDPaint hook
so I don't see how the function could run with no proper player. This error is fairly common as well.
The only source of the problem I can imagine is something like this.
Evil coder:
[lua]
LocalPlayer().Alive = nil --Durrr
[/lua]
What could be the issue? Why is the Alive() function missing? Hard to tell in my opinion.
[QUOTE=Sakarias88;39577059]Some of the errors I get from [url]http://errors.garrysmod.com[/url] doesn't make any sense to me.
Maybe I just don't understand why they happen or maybe the client broke GMod by themselves.
I'm not sure.
Here is one example.
"lua/autorun/client/scarracemessages.lua:45: attempt to call method 'Alive' (a nil value)"
And here is line.
[lua]
if !LocalPlayer():Alive() then return end
[/lua]
LocalPlayer is a player. All players should have the Alive() function. The alive function is shared
so it shouldn't matter if it's called on server or client. The code is running on the client in a HUDPaint hook
so I don't see how the function could run with no proper player. This error is fairly common as well.
The only source of the problem I can imagine is something like this.
Evil coder:
[lua]
LocalPlayer().Alive = nil --Durrr
[/lua]
What could be the issue? Why is the Alive() function missing? Hard to tell in my opinion.[/QUOTE]
There's a few seconds sometimes when joining servers when LocalPlayer is nil. Not sure why. It could be related to that.
[QUOTE=Sakarias88;39577059]Some of the errors I get from [url]http://errors.garrysmod.com[/url] doesn't make any sense to me.
Maybe I just don't understand why they happen or maybe the client broke GMod by themselves.
I'm not sure.
Here is one example.
"lua/autorun/client/scarracemessages.lua:45: attempt to call method 'Alive' (a nil value)"
And here is line.
[lua]
if !LocalPlayer():Alive() then return end
[/lua]
LocalPlayer is a player. All players should have the Alive() function. The alive function is shared
so it shouldn't matter if it's called on server or client. The code is running on the client in a HUDPaint hook
so I don't see how the function could run with no proper player. This error is fairly common as well.
The only source of the problem I can imagine is something like this.
Evil coder:
[lua]
LocalPlayer().Alive = nil --Durrr
[/lua]
What could be the issue? Why is the Alive() function missing? Hard to tell in my opinion.[/QUOTE]
I caused ULX to throw a fit. The autocomplete code assumes that it's single player, but I managed to get the single player server running without being connected to it :v:
So im i made a small map with hammer where i made an entity and renamed it to "test_repeonkana_spawn" ( insidejk) and then i created team.SetSpawnPoint( 1, "test_repeonkana_spawn" ) in my "gamemodes" shared.lua. I didnt have time to test it cuz i ran out of time and now its 2.45 at night here in Finland and i cant get sleep since im thinking it someone tell me does it work or em i even close
[B]shut up this post wast made with great coverup story to cheat u how newb im![/B]
[QUOTE=Nak;39576314]RunConsoleCommand("+attack2") should work.
.. are you sure you did RunConsoleCommand("-attack2") to reset it after?[/QUOTE]
You know, if +attack2 worked I would totaly do -attack2 afterwards -.-
Can someone who actually knows the issue reply ?
I do:
[lua]LocalPlayer():ConCommand("+attack2")
RunConsoleCommand("+attack2")[/lua] Neither of these work, but....
[lua]LocalPlayer():ConCommand( "use weapon_real_cs_knife")[/lua] works just fine
[QUOTE=Monttumopo;39580831]So im i made a small map with hammer where i made an entity and renamed it to "test_repeonkana_spawn" ( insidejk) and then i created team.SetSpawnPoint( 1, "test_repeonkana_spawn" ) in my "gamemodes" shared.lua. I didnt have time to test it cuz i ran out of time and now its 2.45 at night here in Finland and i cant get sleep since im thinking it someone tell me does it work or em i even close
[/QUOTE]
I think that should work as long as team.SetSpawnPoint() is allowed to use any entity and I'd believe it does.
Is there a simple way to change the owner of an entity in DarkRP? I'm wanting to make it so that when someone activates a printer, they own it and if the original owner disconnects, it won't be removed.
Current code:
[CODE]
if activator != self.dt.owning_ent then
GAMEMODE:Notify(self.dt.owning_ent, 1, 4, "Someone now owns your money printer!")
self:UnOwn(self.dt.owning_ent)
self.dt.owning_ent = activator
self:Own(self.dt.owning_ent)
GAMEMODE:Notify(self.dt.owning_ent, 0, 4, "You now own this printer!")
end[/CODE]
Did Garry decide to get creative with the wiki again...
[thumb]http://puu.sh/22hwS[/thumb]
...and then get mad at the working themes?
[IMG]http://puu.sh/22hxN[/IMG]
How can I add music at the start of every round?
I've tried searching and I can't seem to find it.
-fixed-
[QUOTE=Science;39585064]Why do my entities not spawn...
This gets printed in console:
[code]Entity [918][atm]
Entity [919][atm]
Entity [920][atm]
Entity [921][atm][/code]
This is the code:
[lua]hook.Add("InitPostEntity", "Do", function()
local map = game.GetMap()
if !bank.Maps[map] then return end
for k,v in pairs(bank.Maps[map]) do
local ent = ents.Create("ATM")
ent:Spawn()
ent:SetPos(v[1] or Vector(0,0,0))
ent:SetAngles(v[2] or Angle(0,0,0))
print(ent)
end
end)[/lua]
And yet nothing apears on the map.[/QUOTE]
Are you sure your entities are drawing in the cl_init file?
[QUOTE=soupface;39585032]How can I add music at the start of every round?
I've tried searching and I can't seem to find it.[/QUOTE]
[URL="http://wiki.garrysmod.com/page/Libraries/sound/Play"]Sound.Play()[/URL]
Does anybody else crash with "Engine error: GetTable - not a table!" sometimes or is it just me?
[QUOTE=Loures;39585468]Does anybody else crash with "Engine error: GetTable - not a table!" sometimes or is it just me?[/QUOTE]
I had the same problem sometimes.
What is wrong with this script? My entity is creating errors because of the istrigger part. I get the following error:
[ERROR] lua/entities/tf2_syringe/init.lua:65: attempt to call method 'IsTrigger' (a nil value)
1. unknown - lua/entities/tf2_syringe/init.lua:65
Here is my code:
[code]
function ENT:Touch( ent )
if not ent:IsTrigger() then
if ent:IsNPC() or ent:IsPlayer() then
ent:TakeDamage(math.random(8,12), self.Owner, self)
ETC...
[/code]
thanks!
What would be the equivilent of DNumSlider in Gmod13?
All i can seem to use is DSlider which to be honest, is plain awful.
I've been faffing about with DTVars a bit recently, and I decided to try making a simple script to make a DTVar with a boolean value alternate between it's false and true values every time I fire the SWEP it's embedded in, and I attached a print function to to return "yes" every time the value switches to true, and to return "no" every time it switches to false, mainly just to see if it's really working like it should.
Problem is, it only ever prints yes.
[code]function SWEP:SetupDataTables()
self:DTVar("Bool",0,"Hols")
end
function SWEP:PrimaryAttack()
if (self.dt.Hols==false) then self.dt.Hols=1 and print("yes")
else self.dt.Hols=0 and print("no")
end
[/code]
Any ideas what I'm doing wrong here?
How do I completely remove a value from a table?
I'm having a problem removing keys/references from a table.
I have a scrolling text panel that reads messages from a table , when a message pops off the end I remove it, recreate it on the right and then try to remove the popped element.
I've tried
[lua]
self.messages[i] = nil
[/lua]
but the length of the table still increases.
Now it 'works' but I'm obviously worried about what may happen over a period of time.
snippet
[lua]
function PANEL:Think()
print(table.Count(self.messages))
local i = 0
for k,v in ipairs(self.messages) do
if IsValid(v) then
local x,y = v:GetPos()
if x <= 0 && not v.inserted then
v:SetPos(x - self.scrollspeed,4)
self:NewMsg(v:GetText())
v.inserted = true
elseif x + v:GetWide() <= 0 then
v:Remove()
self.messages[i] = nil
else
v:SetPos(x - self.scrollspeed, 4)
end
end
end
end
function PANEL:NewMsg(txt)
local msg = vgui.Create("DLabel",self)
msg:SetPos(ScrW(),4)
msg:SetText(txt)
msg:SizeToContents()
for k,v in pairs(self.messages) do
if IsValid(v) then
local x,y = v:GetPos()
if x + self.spacing > msg.x then
msg.x = v.x + self.spacing
end
end
end
table.insert(self.messages, msg)
end
[/lua]
[editline]14th February 2013[/editline]
[QUOTE=elowin;39586515]Any ideas what I'm doing wrong here?[/QUOTE]
You haven't closed the function, but I reckon that's just a problem with copy and paste...
That's a weird way of doing an if statement though, what are you trying to do with;
[lua]and[/lua]
try this,
[lua]
function SWEP:SetupDataTables()
self:DTVar("Bool",0,"Hols")
end
function SWEP:PrimaryAttack()
if (self.dt.Hols == false) then
self.dt.Hols = 1
print("yes")
else
self.dt.Hols=0
print("no")
end
end
[/lua]
[editline]14th February 2013[/editline]
[QUOTE=Science;39586276]What would be the equivilent of DNumSlider in Gmod13?
All i can seem to use is DSlider which to be honest, is plain awful.[/QUOTE]
You [I]could[/I] make your own one.
[QUOTE=jaooe;39586602]You haven't closed the function, but I reckon that's just a problem with copy and paste...
That's a weird way of doing an if statement though, what are you trying to do with;
[lua]and[/lua]
try this,
[lua]
function SWEP:SetupDataTables()
self:DTVar("Bool",0,"Hols")
end
function SWEP:PrimaryAttack()
if (self.dt.Hols == false) then
self.dt.Hols = 1
print("yes")
else
self.dt.Hols=0
print("no")
end
end
[/lua][/QUOTE]
Not really sure what I was doing with those ands either, just felt right I guess, removed them.
And yeah, the function is closed, just didn't copy paste the whole function since the problem is in this particular part.
Anyway, it's still just printing "no" constantly, so there's still something else wrong with what i'm doing here.
I find this a little perplexing to be honest, I just can't figure out what I'm doing wrong at all.
[code]function SWEP:SetupDataTables()
self:DTVar("Bool",0,"Hols")
end
function SWEP:PrimaryAttack()
if (self.dt.Hols==false) then
self.dt.Hols=1
print("yes")
else self.dt.Hols=0
print("no")
end
[/code]
Looks just fine to me :v:
I've never used data tables before so I don't have a clue either.
If I were you I would try
[lua]
function SWEP:SetupDataTables()
self.holstered = false
end
function SWEP:PrimaryAttack()
if !self.holstered then
print("yes")
self.holstered = !self.holstered
else
print("no")
self.holstered = !self.holstered
end
end
[/lua]
That will toggle the value of self.holstered between true and false, starting at false.
I am trying to make clothing for Clockwork, for the citizens. How do I make so different models leads to different models?
I mean, if male_09 equips the clothing, how do I make it so he's still male_09, but with the clothing on? Right now I only have a small if female then one model, else it must be a guy, therefore the other model, but there are 18 different human models, so I can't go with that as far as I know.
[editline]14th February 2013[/editline]
Wait nevermind looked into the rebel clothing and copied the part from there.
Sorry, you need to Log In to post a reply to this thread.