• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Flying

Capaverde

New Member
Joined
Sep 30, 2007
Messages
107
Reaction score
4
Let's discuss flying in otservers. :)


I think one problem is you can only teleport to places with tiles, so you'd have to fill your maps with tiles of id 460 to allow the players to fly everywhere.
You can't create a ground item (of id 460) in a place where there is no tile, and the tiles are only created when the map is loaded, and only created where there are tiles in the otbm.

So I've made three lua functions, one to check if there is a tile in a certain position, other to create tiles (i.e. class Tile, from tile.h) even after the map loading, and another to remove tiles.

Code:
		static int32_t luaPosExists(lua_State *L);
		static int32_t luaSetTile(lua_State *L);
		static int32_t luaRemoveTile(lua_State *L);

Code:
	//posExists(pos)
	lua_register(m_luaState, "posExists", LuaScriptInterface::luaPosExists);

	//setTile(pos)
	lua_register(m_luaState, "setTile", LuaScriptInterface::luaSetTile);
	
	//removeTile(pos)
	lua_register(m_luaState, "removeTile", LuaScriptInterface::luaRemoveTile);

Code:
int32_t LuaScriptInterface::luaPosExists(lua_State* L)
{
	//posExists(pos)

	PositionEx pos;
	popPosition(L, pos);

	Tile* tile = g_game.getTile(pos.x, pos.y, pos.z);
	if(!tile)
	{
		lua_pushnumber(L, LUA_FALSE);
		return 1;
	}
		lua_pushnumber(L, LUA_TRUE);
		return 1;
}

int32_t LuaScriptInterface::luaSetTile(lua_State* L)
{
	PositionEx pos;
	popPosition(L, pos);
	
	Tile* tile = new Tile(pos.x, pos.y, pos.z);
	g_game.setTile(pos.x, pos.y, pos.z, tile);
	return 1;
}

int32_t LuaScriptInterface::luaRemoveTile(lua_State* L)
{
	PositionEx pos;
	popPosition(L, pos);
	g_game.removeTile(pos.x, pos.y, pos.z);
	return 1;
}

So let's say we want to teleport the player to a certain position to simulate flying, we can check if there is a tile in that position with posExists(pos), if there isn't, we can create the tile with setTile(pos), then add a ground item to that tile with doCreateItem(460, 1, pos) and teleport the player there with doTeleportThing(cid, pos), after this we can add an event to remove the tile after a few seconds with removeTile(pos).

talkaction example:
Code:
--flyup
function myremove(pos)
mcreature = getTopCreature(pos)
if mcreature.uid == 0 then  --if you remove a tile where there is a creature, the server crashes
removeTile(pos)
else
addEvent(myremove, 15000, pos)
end
end

function onSay(cid, words, param)
pos = getThingPos(cid)
pos.z = pos.z-1
if pos.z >= 0 and posExists(pos) == 0 then
setTile(pos)
doCreateItem(460, 1, pos)
doTeleportThing(cid, pos)
addEvent(myremove, 15000, pos)
end
return 0
end

a different myremove :
Code:
function myremove(pos)
 if getTopCreature(pos).uid > 0 then
  local mpos
	for z=pos.z+1,15 do
	 mpos = {x=pos.x,y=pos.y,z=z}
		if posExists(mpos) == 1 then
		 break
		end
	end
  doRelocate2(pos,mpos)
 end
removeTile(pos)
end

a video:

[video=youtube_share;AplHGgESzoQ]http://youtu.be/AplHGgESzoQ[/video]
 
Last edited:
i was thinking about how it would be cool to make 'war in the sky', and as i was testing things here i just found out that you can send magic effects to positions without tiles, so you would not have to create tiles for all the sqms affected by the spell, you'd just send the magic effect if the tile doesn't exist, and if the tile exists you'd check for creatures and damage them. I don't know if it can be made with a callback or if you'd have to make some source edits but it is indeed possible to be done


you can't make it with docombat, because docombat makes a tile list, you'd have to make a position list instead
 
Back
Top