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.
To install rtd in your gamemode:
-
Copy rollthedice/ into your game/scripts/vscripts/libraries folder
-
Copy game/scripts/vscripts/lua_rtd/ to the same spot in your gamemode
-
Copy game/scripts/rtd/ to the same spot in your gamemode
-
Copy game/resource/flash3/images/spellicons/holdout_guardian_angel to the same spot in your gamemode. This is the texture for the RTD buff.
-
In addon_game_mode.lua initialize it with the following BEFORE require('events.lua')
require ('libraries/rollthedice/rollthedice')
-
In events.lua under GameMode:OnPlayerChat(keys) call
rollthedice:OnPlayerChat(keys, playerID)
and rollthedice will take care of the rest!
The main configuration files are rollthedice_results.txt and rollthedice_modifiers.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
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.
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 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" } } } } } } }
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>!"
}
}
rollthedice.lua respects:
RTD_COOLDOWN = 60 -- cooldown between using rtd