I am trying to port this: [url]http://www.garrysmod.org/downloads/?a=view&id=48931[/url]
to TTT and Garry's Mod 13. It is working fine but I keep getting this error:
[CODE][ERROR] lua/weapons/weapon_microwaverifle/shared.lua:1141: attempt to call method 'Fire' (a nil value)
1. unknown - lua/weapons/weapon_microwaverifle/shared.lua:1141[/CODE]
Thanks guys!
Edit: Here is my shared.lua: [url]http://pastebin.com/ef3WBzwX[/url]
I am having a strange issue again:
[lua] local vars = {}
vars.xp = FetchData[1].xp
vars.fame = FetchData[1].fame
vars.infamy = FetchData[1].infamy
for lvl, exp in pairs (XPM.LvlTbl) do
if vars.xp >= exp then
vars.xplvl = lvl
end
if vars.fame >= exp then
vars.famelvl = lvl
end
if vars.infamy >= exp then
vars.infamylvl = lvl
end
end
for key, value in pairs (vars) do
self:XPM_SetVars(key, value)
end
end[/lua]
Outputs "[ERROR] gamemodes/darkrp/gamemode/server/sv_xpmod.lua:27: attempt to compare number with string"
While XPM.LvlTbl contains only numbers:
[lua]XPM.LvlTbl = {}
XPM.LvlTbl[2] = 500
XPM.LvlTbl[3] = 1000
XPM.LvlTbl[4] = 2000
XPM.LvlTbl[5] = 4000
XPM.LvlTbl[6] = 8000
XPM.LvlTbl[7] = 16000
XPM.LvlTbl[8] = 32000
XPM.LvlTbl[9] = 64000
XPM.LvlTbl[10] = 128000[/lua]
[QUOTE=Netheous;39117154]I am having a strange issue again:
[lua] local vars = {}
vars.xp = FetchData[1].xp
vars.fame = FetchData[1].fame
vars.infamy = FetchData[1].infamy
for lvl, exp in pairs (XPM.LvlTbl) do
if vars.xp >= exp then
vars.xplvl = lvl
end
if vars.fame >= exp then
vars.famelvl = lvl
end
if vars.infamy >= exp then
vars.infamylvl = lvl
end
end
for key, value in pairs (vars) do
self:XPM_SetVars(key, value)
end
end[/lua]
Outputs "[ERROR] gamemodes/darkrp/gamemode/server/sv_xpmod.lua:27: attempt to compare number with string"
While XPM.LvlTbl contains only numbers:
[lua]XPM.LvlTbl = {}
XPM.LvlTbl[2] = 500
XPM.LvlTbl[3] = 1000
XPM.LvlTbl[4] = 2000
XPM.LvlTbl[5] = 4000
XPM.LvlTbl[6] = 8000
XPM.LvlTbl[7] = 16000
XPM.LvlTbl[8] = 32000
XPM.LvlTbl[9] = 64000
XPM.LvlTbl[10] = 128000[/lua][/QUOTE]
What line is line 27? Print the type of each of the variables you're using a logical compare on... or just tonumber both variables on the line which is erroring.
[QUOTE=zzaacckk;39117180]What line is line 27? Print the type of each of the variables you're using a logical compare on... or just tonumber both variables on the line which is erroring.[/QUOTE]
But what's the point of that, both are numbers, I already did print(lvl, exp, vars.xp) I always do.
Shouldn't it work without doing tonumber() ?
[QUOTE=Netheous;39117190]But what's the point of that, both are numbers, I already did print(lvl, exp, vars.xp) I always do.
Shouldn't it work without doing tonumber() ?[/QUOTE]
When you run print, it only prints what is returned by the tostring metamethod of that object, so you're unable to see if a number is an actual number or a string.
I would pass all variables in the vars table through tonumber to assure they are integers and aren't strings, unless you're sure they will be an integer, although you should already know what type each variable will be.
[QUOTE=zzaacckk;39117322]When you run print, it only prints what is returned by the tostring metamethod of that object, so you're unable to see if a number is an actual number or a string.
I would pass all variables in the vars table through tonumber to assure they are integers and aren't strings, unless you're sure they will be an integer, although you should already know what type each variable will be.[/QUOTE]
I see, I ran tonumber(vars.xp), because appearently reading tables off the sql database outputs numbers as strings now
What is a simple addon I can download that is a good example?
when you pull things from a database they are strings
that's how it works with MySQLOO/tmysql anyway
Can anyone please help me with my crafting system? I can't wrap my head around it. I don't have any code worth while to show but basically I'm sending the slots of the crafting gui(Which looks like Minecrafts crafting system) to the server using console commands and receiving them with no problem. But the issue is I can't figure out how to see which slots have the right amount in a stack, and if they don't look for the next stack. It's a 36 slot inventory system. Here's any related code:
[lua]
bCraft.DoClick = function()
RunConsoleCommand("grp_craft_item",craftSlots[1],craftSlots[2],craftSlots[3],craftSlots[4],craftSlots[5],craftSlots[6],craftSlots[7],craftSlots[8],craftSlots[9])
end
--Here's my shitty attempt at doing it(Maybe this can give an idea of what I'm trying to do)
--[[ concommand.Add("grp_craft_item",function(player,cmd,args)
local rebuildTbl = {}
if args then
for k,v in pairs(global_recipes) do
if table.IsEqual(v.Slots,args) then
for a,b in pairs(args) do
if b != "Empty" then
if !rebuildTbl[b] then
rebuildTbl[b] = 1
else
rebuildTbl[b] = rebuildTbl[b] + 1
end
end
end
for a,b in pairs(rebuildTbl) do
local i, amt = player:GetInventoryItem(a)
local tbl = player:GetItemSlots(a)
for c,d in pairs(tbl) do
for i = 1, b do
p
player:SetInventoryItem(c,a,amt - 1)
break
end
end
end
break
end
end
end
end) ]]
[/lua]
If anyone could help me I'd really appreciate it, this is the only thing holding me back from getting anywhere in my gamemode :/
Any up to date addon making tutorials?
[QUOTE=jrj996;39119009]Can anyone please help me with my crafting system? I can't wrap my head around it. I don't have any code worth while to show but basically I'm sending the slots of the crafting gui(Which looks like Minecrafts crafting system) to the server using console commands and receiving them with no problem. But the issue is I can't figure out how to see which slots have the right amount in a stack, and if they don't look for the next stack. It's a 36 slot inventory system. Here's any related code:
[lua]
bCraft.DoClick = function()
RunConsoleCommand("grp_craft_item",craftSlots[1],craftSlots[2],craftSlots[3],craftSlots[4],craftSlots[5],craftSlots[6],craftSlots[7],craftSlots[8],craftSlots[9])
end
--Here's my shitty attempt at doing it(Maybe this can give an idea of what I'm trying to do)
--[[ concommand.Add("grp_craft_item",function(player,cmd,args)
local rebuildTbl = {}
if args then
for k,v in pairs(global_recipes) do
if table.IsEqual(v.Slots,args) then
for a,b in pairs(args) do
if b != "Empty" then
if !rebuildTbl[b] then
rebuildTbl[b] = 1
else
rebuildTbl[b] = rebuildTbl[b] + 1
end
end
end
for a,b in pairs(rebuildTbl) do
local i, amt = player:GetInventoryItem(a)
local tbl = player:GetItemSlots(a)
for c,d in pairs(tbl) do
for i = 1, b do
p
player:SetInventoryItem(c,a,amt - 1)
break
end
end
end
break
end
end
end
end) ]]
[/lua]
If anyone could help me I'd really appreciate it, this is the only thing holding me back from getting anywhere in my gamemode :/[/QUOTE]
Why don't you use the net library instead of concommands and send a table?
[QUOTE=Hyper Iguana;39119665]Why don't you use the net library instead of concommands and send a table?[/QUOTE]
The only clientside part in that is bCraft part.
You can't use net to send from the client to the server can you? :v:
[QUOTE=jrj996;39119707]The only clientside part in that is bCraft part.
You can't use net to send from the client to the server can you? :v:[/QUOTE]
You can.
_______
As a question, why do DNumSliders give me this new awkward method instead of how it's supposed to be:
[img]http://i.imgur.com/otzPb.png[/img]
Why the buoyancy ratio won't work for me?
I've tried values from 1 to few thousand and it does not change shit.
Update, now it works until I touch the entity with physgun, after this it seems to loose the buoyancy at all.
[CODE]function ENT:Initialize()
if (SERVER) then
self:LoadModel() -- We don't know yet if we're using a random model or a static one!
self:PhysicsInit( SOLID_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetUseType( ONOFF_USE ) -- doesen't fucking work
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:SetMass(self.Mass)
if(self.IsTorpedo) then
phys:SetMaterial("metal")
end
phys:SetBuoyancyRatio(self.Buoyancy)
phys:Wake()
end
local skincount = self:SkinCount()
if (skincount > 0) then
self:SetSkin(math.random(0,skincount))
end
self.Burnt = false
if(self.Dumb) then
self.Armed = true
else
self.Armed = false
end
self.Ignition = false
self.Exploded = false
self.Used = false
end
end[/CODE]
[QUOTE=Hyper Iguana;39119831]You can.
_______
As a question, why do DNumSliders give me this new awkward method instead of how it's supposed to be:
[img]http://i.imgur.com/otzPb.png[/img][/QUOTE]
Unfortunately that's the new one :/
Also I did what you said but now what? I don't know where to go from here...
[QUOTE=Sparky-Z;39115465]Well, no one can really help you if we can't see the code. Show us init.lua.[/QUOTE]
[url]https://www.dropbox.com/s/jxucarkcc6y1a6a/init.lua[/url]
[QUOTE=jrj996;39120640]Unfortunately that's the new one :/
Also I did what you said but now what? I don't know where to go from here...[/QUOTE]
The weapon+player color menu still has the old one.
---
[url]http://wiki.garrysmod.com/page/Lua/Tutorials/Using_the_net_library[/url]
[QUOTE=Hyper Iguana;39119831]As a question, why do DNumSliders give me this new awkward method instead of how it's supposed to be:
*img*[/QUOTE]
[QUOTE=jrj996;39120640]Unfortunately that's the new one :/[/QUOTE]
Awkward? Unfortunately? I think it's a great idea. It lets you easily have high precision with your sliders.
[QUOTE=Divran;39121555]Awkward? Unfortunately? I think it's a great idea. It lets you easily have high precision with your sliders.[/QUOTE]
I find it an absolute pain to use precisely. Not that the old one was any easier though, I always have and always will just type the number I want into the box
[QUOTE=Slacker101;39120762][url]https://www.dropbox.com/s/jxucarkcc6y1a6a/init.lua[/url][/QUOTE]
All I can tell you is that SetGamemodeTeam isn't a valid player function. Look through the gamemode files and try to find where the custom player functions are being setup. Either it's not there or there's something wrong with it.
Edit:
Try looking at player.lua, I see you're including it in init.
[QUOTE=Drakehawke;39121777]I find it an absolute pain to use precisely. Not that the old one was any easier though, I always have and always will just type the number I want into the box[/QUOTE]
How does the weapon + player color chooser (context menu) still use the old one though?
Hello all,
I'm making a new SWEP, and I want the player to stick to the wall, but still be able to climb as if on a ladder. Is this possible without making a ladder?
[QUOTE=Hyper Iguana;39122253]How does the weapon + player color chooser (context menu) still use the old one though?[/QUOTE]
Poking around the source of DColorMixer (which is what that uses), it uses a DNumberWang instead.
Actually looking at the source for the DNumSlider, you can still access the old one by using a Slider instead.
Netheous why you use a table for your levels ?
Simple but works good...
[LUA]
function CalcExpInc( level )
if(level < 1) then
exp = GetConVarNumber("rlevel_startxp")
return exp
else
exp = ((level*GetConVarNumber("rlevel_startxp"))+GetConVarNumber("rlevel_xpinc"))
return exp
end
end
function CalcLevelUp( pl )
local exp = pl:GetNWInt("xp")
local level = pl:GetNWInt("level")
exp_req = CalcExpInc(level)
if( exp >= exp_req ) then
level = level + 1
exp = exp - exp_req
player:SetNWInt("level",level)
player:SetNWInt("xp",exp)
end
end
[/LUA]
I'm trying to get individual spawns for 2 different teams and I got this code:
[CODE]/*function GM:PlayerSelectSpawn( ply )
local spawns = ents.FindByClass( "info_player_start" )
local random = math.random(spawns)
if ply:Team() == 1 then
spawns[random]
end
end */
[/CODE]
But that only works to make team 1 spawn in any of the info_player_start entities and I have no idea how to separate one team's spawns from anothe's.
would i just use a different entity?
[editline]7th January 2013[/editline]
Okay now I just get an error saying it expected a '=' near 'end' even though it worked fine before!
[QUOTE=Turtle95;39122611]Hello all,
I'm making a new SWEP, and I want the player to stick to the wall, but still be able to climb as if on a ladder. Is this possible without making a ladder?[/QUOTE]
You could have it check if the player is holding down IN_FORWARD and if their eye angles are above a certain threshold, it pushes them up (depending on how you set up the sticking, it could add velocity or just adjust the Z position of the player).
I have another problem, the weapons I'm using are SWEPs and they sorta make sound but dont. In single player everything is dandy and makes sound but when in multiplayer, the first person doesnt make sound. If that makes sense, let me put it this way, your gun doesn't make sound, everything else does, INCLUDING the sounds of other players shooting. So its like your gun doesnt make sounds but everything else does, including the "Third person" sound of other people firing the same gun [B][I][U]HELP[/U][/I][/B]
[QUOTE=Sparky-Z;39122056]All I can tell you is that SetGamemodeTeam isn't a valid player function. Look through the gamemode files and try to find where the custom player functions are being setup. Either it's not there or there's something wrong with it.
Edit:
Try looking at player.lua, I see you're including it in init.[/QUOTE]
[url]https://www.dropbox.com/s/yl0oh5inwq49nje/player.lua[/url]
Is it possible to have a function called through console so that I can debug it as I change the code, or do I need to restart the server each time?
I'm working on setting up a database installation script (alpha at this point, just trying to get at the data)
Sure at this point it isn't a function, I would change it to one, if there were a way I could edit the code and quickly reprint the output to the console though. I've been restarting the server each time D:
I just want a quick way to reprint the output of install.lua as I make changes to the code.
Code is GPLv3
init.lua
[PHP]-- AddCSLuaFile( String FileName )
-- Sending to the clients the files they need
-- http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexe9af-2.html
--
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
-- include( String Filename )
--
include("shared.lua")
-- include("utilities/db.lua")
function runInstall()
include("utilities/install.lua")
end
concommand.Add("schema",runInstall)
-- GM:PlayerConnect( String name, String address )
-- Called whenever a player connects
-- http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0d60.html
--
function GM:PlayerConnect(name, ip)
print ("Player " .. name .. "has joined the game.")
end
-- GM:PlayerInitialSpawn( Player Player )
-- Is called when the player first spawns into the world.
-- http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2901.html
--
function GM:PlayerInitialSpawn(ply)
print ("Player " .. ply:Nick() .. "has spawned.")
end
-- GM:PlayerSpawn( Player Player )
-- Called whenever a player respawns.
-- http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index249d.html
--
function GM:PlayerSpawn(ply)
ply:SetModel("models/player/group01/male_07.mdl")
end
-- GM:PlayerAuthed( Player ply, String SteamID, Integer UniqueID )
-- Called whenever the player is Authed with Steam and recieves the SteamID
-- http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexc4b1.html
--
function GM:PlayerAuthed(ply, steamID, uniqueID)
print ("Player " .. ply:Nick() .. "has authenticated.")
end
[/PHP]
install.lua
[PHP]
schema = {}
-- Load Abstracted DB Schema
include("../modules/player/playerdb.lua")
include("../modules/groups/groupsdb.lua")
include("../modules/characters/charactersdb.lua")
for i,v in pairs(schema) do
print (i, v)
for j,k in pairs(v) do
print (j,k)
if type(k) == 'table' then
for l,m in pairs(k) do
print (l,m)
if type(m) == 'table' then
for n,o in pairs(m) do
print (n,o)
end
end
end
end
end
end
[/PHP]
playerdb.lua
[PHP]schema['players'] = {
['description'] = 'Base table for Players',
['fields'] = {
['id'] = {
['description'] = 'Primary identifier for a player',
['type'] = 'int',
['unsigned'] = TRUE,
['not null'] = TRUE
},
['steamid'] = {
['description'] = 'SteamID identifier for a player',
['type'] = 'varchar',
['unsigned'] = TRUE,
['not null'] = TRUE,
['length'] = '25'
},
['characterLimit'] = {
['description'] = 'How many characters this player may create',
['type'] = 'int',
['unsigned'] = TRUE,
['not null'] = TRUE,
['default'] = '1'
}
},
['primary key'] = {'id'}
}
schema['roles'] = {
['description'] = 'Player Roles Definitions',
['fields'] = {
['id'] = {
['description'] = 'Primary identifier for a role',
['type'] = 'int',
['unsigned'] = TRUE,
['not null'] = TRUE
},
['title'] = {
['description'] = 'Name of the role for permissions',
['type'] = 'varchar',
['length'] = '60',
['not null'] = TRUE
},
['description'] = {
['description'] = 'Description of this role',
['type'] = 'varchar',
['length'] = '255',
['not null'] = TRUE,
['default'] = ''
}
},
['primary key'] = {'id'}
}
schema['playerRoles'] = {
['description'] = 'Index of players and respective role assignments',
['fields'] = {
['playerId'] = {
['description'] = 'Player Identifier',
['type'] = 'int',
['unsigned'] = TRUE,
['not null'] = TRUE
},
['roleId'] = {
['description'] = 'Role Identifier',
['type'] = 'int',
['unsigned'] = TRUE,
['not null'] = TRUE,
['default'] = '0'
}
}
}
schema['permissions'] = {
['description'] = 'Permissions settings',
['fields'] = {
['id'] = {
['description'] = 'Primary identifier for permission',
['type'] = 'int',
['unsigned'] = TRUE,
['not null'] = TRUE
},
['title'] = {
['description'] = 'Description of permission for role',
['type'] = 'varchar',
['length'] = '60',
['not null'] = TRUE
},
['name'] = {
['description'] = 'Name of permission to be returned to gamemode',
['type'] = 'varchar',
['length'] = '60',
['not null'] = TRUE
}
},
['primary key'] = {'id'}
}
[/PHP]
Might have solved my own problem - found [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexd95c.html[/url] concommand.add
Attempt 1: Hmm nope, adding it to a function and having it load with a concommand uses a stored instance of the function.
Attempt 2: Loading install.lua through include via function. FAIL: Couldn't include file 'utilities/install.lua' (File not found) (@gamemodes/gorp/gamemode/init.lua (line 14)) Was kind of lame but worth a shot
Attempt 3: Giving up, just installing lua and running the bits through command line
[QUOTE=Slacker101;39125803][url]https://www.dropbox.com/s/yl0oh5inwq49nje/player.lua[/url][/QUOTE]
Okay, a couple things. First of all in init.lua you need to tell the server to download player.lua. So up at the top put another AddCSLuaFile for player.lua. The other thing is that there are a bunch of syntax errors in player.lua. You need to use brackets {} when defining a table. So the way you have this table setup is all wrong and won't work.
Current:
[lua]
local teams = ()
teams(0) = (name = "Blue", color = Vector ( .2, .2, 1.0 ), weapons = ("weapon_crowbar","weapon_pistol"))
teams(1) = (name = "Red", color = Vector ( 1.0, .2, .2 ) , weapons = ("weapon_crowbar","weapon_pistol"))
[/lua]
Fixed:
[lua]
local teams = {}
teams[0] = {name = "Blue", color = Vector ( .2, .2, 1.0 ), weapons = {"weapon_crowbar","weapon_pistol"}}
teams[1] = {name = "Red", color = Vector ( 1.0, .2, .2 ) , weapons = {"weapon_crowbar","weapon_pistol"}}
[/lua]
Sorry, you need to Log In to post a reply to this thread.