What would be the best way to call functions from other files? I have a money system in one file and I'd like to be able to access its functions and variables.
For example:
in one file I have this:
function titlestuff(ply)
print(ply:Money_Get())
if ( ply:Money_Get() > CUSTOMTITLE_PRICE ) then
ply:Money_Take(CUSTOMTITLE_PRICE)
print("yes")
return true
else
print("not enough.")
return false
end
end
Which calls the "Money_Get()" function (in a different file) as seen here:
local pm = FindMetaTable("Player")
function pm:Money_Get() -- player:Money_Add = GET THE MONEY FOR A PLAYER
local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money
return current
end
However, when I try to use that I get this error:
[ERROR] addons/title_store/lua/autorun/server/sv_titlestore_chatcom.lua:90: attempt to index a string value with bad key ('Money_Get' is not part of the string library)
1. error - [C]:-1
2. __index - lua/includes/extensions/string.lua:297
3. titlestuff - addons/title_store/lua/autorun/server/sv_titlestore_chatcom.lua:90
4. func - addons/title_store/lua/autorun/server/sv_titlestore_chatcom.lua:104
5. unknown - lua/includes/extensions/net.lua:32
Thanks in advance for any help.
what you're doing is fine, but wherever you're using titlestuff, you're passing a string, while the function expects a player.
That was it, thank you so much!
Another question before I close this;
I use this to send stuff from the client to the server:
net.Start("ts_shekelberg")
net.WriteString(clSelectPlayer:GetSelected())
net.WriteEntity(LocalPlayer())
net.WriteString(cltitleEntry:GetValue())
net.WriteString(cltitleAnimation:GetSelected())
net.WriteVector(Vector(clmixer:GetColor().r,clmixer:GetColor().g,clmixer:GetColor().b))
PrintTable(clmixer:GetColor())
net.SendToServer()
and it receives it like this:
net.Receive("ts_shekelberg", function(len,ply)
local ply = net.ReadString()
local pl = net.ReadEntity()
print(pl)
local result = titlestuff(pl)
if (result == true) then
for k,v in pairs(player.GetAll()) do
if v:Nick() == ply then
local steamid = v:SteamID64()
player.GetBySteamID64(steamid):TitleStore_JSON_RemoveData()
local text = net.ReadString()
local anim = net.ReadString()
local color = net.ReadVector()
local saveTable = {id = steamid, title = text, animation = anim, color = color}
player.GetBySteamID64(steamid):TitleStore_JSON_InsertData(saveTable)
break
end
end
end
end)
how come "pl" is a null object? I've used "net.WriteEntity(LocalPlayer())" to send the player info to the server, why does it not work in this instance?
Don't write local player, it's already in callback arguments (net.Receive("ts_shekelberg", function(len, ply))
Sorry, you need to Log In to post a reply to this thread.