[QUOTE=AIX-Who;45747956]Ok, im making a little mining system for a gamemode im working on and everything is working fine apart from displaying the data in a gui.
[/QUOTE]
You're trying to set the text to a vgui element? Of course that will cause errors.
[lua]
local rock = vgui.Create( "DButton", frame ) // Here you're defining rock
...
rock:SetText( "Rock(s):"..tonumber(rock) ) // And now you're treating it as a string/number?
[/lua]
[QUOTE=ms333;45749056]You're trying to set the text to a vgui element? Of course that will cause errors.
[lua]
local rock = vgui.Create( "DButton", frame ) // Here you're defining rock
...
rock:SetText( "Rock(s):"..tonumber(rock) ) // And now you're treating it as a string/number?
[/lua][/QUOTE]
Is there a __tonumber element on metatables like there is with tostring?
Does anyone know of conflicting between a gamemode and an addon, causing some functions of said addon to no longer be found/recognised?
The [url=http://steamcommunity.com/sharedfiles/filedetails/?id=266512527&searchtext=hide+and+seek]Hide and Seek[/url] gamemode seems to be conflicting with [url=https://github.com/Jake-TD/Clocky]Clocky[/url].
All the files load up fine so there shouldn't be any problem, but this error occurs:
[img]http://i.imgur.com/RAWjVZz.png[/img]
The bit of code it's trying to call in question:
[lua]
function Clocky:GetData(ply)
local qs = "SELECT timeplayed FROM clocky_userinfo WHERE steamid = '" .. ply:SteamID() .. "' LIMIT 1"
local q = ClockyDB:query(qs)
function q:onSuccess(data)
ply.ClockySQLTime = data
ply:LoadClockySQL()
end
function q:onError(err)
print('++Clocky error loading user++\n Error: ' .. err)
if ClockyDB:status() == mysqloo.DATABASE_NOT_CONNECTED then
print('++Clocky not connected while fetching data, refreshing++')
ClockyDB:connect() --This stops it from timing out for dumb reasons and not getting the data properly by reconnecting and redoing it if needed
ClockyDB:wait()
print('++Clocky attempting to fetch data++')
Clocky:GetData(ply)
return
end
end
q:start()
end
[/lua]
It only seems to be with this gamemode.
From what I can tell, manually reloading the addon (by saving and thus running the init again) after the gamemode has loaded seems to fix it.
[QUOTE=HumbleTH;45749268]Is there a __tonumber element on metatables like there is with tostring?[/QUOTE]
No, but you can make one:
[code]
local tn = tonumber
rawtonumber = tn
function tonumber(val)
local mt = getmetatable(val)
if istable(mt) and mt.__tonumber then
return mt.__tonumber(val)
end
return tn(val)
end
[/code]
I know this is gonna sound really stupid,and it is probably gonna be a easy fix. I coded a base entity class and started deriving stuff from that base,but I can't overwrite one of the functions.
I tried retyping the function name and expected it to call the one in that derived entity class, but it constantly calls the one in the base entity class.
Does anyone know how I can overwrite the base entity class functions?
[QUOTE=bran92don;45754008]I know this is gonna sound really stupid,and it is probably gonna be a easy fix. I coded a base entity class and started deriving stuff from that base,but I can't overwrite one of the functions.
I tried retyping the function name and expected it to call the one in that derived entity class, but it constantly calls the one in the base entity class.
Does anyone know how I can overwrite the base entity class functions?[/QUOTE]
What function is it and can you show an example of how you're trying to override it?
[QUOTE=Jeezy;45754120]What function is it and can you show an example of how you're trying to override it?[/QUOTE]
This is in the base class:
[lua]
function infect(ply) --custom function to infect player
if ply.commoncold == NULL or ply.commoncold == nil or ply.commoncold == false then
ply.commoncold = true --Set value
timer.Create( ply:UniqueID() .. "commoncold", 1, 45, function()
local cough_noise = {"player/damage/male/minorpain2.wav","player/damage/male/minorpain7.wav"}
//if virnum >= 1 and virnum <= 35 and ply.commoncold == true then
if timer.RepsLeft( ply:UniqueID() .. "commoncold" )%6 == 0 then
ply:ViewPunch( Angle( -10, 0, 0 ) ) --cough punch
ply:ViewPunch( Angle( -10, 0, 0 ) ) --cough punch
ply:EmitSound(cough_noise[math.random(1,#cough_noise)],40,100 ) --cough sound
ply:SetHealth( ply:Health() - 1)
if ply:Health() <= 0 then
ply.commoncold = false -- set it to false
ply:Kill()
end
--Create new virus area
local virnum = math.random(1,100)
if virnum >= 1 and virnum <= 35 and ply.commoncold == true then
local virus = ents.Create( "common_cold" )
virus:SetPos( ply:GetPos() )
virus:Spawn()
timer.Simple(30, function()
if virus:IsValid() then
virus:Remove()
end
end)
end
end
if timer.RepsLeft( ply:UniqueID() .. "commoncold" ) <= 2 then
ply.commoncold = false
end
end)
end
end
[/lua]
Then in the shared file I do this:
[lua]
function infect(ply)
print("test")
end
[/lua]
[QUOTE=bran92don;45754281][lua]Lua[/lua][/QUOTE]
You are making global functions, they aren't attached to your entity class in any way. Whichever file loads last will override your function.
Without seeing the rest of the code the most basic suggestion is to change function infect(ply) to function ENT:infect(ply) , and anywhere you are calling it call it like self:infect(ply)
-snip-
[QUOTE=Robotboy655;45728982]What's the best way to render a png or jpg from Internet, without using HTML control? ( because it spawns infinite amount of Awesomium processes )[/QUOTE]
[url]https://github.com/CapsAdmin/pac3/blob/master/lua/pac3/core/client/libraries/urltex.lua[/url]
How to GetPos() of entity on client, if I'm creating it serverside? I want to use it in trace
[QUOTE=TheMostUpset;45759120]How to GetPos() of entity on client, if I'm creating it serverside? I want to use it in trace[/QUOTE]
If the entity exists on client, same as on server, if not, you can't.
I'm doing like that and it works in singleplayer, in multiplayer it gives error on client.
[code][ERROR] shared.lua:39: attempt to call field 'Create' (a nil value)
1. unknown - shared.lua:39
[/code]
[code]local pos = self.Owner:GetShootPos()
local ang = self.Owner:GetAimVector():Angle()
pos = pos +ang:Forward() *-20 +ang:Right() *4 +ang:Up() *-5
local ent = ents.Create("entname")
ent:SetAngles(ang)
ent:SetPos(pos)
ent:SetOwner(self.Owner)
ent:Spawn()
ent:Activate()
local phys = ent:GetPhysicsObject()
if IsValid(phys) then
phys:SetVelocity(ang:Up() *15 +ang:Right() *-25 +ang:Forward() *10000)
end
local tr = util.TraceLine({
start = self.Owner:GetShootPos(),
endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 10^14,
filter = self.Owner
})
if !IsValid(tr.Entity) then
tr = util.TraceHull({
start = ent:GetPos(),
endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 10^14,
filter = self.Owner
})
end[/code]
If add "if SERVER then", it can't get pos of the entity. So how?
What's the correct method of reskinning default Vgui stuff? I'm looking at DComboBox, with surface.DrawRect in the name.Paint = function() and right now it looks like this:
[img]http://puu.sh/b2dHh/34d651a939.png[/img]
Sort of what I want, but I want to redesign the actual drop downs menu options can't seem to see it on the relating wiki pages.
Something like this
[img]http://puu.sh/b2dZI/2aff4c375e.png[/img]
(I generally know VGUI pretty well and have used surface stuff plenty of times on it, but don't how to reskin DComboBox specifically)
The correct way to reskin derma is to use Derma skins.
You can then either force the skin onto everything via a hook, or force it upon specific panels via Pnl:SetSkin()
EDIT: However there are some limitations with it, in which case you'll have to make your own versions of the panels to match your needs.
Ahh, much appreciated, I don't know too much about Derma Skins but I'll see if I can go find a reference to go off
Although what's hidden/in this drop down are DButtons, so I may use DCollapsibleCategory instead
Hello, I was wondering if there was a way to split the health up into differet sections, like say I want the health to be 200, but want it to display as 12000. So 200 = 12000. Anyway to do that?
How do you get a teams ID if you only have its name?
Also, I want to pass the contents of a table as the arguments of function but i'm not sure how. Example:
[lua]local args = {"blob","bob","orange","jim"}
print(args) -- this prints out "table: 0x2c92a168"
-- I want it to print out "blob bob orange jim"[/lua]
I'm not using it with print, it's just a example of what i want.
How do I make the player play an animation once?
Can't find the thing for this... I'm using Nutscript (Not specifically relevant, except it is relevant in the fact that [i]our player is going to be using NPC animations, and I want him to play an NPC animation (doorkickbaton)[/i])
I don't know how... help? I mean I looked it up but it looked like it was only for player animations. I want the player to be forced to stand 100% still while the animation is happening, have it play ONLY once, then let him go. (the animation is doorkickbaton)
[QUOTE=highvoltage;45763873]How do you get a teams ID if you only have its name?
Also, I want to pass the contents of a table as the arguments of function but i'm not sure how. Example:
[lua]local args = {"blob","bob","orange","jim"}
print(args) -- this prints out "table: 0x2c92a168"
-- I want it to print out "blob bob orange jim"[/lua]
I'm not using it with print, it's just a example of what i want.[/QUOTE]
for getting the team id, you could try
[lua]
_G["TEAM_" .. name:upper()]
[/lua]
and if I'm understanding your question about arguments you can do
[lua]
print(unpack(args))
[/lua]
Ok, how to make clientside entity/effect with model and specified speed? And remove when it hit a wall.
I've got plenty of questions, since I have never played with NPCs.
-How do I change their movement speed
-How do I change the pitch of their voice
Oh, well, I guess 2 will do for now.
[QUOTE=PortalGod;45764548]for getting the team id, you could try
[lua]
_G["TEAM_" .. name:upper()]
[/lua]
[/QUOTE]
Horrible method.
[code]
function GetTeamByName( id )
for k,v in pairs(team.GetAllTeams( )) do
if v:GetName() == id then return k end
end
return nil
end
[/code]
How does one go about finding out if a player is Admin / Operator of a steam group without furryfinder? I'm just using http.Fetch on the steam group page at the moment to find players IN the group. ( I'm just using memberslistxml )
I can't seem to find a way to find out if a player is operator or admin of the group.
[QUOTE=highvoltage;45763873]Also, I want to pass the contents of a table as the arguments of function but i'm not sure how.[/QUOTE]
You could try using [URL="http://wiki.garrysmod.com/page/table/concat"]table.concat[/URL]
[code]
function myFunction(a)
a = table.concat(a, " ")
print(a)
end
myFunction( {"Hello,", "world!", "This", "uses", "table.concat()."} )
-- Should print "Hello, world! This uses table.concat()."
[/code]
Edit: Crap I misinterpreted that. PortalGod and Willox were right, unpack() is what you're looking for.
[QUOTE=highvoltage;45763873]
Also, I want to pass the contents of a table as the arguments of function but i'm not sure how. Example:
[lua]local args = {"blob","bob","orange","jim"}
print(args) -- this prints out "table: 0x2c92a168"
-- I want it to print out "blob bob orange jim"[/lua]
I'm not using it with print, it's just a example of what i want.[/QUOTE]
[url]http://wiki.garrysmod.com/page/Global/unpack[/url]
[code]
local args = {"blob","bob","orange","jim"}
print(unpack(args))
[/code]
What happens if I update the datapack mid-game? Like I'll be working on some files, and edit a client-side file, and when I reload the addon it calls "AddCSLuaFile" to the updated file. GMod throws the "datapack updated - this should never happen!" error. But everything is okay, clients I assume don't see the changes. But will new players, or do I need a server restart?
[QUOTE=Drak_Thing;45768132]What happens if I update the datapack mid-game? Like I'll be working on some files, and edit a client-side file, and when I reload the addon it calls "AddCSLuaFile" to the updated file. GMod throws the "datapack updated - this should never happen!" error. But everything is okay, clients I assume don't see the changes. But will new players, or do I need a server restart?[/QUOTE]
I think it's the opposite, clients will see new changes, but everyone who joins after can have the whole server/gamemode fucked up sometimes.
At least this is what I learned from doing this.
Alrighty, I'd mainly appreciate some advice here. I'm creating a derma based addon with alternative skins which I plan to release; because of this I'm trying to make it as easy to custom as I can.
I have a general config file, which has things like the main panel colour, button sizes, etc. On Skin1, the buttons are rectangles with text in them, but on Skin2, I have used images to display them. Skin1 can hold up to 10 buttons, but due to the image size on Skin2, I can only have five.
So far, I have design_config.lua, skin1_config.lua and skin2_config.lua. Is it a good idea to a separate file for each config or do you feel it would make the addon folder a bit cluttered?
[QUOTE=NiandraLades;45768369]Alrighty, I'd mainly appreciate some advice here. I'm creating a derma based addon with alternative skins which I plan to release; because of this I'm trying to make it as easy to custom as I can.
I have a general config file, which has things like the main panel colour, button sizes, etc. On Skin1, the buttons are rectangles with text in them, but on Skin2, I have used images to display them. Skin1 can hold up to 10 buttons, but due to the image size on Skin2, I can only have five.
So far, I have design_config.lua, skin1_config.lua and skin2_config.lua. Is it a good idea to a separate file for each config or do you feel it would make the addon folder a bit cluttered?[/QUOTE]
Make a separate folder called skins then use include to load the selected skin.
Sorry, you need to Log In to post a reply to this thread.