summaryrefslogtreecommitdiff
path: root/src/scripting/lua.cpp
AgeCommit message (Collapse)AuthorFilesLines
2012-03-02Use callbacks for handling character death and respawnThorbjørn Lindeijer1-0/+26
Rather than relying on the availability of global functions with certain predefined names, the Lua script now calls API functions to set which function should be called on these global events. This mechanism should make it easier to avoid name collisions in the global namespace, which is important now that there is only a single script state. For these global events this was not likely to become a problem, but this solution can also be used for callbacks on specific item or monster types, or even allow setting callbacks on certain instances. Reviewed-by: Erik Schilling Reviewed-by: Yohann Ferreira
2012-03-02Simplified some of the Lua backendThorbjørn Lindeijer1-67/+29
Mainly introduced a helper function for getting to the Script instance for the current Lua state. Reviewed-by: Erik Schilling Reviewed-by: Yohann Ferreira
2012-02-03Added a generic Lua user data cacheThorbjørn Lindeijer1-2/+2
Based on a native Lua table with weak values, so that the user data objects that are created can be garbage collected when no longer referenced. Reviewed-by: Yohann Ferreira
2012-01-31Use a full user data object for MapObject referencesThorbjørn Lindeijer1-46/+20
Based on a templated helper class, MapObject references in Lua scripts are now full user data objects. Using the '__index' member of their metatable, a library is associated with it so that member functions can be called directly on the object. Reviewed-by: Yohann Ferreira Reviewed-by: Erik Schilling
2012-01-30Fixed some lua_newtable/createtable usageThorbjørn Lindeijer1-2/+2
When creating a Lua table, it is possible to specify in advance how many array elements and how many non-array elements this table will contain, to avoid dynamic reallocations while filling the table. This wasn't used optimally by the pushSTLContainer helper methods and some other cases. Reviewed-by: Erik Schilling Reviewed-by: Yohann Ferreira
2012-01-25Fixed use of checkstring method in the script functionsErik Schilling1-4/+7
luaL_checkstring might not return so the destructor of string will not be called. Reviewed-by: Bjorn.
2012-01-22Added announce(text [, sender]) lua functionErik Schilling1-4/+18
The function will cause a global announcement. If no sender ist set "Server" will be used. Reviewed-by: Bjorn.
2012-01-18Added the chr_get_inventory and chr_get_equipment functions.Yohann Ferreira1-0/+137
Those will make the scripters able to get a full view of the current player's possessions. Use with care. + Fixes following Ablu's review. Resolves: Mana-Mantis #207. Reviewed-by: Ablu
2012-01-18Fixed the chr_inv_count function to handle equipment.Yohann Ferreira1-6/+11
the function can now count in the inventory and/or the player's equipment. I also fixed the script function and added a use case in the example map. + Fixes after Ablu's review. + 2nd fix after Ablu's review: Fix the inventory remove behaviour. Resolves: Mana-Mantis #288 Reviewed-by: Ablu
2012-01-16Made the lua item_drop script function returns whether it succeeded.Yohann Ferreira1-4/+4
Part of Mana-Mantis #339. Reviewed-by: Ablu
2012-01-16Added several script warnings on errors.Yohann Ferreira1-7/+10
As requested by Ablu. Reviewed-by: Ablu.
2012-01-10Random small fixes linked to lua c++ scripting functions.Yohann Ferreira1-10/+39
Reviewed-by: Ablu
2012-01-10Added unequip lua script functions.Yohann Ferreira1-0/+65
You can unequip using the slot or an item id. + Fixes from Ablu's review. Resolves: Mana-Mantis #350. Reviewed-by: Ablu.
2012-01-10Added equip lua script functions.Yohann Ferreira1-0/+71
One per inventory slot, one per item id or name. + Fixes from 2 Ablu's reviews. Reviewed-by: Ablu. 1st part of Mana-Mantis #339, 350.
2012-01-02Made all beings capable of having a genderErik Schilling1-17/+21
Reviewed-by: o11c, bjorn, Bertram.
2011-11-01Merge github.com:mana/manaservYohann Ferreira1-1/+1
Conflicts: src/game-server/character.cpp src/scripting/lua.cpp
2011-10-22Fixed the get_level doxygen documentation.Yohann Ferreira1-1/+1
Thanks to Ablu.
2011-10-22Added the chr_get_level script function.Yohann Ferreira1-0/+18
Reviewed-by: Ablu.
2011-10-22Added the chr_set_gender() script function.Yohann Ferreira1-0/+20
Reviewed-by: Ablu.
2011-10-19Merge branch 'master' of github.com:mana/manaservYohann Ferreira1-3/+147
Conflicts: src/game-server/accountconnection.cpp
2011-10-19Made get_beings_in_circle capable of taking a being as argument.Erik Schilling1-3/+16
Instead of giving the x, y coordinates of the circle you can give a being which is in the center of the circle.
2011-10-15Added script bindings for reading map objectsErik Schilling1-0/+131
map_get_objects([string filter]): returns all object of the current map optionally filtered by type. map_get_object_property(handle object, string key): returns the value of the property of the object. map_get_object_bounds(handle object): returns x, y, width, height of an object. map_get_object_name(handle object): returns name of an object. map_get_object_type(handle object): returns type of an object. Mantis-issue: 397 Reviewed-by: Thorbjørn Lindeijer
2011-09-28Added the chr_set_gender() script function.Yohann Ferreira1-0/+20
2011-09-28Added the chr_get_level script function.Yohann Ferreira1-0/+18
2011-09-28Made the npc_create() function use insertion enqueueing.Yohann Ferreira1-4/+1
As the server was exitting when the insertion was failing anyway, and because the GameState::update() doesn't allow actor insertion while the update process, it was then pretty weird to not use an enqueued insertion for it. Plus, it fixes an assertion failure when scheduling an npc creation. Resolves: Mana-Mantis #360. Reviewed-by: o11c.
2011-08-30Made the monster removal not using queues to avoid a crash.Yohann Ferreira1-4/+4
A race condition on the being pointer could happen when the being queue was highly requested. IMHO, using queues to add being but remove them directly is the way to go. Resolves: Mana-Mantis #384
2011-08-26Made the npc_create() function use insertion enqueueing.Yohann Ferreira1-4/+1
As the server was exitting when the insertion was failing anyway, and because the GameState::update() doesn't allow actor insertion while the update process, it was then pretty weird to not use an enqueued insertion for it. Plus, it fixes an assertion failure when scheduling an npc creation. Resolves: Mana-Mantis #360.
2011-08-25Merge branch 'equipment-fix' of github.com:Bertram25/manaservYohann Ferreira1-4/+5
2011-08-25Allowed map names in chr_warp function.Erik Schilling1-2/+6
Resolves: Mana-Mantis #293. Reviewed-by: Bertram.
2011-08-25Created function to make getting monsters easier in scripts.Erik Schilling1-14/+3
2011-08-23Allowed map names in chr_warp function.Erik Schilling1-2/+6
Resolves: Mana-Mantis #293. Reviewed-by: Bertram.
2011-08-19Created function to make getting monsters easier in scripts.Erik Schilling1-14/+3
2011-08-18Added LUA function for changing anger of monsters.Erik Schilling1-0/+30
You now can change the anger of a monster to a being using mana.monster_change_anger(monster, being, anger) Resolves: Mana-Mantis #366.
2011-08-18Added LUA function for changing anger of monsters.Erik Schilling1-0/+30
You now can change the anger of a monster to a being using mana.monster_change_anger(monster, being, anger) Resolves: Mana-Mantis #366.
2011-08-11Merge branch 'master' of ↵Yohann Ferreira1-4/+5
git://gitorious.org/~bertram/mana/manaserv-equipment-fix into equipment-fix Conflicts: src/common/manaserv_protocol.h
2011-08-10Made chr_inv_count and npc_trade capable of taking a name or an id.Erik Schilling1-3/+36
Resolves: Mana-Mantis #318. Reviewed-by: Bertram.
2011-08-04Merge branch 'master' of git://gitorious.org/mana/manaservYohann Ferreira1-27/+100
2011-08-04Added new LUA functions used to get items and monster names.Erik Schilling1-0/+37
mana.monster_get_name(id) and mana.item_get_name(id) can be used to get the name of an item or a monster if only an id is given. Reviewed-by: Bertram.
2011-08-04Allowed names of items and monsters in scripts - part 1.Erik Schilling1-27/+63
You can now use either the name or the id of the item in the LUA functions chr_inv_change, monster_create, item_drop. Part of: Mana-Mantis #318. Reviewed-by: Bertram.
2011-08-04Merge branch 'master' of git://gitorious.org/mana/manaservYohann Ferreira1-159/+276
2011-08-03Unified the lua.cpp documentation.Yohann Ferreira1-162/+200
I also changed the chatmessage function to chat_message to follow the coding standard.
2011-08-03Added is_walkable lua function.Erik Schilling1-0/+30
mana.is_walkable(x, y) can now be used to check wether the pixel on the current map is walkable or not. Reviewed-by: Bertram.
2011-08-03Added monster_remove lua function.Erik Schilling1-0/+25
mana.monster_remove(monster) can now be used to remove a monster from a map. Resolves: Mana-Mantis #352. Reviewed-by: Bertram.
2011-08-03Added get_map_property lua function.Erik Schilling1-0/+24
mana.get_map_prpoperty(string) can now be used to read a property from a map file. String is the property name. Resolves: Mana-Mantis #353. Reviewed-by: Bertram.
2011-07-27Removed the inventory delay mode for now.Yohann Ferreira1-4/+5
I said I wouldn't do it, but I change my mind. Here is why: The delay mode is used in the trading code, and in the inventory code for lua only. In the lua part, the delay mode is useless as it is used only when the script is requesting removal of more items than owned. This is something that can't be handled well anyway, as for the script part, even when the character was still keeping its items. Plus, it's not actually an error, IMHO. In the trading code, it made sense. But the next commit will bring design changes making the inventory items and the equipment items not linked anymore. Hence, making it impossible to trade equipped items, for instance, which is a good thing IMHO. It will also remove the need of a delayed inventory mode in that case. The two cases where it is used will disappear, making it useless. Last but no least, the part watching for equipment changes in the commit() function is not something easy to debug without first having a proper and working base. (checking of two multimaps changes, for instance). We can add it back once the code has been fully debugged for the most skilled among us. And yes, I am sure of what I'm currently doing. For now the whole inventory and trading code is in need of review but it already was, anyway.
2011-07-04Added new lua function for calculating distances.Ablu1-0/+32
You can now call mana.get_distance(being1, being2) or mana.get_distance(x1, y1, x2, y2) for calculating distances. Reviewed-by: Jaxad0127, Bertram. Resolves: Mana-Mantis #370.
2011-07-02Added LUA function get_beings_in_rectangle.Ablu1-0/+39
Reviewed-by: Bertram. Resolves: Mana-Mantis #369.
2011-06-27Added Lua function for logging.Ablu1-0/+16
You can now call mana.log(loglevel, message) to log messages with scripts. For loglevel you can use the new constants defined in libmana-constants.lua Resolves: Mana-Mantis #359
2011-03-18Improved error handling in chr_shake_screen Lua functionThorbjørn Lindeijer1-22/+10
It's better to use luaL_checkint than manually checking and printing out an error, since using the helper function makes a more informative error message. Also, scripts errors need to be raised before constructing objects, since due to the way Lua does error handling the destructors of the objects will not be called. Also fixed an issue with the 4th parameter, which was first cast to integer and then multiplied by 10000. Now the multiplication happens before the casting to integer. Reviewed-by: Crush
2011-03-17Micro-optimizations related to std::stringThorbjørn Lindeijer1-2/+2
* Rely on the fact that a std::string is empty by default * Use std::string::empty() rather than comparing to "" * Construct with std::string() rather than from "" Reviewed-by: Bertram