generated from TShockResources/PluginTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,84 @@ | ||
# PluginTemplate | ||
# Average's Simple Economy | ||
Support me & this plugin's (along with several others) development on Ko.Fi: [Here!](https://ko-fi.com/averageterraria) | ||
|
||
This repository acts as a baseline plugin to allow you to quickly and easily create new TShock plugins. | ||
A super simple and lightweight tShock V5 plugin. This serves as a framework(ish) where other plugin developers can utilize this plugin to integrate a form of economy. There are also a few commands that this plugin implements. Everything you will need to know will be listed here! If I have missed anything, contact me on Discord: Average#1305| /bal |Shows the player's balance |/gen (option) [number required] [specific type of certain option] | se.user | | ||
|
||
# Plugin Development | ||
### Notes | ||
- SQLite is currently the only usable DB type. If your TShock server utilizies MySQL, you are currently out of luck (this will be changed soon, however) | ||
- Balances are stored in `tshock/SimpleEcon.sqlite` | ||
|
||
For more information on TShock plugin development feel free to visit the [TShock forums](https://tshock.co/xf/index.php), the [TShock ReadMe](https://tshock.readme.io/docs/) or the official [TShock Discord](https://discordapp.com/invite/zMsNNb). | ||
## Config Explained | ||
(tshock/SimpleEcon.json) | ||
|
||
```json | ||
{ | ||
"currencyNameSingular": "dollar", | ||
"currencyNamePlural": "dollars", | ||
"giveRewardsForPlaytime": false, | ||
"rewardtimer": 5 | ||
} | ||
|
||
``` | ||
All of this is extremely simple, and intuitive. `currencyNameSingular` and `currencyNamePlural` dictate what the currency will be called within this plugin, and others! | ||
|
||
`giveRewardsForPlaytime` will give the player a singular currency each time the `rewardTimer` goes off. To explain it better, if enabled, every <x> minutes (defined by `rewardTimer`), the player is given one currency! | ||
|
||
## Commands List | ||
|
||
| Command |Description |Usage |Permission | | ||
| ------------- |:-------------:| :-----:| :-----------:| | ||
| /bal |Shows the player's balance | /bal (Aliases: /eco, /balance) | se.user | | ||
| /baltop |Shows the top balances of the server | /baltop (Aliases: /ecotop, /top) | se.user | | ||
| /transfer |Takes money out of the user's account and sends it to another | /transfer `player` `quantity` (Alias: /pay) | se.user | | ||
| /givebal |**ADMIN COMMAND**: allows a user to modify the user's balance (use negative value to take away) | /givebal `player` `quantity` (Alias: /gbal) | se.admin | | ||
|
||
## Plugin Dev Implementations | ||
Simply add this plugin as a dependency for yours and you'll be able to use the following: | ||
|
||
### Retrieving a user's balance | ||
```c# | ||
|
||
//Retrieve a user balance: | ||
SimpleEcon.PlayerManager.GetPlayer(playerName).balance | ||
|
||
//Example - will check if user has certain amount | ||
var p = SimpleEcon.PlayerManager.GetPlayer(playerName).balance; | ||
|
||
if(SimpleEcon.PlayerManager.GetPlayer(playerName).balance >= 50) { | ||
// has enough | ||
}else{ | ||
// not enough | ||
} | ||
|
||
``` | ||
|
||
### Updating a user's balance | ||
```c# | ||
|
||
//Updating a user balance: | ||
SimpleEcon.PlayerManager.UpdatePlayerBalance(playerName, amount); | ||
|
||
//Example - will update a user balance to 5000 | ||
var pm = SimpleEcon.PlayerManager; | ||
|
||
pm.UpdatePlayerBalance("John Doe", 5000) | ||
//negative values ARE possible! | ||
``` | ||
|
||
### Getting currency name | ||
```c# | ||
|
||
//Getting the singular currency name | ||
SimpleEcon.SimpleEcon.config.currencyNameSingular; | ||
|
||
//Getting the plural currency name | ||
SimpleEcon.SimpleEcon.config.currencyNamePlural; | ||
|
||
//Example - send message to user on money update | ||
player.SendSuccessMessage($"The moderator {args.Player.Name} has manipulated your currency and given you {amount} {(amount == 1 ? config.currencyNameSingular : config.currencyNamePlural)}! Your new balance is: {PlayerManager.GetPlayer(player.Name).balance} {(PlayerManager.GetPlayer(player.Name).balance == 1 ? config.currencyNameSingular : config.currencyNamePlural)}"); | ||
|
||
``` | ||
|
||
### Some dev notes: | ||
- Currencies are stored as a float, so decimal values are possible. |