summaryrefslogtreecommitdiff
path: root/example/scripts/crafting.lua
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-02-26 23:28:43 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-03-02 18:12:17 +0100
commita36e231883d595bcba91d44e19f24b31eaf0431b (patch)
tree879aad2008eb3675153bb9912c4cc724253f87c6 /example/scripts/crafting.lua
parent34ac0d64e23f2b2d3981dbb0ea72157f334805dd (diff)
downloadmanaserv-a36e231883d595bcba91d44e19f24b31eaf0431b.tar.gz
manaserv-a36e231883d595bcba91d44e19f24b31eaf0431b.tar.bz2
manaserv-a36e231883d595bcba91d44e19f24b31eaf0431b.tar.xz
manaserv-a36e231883d595bcba91d44e19f24b31eaf0431b.zip
A bunch of cleanups to example Lua scripts
Mostly removed bulky copyright headers and fixed indentation and line length. Reviewed-by: Yohann Ferreira Reviewed-by: Erik Schilling
Diffstat (limited to 'example/scripts/crafting.lua')
-rw-r--r--example/scripts/crafting.lua44
1 files changed, 16 insertions, 28 deletions
diff --git a/example/scripts/crafting.lua b/example/scripts/crafting.lua
index eae26a41..54e8c9aa 100644
--- a/example/scripts/crafting.lua
+++ b/example/scripts/crafting.lua
@@ -1,17 +1,8 @@
--------------------------------------------------------------
--- Example crafting script file --
--- --
--- This file allows you to implement your own crafting --
--- system. --
-----------------------------------------------------------------------------------
--- Copyright 2011 Manasource Development Team --
--- --
--- This file is part of Manasource. --
--- --
--- Manasource is free software; you can redistribute it and/or modify it --
--- under the terms of the GNU General Public License as published by the Free --
--- Software Foundation; either version 2 of the License, or any later version. --
-----------------------------------------------------------------------------------
+--[[
+
+ This file provides an example of a simple crafting system.
+
+--]]
-- This function is called by the game engine when a character tries to craft
-- something from items in its inventory
@@ -19,10 +10,10 @@ function on_craft(ch, recipe)
-- ch is the crafting character
--
-- recipe is a table with the ingredients.
- -- it is a common 1-based array. each element of this array is a table with the
- -- two keys "id" and "amount".
- -- The engine has already checked that the character owns enough of those things,
- -- so you needn't do this again.
+ -- it is a common 1-based array. each element of this array is a table with
+ -- the two keys "id" and "amount".
+ -- The engine has already checked that the character owns enough of those
+ -- things, so you needn't do this again.
-- uncomment one (but not both!) of the following three lines to enable the
-- example crafting systems
@@ -57,8 +48,8 @@ function craft_lax(ch, recipe)
recipe[2].id == 9 and recipe[2].amount >= 1) -- and at least one wood
then
mana.chr_inv_change(ch,
- 8, -2, --take away the iron
- 9, -1, --take away the wood
+ 8, -2, -- take away the iron
+ 9, -1, -- take away the wood
5, 1 ) -- give a sword
mana.chat_message(ch, "You've crafted a sword")
return
@@ -68,10 +59,9 @@ end
-- this turns multiple occurences of the same item into one by adding up
-- their amounts and sorts the recipe by item ID.
--- This makes stuff a lot easier when your crafting system isn't supposed to care
--- about the order items are in.
+-- This makes stuff a lot easier when your crafting system isn't supposed to
+-- care about the order items are in.
function make_condensed_and_sorted_item_list(recipe)
-
local condensed = {}
for index, item in pairs(recipe) do
if condensed[item.id] == nil then
@@ -90,10 +80,8 @@ function make_condensed_and_sorted_item_list(recipe)
end
table.sort(sorted, function(item1, item2)
- return (item1.id < item2.id)
- end
- )
+ return (item1.id < item2.id)
+ end)
return sorted
-
-end \ No newline at end of file
+end