[QUOTE=Ericson666;39098068]Is there any way to access an entity's information and tables if they're not spawned? Making a gungame mod, and I want to show the next and previous weapons on the HUD.
One of the main things about the gamemode is how you just need to put the weapon's folder w/ the shared.lua in the ents folder, and then put the name of the entity in weapon list. The gamemode handles randomizing and leveling up everyone with no further configuration. If it wasn't for this, I could just write another table with PrintNames and get them with a for loop, but that would require more configuration when it comes to adding/removing weapons, and it'd be a lot easier if I could get to the PrintName that's already in each weapon's shared.lua
Now that leads me to the small issue of getting the PrintName from a SWEP for the last/next weapon thing on the HUD. I can send the name of the entity from the weapon list ("gy_m249" for example) easily, but I'd rather have the actual PrintName, not the entity name.
[lua]ply:GetActiveWeapon().PrintName[/lua]
Using ^that, I can get the current weapon's name, but that's not really helping me with the previous and next weapon's PrintNames. Is there any way that I can look through the tables [URL="http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index0a10.html"](like with this)[/URL] of an entity that isn't currently spawned?[/QUOTE]
Non-active weapons are still spawned and can be accessed, [url]http://wiki.garrysmod.com/page/Classes/Player/GetWeapons[/url]
[QUOTE=Drakehawke;39098431]Non-active weapons are still spawned and can be accessed, [url]http://wiki.garrysmod.com/page/Classes/Player/GetWeapons[/url][/QUOTE]
The thing is, the weapons aren't in their inventory, after each kill their weapons are stripped and they get the next level's weapon. I want to be able to access the entities/weapons/gy_weapon/shared.lua file while it's not spawned. After 2 hours of search, I'm starting to think it isn't possible without manually making a table
[QUOTE=shadowndacorner;39098423]Put a print function (print("CHANGING MATERIALS") or something) where you're doing that to make sure the code is actually running.
[editline]January 4 2013[/editline]
Actually, it should be SetMaterialTexture, not SetTexture. Ex.
[lua]
oldMaterial:SetMaterialTexture("$basetexture", GetHandsTexture(model):GetMaterialTexture("$basetexture"))
[/lua][/QUOTE]
I thought it's been SetTexture ever since Gmod13?
[QUOTE=Ericson666;39098485]The thing is, the weapons aren't in their inventory, after each kill their weapons are stripped and they get the next level's weapon. I want to be able to access the entities/weapons/gy_weapon/shared.lua file while it's not spawned. After 2 hours of search, I'm starting to think it isn't possible without manually making a table[/QUOTE]
OH, I see what you mean, you're looking for weapons.Get( "classname" )
[QUOTE=brandonj4;39097542][lua]
for _, model in pairs(GModZ.Config[ value .. " Survivor Models"]) do
local Icon = vgui.Create( "SpawnIcon")
Icon:SetSize( 60, 60 )
Icon:SetModel(model)
Icon.Mdl = model
Icon:SetToolTip(nil)
Icon.DoClick = function(self)
charmdl = self.Mdl
end
end
[/lua]
????[/QUOTE]
Yey, thank god. Well, that was a simple solution. I was just being a idiot.
Is it possible to fill a rounded box with a gradient colour?
I have this code for giving a player a random melee weapon on spawn. I haven't gotten around to testing it yet but just want to check if I've got it right . Also, would this give each player a random weapon from that table or would it randomly pick one and give it to all players?
[lua]if (SERVER) then
AddCSLuaFile("autorun/ttt_randommelee.lua")
end
-- List of Melee Weapons
local ttt_melee = {
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1",
};
local function RandomMeleeWeapon()
for k,v in pairs( player.GetAll() ) do
ply:Give(table.Random(ttt_melee))
end
end
hook.Add( "TTTBeginRound", "RandomMeleeWeapon", RandomMeleeWeapon ) [/lua]
[QUOTE=Neddy;39104256]I have this code for giving a player a random melee weapon on spawn. I haven't gotten around to testing it yet but just want to check if I've got it right . Also, would this give each player a random weapon from that table or would it randomly pick one and give it to all players?
[lua]if (SERVER) then
AddCSLuaFile("autorun/ttt_randommelee.lua")
end
-- List of Melee Weapons
local ttt_melee = {
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1",
};
local function RandomMeleeWeapon()
for k,v in pairs( player.GetAll() ) do
ply:Give(table.Random(ttt_melee))
end
end
hook.Add( "TTTBeginRound", "RandomMeleeWeapon", RandomMeleeWeapon ) [/lua][/QUOTE]
Looks fine to me. It should give every player a different random weapon from that table. However, I believe this whole thing should be serverside so you won't really need that if statement at the beginning unless this is a shared file for some reason.
Edit:
Damn commas!!
[QUOTE=Neddy;39104256]I have this code for giving a player a random melee weapon on spawn. I haven't gotten around to testing it yet but just want to check if I've got it right . Also, would this give each player a random weapon from that table or would it randomly pick one and give it to all players?
[lua]if (SERVER) then
AddCSLuaFile("autorun/ttt_randommelee.lua")
end
-- List of Melee Weapons
local ttt_melee = {
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1",
};
local function RandomMeleeWeapon()
for k,v in pairs( player.GetAll() ) do
ply:Give(table.Random(ttt_melee))
end
end
hook.Add( "TTTBeginRound", "RandomMeleeWeapon", RandomMeleeWeapon ) [/lua][/QUOTE]
Looks functional but it would give all players a random weapon each time that hook is called.
[QUOTE=Neddy;39104256]I have this code for giving a player a random melee weapon on spawn. I haven't gotten around to testing it yet but just want to check if I've got it right . Also, would this give each player a random weapon from that table or would it randomly pick one and give it to all players?
[lua]if (SERVER) then
AddCSLuaFile("autorun/ttt_randommelee.lua")
end
-- List of Melee Weapons
local ttt_melee = {
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1"
"weapon_ttt_something1",
};
local function RandomMeleeWeapon()
for k,v in pairs( player.GetAll() ) do
ply:Give(table.Random(ttt_melee))
end
end
hook.Add( "TTTBeginRound", "RandomMeleeWeapon", RandomMeleeWeapon ) [/lua][/QUOTE]
The table is wrong.
It should be :
[lua]
local ttt_melee = {
"weapon_ttt_something1",
"weapon_ttt_something1",
"weapon_ttt_something1",
"weapon_ttt_something1",
"weapon_ttt_something1",
"weapon_ttt_something1"
}
[/lua]
[editline]5th January 2013[/editline]
Also, you don't need to AddCSLuaFile.
[lua]
-- List of Melee Weapons
local ttt_melee = {
"weapon_ttt_melee1",
"weapon_ttt_melee2"
}
local function RandomMeleeWeapon( ply )
for k,v in pairs( player.GetAll() ) do
if ply:IsAlive()then
ply:Give(table.Random(ttt_melee))
end
end
end
hook.Add( "TTTBeginRound", "RandomMeleeWeapon", RandomMeleeWeapon )
[/lua]
But now ply is returning nill now though. Hm.
wait so you're looping through all of the players, and for every player you are giving the same player a random weapon?
[QUOTE=Banana Lord.;39105323]wait so you're looping through all of the players, and for every player you are giving the same player a random weapon?[/QUOTE]
Ohh.. I've just noticed what i've done wrong.. I feel so retarded right now
[editline]5th January 2013[/editline]
[lua]
-- List of Melee Weapons
local ttt_melee = {
"weapon_ttt_melee1",
"weapon_ttt_melee2"
}
function RandomMeleeWeapon(ply)
if ply:IsAlive()then
ply:Give(table.Random(ttt_melee))
end
end
hook.Add( "TTTBeginRound", "RandomMeleeWeapon", RandomMeleeWeapon )
[/lua]
Nope. Still coming up as nill. I have no idea what I've done wrong.
Is PlayerSay broken with gmod13? Even if I copy their example from the site i get back
[QUOTE][ERROR] lua/includes/util.lua:184: attempt to index local 'object' (a number value)
1. IsValid - lua/includes/util.lua:184
2. unknown - lua/includes/modules/hook.lua:90[/QUOTE]
[CODE]hook.Add("PlayerSay", 0, function( ply, text, team )
print("u said something")
end )[/CODE]
doesn't even work.
[QUOTE=Neddy;39105351]Ohh.. I've just noticed what i've done wrong.. I feel so retarded right now
[editline]5th January 2013[/editline]
[lua]
-- List of Melee Weapons
local ttt_melee = {
"weapon_ttt_melee1",
"weapon_ttt_melee2"
}
function RandomMeleeWeapon(ply)
if ply:IsAlive()then
ply:Give(table.Random(ttt_melee))
end
end
hook.Add( "TTTBeginRound", "RandomMeleeWeapon", RandomMeleeWeapon )
[/lua]
Nope. Still coming up as nill. I have no idea what I've done wrong.[/QUOTE]
[lua]
-- List of Melee Weapons
local ttt_melee = {
"weapon_ttt_melee1",
"weapon_ttt_melee2"
}
local function RandomMeleeWeapon()
for k,v in pairs( player.GetAll() ) do
if v:IsAlive()then
v:Give(table.Random(ttt_melee))
end
end
end
hook.Add( "TTTBeginRound", "RandomMeleeWeapon", RandomMeleeWeapon )
[/lua]
Changed ply to v. You don't even need the ply variable for what you're trying to do.
[QUOTE=tissue902;39105763]Is PlayerSay broken with gmod13? Even if I copy their example from the site i get back
[CODE]hook.Add("PlayerSay", 0, function( ply, text, team )
print("u said something")
end )[/CODE]
doesn't even work.[/QUOTE]
Doesn't the name of the hook need to be a string?
[lua]
hook.Add("PlayerSay", "0", function( ply, text, team )
[/lua]
-snip-
what he said ^
[QUOTE=Sparky-Z;39105801]-snip-
what he said ^[/QUOTE]
that would be it. thanks
[QUOTE=Sparky-Z;39105776][lua]
-- List of Melee Weapons
local ttt_melee = {
"weapon_ttt_melee1",
"weapon_ttt_melee2"
}
local function RandomMeleeWeapon()
for k,v in pairs( player.GetAll() ) do
if v:IsAlive()then
v:Give(table.Random(ttt_melee))
end
end
end
hook.Add( "TTTBeginRound", "RandomMeleeWeapon", RandomMeleeWeapon )
[/lua]
Changed ply to v. You don't even need the ply variable for what you're trying to do.[/QUOTE]
Tried that.
[lua]
-- List of Melee Weapons
local ttt_melee = {
"weapon_ttt_melee1",
"weapon_ttt_melee2"
}
local function RandomMeleeWeapon()
for k,v in pairs( player.GetAll() ) do
v:Give(table.Random(ttt_melee))
end
end
hook.Add( "TTTBeginRound", "RandomMeleeWeapon", RandomMeleeWeapon )
[/lua]
But now Give is returning nill
Ah nvm. I realise why now ;p
I am having an issue with SQL database.
Fetching for what's saved inside returns table with "[1]" before it which makes sending it and changing it really troublesome
Doing:
[lua]local FetchData = sql.Query("SELECT xp, fame, infamy FROM xpm_players WHERE id ='"..self:SteamID().."'")[/lua]
Outputs:
[lua]
1:
xp = 133
fame = 144
infamy = 155
[/lua]
And to modify the stats I have to do self.XPMvars[1] = blah blah
[QUOTE=Netheous;39107268]I am having an issue with SQL database.
Fetching for what's saved inside returns table with "[1]" before it which makes sending it and changing it really troublesome
Doing:
[lua]local FetchData = sql.Query("SELECT xp, fame, infamy FROM xpm_players WHERE id ='"..self:SteamID().."'")[/lua]
Outputs:
[lua]
1:
xp = 133
fame = 144
infamy = 155
[/lua]
And to modify the stats I have to do self.XPMvars[1] = blah blah[/QUOTE]
self.XPMvars = self.XPMvars[1]
?
or just when you set it use the first index of the SQL result
[QUOTE=BL00DB4TH;39107905]self.XPMvars = self.XPMvars[1]
?
or just when you set it use the first index of the SQL result[/QUOTE]
Well if I do self.XPMvars = self.XPMvars[1] wouldn't that make 2 tables:
self.XPMvars and self.XPMvars[1]
Is it possible to limit the number of the SWEP I am making to 1 at a time on the server? I don't want multiple people using it at once.
[QUOTE=Turtle95;39108333]Is it possible to limit the number of the SWEP I am making to 1 at a time on the server? I don't want multiple people using it at once.[/QUOTE]
You could make a table for each restricted weapon and put players that pick them up inside.
Then if there are N players in the table and someone wants to pickup the weapon it'll simply return false
@Edit: Also, when I come to think about it, you could simply do table of restricted weapons and check for players with that weapon each time someone tries to pickup restricted weapon.
[QUOTE=Netheous;39108500]You could make a table for each restricted weapon and put players that pick them up inside.
Then if there are N players in the table and someone wants to pickup the weapon it'll simply return false[/QUOTE]
Thanks! :)
[QUOTE=Turtle95;39108653]Thanks! :)[/QUOTE]
Well, I guess I can help you with that, so feel free to add me
[QUOTE=Netheous;39108670]Well, I guess I can help you with that, so feel free to add me[/QUOTE]
OK, I'll add you. I also need to figure out how to stop playing a looping sound in the SWEP when the owner dies, because I can't get that.
Here's an easy one for you
[CODE][ERROR] gamemodes/odst/gamemode/init.lua:14: attempt to call method 'SetGamemodeTeam' (a nil value)
1. unknown - gamemodes/odst/gamemode/init.lua:14
[/CODE]
What did I do.
[QUOTE=Slacker101;39114707]Here's an easy one for you
[CODE][ERROR] gamemodes/odst/gamemode/init.lua:14: attempt to call method 'SetGamemodeTeam' (a nil value)
1. unknown - gamemodes/odst/gamemode/init.lua:14
[/CODE]
What did I do.[/QUOTE]
Well, no one can really help you if we can't see the code. Show us init.lua.
What data type to people use to store the steam id in that is returned on GM:PlayerAuthed? I saw that it is a 64bit integer, but that seems a little specialized for what is provided through mysql and sqlite.
Sorry, you need to Log In to post a reply to this thread.