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

Position - simple creation of position, returns LUA_ERROR if position is invalid

Colandus

Advanced OT User
Senator
Joined
Jun 6, 2007
Messages
2,434
Solutions
19
Reaction score
219
Location
Sweden
This function will create a position and check if it's valid or not. You don't need this x=, y=, z=, stackpos= :D

TFS 0.3+ put in data/lib/functions.lua
TFS 0.2 or other put in data/global.lua
Code:
function Position(x, y, z, stackpos)
	if tonumber(x..y..z) then
		local pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}
		if tonumber(stackpos)then
			pos.stackpos = tonumber(stackpos)
		end
		
		return pos
	end
	
	return LUA_ERROR
end

Usage:
Code:
local pos = Position(143, 543, 324) -- Add ", 1" for stackpos 1 or w/e stackpos u want
 
Last edited:
Useful ;) but I would do it without these checks (It won't do nothing, because if pos is wrong, then lua will print it)
 
Useful ;) but I would do it without these checks (It won't do nothing, because if pos is wrong, then lua will print it)

Indeed, but now after this edit they're worth it :)
Now if you make like talkaction:
Code:
function onSay(cid, _, param)
    if #param == 0 then
        doPlayerSendCancel(cid, "Please enter a text and position!")
        return TRUE
    end

    local data = string.explode(param, "|")
    if not data[2] then
        doPlayerSendCancel(cid, "Please enter a position!")
        return TRUE
    end

    local tmp = string.explode(param, " ")
    local pos = Position(unpack(tmp))
    if pos == LUA_ERROR then
        doPlayerSendCancel(cid, "Invalid position specified!")
        return TRUE
    end

    doCreatureSay(cid, data[1], TALKTYPE_SAY, pos)
end
 
Last edited:
Back
Top