• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Save Position and Send to Position (for GMS)

Qwe

Banned User
Joined
May 19, 2009
Messages
122
Reaction score
8
Location
$user->getLocation();
Hi, I created a simple script, allowing us to save the item, and then teleport to the item using the stored name. Nice for Gamemasters :)

* Commands *
- /savepos POS_NAME
- /tp POS_NAME

!! EASY INSTALLATION !!
in data/talkactions/scripts/ create file tpsys.lua and paste this code:
PHP:
local config = {
	GroupID = 3,
}

local function getPosition(cid, posName)
	local result = db.getResult("SELECT `pos_x`, `pos_y`, `pos_z` FROM `teleports` WHERE `pos_name` = '" .. db.escapeString(posName) .. "' and `pos_player`= " .. getPlayerGUID(cid) ..";")
	local ret =  (result:getID() == -1) and false or {
		x = result:getDataInt("pos_x"),
		y = result:getDataInt("pos_y"),
		z = result:getDataInt("pos_z")
	}
	result:free()
	return ret
end

local function savePosition(cid, posName)
	if (not getPosition(cid, name)) then
		local pos = getCreaturePosition(cid)
		local query = db.executeQuery("INSERT INTO `teleports` (`pos_name`, `pos_player`, `pos_x`, `pos_y`, `pos_z`) VALUES ('" .. db.escapeString(posName) .. "', " .. getPlayerByGUID(cid) .. ", ".. pos.x ..", ".. pos.y ..", ".. pos.z ..");")
		if query then
			doPlayerSendTextMessage(cid, 22, "Position " .. posName .. " has been saved on position [x="..pos.x.." y="..pos.y..", z="..pos.z.."]!")
		else
			doPlayerSendCancel(cid, "Error in saving position.")
		end
	else
		doPlayerSendCancel(cid, "Position with this name is already saved for you.")
	end
end

function onSay(cid, words, param, channel)
	if(param == "")then
		doPlayerSendCancel(cid, "This command require param.")
		return true
	end

	if(getConfigValue("sqlType") == "mysql")then
		db.executeQuery("CREATE TABLE IF NOT EXISTS `"..(getConfigValue("sqlDatabase") or "").."`.`teleports` (`id` INT( 11 ) NOT NULL, `pos_name` VARCHAR( 255 ) NOT NULL ,`pos_player` INT( 11 ) NOT NULL ,`pos_x` INT( 11 ) NOT NULL , `pos_y` INT( 11 ) NOT NULL ,`pos_z` INT( 11 ) NOT NULL ,INDEX ( `id` ))")
	elseif(getConfigValue("sqlType") == "sqlite")then
		db.executeQuery("CREATE TABLE IF NOT EXISTS `teleports` (id INTEGER, pos_name VARCHAR, pos_player INTEGER, pos_x INTEGER, pos_y INTEGER, pos_z INTEGER );");
	end
	
	if(getPlayerGroupId(cid) >= config.GroupID)then
		if(words == "/tp")then
			local pos = getPosition(cid, posName)
			if pos then
				doTeleportThing(cid, pos, true)
			else
				doPlayerSendCancel(cid, "Position not found.")
			end
		elseif(words == "/savepos")then
			savePosition(cid, param)
		end
	else
		doPlayerSendCancel(cid, "You cannot execute this command.")
	end
	return true
end

and in talkactions.xml add:
PHP:
<talkaction log="yes" words="/tp;/savepos" access="3" event="script" value="tpsys.lua"/>

!! If GM XXX save position by name: "lolnoob", GM ZZZ can save other position with this name, and both saves are useable.
 
Last edited:
I must say that! This is a very useful for game operators. :)
Nice!

#Edit
Auto tables creating - nice feature! : )
 
Fixed just a few small typo's
Code:
local config = {
	GroupID = 3,
}

local function getPosition(cid, posName)
	local result = db.getResult("SELECT `pos_x`, `pos_y`, `pos_z` FROM `teleports` WHERE `pos_name` = '" .. db.escapeString(posName) .. "' and `pos_player`= " .. getPlayerGUID(cid) ..";")
	local ret =  (result:getID() == -1) and false or {
		x = result:getDataInt("pos_x"),
		y = result:getDataInt("pos_y"),
		z = result:getDataInt("pos_z")
	}
	result:free()
	return ret
end

local function savePosition(cid, posName)
	if (not getPosition(cid, name)) then
		local pos = getCreaturePosition(cid)
		local query = db.executeQuery("INSERT INTO `teleports` (`pos_name`, `pos_player`, `pos_x`, `pos_y`, `pos_z`) VALUES ('" .. db.escapeString(posName) .. "', " .. getPlayerByGUID(cid) .. ", ".. pos.x ..", ".. pos.y ..", ".. pos.z ..");")
		if query then
			doPlayerSendTextMessage(cid, 22, "Position " .. posName .. " has been saved on position [x="..pos.x.." y="..pos.y..", z="..pos.z.."]!")
		else
			doPlayerSendCancel(cid, "Error in saving position.")
		end
	else
		doPlayerSendCancel(cid, "Position with this name is already saved for you.")
	end
end

function onSay(cid, words, param, channel)
	if(param == "")then
		doPlayerSendCancel(cid, "This command require param.")
		return true
	end

	if(getConfigValue("sqlType") == "mysql")then
		db.executeQuery("CREATE TABLE IF NOT EXISTS `"..(getConfigValue("sqlDatabase") or "").."`.`teleports` (`id` INT( 11 ) NOT NULL, `pos_name` VARCHAR( 255 ) NOT NULL ,`pos_player` INT( 11 ) NOT NULL ,`pos_x` INT( 11 ) NOT NULL , `pos_y` INT( 11 ) NOT NULL ,`pos_z` INT( 11 ) NOT NULL ,INDEX ( `id` ))")
	elseif(getConfigValue("sqlType") == "sqlite")then
		db.executeQuery("CREATE TABLE IF NOT EXISTS `teleports` (id INTEGER, pos_name VARCHAR, pos_player INTEGER, pos_x INTEGER, pos_y INTEGER, pos_z INTEGER );");
	end
	
	if(getPlayerGroupId(cid) >= config.GroupID)then
		if(words == "/tp")then
			local pos = getPosition(cid, posName)
			if pos then
				doTeleportThing(cid, pos, true)
			else
				doPlayerSendCancel(cid, "Position not found.")
			end
		elseif(words == "/savepos")then
			savePosition(cid, param)
		end
	else
		doPlayerSendCancel(cid, "You cannot execute this command.")
	end
	return true
end
 
#up
Im edit first post and too leave commas, thanks for report. :))

I mistake it, because i have it before posting in class, but i leave class because i have more functions useable for my other scripts.
 
Back
Top