Talkaction teleports for player.

adamox223

Member
Joined
Oct 21, 2017
Messages
83
Reaction score
4
Hi, i need help with set special area, when target is in {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}}
then we cant teleport to him with this talkaction: doPlayerSendCancel(cid, "You cant teleport to this target.")

But i cant add this, idk why, can you help me? ( i need this because quests and players cant teleport for quests.)
@Xikini - can you?
Code:
function onSay(cid, words, param)
local mana = getCreatureMaxMana(cid)/100*80
local pid = 0
pid = getPlayerByNameWildcard(param)

if(not pid or (isPlayerGhost(pid) and getPlayerGhostAccess(pid) > getPlayerGhostAccess(cid))) then
        doPlayerSendCancel(cid, "Player " .. param .. " is not currently online.")
        return true
end

if(getCreatureMana(pid) >= (getCreatureMaxMana(pid)/2)) then
    if(getCreatureMana(cid) >= (getCreatureMaxMana(cid)/100*80)) then
        if(not(isPlayerPzLocked(cid))) then
            if(not(getTilePzInfo(getCreaturePosition(cid)))) then
                if(not(getTilePzInfo(getCreaturePosition(pid)))) then
                    doTeleportThing(cid, getCreaturePosition(pid))
                    doPlayerAddMana(cid, -mana)
                else
                    doPlayerSendCancel(cid, "Your target is in Protection Zone.")
                end
            else
                doPlayerSendCancel(cid, "You are in Protection Zone.")
            end
        else
            doPlayerSendCancel(cid, "You are in battle.")
        end
    else
        doPlayerSendCancel(cid, "You do not have enough mana.")
    end
else
    doPlayerSendCancel(cid, "Your target do not have enough mana.")
end
return true
end
 

Xikini

I whore myself out for likes
Joined
Nov 17, 2010
Messages
3,925
Reaction score
2,046
Hi, i need help with set special area, when target is in {from = {x = 100, y = 100, z = 7}, to = {x = 200, y = 200, z = 7}}
then we cant teleport to him with this talkaction: doPlayerSendCancel(cid, "You cant teleport to this target.")

But i cant add this, idk why, can you help me? ( i need this because quests and players cant teleport for quests.)
@Xikini - can you?
Code:
function onSay(cid, words, param)
local mana = getCreatureMaxMana(cid)/100*80
local pid = 0
pid = getPlayerByNameWildcard(param)

if(not pid or (isPlayerGhost(pid) and getPlayerGhostAccess(pid) > getPlayerGhostAccess(cid))) then
        doPlayerSendCancel(cid, "Player " .. param .. " is not currently online.")
        return true
end

if(getCreatureMana(pid) >= (getCreatureMaxMana(pid)/2)) then
    if(getCreatureMana(cid) >= (getCreatureMaxMana(cid)/100*80)) then
        if(not(isPlayerPzLocked(cid))) then
            if(not(getTilePzInfo(getCreaturePosition(cid)))) then
                if(not(getTilePzInfo(getCreaturePosition(pid)))) then
                    doTeleportThing(cid, getCreaturePosition(pid))
                    doPlayerAddMana(cid, -mana)
                else
                    doPlayerSendCancel(cid, "Your target is in Protection Zone.")
                end
            else
                doPlayerSendCancel(cid, "You are in Protection Zone.")
            end
        else
            doPlayerSendCancel(cid, "You are in battle.")
        end
    else
        doPlayerSendCancel(cid, "You do not have enough mana.")
    end
else
    doPlayerSendCancel(cid, "Your target do not have enough mana.")
end
return true
end
haha, it seems @Username doesn't alert people anymore. xP

Wonder how many I missed.

I never recommend scripting stuff this way, because this many nested if's is terrible to read.
Always try to break nested if's apart into readable sections.
(also removing all of those unnecessary brackets. holy crap brackets.)

