Last active
November 26, 2016 02:42
-
-
Save livibetter/aefdadcc87cd8dedb499d18af22f2625 to your computer and use it in GitHub Desktop.
cheating in the Battle for Wesnoth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Cheating script for the Battle for Wesnoth | |
-- By Yu-Jie Lin | |
-- | |
-- Created at 2016-11-16T05:06:--Z | |
-- Updated at - | |
-- Gist at https://gist.github.com/livibetter/aefdadcc87cd8dedb499d18af22f2625 | |
-- Written w/ Wesnoth 1.12.5 | |
-- | |
-- Placed in the public domain, if applicable, | |
-- otherwise licensed under the UNLICENSE license. | |
-- | |
---------------------------------------- | |
-- | |
-- I am not a Lua coder and not familiar with Wesnoth's environment, this is a | |
-- script I managed to write, any changes are most likely better solutions and | |
-- definitely welcome. | |
-- | |
---------------------------------------- | |
-- | |
-- Store this file at, for example, with Version 1.12.X on Linux: | |
-- | |
-- ~/.local/share/wesnoth/1.12/data/add-ons/cheats.lua | |
-- | |
-- Run the following command with Debug on: | |
-- | |
-- :lua wesnoth.dofile "~add-ons/cheats.lua" | |
-- | |
-- Press [r] to reload this script after every reload. | |
-- | |
---------------------------------------- | |
-- | |
-- Functions in Cheat Menu, using [c] key: | |
-- | |
-- 1. Cheating | |
-- | |
-- A. Leaders and loyal units of the current side will have: | |
-- | |
-- a. hitpoints and max_hitpoints set to 999, if max_hitpoints < 999, | |
-- otherwise reset to max_hitpoints, | |
-- b. attacks_left and max_attacks set to 999, | |
-- c. cures to poison and petrified. | |
-- | |
-- B. Allied leaders of current side will have: | |
-- | |
-- a. hitpoints set to 999 if max_hitpoints < 999, otherwise reset to | |
-- max_hitpoints, | |
-- b. cures to poison and petrified. | |
-- | |
-- 2. Windsong Recruiter | |
-- | |
-- Your side have joined the Windsong Foundation, and girl snatchers are | |
-- working hard to recruit for your cause. | |
-- | |
-- 3. Broken Enemies | |
-- | |
-- All enemies of the current side will be so broken. | |
-- | |
-- 4. Forest Gump (Selected Unit) | |
-- | |
-- The currently selected unit could run like Forest Gump, moves set to | |
-- 999. | |
-- | |
-- 5. Beef Up (Selected Unit) | |
-- | |
-- The currently selected unit will be beefed up like in 1.A. | |
-- u999: user with 999 values | |
local function u999(u) | |
u.moves = u.max_moves | |
-- u.max_* are readonly, but :unit max_* are not. | |
-- must use modify_unit to change max_*'s values. | |
wesnoth.fire("modify_unit", {{"filter", {x=u.x, y=u.y}}, max_attacks=999}) | |
u.attacks_left = 999 | |
if u.max_hitpoints < 999 then | |
wesnoth.fire("modify_unit", {{"filter", {x=u.x, y=u.y}}, max_hitpoints=999}) | |
end | |
u.hitpoints = u.max_hitpoints | |
cure(u) | |
end | |
function cure(u) | |
u.status.petrified = nil | |
u.status.poisoned = nil | |
end | |
-- c: cheating | |
function c() | |
for _, u in ipairs(wesnoth.get_units()) do | |
if u.side == wesnoth.current.side then | |
wesnoth.fire("store_unit", {variable="my_unit", {"filter", {id=u.id}}}) | |
-- no .upkeep in proxy unit in earlier than 1.13.5 | |
local upkeep = wesnoth.get_variable("my_unit[0].upkeep") | |
wesnoth.set_variable("my_unit", nil) | |
if u.canrecruit or upkeep == "loyal" then | |
u999(u) | |
else | |
u.hitpoints = u.max_hitpoints | |
cure(u) | |
end | |
elseif not wesnoth.is_enemy(wesnoth.current.side, u.side) | |
and u.canrecruit then | |
if u.max_hitpoints < 999 then | |
u.hitpoints = 999 | |
else | |
u.hitpoints = u.max_hitpoints | |
end | |
cure(u) | |
end | |
end | |
end | |
-- wr: Windsong Recruiter | |
function wr() | |
for _, u in ipairs(wesnoth.get_units({canrecruit=false, gender="female"})) do | |
if wesnoth.is_enemy(wesnoth.current.side, u.side) then | |
u.side = wesnoth.current.side | |
end | |
end | |
end | |
-- be: Broken Enemies | |
function be() | |
local sides = wesnoth.get_sides({ | |
{"has_unit", {canrecruit=true}}, | |
{"enemy_of", {side=wesnoth.current.side}} | |
}) | |
for _, s in ipairs(sides) do | |
s.gold = -99999 | |
end | |
end | |
-- fg: Forest Gump | |
function fg() | |
local u = wesnoth.get_displayed_unit() | |
if u then | |
u.moves = 999 | |
end | |
end | |
-- bu: Beef Up | |
function bu() | |
local u = wesnoth.get_displayed_unit() | |
if u then | |
u999(u) | |
end | |
end | |
-- cm: Cheat Menu | |
function cm() | |
local helper = wesnoth.require "lua/helper.lua" | |
local result = helper.get_user_choice({speaker = "narrator"}, { | |
"Cheating", | |
"Windsong Recruiter", | |
"Broken Enemies", | |
"Forest Gump (Selected Unit)", | |
"Beef Up (Selected Unit)" | |
}) | |
if result == 1 then | |
c() | |
elseif result == 2 then | |
wr() | |
elseif result == 3 then | |
be() | |
elseif result == 4 then | |
fg() | |
elseif result == 5 then | |
bu() | |
end | |
end | |
wesnoth.fire("set_menu_item", { | |
id="cm00", | |
description="Reload Cheats", | |
{"default_hotkey", {key="r"}}, | |
{"command", {{"lua", { | |
code='wesnoth.clear_messages(); wesnoth.dofile "~add-ons/cheats.lua"' | |
}}}} | |
}) | |
wesnoth.fire("set_menu_item", { | |
id="cm01", | |
description="Cheat Menu", | |
{"default_hotkey", {key="c"}}, | |
{"command", {{"lua", {code='cm()'}}}} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <http://unlicense.org/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment