//Polarity's RP script serverside //Define RP table RP = {} RP.Clients = {} //User changable vars RP.SyncInterval = 30 //How often to update clients. This only affects other players. The smaller the value, the more bandwidth used. RP.PaydayInterval = 300 //In seconds RP.PaydayAmount = 100 //This will become scaled with economy eventually RP.MoneyDropSize = 100 //Set this to whatever you like, it's a workaround for a bug I'll fix soon. //Stuff to load the script function RP.SetupScript() include('shared.lua') AddCSLuaFile("shared.lua") AddCSLuaFile("cl_init.lua") local allplayers = player.GetAll() for _, pl in pairs(allplayers) do if pl:IsConnected() then local userid = pl:UserID() RP.Clients[userid] = {} RP.Clients[userid].Name = pl:Name() RP.Clients[userid].Money = 0 RP.Clients[userid].Job = "Unemployed" end end hook.Add("PlayerInitialSpawn","RP_CreatePlayer",RP.CreatePlayer) hook.Add("PlayerSay","RP_ChatCommands",RP.ChatCommands) timer.Create("RP_SyncTables",RP.SyncInterval,0,RP.SyncTables) timer.Create("RP_Payday",RP.PaydayInterval,0,RP.Payday) RP.SyncTables() end function RP.CreatePlayer(pl) Msg("Polarity's RP: Player joined the game.\n") local userid = pl:UserID() RP.Clients[userid] = {} RP.Clients[userid].Name = pl:Name() RP.Clients[userid].Money = 0 RP.Clients[userid].Job = "Unemployed" RP.SyncTables() end function RP.ChatCommands(pl,message) local userid = pl:UserID() if string.sub(message,0,4) == "/job" then local job = string.sub(message,6,string.len(message)) RP.Clients[userid].Job = job RP.SyncTables() return nil elseif string.sub(message,0,5) == "/item" then RP.SpawnItem(pl,"item",0) RP.SyncTables() return nil else return message end end function RP.SyncTables() local allplayers = player.GetAll() for _, pl in pairs(allplayers) do local userid = pl:UserID() if pl:IsConnected() then pl:SendLua("RP.Client.Name = \""..RP.Clients[userid].Name.."\"") pl:SendLua("RP.Client.Money = \""..RP.Clients[userid].Money.."\"") pl:SendLua("RP.Client.Job = \""..RP.Clients[userid].Job.."\"") end end end function RP.Payday() Msg("Polarity's RP: Starting payday loop\n") local allplayers = player.GetAll() for _, pl in pairs(allplayers) do local userid = pl:UserID() if RP.Clients[userid].Job != "Unemployed" then RP.Clients[userid].Money = RP.Clients[userid].Money + RP.PaydayAmount end end RP.SyncTables() Msg("Polarity's RP: Finished payday loop\n") end function RP.SpawnItem(pl,item,amount) local vStart = pl:GetShootPos() local vForward = pl:GetAimVector() local trace = {} trace.start = vStart trace.endpos = vStart + (vForward * 2048) trace.filter = pl local tr = util.TraceLine( trace ) local ent = ents.Create( item ) if ( !ent:IsValid() ) then return end ent:SetPos( tr.HitPos ) ent:Spawn() ent:Activate() end //LAUNCH FIGHTERS RP.SetupScript()