PivityGmodStore

[DarkRP] Setting up a Casino Manager

A casino manager can be a fun and interesting job to introduce to your community. Here I will show you how to give a specific job a cut of losses made with the casinos machines/tables. It is important to mention that pCasino does not support allowing jobs to make machines/tables, only take a cut from pre-existing ones.


First we must set up the job and file.

  1. You will first need to create a DarkRP job for the casino manager. There is nothing special to be done here, just a normal DarkRP job.
  2. Next you will need to create a file that we will use to input the code that makes it all work. This file can be put anywhere as long as it is loaded. For simplicity, we will be putting it inside the pCasino addon folder. specifically: pcasino/lua/perfectcasino/config. If your Lua knowledge is limited, it is suggested you also put it in there. If you place it inside of the pCasino folder, ensure that the file name format is as follows: sv_something.lua. For the sake of this tutorial, I will be calling it sv_manager.lua. You can also name it this.
  3. Next open the file, here is where we will be putting the code in order to have the casino manager receive the money.


Now we must give the casino managers money based on casino activity.

There are 3 different times you can give a casino manager money when the casino is being used:

  1. When a player places a bet
  2. When a player wins a bet
  3. When a player loses a bet

For the sake of simplicity, we will be giving the casino manager money only when a bet is lost. If you wish to give the casino manager on bet placing or bet wins, you can take a look at the documentation for those hooks here.

local function rewardManager(loser, game, originalBet) -- The function used to process the managers cut on bet losses
    local managers = team.GetPlayers(TEAM_CASINOMANAGER) -- Change TEAM_CASINOMANAGER to whatever the name of the job is you created.
    if table.Count(managers) == 0 then return end -- There are no managers online, no need to do anything


    for k, ply in ipairs(managers) do -- Loop all the managers
        PerfectCasino.Config.AddMoney(ply, math.Round(originalBet * 0.2)) -- Give each manager 20% of the original bet price.
    end
end


-- Link the rewardManager function to the loss hooks.
hook.Add("pCasinoOnBlackjackLoss", "CasinoManagerReward", rewardManager)
hook.Add("pCasinoOnRouletteLoss", "CasinoManagerReward", rewardManager)
hook.Add("pCasinoOnBasicSlotMachineLoss", "CasinoManagerReward", rewardManager)
hook.Add("pCasinoOnWheelSlotMachineLoss", "CasinoManagerReward", rewardManager)


-- We handle Poker slightly differently, given that players can win eachothers money.
hook.Add("pCasinoOnPokerRake", "CasinoManagerReward", function(table, rake)
    local managers = team.GetPlayers(TEAM_CASINOMANAGER) -- Change TEAM_CASINOMANAGER to whatever the name of the job is you created.
    if table.Count(managers) == 0 then return end -- There are no managers online, no need to do anything


    for k, ply in ipairs(managers) do -- Loop all the managers
        PerfectCasino.Config.AddMoney(ply, math.Round(rake * 0.8)) -- Give each manager 80% of the rake.
    end
 end)


Placing the above snippet in sv_manager.lua and change the team provided.


Finally, you should now have a working Casino Manager job.

Credit to VALERY for showing me team.GetPlayers even existed.

Can't find what you're looking for?

Contact support