• 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!

TalkAction Waypoint system

Nostradamus

Member
Joined
Jun 2, 2007
Messages
219
Reaction score
6
I saw one post of The Chaos, making this in-sources, so i decided to make in LUA.

What is it?

It's a waypoint system to teleport a player to a location that you set, without needing the coordinates. It is a talkaction script.

I don't know if it will works, i did for a friend in about one minute, and i'm currently busy now, but if you found a bug, post here.

Database

Create a table named 'teleport' in the SQL database that you use in your server with:

  • pos
  • name
Global.lua

Code:
dofile('./config.lua')
env = assert(luasql.mysql())
connect = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))

This will be better to use LuaSQL again after.

Teleporter.lua

Code:
dofile('./config.lua')
env = assert(luasql.mysql())
connect = assert(env:connect(mysqlDatabase, mysqlUser, mysqlPass, mysqlHost, mysqlPort))

function doSetWaypoint(pos, name)
	if (string.find(name, '^[a-zA-Z0-9 -_]+$')) then
		debugPrint('[Waypoint System] Wrong characteres to the name of waypoint.')
		return FALSE
	end
	local cursor = assert(connect:execute("SELECT * FROM `teleports` WHERE `pos` = " .. pos .. ";"))
	if (cursor:numrows() > 0) then
		local query = assert(connect:execute("UPDATE `teleports` SET `pos` = " .. pos .. " WHERE `name` = " .. name .. ");"))
		return TRUE
	else
		local query = assert(connect:execute("INSERT INTO `teleports` (`pos`, `name`) VALUES (" .. pos .. ", " .. name .. ");"))
		return TRUE
	end
end

function doDeleteWaypoint(pos)
	local cursor = assert(connect:execute("SELECT * FROM `teleports` WHERE `pos` = " .. pos .. ";"))
	if (cursor:numrows() > 0) then
		local query = assert(connect:execute("DELETE FROM `teleports` WHERE `pos ` = " .. pos ";"))
		return TRUE
	else
		return FALSE
	end
end
function getWaypoint(name)
	local cursor = assert(connect:execute("SELECT * FROM `teleports` WHERE `name` = " .. name .. ";"))
	local arr = {}
	
	if (cursor:numrows() > 0) then
		cursor:fetch(arr)
		position = arr[1]
		return position
	else
		return FALSE
	end
end

function onSay(cid, words, param)
	if (string.find(param, '^[a-zA-Z0-9 -_]+$')) then
		if ((words == "!set") and (getPlayerGroupId(cid) >= GID_GOD)) then
				doSetWaypoint(getCreaturePosition(cid), param)
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "New waypoint: " .. param .. " ( " .. getCreaturePosition(cid) .. ").")
			elseif (words == "!unset") then
				doDeleteWayPoint(getCreaturePosition(cid))
			elseif (words == "!teleport") then
				local position = getWaypoint(param)
				doTeleportThing(cid, position)
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Teleported to waypoint " .. param .. " ( " .. position .. ").")
			else
				return FALSE
			end
		end
	end
end

Talkactions.xml

Code:
<talkaction words="!set" script="Teleporter.lua" />
<talkaction words="!unset" script="Teleporter.lua" />
<talkaction words="!teleport" script="Teleporter.lua" />
 
Last edited:
Back
Top