try this
Lua:
function onSay(cid, words, param)
    local pid = 0
    pid = getPlayerByNameWildcard(param)
    
    if not pid or isPlayerGhost(pid) and getPlayerGhostAccess(pid) > getPlayerGhostAccess(cid) then
        doPlayerSendCancel(cid, "Player " .. param .. " is not currently online.")
        return true
    end
    
    if getCreatureMana(pid) < getCreatureMaxMana(pid) / 2 then
        doPlayerSendCancel(cid, "Your target do not have enough mana.")
        return true
    end
    
    local mana = getCreatureMaxMana(cid) / 100 * 80
    if getCreatureMana(cid) < mana then
        doPlayerSendCancel(cid, "You do not have enough mana.")
        return true
    end
    
    if isPlayerPzLocked(cid) then
        doPlayerSendCancel(cid, "You are in battle.")
        return true
    end
    
    if getTilePzInfo(getCreaturePosition(cid)) then
        doPlayerSendCancel(cid, "You are in Protection Zone.")
        return true
    end
    
    local pid_pos = getCreaturePosition(pid)
    if getTilePzInfo(pid_pos) then
        doPlayerSendCancel(cid, "Your target is in Protection Zone.")
        return true
    end
    
    local from, to = {x = 100, y = 100, z = 7}, {x = 200, y = 200, z = 7}
    if pid_pos.z >= from.z and pid_pos.z <= to.z then
        if pid_pos.y >= from.y and pid_pos.y <= to.y then
            if pid_pos.x >= from.x and pid_pos.x <= to.x then
                doPlayerSendCancel(cid, "Your target is in Protected Area.")
                return true
            end
        end
    end   
                    
    doTeleportThing(cid, getCreaturePosition(pid))
    doPlayerAddMana(cid, -mana)
    return true
end
 

roriscrave

Intermediate OT User
Joined
Dec 7, 2011
Messages
286
Reaction score
21
Code:
function onSay(cid, words, param)
local mana = getCreatureMaxMana(cid)/100*80
local pid = 0
pid = getPlayerByNameWildcard(param)
local fromPosition1,toPosition1 = {x = 100, y = 100, z = 7},{x = 200, y = 200, z = 7}

if(not pid or (isPlayerGhost(pid) and getPlayerGhostAccess(pid) > getPlayerGhostAccess(cid))) then
        doPlayerSendCancel(cid, "Player " .. param .. " is not currently online.")
        return true
end

if(getCreatureMana(pid) >= (getCreatureMaxMana(pid)/2)) then
    if(getCreatureMana(cid) >= (getCreatureMaxMana(cid)/100*80)) then
        if(not(isPlayerPzLocked(cid))) then
            if(not(getTilePzInfo(getCreaturePosition(cid)))) then
                if(not(getTilePzInfo(getCreaturePosition(pid)))) then
                    if not isInArea(getCreaturePosition(pid), fromPosition1, toPosition1) then
                        doTeleportThing(cid, getCreaturePosition(pid))
                        doPlayerAddMana(cid, -mana)
                    else
                    doPlayerSendCancel(cid, "Cant go in this area.")
                else
                    doPlayerSendCancel(cid, "Your target is in Protection Zone.")
                end
            else
                doPlayerSendCancel(cid, "You are in Protection Zone.")
            end
        else
            doPlayerSendCancel(cid, "You are in battle.")
        end
    else
        doPlayerSendCancel(cid, "You do not have enough mana.")
    end
else
    doPlayerSendCancel(cid, "Your target do not have enough mana.")
end
return true
end
 
Last edited:

Xikini

I whore myself out for likes
Joined
Nov 17, 2010
Messages
3,925
Reaction score
2,046
Code:
function onSay(cid, words, param)
local mana = getCreatureMaxMana(cid)/100*80
local pid = 0
pid = getPlayerByNameWildcard(param)
local fromPosition1,toPosition1 = {x = 100, y = 100, z = 7},{x = 200, y = 200, z = 7}

if(not pid or (isPlayerGhost(pid) and getPlayerGhostAccess(pid) > getPlayerGhostAccess(cid))) then
        doPlayerSendCancel(cid, "Player " .. param .. " is not currently online.")
        return true
end

if(getCreatureMana(pid) >= (getCreatureMaxMana(pid)/2)) then
    if(getCreatureMana(cid) >= (getCreatureMaxMana(cid)/100*80)) then
        if(not(isPlayerPzLocked(cid))) then
            if(not(getTilePzInfo(getCreaturePosition(cid)))) then
                if(not(getTilePzInfo(getCreaturePosition(pid)))) then
                    if not isInArea(getCreaturePosition(pid), fromPosition1, toPosition1) then
                        doTeleportThing(cid, getCreaturePosition(pid))
                        doPlayerAddMana(cid, -mana)
                    else
                    doPlayerSendCancel(cid, "Can go in this area.")
                else
                    doPlayerSendCancel(cid, "Your target is in Protection Zone.")
                end
            else
                doPlayerSendCancel(cid, "You are in Protection Zone.")
            end
        else
            doPlayerSendCancel(cid, "You are in battle.")
        end
    else
        doPlayerSendCancel(cid, "You do not have enough mana.")
    end
else
    doPlayerSendCancel(cid, "Your target do not have enough mana.")
end
return true
end
You're missing an end after ' doPlayerSendCancel(cid, "Can go in this area.") ' - line 21
 
Top