Hi there everybody!
So I'm basically trying to create an time-experience system where every minute you play as either a criminal or hero job, you get a +1 experience in either path.
I have no idea how player stored vars work so please someone help me out
This is what I just scratched up I don't even know if it works, please let me know what I'm doing and not doing, cheers.
[CODE]
local clock = os.clock
function sleep(n) -- seconds
local t0 = clock()
while clock() - t0 <= n do end
end
function PLAYER:SetupDataTables()
self.Player:NetworkVar("Int", 0, "CriminalExperience" )
self.Player:NetworkVar("Int", 0, "HeroExperience" )
if SERVER then
hook.add("OnPlayerChangedTeam", "InitXPGain", function()
while after == TEAM_THUG or after == TEAM_MOBSTER do
sleep(60)
self:SetCriminalExperience((self:CriminalExperience + 1))
end
while after == TEAM_POLICE or after == TEAM_SWAT do
sleep(60)
self:SetHeroExperience((self:HeroExperience + 1))
end
end
end[/CODE]
I dont know what "after" is but I think it should be :
[CODE]
while getDarkRPVar("job") == "Thug" or getDarkRPVar == "Mobster" do
end
-- OR, easier path --
CriminalJobs = {
"Mobster",
"Thug",
}
while getDarkRPVar("job") == CriminalJobs do
BLAH BLAH
end
[/CODE]
[QUOTE=ZeroToHero;52564959]I dont know what "after" is but I think it should be :
[CODE]
while getDarkRPVar("job") == "Thug" or getDarkRPVar == "Mobster" do
end
-- OR, easier path --
CriminalJobs = {
"Mobster",
"Thug",
}
while getDarkRPVar("job") == CriminalJobs do
BLAH BLAH
end
[/CODE][/QUOTE]
after is an arg of OnPlayerChangedTeam, but yeah I like your method better, and what do you think about the datatables stuff?
It should work fine
Also, the sleep function will just crash the server. You should use instead timers, as of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Simple]timer.Simple[/url]
[editline]12th August 2017[/editline]
And so will the "while" function you've got there. You have to find another way of approaching this without using loops like that. They may work in normal Lua, but not in gmod. In Gmod it will just crash the engine.
[QUOTE=geferon;52565033]Also, the sleep function will just crash the server. You should use instead timers, as of [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Simple]timer.Simple[/url]
[editline]12th August 2017[/editline]
And so will the "while" function you've got there. You have to find another way of approaching this without using loops like that. They may work in normal Lua, but not in gmod. In Gmod it will just crash the engine.[/QUOTE]
But regarding everything else?, it should work right?
Sorry, you need to Log In to post a reply to this thread.