While coding a new jail system I'm storing coordinates for jail positions in a global table defined in gamemodes/AbyssRP/gamemode/jailpos.lua
[lua]
if string.lower(tostring(game.GetMap())) == "rp_downtown_v2" then
JailPoses = {
Vector(-1901.9425 193.9865 -195.9688),
Vector(-1997.0541 197.7970 -195.9688),
Vector(-2099.8928 196.5997 -195.9688),
Vector(-2199.5940 191.3833 -195.9688)
}
JailSupport = true
elseif string.lower(tostring(game.GetMap())) == "rp_abysscity" then
/*
JailPoses = {
"Enter Vector here",
"Enter Vector here",
"Enter Vector here",
"Enter Vector here",
"Enter Vector here",
"Enter Vector here"
}
*/
JailSupport = true
else
JailSupport = false
end
[/lua]
But upon calling the tables or even JailSupport it just returns nil, and trying to run PrintTable errors too. How can I make these tables global so they can be called from anywhere?
As long as you haven't got
[lua]
local JailPoses
local JailSupport
[/lua]
anywhere, you should be fine, are you definitely including the file?
Well that file is in gamemodes/AbyssRP/gamemode called jailpos.lua and I'm attempting to call the table from gamemodes/AbyssRP/entities/weapons/arrest_stick/shared.lua and addons/Evolve/lua/ev_plugins/sh_jail2.lua
Code extracts:
sh_jail2.lua
[lua]
if JailSupport then
pl.JailNum = math.random(1,table.Count(JailPoses))
pl.JailPos = JailPoses[pl.JailNum]
pl:SetPos( pl.JailPos )
else
pl:SetPos( evolve.jailPos )
end
[/lua]
arrest_stick/shared.lua
[lua]
if JailSupport then
i = math.random(1,table.Count(JailPoses))
trace.Entity:SetPos(JailPoses[i])
else
trace.Entity:SetPos(evolve.jailPos)
end
[/lua]
Edit:
And including it where?
Do you have include( "jailpos.lua" ) in your gamemodes init.lua file?
OH I JUST NOTICED IT.
You need commas in your vectors, eg:
[lua]
Vector(-1901.9425 193.9865 -195.9688)
-- should be:
Vector(-1901.9425, 193.9865, -195.9688)
[/lua]
That would have prevented the file from loading and therefore JailPoses and JailSupport would be nil.
Oh! I'll test that now, thanks!
[editline]25th December 2011[/editline]
Brilliant! It work's perfectly, thanks!
Sorry, you need to Log In to post a reply to this thread.