-
Notifications
You must be signed in to change notification settings - Fork 101
Attributes
Tomm edited this page Apr 7, 2019
·
5 revisions
Attributes are a way to store individual values for players and npcs.
If you need to save a value for a player or npc for later use, you would want to use an attribute.
Attributes are made up of two parts:
AttributeKey
AttributeMap
AttributeKey
s are defined in your plugin file and the AttributeMap
is stored for each player and can be accessed via player.attr
.
package gg.rsmod.plugins.content.minigames.pestcontrol
// If we want the attribute to save on log-out, we specify a name
// inside the AttributeKey. In this case, it'll be saved as
// "pc_win_count"
val GAME_WIN_COUNT = AttributeKey<Int>("pc_win_count")
fun inform_of_win_count(player: Player) {
val wins = player.attr.getOrDefault(GAME_WIN_COUNT, 0)
player.message("You have won $wins pest control games.")
}
fun set_win_count(player: Player, count: Int) {
player.attr[GAME_WIN_COUNT] = count
player.message("You now have $count pest control wins.")
}
Join the Discord if you have any questions or want to chat with the community
- User Guide