Skip to content

Instantly share code, notes, and snippets.

@nijikokun
Created July 24, 2011 05:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nijikokun/1102299 to your computer and use it in GitHub Desktop.
Save nijikokun/1102299 to your computer and use it in GitHub Desktop.
Roll the dice for Minecraft RubyBukkit, TF2 style. [VERSION 0.13] (Toxic coming soon...)
# Boring information.
# Its made by @Nijikokun <nijikokun@shortmail.com>
# Copyright (2011)
# AOL License <http://aol.nexua.org>
Plugin.is {
name "Roll The Dice"
main "RTD"
version "0.1"
author "Nijikokun"
commands :rtd => {
:usage => "/rtd - Roll out~"
}
}
# Importing?!
# Eets cheeper.
import 'org.bukkit.Location'
import 'org.bukkit.event.Event'
import 'org.bukkit.event.entity.EntityDamageByEntityEvent'
import 'org.bukkit.event.entity.EntityDamageEvent'
import 'org.bukkit.util.Vector'
import 'org.bukkit.ChatColor'
# Use Permissions?
# OHCOURSE.
require 'bukkit/permissions'
# Randomizer for Array
# Oh yeah, I just altered Arrays for ruby.
# Amazing!
class Array
# Pick ticket?
# Nope just a random amount from the list.
# Oh, just one please.
# Not yet, later on.
def pick(number)
# Oh you sorted them for me.
# Haha. Kinda?
# Why are they randomly sorted!? AAAAHHHHHH
# Tehe.
selected = sort_by{ rand }.slice(0...number)
# Array shmay.
# We want what the object is!
return selected[0]
end
end
# Lets add our randomizer to Hashes
# No not drugs! Dictionaries! Learn!
class Hash
@keys_used = []
# Picking one, not multiple this time!
# Make life easier!
def pick
@keys_used = [] if @keys_used.size == self.size
key = self.keys[rand(self.size)]
while @keys_used.include?(key)
key = self.keys[rand(self.size)]
end
@keys_used << key
return key
end
end
# RTD stands for
# Random tangent dice.
# Just kidding, it stands for "Roll the dice!"
# Thats what this plugin is about.
class RTD < RubyPlugin
def initialize
# Empty victim, sigh.
@victim = nil
# Is it running?
@running = false
# How long it done been since dis started?
@duration = nil
# This is for tasks, cause we gotta have a timer.
@task = nil
# Verdict, its kinda needed ya kno?
@verdict = nil
# Casualties, none yet -cries-
@casualties = nil
# Roll variables, Sometimes.
@variables = {
'enabled' => true, # Is the plugin enabled?
'timeout' => 120, # Time between rolls, 0 for no timeout.
'interval' => 5, # Interval for certain things, in ticks.
'duration' => 60, # Duration of effects, in ticks.
'reward' => 0.5, # Chance to get a reward and not a bad roll, 0 .. 1 ( 0 = never, inbetween = chance, 1 = always)
'launch' => 50, # Rocket distance, Between 2 & x
'health' => 5, # Health Gain, Between 1 & x
'eject' => 10, # Ejection distance, Between 2 & x
'poison' => 0.5, # Hearts to take away at a x tick interval
'crit' => 0.3, # Chance to crit, 0 .. 1 ( 0 = never, inbetween = chance, 1 = always)
'amount' => 5, # Hit amount, 1 -> 5
'god' => 1, # Allow godmode?
'cloak' => 1, # Allow invisibility / sneaking?
'shock' => 1, # Allow shocking?
'freeze' => 1, # Allow freezing?
'bomb' => 8, # Time for bombing, Between 1 & x
'power' => 4, # Power of the bomb, 1-4, 0 for no power.
'toxic' => 0.5, # Amount of hearts to take if a player touches someone with toxicity
'slide' => 1 # Allow sliding?
}
# Rewards, oh this is gonna be good.
@rewards = [ 'god', 'cloak', 'health', 'crit' ]
# What these are bad?! OH GOD.
@consequences = [ 'freeze', 'shock', 'bomb', 'poison', 'eject', 'launch', 'slide' ]
# We need some messages!
@messages = {
:empty => "`rWhoops, nobody around to target!",
:running => "`yPlease wait for RTD to cool down before using again!",
:freeze => "`bYou have been frozen for %s seconds.",
:cloak => "`sYou are now invisible for the next `w%s`s seconds.",
:shock => "`YBPPTTZZZZ. `yA god throws lightning at you.",
:toxic => "`pYou are now toxic to the touch, poison everyone!",
:poison => "`pYou were forced to drink poison, idiot!",
:health => "`gPower floods your viens, health rises!",
:eject => "`sFLY YOUNG PADOWAN. Oh wait you're human.",
:launch => "`sLAST FRONTIER? That wasn't the last rocket, you are!",
:god => "`YAll mighty for `y%s`Y seconds. Feels niec.",
:crit => "`gHit everything, you might just explode.",
:bomb => "`rT-minus `R%s`r seconds until explosion.",
:expire => "`SThe effects from the dice slowly fade away...",
:slide => "`bEverything is like ice, whats going on!?"
}
end
# Enable this plugin
# Are we even sure that was to want to do this?
def onEnable
# Can I get some privacy here?
# Move and I know?
# GAH.
registerEvent(Event::Type::PLAYER_MOVE, Event::Priority::Normal) {
|move|
# Pfft, no victim? Boring.
if @victim == nil then
return true
end
# Oh we have one? Dericious.
player = move.getPlayer;
# So i herd u were mah victim.
if player.getName == @victim.getName then
# In that case.. OHOHOH.
case @verdict
# Are u frozen? Must be hard.
when "freeze"
from = move.getFrom
move.setTo(from)
return false
# Just realized both of these relate to cold / ice.
# Nice.
when "slide"
player.setVelocity(player.getLocation.getDirection.multiply(0.5).setY(0));
end
end
# GO AWAY. Okay... you can stay.
true
}
# Registered sex damager.
# Oh nevermind, this is what damage does.
# Sometimes.
registerEvent(Event::Type::ENTITY_DAMAGE, Event::Priority::Normal) {
|damaged|
# We don't want no posers!~
if @victim == nil or @verdict != "crit" then
return true
end
# This is confusing, don't stare or your brain will melt.
if damaged.cause == EntityDamageEvent::DamageCause::ENTITY_ATTACK then
e = damaged.to_java(EntityDamageByEntityEvent)
if e.getDamager.java_kind_of?(Java::OrgBukkitCraftbukkitEntity::CraftPlayer) then
player = e.getDamager.to_java(Java::OrgBukkitCraftbukkitEntity::CraftPlayer)
if player.name == @victim.name then
if @verdict == "crit" then
if @variables['crit'] > rand then
damaged.damage = damaged.damage * rand(@variables['amount'])
end
end
end
end
end
# Huge end line?
# Then true?
# confusing++
true
}
print "[" + description.name + "] " + description.main + " enabled."
end
# Sorry, that was a joke, we are actually disabling it.
# Heh, that was too, I should stop.
def onDisable
print "[" + description.name + "] was disabled."
end
# Commander!
# Yes?
# Not you! On Commander!
# Oh yes?
# Tell us what they said!
def onCommand(sender, command, label, args)
if !@variables['enabled'] then
return true
end
# Lets make everyone get in a group.
# Nobody should be forever alone.
# Share the soup!
if getServer.getOnlinePlayers.length > 0 then
players = getServer.getOnlinePlayers.to_a
end
# Is it a player?
# Yes!
# Well do they have (x) ?
# I don't know yet, I'm a comment!
if !sender.isPlayer || sender.has("rubybukkit.rtd") then
# If it's already running, then we don't want to start it up again.
# Overload anyone?
if @running then
sender.sendMessage @messages[:running]
return true
end
# Nobody around? That's kind of sad.
# Hopefully it gets better...
if players == nil then
sender.sendMessage colorize(@messages[:empty])
return true
end
# Fetch only one of those bad boys, or good girls!
@victim = players.pick( 1 )
# Oh the suspense!
@verdict = roll
# Debugging ~
# Removing them bugs.
# sender.sendMessage @verdict + " - " + @victim.name
# Setup that duration!
# Hope you can run!
@duration = @variables['duration']
# Check those timing buddies
case @verdict
# One time I was a god..
# That ended fast.
when "god"
@victim.sendMessage colorize(@messages[:god] % @duration.to_s)
@victim.setHealth(200)
@task = scheduleSyncRepeatingTask(0, @variables['interval'] * 10) {
if @victim == nil then
return false
end
@victim.setHealth(200)
@duration = @duration - @variables['interval']
reset
}
scheduleSyncDelayedTask((@variables['duration'] - 2) * 10) {
@victim.setHealth(20)
}
# Cloaks? Like in harry po...
# IM SORRY MASTAH I WONT SAY IT AGAIN!
when "cloak"
@victim.sendMessage colorize(@messages[:cloak] % @duration.to_s)
@victim.setSneaking(true)
scheduleSyncDelayedTask((@variables['duration'] - 2) * 10) {
if @victim == nil then
return false
end
@victim.setSneaking(false)
}
# Slip n Slide
# Just don't go face first!
when "slide"
@victim.sendMessage colorize(@messages[:slide])
# HAHAHAHA IM THOR.
# AND YOU ARE A HUMAN.
# TAKE MY LIGHTNING WH.. oh sorry pg 13.
when "shock"
@victim.sendMessage colorize(@messages[:shock])
@victim.getWorld.strikeLightning(@victim.getLocation)
# Don't drink or eat this in real life!
# It will kill you.
when "poison"
@victim.sendMessage colorize(@messages[:poison])
@task = scheduleSyncRepeatingTask(0, @variables['interval'] * 10) {
if @victim == nil then
return false
end
@victim.setHealth(@victim.getHealth - @variables['poison'])
@duration = @duration - @variables['interval']
reset
}
# This should be good!
when "health"
@victim.sendMessage colorize(@messages[:health])
@task = scheduleSyncRepeatingTask(0, @variables['interval'] * 10) {
if @victim == nil then
return false
end
@victim.setHealth(@victim.getHealth + rand(@variables['health']))
@duration = @duration - @variables['interval']
reset
}
# Don't try this at home.
when "bomb"
till = rand(@variables[@verdict])
@victim.sendMessage colorize(@messages[:bomb] % till.to_s)
scheduleSyncDelayedTask(till * 10) {
@victim.getWorld.createExplosion(@victim.getLocation, @variables['power']);
}
# Or this, in an moving vehicle.
# That was a bad day.
when "eject"
@victim.sendMessage colorize(@messages[:eject])
@victim.setVelocity(Vector.new(rand * 5 - 2.5, rand * 5, rand * 5 - 2.5))
# This is what we call "Rocket Science"
when "launch"
@victim.sendMessage colorize(@messages[:launch])
@victim.setVelocity(Vector.new(0, 50, 0))
# Stop. Hammer Time.
# Oh wait, minecraft doesn't have those... Diamond time.
when "freeze"
@victim.sendMessage colorize(@messages[:freeze] % @duration.to_s)
end
# Just some boring tasks.
# Repetitive coding. Boring.
if @task == nil then
@task = scheduleSyncRepeatingTask(0, 10) {
if @duration != nil
@duration = @duration - 1
end
reset
}
end
# Whattt time out? Not again!
if @variables['timeout'] != 0 then
# Initialize dat we have started!
@running = true
# This is for when we timeout.
scheduleSyncDelayedTask(@variables['timeout'] * 10) {
@running = false
}
end
end
# Truefax.
# Always need these.
true
end
# INTERDASTING TECHNOLOGY
# RESET IN 2011?
def reset
if @duration == nil or @duration <= 0 then
self.cancelTask(@task)
if !["bomb", "launch", "eject", "shock"].include?(@verdict) then
@victim.sendMessage colorize(@messages[:expire])
end
@variables['enabled'] = true
@victim = nil
@verdict = nil
@duration = nil
end
end
# Oh here is where alignment comes from.
# I was going down the right road all along.
def alignment
if @variables['reward'].to_f > rand then
return true
end
# You don't want this.
# I mean it.
return false
end
# I wonder what this does?
# I have no clue. Yet.
def roll
# By default it's going to be bad!
good = alignment
# Nothing is chosen, yet.
# Dear lord, let it be good.
chosen = nil
# Oh this looks nice
if good then
# Oh yes, this looks really nice.
chosen = @rewards.pick( 1 )
else
# NO NO NO.
# BAD.
chosen = @consequences.pick( 1 )
end
# We only need a true variable!
# None of them posers!
if @variables[chosen] != 0 then
return chosen
end
# ROLL OUT~
return roll
end
# OMG COLORS
# SO BRIGHT, SO BEAUTIFUL
# RAINBOWWWZZZZZZ AMG>
def colorize(s)
map = {
'`r' => ChatColor::RED,
'`R' => ChatColor::DARK_RED,
'`y' => ChatColor::YELLOW,
'`Y' => ChatColor::GOLD,
'`g' => ChatColor::GREEN,
'`G' => ChatColor::DARK_GREEN,
'`c' => ChatColor::AQUA,
'`C' => ChatColor::DARK_AQUA,
'`b' => ChatColor::BLUE,
'`B' => ChatColor::DARK_BLUE,
'`p' => ChatColor::LIGHT_PURPLE,
'`P' => ChatColor::DARK_PURPLE,
'`s' => ChatColor::GRAY,
'`S' => ChatColor::DARK_GRAY,
'`w' => ChatColor::WHITE,
'`k' => ChatColor::BLACK,
}
map.each do|i,v|
s = s.gsub(i, v.to_s)
end
s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment