What's the difference between table.Count(tbl) and #tbl?
returning in 5 mins!
[QUOTE=Sam7100;39531999]Hm, still can't find any solution!?
Isn't it correct that it should be pretty easy??[/QUOTE]
Try posting the full function you're using it in
How would you include an addon file from an entity directory in a gamamode folder?
[QUOTE=jaooe;39530117]
What do you mean by group?
Like, all the male_x models?
or folders?[/QUOTE]
Something that gives me for example "Male_01" or Female_03, just that pice of info.
Like if I have this model: model/humans/group3/male_05.mdl, I would like a function or something, that tells me what model I have, that being male_05, and only male_0X, not the other crap.
Like I have a function, that set a model like this, model/humans/..group.id../*Here I need the model name* so I can change to diffrent groups, and get the correct model I already have, like if I have male 7 with citizen clothing, and I like to change it to group3m I'd like to have the medical resistance model, with the same face.
How would I go about letting players talk and type while a derma menu is open? I have an end of round votemap for TTT but players cannot communicate with each other.
[QUOTE=Kuro Light;39531495]How do you make ULX ban someone via an addon.
I've tried
RunConsoleCommand("ulx ban", Sam, 5)
RunConsoleCommand("ulx ban", "Sam", "5")
RunConsoleCommand("ulx ban", ply:GetName(), "5")
RunConsoleCommand("ulx ban", v:Nick(), "5")
Can someone help me out here?
It's RunConsoleCommand("ulx","ban")[/QUOTE]
Progress! The addon is now able to load.
Still, by using this:
RunConsoleCommand("ulx","ban","ply:GetName()","bantime")
I can't get it to ban an player.
My console returns this:
Command "ulx ban", argument #1: No target found or target has imunity.
Hm, i guess i can't use ply:GetName() to find the player.
It's serverside lua.
Is there an accurate way to get the exact opposite of a color (excluding alpha)?
I know there is but I can't write math functions. Can anyone help me out?
[QUOTE=Sam7100;39532334]Progress! The addon is now able to load.
Still, by using this:
RunConsoleCommand("ulx","ban","ply:GetName()","bantime")
I can't get it to ban an player.
My console returns this:
Command "ulx ban", argument #1: No target found or target has imunity.
Hm, i guess i can't use ply:GetName() to find the player.
It's serverside lua.[/QUOTE]
You don't put the string tags around it..
it's
[lua]
RunConsoleCommand("ulx","ban",ply:GetName(),tonumber(args[2]) or 0)
[/lua]
args[2] being the 2nd string entered in chat or etc. (Assuming the first one is used to find the ply)
[QUOTE=Kuro Light;39532790]You don't put the string tags around it..
it's
[lua]
RunConsoleCommand("ulx","ban",ply:GetName(),tonumber(args[2]) or 0)
[/lua]
args[2] being the 2nd string entered in chat or etc. (Assuming the first one is used to find the ply)[/QUOTE]
I would like to thank you!
It's working now, and i have found some great pages i can read more about strings, tags, ply: and so on. Thank you!
[QUOTE=>>;39532373]Is there an accurate way to get the exact opposite of a color (excluding alpha)?
I know there is but I can't write math functions. Can anyone help me out?[/QUOTE]
I got it anyways
[lua]local function ColorOpposite(color,g,b,a)
local iscolor = type(color) ~= "number"
if iscolor then
r = color.r
g = color.g
b = color.b
a = color.a
else
r = color
end
-- invert the colors
r = (r + (255-r) - r)
g = (g + (255-g) - g)
b = (b + (255-b) - b)
return Color(r,g,b,a)
end[/lua]
The surface things are not showing in singleplayer.
[CODE] 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
function CafeBene()
if ( CLIENT ) then
surface.SetTexture( surface.GetTextureID( "ending/cafebene" ) )
surface.SetDrawColor ( 255, 255, 255, 255 )
surface.DrawTexturedRect( ScrW() /2 - 70, ScrH() -166, 256, 85 )
end
end
timer.Simple( 0.16, function() hook.Add("HUDPaint", "ProduceSupportFunc", ProduceSupportFunc ) end )
timer.Simple( 0.16, function() hook.Add("HUDPaint", "CafeBene", CafeBene ) end )
timer.Simple( 1.36, function() hook.Remove("HUDPaint", "ProduceSupportFunc" ) end )
[/CODE]
but it works fine in multiplayer.
i think [CODE]if ( CLIENT ) then[/CODE] is not right, but i can't figure out what to replace.
How do I do this?!
sorry not good at english
I'm having trouble getting an npc health bar addon working. It worked fine before Gmod 13 but like most addons it no longer works. I read that changing the "info.txt" file to "addon.txt" apparently fixes it. But now when I load up a single player game, it returns to the main menu, apparently from lua errors. When I load up the console it says this:
[CODE]
[ERROR] addons/healthbar/lua/autorun/healthbar.lua:2: bad argument #2 to 'CreateFont' (table expected, got number)
1. CreateFont - [C]:-1
2. unknown - addons/healthbar/lua/autorun/healthbar.lua:2[/CODE]
I am completely unfamiliar with lua scripting and I have no idea how to fix this, I checked this thread:
[URL]http://www.facepunch.com/showthread.php?t=1220466[/URL]
but I wasn't able to get it working. Could anyone help me out?
-snyup-
[vid]http://puu.sh/205db[/vid]
In this video, the hat is positioned by adding the offset of the hat to the position of the player's eyes. How can i get an accurate offset so that the hat positions itself like a hat is supposed to?
[QUOTE=>>;39533642]I got it anyways
[lua]local function ColorOpposite(color,g,b,a)
local iscolor = type(color) ~= "number"
if iscolor then
r = color.r
g = color.g
b = color.b
a = color.a
else
r = color
end
-- invert the colors
r = (r + (255-r) - r)
g = (g + (255-g) - g)
b = (b + (255-b) - b)
return Color(r,g,b,a)
end[/lua][/QUOTE]
You don't need to do
[lua]
r = (r + (255 - r) -r)
[/lua]
It's just the same as
[lua]
r = 255 - r
[/lua]
same with g and b
[lua]
local function SpawnEntities()
if SERVER then
local zombie = ents.Create("npc_zombie")
local pistolammo = ents.Create("item_ammo_pistol")
local threefiftyammo = ents.Create("item_ammo_357")
local spawn = true
for k, v in pairs(ents.FindInSphere(Vector(-4155, -809, 130), 600)) do
if v:GetClass() == "npc_zombie" then
spawn = false
end
end
if spawn == true then
zombie:SetPos(Vector(-4155, -809, 130))
zombie:SetAngles(Angle(0, 0, 0))
zombie:Spawn()
end
end
end
timer.Create("SpawnEntityTimer", 4, 0, SpawnEntities)
[/lua]
Trying to get this code to spawn one zombie, and when that zombie dies, another spawns. Any help?
[QUOTE=I Like Cereal;39534118]
Trying to get this code to spawn one zombie, and when that zombie dies, another spawns. Any help?[/QUOTE]
What's the problem?
Are you getting an error?
[editline]10th February 2013[/editline]
[QUOTE=Meka;39533703]I'm having trouble getting an npc health bar addon working. It worked fine before Gmod 13 but like most addons it no longer works. I read that changing the "info.txt" file to "addon.txt" apparently fixes it. But now when I load up a single player game, it returns to the main menu, apparently from lua errors. When I load up the console it says this:
[ERROR] addons/healthbar/lua/autorun/healthbar.lua:2: bad argument #2 to 'CreateFont' (table expected, got number)
1. CreateFont - [C]:-1
2. unknown - addons/healthbar/lua/autorun/healthbar.lua:2
I am completely unfamiliar with lua scripting and I have no idea how to fix this, I checked this thread:
[URL]http://www.facepunch.com/showthread.php?t=1220466[/URL]
but I wasn't able to get it working. Could anyone help me out?[/QUOTE]
What's on line 2 of healthbar.lua?
[QUOTE=jaooe;39534133]What's the problem?
Are you getting an error?[/QUOTE]
No, it just doesnt spawn a zombie at all. If I remove the:
[lua]
for k, v in pairs(ents.FindInSphere(Vector(-4155, -809, 130), 600)) do
if v:GetClass() == "npc_zombie" then
spawn = false
end
end
if spawn == true then
zombie:SetPos(Vector(-4155, -809, 130))
zombie:SetAngles(Angle(0, 0, 0))
zombie:Spawn()
end
[/lua]
And add the position to the root function, the zombies spawn inside each other unless someone is near. I'd like for the zombies to only spawn if the previous one is dead.
[editline]9th February 2013[/editline]
Ooops thought you were talking to me...
[QUOTE=jaooe;39534133]What's the problem?
Are you getting an error?
[editline]10th February 2013[/editline]
What's on line 2 of healthbar.lua?[/QUOTE]
[CODE]surface.CreateFont( "coolvetica", 22, 50, true, false, "HealthNumberFont" )[/CODE]
I don't know if you need it but the line above is:
[CODE]surface.CreateFont( "coolvetica", 30, 80, true, false, "HealthFont" )[/CODE]
[QUOTE=Archemyde;39534041]-snyup-
[vid]http://puu.sh/205db[/vid]
In this video, the hat is positioned by adding the offset of the hat to the position of the player's eyes. How can i get an accurate offset so that the hat positions itself like a hat is supposed to?[/QUOTE]
[QUOTE=Kogitsune;22060923]Not tested ( since I don't have the actual code with me ), but this is close to what I used to do this:
[hd]http://www.youtube.com/watch?v=De7t2SUW-iA[/hd]
[lua]local hats = { }
local function CreateHat( pl, model )
SafeRemoveEntity( pl.Hat )
local hat
hat = ClientsideModel( model, RENDERGROUP_OPAQUE )
hat:SetNoDraw( true )
pl.Hat = hat
hat.Owner = pl
table.insert( hats, hat )
end
local function CleanHats( )
local k, v
for k, v in pairs( hats ) do
if not ValidEntity( v ) then
hats[ k ] = nil
elseif not ValidEntity( v.Owner ) then
SafeRemoveEntity( v )
hats[ k ] = nil
end
end
end
local function DrawHats( )
local k, v, pos, ang
CleanHats( )
for k, v in ipairs( player.GetAll( ) ) do
if not v:Alive( ) and ValidEntity( v.Hat ) then
SafeRemoveEntity( v.Hat )
v = v:GetRagdollEntity( )
end
if not ValidEntity( v.Hat ) then
CreateHat( v, "models/combine_helictoper/helicopter_bomb01.mdl" )
end
pos, ang = v:GetBonePosition( 6 )
v.Hat:SetPos( pos )
v.Hat:SetAngles( ang )
v.Hat:DrawModel( )
end
end
hook.Add( "PostDrawOpaqueRenderables", "Draw Hats.PostDrawOpaqueRenderables", DrawHats )[/lua][/QUOTE]
[QUOTE=Meka;39534170][CODE]surface.CreateFont( "coolvetica", 50, 22, true, false, "HealthNumberFont" )[/CODE]
I don't know if you need it but the line above is:
[CODE]surface.CreateFont( "coolvetica", 80, 30, true, false, "HealthFont" )[/CODE][/QUOTE]
surface.CreateFont is a table in GMod 13. You must make it a table.
[editline]9th February 2013[/editline]
Example font:
[lua]
surface.CreateFont("Font",
{
font = "Arial",
size = 50,
weight = 200,
antialias = false,
shadow = false
})
[/lua]
[QUOTE=I Like Cereal;39534204]surface.CreateFont is a table in GMod 13. You must make it a table.
[editline]9th February 2013[/editline]
Example font:
surface.CreateFont("Font", { font = "Arial", size = 50, weight = 200, antialias = false, shadow = false }) [/QUOTE]
I'm not sure if I'm doing this right.. I'm still getting the error.
Heres what the lua file looks like in it's entirety after the change I made:
[lua]
if CLIENT then
( "coolvetica", 30, 80, true, false, "HealthFont" )
("Font",
{
font = "Arial",
size = 200,
weight = 50,
antialias = false,
shadow = false
})
function HealthBar()
if GetConVarNumber("cl_showhealthbar") == 1 && LocalPlayer():GetNWInt("HealthBarDisable") == 0 then
local tr = utilx.GetPlayerTrace( LocalPlayer(), LocalPlayer():GetCursorAimVector() )
local trace = util.TraceLine( tr )
if (!trace.Hit) then return end
if (!trace.HitNonWorld) then return end
local font = "TargetID"
local length = LocalPlayer():GetNWInt("LookingHealth") / LocalPlayer():GetNWInt("LookingMaxHealth") * 150
local x, y = gui.MousePos()
draw.SimpleText(trace.Entity:GetClass(), "HealthFont", x+100, y + 20, Color(255,255,255,255),1,1)
if LocalPlayer():GetNWInt("LookingHealth") != 0 && LocalPlayer():GetNWInt("LookingMaxHealth") >= LocalPlayer():GetNWInt("LookingHealth") then
surface.SetDrawColor( 255,0,0,255 )
surface.DrawRect( x + 20, y + 40, 150, 15 )
surface.SetDrawColor( 0,255,0,255 )
surface.DrawRect( x + 20, y + 40, length, 15 )
surface.SetDrawColor( 0,0,0,255 )
surface.DrawRect( x + 16, y + 40, 4, 15 )
surface.DrawRect( x + 170, y + 40, 5, 15 )
surface.DrawRect( x + 16, y + 36, 159, 4 )
surface.DrawRect( x + 16, y + 55, 159, 4 )
surface.DrawRect( x + 15, y + 42, 1, 13 )
surface.DrawRect( x + 175, y + 42, 1, 13 )
surface.DrawRect( x + 14, y + 44, 1, 9 )
surface.DrawRect( x + 176, y + 44, 1, 9 )
draw.SimpleText(LocalPlayer():GetNWInt("LookingHealth") .. "/" .. LocalPlayer():GetNWInt("LookingMaxHealth"), "HealthNumberFont", x + 90, y + 49, Color(0,0,255,255),1,1)
elseif LocalPlayer():GetNWInt("LookingHealth") != 0 && LocalPlayer():GetNWInt("LookingMaxHealth") <= LocalPlayer():GetNWInt("LookingHealth") then
surface.SetDrawColor( 255,0,0,255 )
surface.DrawRect( x + 20, y + 40, 150, 15 )
surface.SetDrawColor( 0,255,0,255 )
surface.DrawRect( x + 20, y + 40, 150, 15 )
draw.SimpleText(LocalPlayer():GetNWInt("LookingHealth") .. "/" .. LocalPlayer():GetNWInt("LookingMaxHealth"), "HealthNumberFont", x + 90, y + 49, Color(0,0,255,255),1,1)
end
end
end
hook.Add("HUDPaint", "bleh", HealthBar)
CreateClientConVar("cl_showhealthbar", 1, true, false)
else
AddCSLuaFile("healthbar.lua")
function HealthBarGetHealth()
for k, v in pairs(player.GetAll()) do
local tr = utilx.GetPlayerTrace( v, v:GetCursorAimVector() )
local trace = util.TraceLine( tr )
if (!trace.Hit) then return end
if (!trace.HitNonWorld) then return end
v:SetNWInt("LookingHealth",trace.Entity:Health())
v:SetNWInt("LookingMaxHealth",trace.Entity:GetMaxHealth())
if GetConVarNumber("sv_showhealthbar") == 0 then
v:SetNWInt("HealthBarDisable",1)
else
v:SetNWInt("HealthBarDisable",0)
end
end
end
hook.Add("Think", "NpcHudGetHealth", HealthBarGetHealth)
CreateConVar("sv_showhealthbar", 1)
end[/lua]
[QUOTE=Meka;39534282]I'm not sure if I'm doing this right.. I'm still getting the error.
Heres what the lua file looks like in it's entirety after the change I made:
[CODE]if CLIENT then
surface.CreateFont( "coolvetica", 30, 80, true, false, "HealthFont" )
surface.CreateFont("Font",
{
font = "Arial",
size = 200,
weight = 50,
antialias = false,
shadow = false
})
function HealthBar()
if GetConVarNumber("cl_showhealthbar") == 1 && LocalPlayer():GetNWInt("HealthBarDisable") == 0 then
local tr = utilx.GetPlayerTrace( LocalPlayer(), LocalPlayer():GetCursorAimVector() )
local trace = util.TraceLine( tr )
if (!trace.Hit) then return end
if (!trace.HitNonWorld) then return end
local font = "TargetID"
local length = LocalPlayer():GetNWInt("LookingHealth") / LocalPlayer():GetNWInt("LookingMaxHealth") * 150
local x, y = gui.MousePos()
draw.SimpleText(trace.Entity:GetClass(), "HealthFont", x+100, y + 20, Color(255,255,255,255),1,1)
if LocalPlayer():GetNWInt("LookingHealth") != 0 && LocalPlayer():GetNWInt("LookingMaxHealth") >= LocalPlayer():GetNWInt("LookingHealth") then
surface.SetDrawColor( 255,0,0,255 )
surface.DrawRect( x + 20, y + 40, 150, 15 )
surface.SetDrawColor( 0,255,0,255 )
surface.DrawRect( x + 20, y + 40, length, 15 )
surface.SetDrawColor( 0,0,0,255 )
surface.DrawRect( x + 16, y + 40, 4, 15 )
surface.DrawRect( x + 170, y + 40, 5, 15 )
surface.DrawRect( x + 16, y + 36, 159, 4 )
surface.DrawRect( x + 16, y + 55, 159, 4 )
surface.DrawRect( x + 15, y + 42, 1, 13 )
surface.DrawRect( x + 175, y + 42, 1, 13 )
surface.DrawRect( x + 14, y + 44, 1, 9 )
surface.DrawRect( x + 176, y + 44, 1, 9 )
draw.SimpleText(LocalPlayer():GetNWInt("LookingHealth") .. "/" .. LocalPlayer():GetNWInt("LookingMaxHealth"), "HealthNumberFont", x + 90, y + 49, Color(0,0,255,255),1,1)
elseif LocalPlayer():GetNWInt("LookingHealth") != 0 && LocalPlayer():GetNWInt("LookingMaxHealth") <= LocalPlayer():GetNWInt("LookingHealth") then
surface.SetDrawColor( 255,0,0,255 )
surface.DrawRect( x + 20, y + 40, 150, 15 )
surface.SetDrawColor( 0,255,0,255 )
surface.DrawRect( x + 20, y + 40, 150, 15 )
draw.SimpleText(LocalPlayer():GetNWInt("LookingHealth") .. "/" .. LocalPlayer():GetNWInt("LookingMaxHealth"), "HealthNumberFont", x + 90, y + 49, Color(0,0,255,255),1,1)
end
end
end
hook.Add("HUDPaint", "bleh", HealthBar)
CreateClientConVar("cl_showhealthbar", 1, true, false)
else
AddCSLuaFile("healthbar.lua")
function HealthBarGetHealth()
for k, v in pairs(player.GetAll()) do
local tr = utilx.GetPlayerTrace( v, v:GetCursorAimVector() )
local trace = util.TraceLine( tr )
if (!trace.Hit) then return end
if (!trace.HitNonWorld) then return end
v:SetNWInt("LookingHealth",trace.Entity:Health())
v:SetNWInt("LookingMaxHealth",trace.Entity:GetMaxHealth())
if GetConVarNumber("sv_showhealthbar") == 0 then
v:SetNWInt("HealthBarDisable",1)
else
v:SetNWInt("HealthBarDisable",0)
end
end
end
hook.Add("Think", "NpcHudGetHealth", HealthBarGetHealth)
CreateConVar("sv_showhealthbar", 1)
end[/CODE][/QUOTE]
Take the surface.CreateFont out of the if statement.
[QUOTE=Meka;39534282]I'm not sure if I'm doing this right.. I'm still getting the error.
Heres what the lua file looks like in it's entirety after the change I made:
[CODE]ahhhhhhhhhh[/CODE][/QUOTE]
You should use the [lua] tags too!
[QUOTE=I Like Cereal;39534302]Take the surface.CreateFont out of the if statement.[/QUOTE]
Okay, it no longer goes back to the main menu after loading but now I get this error:
[CODE][ERROR] addons/healthbar/lua/autorun/healthbar.lua:3: ambiguous syntax (function call x new statement) near '('
1. unknown - addons/healthbar/lua/autorun/healthbar.lua:0
[/CODE]
[QUOTE=Meka;39534336]Okay, it no longer goes back to the main menu after loading but now I get this error:
[CODE][ERROR] addons/healthbar/lua/autorun/healthbar.lua:3: ambiguous syntax (function call x new statement) near '('
1. unknown - addons/healthbar/lua/autorun/healthbar.lua:0
[/CODE][/QUOTE]
You still have one of those not table surface.CreateFonts in there on line 2...
[QUOTE=I Like Cereal;39534157]No, it just doesnt spawn a zombie at all. [/QUOTE]
Try something like
[lua]
function ZombieNear(pos,range)
for k,v in pairs(ents.findInSphere(pos)) do
if(v:GetClass() == "npc_zombie" then
return true
end
end
return false
end
function SpawnZombie(pos)
//Spawn Zombie
end
function UpdateZombies(pos,range)
if ZombieNear(pos,range) then
return
else
SpawnZombie(pos)
end
end
[/lua]
Create a timer that calls UpdateZombies() at whatever interval you wish... I think it should work, not sure, a dead zombie could appeaer as an npc_zombie...
[QUOTE=I Like Cereal;39534344]You still have one of those not table surface.CreateFonts in there on line 2...[/QUOTE]
Sorry.. I really have no idea what I'm doing. I got rid of the surface.CreateFonts on line 2 but now I'm also getting this error:
[CODE][ERROR] addons/healthbar/lua/autorun/healthbar.lua:2: ')' expected near ','
1. unknown - addons/healthbar/lua/autorun/healthbar.lua:0
[/CODE]
I know this is a really stupid question, but how do I use lua tags? I tried it earlier manually but it only screwed up my post and I can't find the option for it in the text settings..
[QUOTE=Meka;39534437]how do I use lua tags? [/QUOTE]
Instead of "CODE", type "lua".
[editline]10th February 2013[/editline]
[url]http://puu.sh/208L5/67192c5ee9[/url]
[QUOTE=Meka;39534437]Sorry.. I really have no idea what I'm doing. I got rid of the surface.CreateFonts on line 2 but now I'm also getting this error:
[CODE][ERROR] addons/healthbar/lua/autorun/healthbar.lua:2: ')' expected near ','
1. unknown - addons/healthbar/lua/autorun/healthbar.lua:0
[/CODE]
I know this is a really stupid question, but how do I use lua tags? I tried it earlier manually but it only screwed up my post and I can't find the option for it in the text settings..[/QUOTE]
Are you sure this your script?:
[lua]
surface.CreateFont("Font",
{
font = "Arial",
size = 200,
weight = 50,
antialias = false,
shadow = false
})
[/lua]
Sorry, you need to Log In to post a reply to this thread.