Giter VIP home page Giter VIP logo

rtd-example's Introduction

rtd-example

This is a gamemode to showcase the rtd command that you can put into your mods. RTD is a common command in counter-strike gamemodes that lets players "roll-the-dice" (with a cooldown) to get random modifiers like 15 seconds invunerability, max gold, negative gold, instant death, 30 seconds max speed, etc.

Barebones installation

To install rtd in your gamemode:

and rollthedice will take care of the rest!

Configuration

The main configuration files are rollthedice_results.txt and rollthedice_modifiers.txt.

rollthedice_results.txt

This file maps rolls to their respective results. Rolls are between 1 and 99 (inclusive). An example file is like so:

"RollTheDice"
{
  "Results"
  {
    "01" "rtd_nothing"
    "02" "rtd_nothing"
    ..omitted..
    "98" "rtd_nothing"
    "99" "rtd_nothing"
  }
}

This would map every roll to the modifier rtd_nothing, which would need to be defined in rollthedice_modifiers.txt

rollthedice_modifiers.txt

This file describes the results that are defined in rollthedice_results.txt. An example of the file with nothing defined would be:

"RollTheDice"
{
}

From here you can add modifiers in one of two ways: DataDriven or Lua. The datadriven option is not as comprehensive as datadriven abilities or items. You may specifiy "AbilitySpecial" like usual, and reference it in the normal fashion.

Lua Modifiers

A lua modifier will attach to a script file which must define a class that matches the name of the modifier in the global context. The class will be provided the context which rollthedice runs in, and rollthedice will strip the modifier from the global context once it has acquired it. The class may override or use the following functions:

-- Called when a player lands on this result. The player is guarranteed
-- to have selected a hero and be alive.
-- 
-- @param keys (table)
--   keys.playerid - the player id who got the result
function rtd_example:OnCreated( keys )

-- Returns the special value for the specified name.
--
-- @params name (string)
--   the name of the special value to find
function rtd_example:GetSpecialValueFor( name )

Example:

"RollTheDice"
{
  "rtd_example"
  {
    "BaseClass" "rtd_lua" // choices are rtd_datadriven or rtd_lua
    "ScriptFile" "scripts/vscripts/lua_rtd/rtd_example.lua"
    
    "AbilitySpecial"
    {
      "01"
      {
        "var_type" "FIELD_INTEGER"
        "duration" "10"
      }
    }
  }
}

with rtd_example.lua as

if not rtd_example then 
  rtd_example = class( {} )
end

function rtd_example:OnCreated( keys )
  local playerid = keys.playerid
  local hero = PlayerResource:GetSelectedHeroEntity( playerid )
  
  hero:AddNewModifier( hero, nil, 'modifier_kill', { Duration = self:GetSpecialValueFor('duration') } )
end

DataDriven modifiers

DataDriven modifiers may currently only apply a modifier to the player. This is done as follows:

Example:

"RollTheDice"
{
  "rtd_example"
  {
    "BaseClass" "rtd_datadriven" // choices are rtd_datadriven or rtd_lua
    
    "AbilitySpecial"
    {
      "01"
      {
        "var_type" "FIELD_INTEGER"
        "duration" "10"
      }
    }
    
    "Modifiers"
    {
      "01"
      {
        "OnCreated"
        {
          "ApplyModifier"
          {
            "ModifierName" "modifier_kill" // As if you were using AddNewModifier
            "Data" // This is passed as modifierData to AddNewModifier
            {
              "Duration" "%duration"
            }
          }
        }
      }
    }
  }
}

Localization

When a player rolls a specific result, the thing printed to everyone on the left menu (as if via SendCustomMessage) can be localized with the name of the modifier. The message will always be prefixed with the name of the player.

There are also a few other self-explanatory options:

addon_english.txt

"lang"
{
  "Language" "English"
  "Tokens"
  {
    "DOTA_Tooltip_modifier_rtd_timer" "RTD Timer"
    "DOTA_Tooltip_modifier_rtd_timer_Description" "Prevents using RTD"
    
    "rtd_alert_too_soon" "[RTD] You can't do that yet! Wait until the buff wears off."
    "rtd_alert_dead" "[RTD] You can only roll the dice while alive."
    "rtd_alert_no_selected_hero" "[RTD] You must have a hero selected to roll the dice."
    
    "rtd_example" "[RTD] You won <b>IMMINENT DEATH</b>!"
  }
}

Settings

rollthedice.lua respects:

RTD_COOLDOWN = 60 -- cooldown between using rtd

rtd-example's People

Contributors

tjstretchalot avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.