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

teleport function

foxkbt

Member
Joined
Sep 29, 2009
Messages
290
Reaction score
7
Location
Salvador
i need one function ho makes the player teleport to otherside of target

ex:

player = 1
target =2

0,0,0
0,2,0
0,0,1

after teleport:
1,0,0
0,2,0
0,0,0
thx
 
Maybe smth like this:
Code:
function onCastSpell(cid, var)
	local target = variantToNumber(target)
	if(isCreature(target)) then
		local targetPos = getPositionByDirection(getCreaturePosition(target), getCreatureLookDirection(target))
		if(doTileQueryAdd(cid, targetPos) == 1) then
			doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
			doTeleportThing(cid, targetPos)
			doSendMagicEffect(targetPos, CONST_ME_TELEPORT)
			return true
		end
	end
	return false
end
 
Last edited:
Maybe smth like this:
Code:
function onCastSpell(cid, var)
	local target = varianToNumber(target)
	if(isCreature(target)) then
		local targetPos = getPositionByDirection(getCreaturePosition(target), getCreatureLookDirection(target))
		if(doTileQueryAdd(cid, targetPos) == 1) then
			doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
			doTeleportThing(cid, targetPos)
			doSendMagicEffect(targetPos, CONST_ME_TELEPORT)
			return true
		end
		return false
	else
		return false
	end
end

u could do it like:
Code:
function onCastSpell(cid, var)
	local target = varianToNumber(target)
	if(isCreature(target)) then
		local targetPos = getPositionByDirection(getCreaturePosition(target), getCreatureLookDirection(target))
		if(doTileQueryAdd(cid, targetPos) == 1) then
			doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
			doTeleportThing(cid, targetPos)
			doSendMagicEffect(targetPos, CONST_ME_TELEPORT)
		end
		return true
	end
	return false
end
also return false is not needed, it returns false alone:
Code:
function onCastSpell(cid, var)
	local target = varianToNumber(target)
	if(isCreature(target)) then
		local targetPos = getPositionByDirection(getCreaturePosition(target), getCreatureLookDirection(target))
		if(doTileQueryAdd(cid, targetPos) == 1) then
			doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
			doTeleportThing(cid, targetPos)
			doSendMagicEffect(targetPos, CONST_ME_TELEPORT)
		end
		return true
	end
end
also why not:
getPositionByDirection(getCreaturePosition(target), getCreatureLookDirection(target))
==
getCreatureLookPosition
Code:
function onCastSpell(cid, var)
	local target = varianToNumber(target)
	if(isCreature(target)) then
		local targetPos = getCreatureLookPosition(target)
		if(doTileQueryAdd(cid, targetPos) == 1) then
			doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
			doTeleportThing(cid, targetPos)
			doSendMagicEffect(targetPos, CONST_ME_TELEPORT)
		end
		return true
	end
end
;<
 
Yea, let's drop false returns everywhere...

@Edit:
And umm, getCreatureLookPosition references to getPosByDir so I don't see difference, you better stfu.

@Edit2:
Edited my post, missed 't' character. :p
 
Last edited:
Yea, let's drop false returns everywhere...

@Edit:
And umm, getCreatureLookPosition references to getPosByDir so I don't see difference, you better stfu.

@Edit2:
Edited my post, missed 't' character. :p
theyre both same
-
getPosByDir = getPositionByDirection
100-compat.lua
getCreatureLookPosition: returns getPosByDir..:
Code:
function getCreatureLookPosition(cid)

	return getPosByDir(getThingPos(cid), getCreatureLookDirection(cid))

end
Edit: heh, nevertheless, since your trying to help
 
Last edited:
theyre both same
-
getPosByDir = getPositionByDirection

So why the fuck do you want to use getCreatureLookPosition when it does refference to getPositionByDirection when you can just use just getPositionByDirection? One function less dude. And i did say getPosByDir instead getPositionByDirection because it's shorter I had to hurry and leave that was the reason I didn't want to write compact function.
 
Last edited:
This will help you..
PHP:
function doTeleport(uid,target)
	local targetPos = type(target) == "table" and target or getThingPos(target)
	local dir = getDirectionTo(getThingPos(uid), targetPos)
	local toPos = isInArray({0,1,2,3},dir) and getPosByDir(getThingPos(uid), dir, getDistanceBetween(getThingPos(uid),targetPos)+1) or getPosByDir(targetPos, dir, 1)
	if not(doTileQueryAdd(uid, toPos) == 1) then
		return false
	end
	doTeleportThing(uid,toPos)
	return toPos
end

Just add to functions file in /lib and then call it in your script, like this:
doTeleport(cid,target) or doTeleport(cid,{x=1,y=1,z=1})

Optionally you can remove this line:
doTeleportThing(uid,toPos)
and the function will only return the position which is behind the target. So you can make checks like if it is a house tile or smth.
 
have a error
i dont copy the error sr!

i add your function in lib/functions.lua
my spell
PHP:
local combat1 = createCombatObject()
setCombatParam(combat1, COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
setCombatParam(combat1, COMBAT_PARAM_USECHARGES, true)

function onGetFormulaValues(cid, level, skill, attack, factor)
local vital = getCreatureHealth(cid)
	local min = -(vital*(skill/50))
	local max = -(vital*(skill/20))
	return min, max
end

setCombatCallback(combat1, CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function doRemoveHealth(cid, var) --by foxkbt
local vital = getCreatureHealth(cid)
	if isCreature(cid) and getCreatureHealth(cid) >= 10 then
		return doCombat(cid, combat1, var)
	end
end

function onCastSpell(cid, var) -- by foxkbt
local vital = getCreatureHealth(cid)
if getPlayerStorageValue(cid, 89456) == 1 then
		doPlayerSendCancel(cid, "voce esta impossibilitado de gastar mana.")
else
        if doRemoveHealth(cid, var) == true then
			doCreatureAddHealth(cid, -(vital - 10))
			doTeleport(cid,target)
		else
	        doPlayerSendTextMessage(cid, 26, "voce nao tem forças para usar esse jutsu")	
            return FALSE
        end
return TRUE
end
end

sr for no rep but my net is down and back now
¬¬
 
Back
Top