GiveCash
GiveCash
Hello,
Another plugin request
I would like a plugin which give money each round. If a file can store the amount to give and a sentence, it will be better
Thanks you
Another plugin request
I would like a plugin which give money each round. If a file can store the amount to give and a sentence, it will be better
Thanks you
Are there any criteria for which players to give money to or is it just give all players the same amount every round? Do you want to set every player's cash to the value or just give them this amount extra each round? By sentence, you mean that it will print a message in chat every round to let each player know they were given cash?
The following is based off of the idea that every player gets the same amount every round, the answer to the second question is 'add cash', and that the answer to the last question is 'yes'.
The location of the 2 files are in the top line comment of each syntax block. Replace <plugin_name> with whatever you name the plugin. Make sure to replace that actual value in the ConfigManager and LangStrings lines so that it creates the config file properly and gets the proper translation file. Then, once you have loaded the plugin once, you can change the value in the ../cfg/source-python/<plugin_name>.cfg file which will take effect when loading the plugin. You can also use the round_cash_amount cvar anytime in the server console or with rcon to change its value live.
The following is based off of the idea that every player gets the same amount every round, the answer to the second question is 'add cash', and that the answer to the last question is 'yes'.
Syntax: Select all
# ../addons/source-python/plugins/<plugin_name>/<plugin_name>.py
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
# Config
from config.manager import ConfigManager
# Cvars
from cvars.flags import ConVarFlags
# Events
from events import Event
# Filters
from filters.players import PlayerIter
# Messages
from messages import SayText2
# Translations
from translations.strings import LangStrings
# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
# Get the translation strings
config_strings = LangStrings('<plugin_name>')
# Get the message to send
message = SayText2(message=config_strings['chat'])
# =============================================================================
# >> CONFIGURATION
# =============================================================================
# Create the config file
with ConfigManager('<plugin_name>') as config:
# Create the cash amount convar
cash_amount = config.cvar(
'round_cash_amount', 100, ConVarFlags.NONE,
'Amount of cash to add to each player at the start of each round.')
# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('round_start')
def give_cash(game_event):
# Get the cash amount
amount = cash_amount.get_int()
# Loop through all living players
for player in PlayerIter('alive', return_types='player'):
# Give the current player the cash amount
player.cash += amount
# Send the message to all players
message.send(amount=amount)
Syntax: Select all
# ../resource/source-python/translations/<plugin_name>.ini
[chat]
en = "You were given $$$amount."
The location of the 2 files are in the top line comment of each syntax block. Replace <plugin_name> with whatever you name the plugin. Make sure to replace that actual value in the ConfigManager and LangStrings lines so that it creates the config file properly and gets the proper translation file. Then, once you have loaded the plugin once, you can change the value in the ../cfg/source-python/<plugin_name>.cfg file which will take effect when loading the plugin. You can also use the round_cash_amount cvar anytime in the server console or with rcon to change its value live.
Change:
To:
Will make it so no matter the situation, when cash is given that the player's cash will never exceed $16000.
Syntax: Select all
player.cash += amount
To:
Syntax: Select all
player.cash = min(player.cash+amount, 16000)
Will make it so no matter the situation, when cash is given that the player's cash will never exceed $16000.
Predz wrote:Change:Syntax: Select all
player.cash += amount
To:Syntax: Select all
player.cash = min(player.cash+amount, 16000)
Will make it so no matter the situation, when cash is given that the player's cash will never exceed $16000.
I tried it but it gives me $17.000...
This is the code :
Syntax: Select all
# ../addons/source-python/plugins/GiveCash/GiveCash.py
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
# Config
from config.manager import ConfigManager
# Cvars
from cvars.flags import ConVarFlags
# Events
from events import Event
# Filters
from filters.players import PlayerIter
# Messages
from messages import SayText2
# Translations
from translations.strings import LangStrings
# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
# Get the translation strings
#config_strings = LangStrings('GiveCash')
# Get the message to send
#message = SayText2(message=config_strings['chat'])
# =============================================================================
# >> CONFIGURATION
# =============================================================================
# Create the config file
with ConfigManager('GiveCash') as config:
# Create the cash amount convar
cash_amount = config.cvar(
'round_cash_amount', 100, ConVarFlags.NONE,
'Amount of cash to add to each player at the start of each round.')
# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('round_start')
def give_cash(game_event):
# Get the cash amount
amount = cash_amount.get_int()
# Loop through all living players
for player in PlayerIter('alive', return_types='player'):
# Give the current player the cash amount
player.cash += min(player.cash+amount, 16000)
# Send the message to all players
message.send(amount=amount)
Take a closer look at the code posted by Predz. This is what he suggested:And this is what you have done:There is a little difference between both versions.
Syntax: Select all
player.cash = min(player.cash+amount, 16000)
Syntax: Select all
player.cash += min(player.cash+amount, 16000)
This is the new code, with the correction :
And it doesn't work anymore. Someone has tested the plugin? Or it's just me??
Syntax: Select all
# ../addons/source-python/plugins/GiveCash/GiveCash.py
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
# Config
from config.manager import ConfigManager
# Cvars
from cvars.flags import ConVarFlags
# Events
from events import Event
# Filters
from filters.players import PlayerIter
# Messages
from messages import SayText2
# Translations
from translations.strings import LangStrings
# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
# Get the translation strings
config_strings = LangStrings('GiveCash')
# Get the message to send
message = SayText2(message=config_strings['chat'])
# =============================================================================
# >> CONFIGURATION
# =============================================================================
# Create the config file
with ConfigManager('GiveCash') as config:
# Create the cash amount convar
cash_amount = config.cvar(
'round_cash_amount', 100, ConVarFlags.NONE,
'Amount of cash to add to each player at the start of each round.')
# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('round_start')
def give_cash(game_event):
# Get the cash amount
amount = cash_amount.get_int()
# Loop through all living players
for player in PlayerIter('alive', return_types='player'):
# Give the current player the cash amount
player.cash = min(player.cash+amount, 16000)
# Send the message to all players
message.send(amount=amount)
And it doesn't work anymore. Someone has tested the plugin? Or it's just me??
I would recommend changing the message so that it shows the actual amount the player gains (or that they are already maxed out). Other than that, it looks like it should work fine to me.
Try this:
Try this:
Syntax: Select all
# ../addons/source-python/plugins/GiveCash/GiveCash.py
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
# Config
from config.manager import ConfigManager
# Cvars
from cvars.flags import ConVarFlags
# Events
from events import Event
# Filters
from filters.players import PlayerIter
# Messages
from messages import SayText2
# Translations
from translations.strings import LangStrings
# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
# Get the translation strings
message_strings = LangStrings('GiveCash')
# Store the give message instance
give_message = SayText2(message=message_strings['Give'])
# Store the max cash message instance
max_message = SayText2(message=message_strings['Max'])
# =============================================================================
# >> CONFIGURATION
# =============================================================================
# Create the config file
with ConfigManager('GiveCash') as config:
# Create the cash amount convar
cash_amount = config.cvar(
'round_cash_amount', 100, ConVarFlags.NONE,
'Amount of cash to add to each player at the start of each round.')
# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('round_start')
def give_cash(game_event):
# Get the cash amount
amount = cash_amount.get_int()
# Loop through all living players
for player in PlayerIter('alive', return_types='player'):
# Get the amount to add to the current player
give_amount = min(player.cash + amount, 16000) - player.cash
# Does the player need any cash?
if give_amount:
# Give the current player the cash amount
player.cash += give_amount
# Send the give message to the player
give_message.send(player.index, amount=give_amount)
# Does the player already have max cash?
else:
# Send the max cash message to the player
max_message.send(player.index)
Syntax: Select all
# ../resource/source-python/translations/GiveCash.ini
[Give]
en = "You were given $$$amount."
[Max]
en = "You are already at max cash, none given."
Who is online
Users browsing this forum: No registered users and 34 guests