The Hidden Dice Plugin
This plugin lets a user roll dice in a message, but have the result hidden for everyone but him. Mostly used by DM's. To roll a hidden dice just use the curly backets insted of the squar brackets. eg. {1d20+5}
import os
import re
import orpg.pluginhandler
class Plugin(orpg.pluginhandler.PluginHandler):
# Initialization subroutine.
#
# !self : instance of self
# !openrpg : instance of the the base openrpg control
def __init__(self, openrpg, plugindb, parent):
orpg.pluginhandler.PluginHandler.__init__(self, openrpg, plugindb, parent)
# The Following code should be edited to contain the proper information
self.name = 'Hidden Dice'
self.author = 'mDuo13'
self.help = 'Roll with curly brackets to hide your roll,\n'
self.help += 'having it display only for you. Other players will\n'
self.help += 'get a message that only says you are rolling.\n'
self.help += 'Useful for GMs who want to roll secretly.'
#You can set variables below here. Always set them to a blank value in this section. Use plugin_enabled
#to set their proper values.
self.hiddenrolls = []
self.dicere = "\{([0-9]*d[0-9]*.+)\}"
def plugin_enabled(self):
pass
def plugin_disabled(self):
pass
def pre_parse(self, text):
print self.dicere
m = re.search(self.dicere, text)
while m:
roll = "[" + m.group(1) + "]"
if text[0]=="/":#it won't be caught by the "post_msg" parser
self.chat.Post("<b>Hidden Roll</b>: " + self.chat.ParseDice(roll))
else:
self.hiddenrolls += [self.chat.ParseDice(roll)]
text = text[:m.start()] + "(hidden roll)" + text[m.end():]
m = re.search(self.dicere, text)
return text
def send_msg(self, text, send):
#This is called when a message is about to be sent out.
#It covers all messages sent by the user, before they have been formatted.
#If send is set to 0, the message will not be sent out to other
#users, but it will still be posted to the user's chat normally.
#Otherwise, send defaults to 1. (The message is sent as normal)
return text, send
def plugin_incoming_msg(self, text, type, name, player):
#This is called whenever a message from someone else is received, no matter
#what type of message it is.
#The text variable is the text of the message. If the type is a regular
#message, it is already formatted. Otherwise, it's not.
#The type variable is an integer which tells you the type: 1=chat, 2=whisper
#3=emote, 4=info, and 5=system.
#The name variable is the name of the player who sent you the message.
#The player variable contains lots of info about the player sending the
#message, including name, ID#, and currently-set role.
#Uncomment the following line to see the format for the player variable.
#print player
return text, type, name
def post_msg(self, text, myself):
c = 0
a = text.find("(hidden roll)")
while len(self.hiddenrolls) > c and a > -1 and myself:
text = text[:a+14].replace("(hidden roll)", self.hiddenrolls[c]) + text[a+14:]
a = text.find("(hidden roll)")
c += 1
if c > 0:
self.hiddenrolls = []
return text
def refresh_counter(self):
#This is called once per second. That's all you need to know.
pass
OpenRPG WIKI - separate login required