summaryrefslogtreecommitdiff
path: root/src/scripting/lua.cpp
diff options
context:
space:
mode:
authorBlue <bluesansdouze@gmail.com>2009-05-06 00:21:51 +0200
committerChuck Miller <shadowmil@gmail.com>2009-05-05 18:49:31 -0400
commit9bf793b93df88fb38c2f29d5ec7643d11899ef2f (patch)
tree3139788a4ac1c936786f1b6ba9cdf2d7680f3ccf /src/scripting/lua.cpp
parenta151d1693572f32fcd7572f20e80ed99500b42fa (diff)
downloadmanaserv-9bf793b93df88fb38c2f29d5ec7643d11899ef2f.tar.gz
manaserv-9bf793b93df88fb38c2f29d5ec7643d11899ef2f.tar.bz2
manaserv-9bf793b93df88fb38c2f29d5ec7643d11899ef2f.tar.xz
manaserv-9bf793b93df88fb38c2f29d5ec7643d11899ef2f.zip
tmwserv - Warp fix
Prevent for warping in a unwalkable area, choose randomly a random place to warp if the asked is unwalkable Added a default value to map::getWalk too.
Diffstat (limited to 'src/scripting/lua.cpp')
-rw-r--r--src/scripting/lua.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index 4ea86985..b4bdb99b 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -192,8 +192,6 @@ static int npc_create(lua_State *s)
static int npc_end(lua_State *s)
{
- LOG_WARN("Conversation's over !");
-
NPC *p = getNPC(s, 1);
Character *q = getCharacter(s, 2);
if (!p || !q)
@@ -293,7 +291,27 @@ static int chr_warp(lua_State *s)
raiseScriptError(s, "chr_warp called with a non-existing map.");
return 0;
}
- GameState::enqueueWarp(q, m, lua_tointeger(s, 3), lua_tointeger(s, 4));
+
+ int x = lua_tointeger(s, 3);
+ int y = lua_tointeger(s, 4);
+
+ Map *map = m->getMap();
+
+ // If the wanted warp place is unwalkable
+ if (!map->getWalk(x / map->getTileWidth(), y / map->getTileHeight()))
+ {
+ int c = 50;
+ LOG_INFO("chr_warp called with a non-walkable place.");
+ do {
+ x = rand() % map->getWidth();
+ y = rand() % map->getHeight();
+ c--;
+ } while (!map->getWalk(x, y) && c);
+ x *= map->getTileWidth();
+ y *= map->getTileHeight();
+ }
+ GameState::enqueueWarp(q, m, x, y);
+
return 0;
}