From a36e231883d595bcba91d44e19f24b31eaf0431b Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 26 Feb 2012 23:28:43 +0100 Subject: 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 --- example/scripts/bomtest.lua | 3 +- example/scripts/crafting.lua | 44 +++++++----------- example/scripts/global_events.lua | 79 +++++++++++++++------------------ example/scripts/items/candy.lua | 26 +++++------ example/scripts/main.lua | 16 +++---- example/scripts/maps/desert.lua | 17 +++---- example/scripts/monster/testmonster.lua | 39 ++++++++-------- example/scripts/npcs/healer.lua | 30 +++++-------- example/scripts/npcs/shaker.lua | 4 -- example/scripts/special_actions.lua | 49 +++++++++----------- 10 files changed, 126 insertions(+), 181 deletions(-) (limited to 'example/scripts') diff --git a/example/scripts/bomtest.lua b/example/scripts/bomtest.lua index d4b0212..4c65084 100644 --- a/example/scripts/bomtest.lua +++ b/example/scripts/bomtest.lua @@ -1,5 +1,4 @@ -------------------------------------------------------------------------------- --- This file verifies that an UTF-8 BOM is correctly handled by manaserv ------ +-- This file verifies that an UTF-8 BOM is correctly handled by manaserv function testUtf8Bom() -- Dummy function, the test is really about whether the hidden BOM at the diff --git a/example/scripts/crafting.lua b/example/scripts/crafting.lua index eae26a4..54e8c9a 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 diff --git a/example/scripts/global_events.lua b/example/scripts/global_events.lua index 548351a..fe4175b 100644 --- a/example/scripts/global_events.lua +++ b/example/scripts/global_events.lua @@ -1,47 +1,43 @@ -------------------------------------------------------------- --- Global event script file -- --- -- --- This file allows you to modify how certain events which -- --- happen frequently in the game on different maps are -- --- supposed to be handled. It is a collection of script -- --- functions which are always called when certain events -- --- happen, regardless on which map. Script execution is -- --- done in the context of the map the event happens on. -- ----------------------------------------------------------------------------------- --- Copyright 2010 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. -- ----------------------------------------------------------------------------------- +--[[ + + Global event script file + + This file allows you to modify how certain events which happen frequently in + the game on different maps are supposed to be handled. It is a collection of + script functions which are always called when certain events happen, + regardless on which map. Script execution is done in the context of the map + the event happens on. + +--]] -- This function is called when the hit points of a character reach zero. function on_chr_death(ch) - mana.being_say(ch, "Noooooo!!!") + mana.being_say(ch, "Noooooo!!!") end --- This function is called when the player clicks on the �OK� button after --- the death message appeared. It should be used to implement the respawn +-- This function is called when the player clicks on the OK button after the +-- death message appeared. It should be used to implement the respawn -- mechanic (for example: warp the character to the respawn location and -- bring HP above zero in some way) function on_chr_death_accept(ch) - mana.being_heal(ch) -- restores to full hp - -- mana.being_heal(ch, 1) --restores 1 hp (in case you want to be less nice) - mana.chr_warp(ch, 1, 815, 100) --warp the character to the respawn location + -- restores to full hp + mana.being_heal(ch) + -- restores 1 hp (in case you want to be less nice) + -- mana.being_heal(ch, 1) + -- warp the character to the respawn location + mana.chr_warp(ch, 1, 815, 100) end -- This function is called after chr_death_accept. The difference is that -- it is called in the context of the map the character is spawned on after -- the respawn logic has happened. function on_chr_respawn(ch) - -- calls the local_respawn_function of the map the character respawned - -- on when the script of the map has one - if local_respawn_function ~= nil then - local_respawn_function(ch) - end + -- calls the local_respawn_function of the map the character respawned + -- on when the script of the map has one + if local_respawn_function ~= nil then + local_respawn_function(ch) + end end @@ -49,30 +45,27 @@ end -- first time. This can, for example, be used to give starting equipment -- to the character and/or initialize a tutorial quest. function on_chr_birth(ch) - -- this message is shown on first login. - mana.chat_message(0, ch, "And so your adventure begins...") + -- this message is shown on first login. + mana.chat_message(0, ch, "And so your adventure begins...") end -- This function is called when a character logs into the game. This can, -- for example, be utilized for a message-of-the-day or for various -- handlings of offline processing mechanics. function on_chr_login(ch) - mana.chat_message(0, ch, "Welcome to Manasource") + mana.chat_message(0, ch, "Welcome to Manasource") end -- This function is called when a character is disconnected. This could -- be useful for various handling of offline processing mechanics. function on_chr_logout(ch) - -- notifies nearby players of logout - local around = mana.get_beings_in_circle( - posX(ch), - posY(ch), - 1000) - local msg = mana.being_get_name(ch).." left the game." - for b in pairs(around) do - if mana.being_type(b) == TYPE_CHARACTER then - mana.chat_message(0, b, msg) - end - end + -- notifies nearby players of logout + local around = mana.get_beings_in_circle(posX(ch), posY(ch), 1000) + local msg = mana.being_get_name(ch).." left the game." + for b in pairs(around) do + if mana.being_type(b) == TYPE_CHARACTER then + mana.chat_message(0, b, msg) + end + end end diff --git a/example/scripts/items/candy.lua b/example/scripts/items/candy.lua index 5ab7c9a..a9c59fe 100644 --- a/example/scripts/items/candy.lua +++ b/example/scripts/items/candy.lua @@ -1,17 +1,13 @@ -------------------------------------------------------------- --- Example use script. Makes the player character say -- --- "*munch*munch*munch*" when using this item. -- --- The HP regeneration effect is handled separately based -- --- on the heal value in items.xml -- ----------------------------------------------------------------------------------- --- Copyright 2009 The Mana World Development Team -- --- -- --- This file is part of The Mana World. -- --- -- --- The Mana World 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. -- ----------------------------------------------------------------------------------- +--[[ + + Example item script. + + Makes the player character say "*munch*munch*munch*" when using this item. + The HP regeneration effect is handled separately based on the heal value in + items.xml. + +--]] + function use_candy(user) - mana.being_say(user, "*munch*munch*munch*") + mana.being_say(user, "*munch*munch*munch*") end diff --git a/example/scripts/main.lua b/example/scripts/main.lua index d5d8bd0..aeaca63 100644 --- a/example/scripts/main.lua +++ b/example/scripts/main.lua @@ -1,15 +1,9 @@ ----------------------------------------------------------------------------------- --- 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 is the main script file loaded by the server, as configured in --- manaserv.xml. It defines how certain global events should be handled. + This is the main script file loaded by the server, as configured in + manaserv.xml. It defines how certain global events should be handled. + +--]] -- At the moment the event handlers are split up over the following files: require "scripts/global_events" diff --git a/example/scripts/maps/desert.lua b/example/scripts/maps/desert.lua index c330247..ffe9062 100644 --- a/example/scripts/maps/desert.lua +++ b/example/scripts/maps/desert.lua @@ -1,14 +1,8 @@ ----------------------------------------------------------- --- Template script for the Desert map -- ----------------------------------------------------------------------------------- --- Copyright 2011 The Mana Development Team -- --- -- --- This file is part of Manasource Project. -- --- -- --- 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. -- ----------------------------------------------------------------------------------- +--[[ + + Example script for the Desert map + +--]] -- From scripts/ require "scripts/lua/npclib" @@ -19,7 +13,6 @@ require "scripts/npcs/merchant" require "scripts/npcs/shaker" atinit(function() - -- Barber examples create_npc("Barber Twin", 1, GENDER_MALE, 14 * TILESIZE + TILESIZE / 2, 9 * TILESIZE + TILESIZE / 2, Barber, nil) create_npc("Barber Twin", 1, GENDER_MALE, 20 * TILESIZE + TILESIZE / 2, 11 * TILESIZE + TILESIZE / 2, npclib.talk(Barber, {14, 15, 16}, {}), nil) diff --git a/example/scripts/monster/testmonster.lua b/example/scripts/monster/testmonster.lua index fa094a8..2701d24 100644 --- a/example/scripts/monster/testmonster.lua +++ b/example/scripts/monster/testmonster.lua @@ -1,26 +1,25 @@ ----------------------------------------------------------------------------------- --- Copyright 2009 The Mana World Development Team -- --- -- --- This file is part of The Mana World. -- --- -- --- The Mana World 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. -- ----------------------------------------------------------------------------------- +--[[ + + Example monster script. + + Makes the monster boost about his abilities and makes both the monster and + the player talkative during battle. + +--]] function update_monster(mob) - local r = math.random(0, 200); - if r == 0 then - mana.being_say(mob, "Roar! I am a boss") - end + local r = math.random(0, 200); + if r == 0 then + mana.being_say(mob, "Roar! I am a boss") + end end function on_maggot_strike(mob, victim, hit) - if hit > 0 then - mana.being_say(mob, "Take this! "..hit.." damage!") - mana.being_say(victim, "Oh Noez!") - else - mana.being_say(mob, "Oh no, my attack missed!") - mana.being_say(victim, "Whew...") - end + if hit > 0 then + mana.being_say(mob, "Take this! "..hit.." damage!") + mana.being_say(victim, "Oh Noez!") + else + mana.being_say(mob, "Oh no, my attack missed!") + mana.being_say(victim, "Whew...") + end end diff --git a/example/scripts/npcs/healer.lua b/example/scripts/npcs/healer.lua index 88335c2..a4a0db5 100644 --- a/example/scripts/npcs/healer.lua +++ b/example/scripts/npcs/healer.lua @@ -1,21 +1,15 @@ ----------------------------------------------------------- --- Healer Function Sample -- ----------------------------------------------------------------------------------- --- Copyright 2009-2010 The Mana World Development Team -- --- -- --- This file is part of The Mana World. -- --- -- --- The Mana World 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. -- ----------------------------------------------------------------------------------- +--[[ + + Healer NPC example + +--]] function Healer(npc, ch) - do_message(npc, ch, "Do you need healing?") - local c = do_choice(npc, ch, "Heal me fully", "Heal 100 HP", "Don't heal me") - if c == 1 then - mana.being_heal(ch) - elseif c == 2 then - mana.being_heal(ch, 100) - end + do_message(npc, ch, "Do you need healing?") + local c = do_choice(npc, ch, "Heal me fully", "Heal 100 HP", "Don't heal me") + if c == 1 then + mana.being_heal(ch) + elseif c == 2 then + mana.being_heal(ch, 100) + end end diff --git a/example/scripts/npcs/shaker.lua b/example/scripts/npcs/shaker.lua index 9d7bafb..ac6b152 100644 --- a/example/scripts/npcs/shaker.lua +++ b/example/scripts/npcs/shaker.lua @@ -18,7 +18,6 @@ function shaker_update(npc) center_x = mana.posX(npc) center_y = mana.posY(npc) tremor(center_x, center_y, 300) - end end @@ -43,6 +42,3 @@ function tremor (center_x, center_y, intensity) end end end - - - diff --git a/example/scripts/special_actions.lua b/example/scripts/special_actions.lua index 135ad35..7cd19b5 100644 --- a/example/scripts/special_actions.lua +++ b/example/scripts/special_actions.lua @@ -1,19 +1,12 @@ -------------------------------------------------------------- --- Special action script file -- --- -- --- This file allows you to implement your special -- --- action system. The system can for example implement -- --- magic, physical attack or also such mundane things -- --- as showing emoticons over the characters heads. -- ----------------------------------------------------------------------------------- --- Copyright 2010 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. -- ----------------------------------------------------------------------------------- +--[[ + + Special action script file + + This file allows you to implement your special action system. The system can + for example implement magic, physical attack or also such mundane things as + showing emoticons over the characters heads. + +--]] local specialCost = {} specialCost[1] = 50 @@ -21,19 +14,19 @@ specialCost[2] = 250 specialCost[3] = 1000 function use_special(ch, id) - -- perform whatever the special with the ID does - if id == 1 then - mana.being_say(ch, "Kaaame...Haaame... HAAAAAA!") - end - if id == 2 then - mana.being_say(ch, "HAA-DOKEN!") - end - if id == 3 then - mana.being_say(ch, "Sonic BOOM") - end + -- perform whatever the special with the ID does + if id == 1 then + mana.being_say(ch, "Kaaame...Haaame... HAAAAAA!") + end + if id == 2 then + mana.being_say(ch, "HAA-DOKEN!") + end + if id == 3 then + mana.being_say(ch, "Sonic BOOM") + end end function get_special_recharge_cost(id) - -- return the recharge cost for the special with the ID - return specialCost[id] + -- return the recharge cost for the special with the ID + return specialCost[id] end -- cgit