TFS 0.X Detect on play fanfare if player is x,y,z position

newby

Active Member
Joined
Jun 11, 2016
Messages
163
Reaction score
26
How to detect when player plays fanfire, if he is in position x=100, y=120, z=7
Send player a msg?
 

Leesne

Member
Joined
Dec 4, 2017
Messages
89
Reaction score
37
Lua:
local MusicEffect = {
    [2076] = CONST_ME_SOUND_GREEN,     --Fanfare
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 2076 then
-- area
        if isInRange(player:getPosition(), Position(32330, 32214, 7), Position(32332, 32216, 7)) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Wow that is a terrible song.")
        end
-- exact location
        if player:getPosition() == Position(32330, 32214, 7) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Wow that is a beautiful song.")
        end
    end

    item:getPosition():sendMagicEffect(MusicEffect[item.itemid])
    return true
end
modified from music.lua

oh sorry i didn't see 0.x.
I don't have sources for 0.x, checkout the music.lua if it has one.
 

Perun

GET SHIT DONE
Premium User
Joined
May 1, 2009
Messages
256
Reaction score
78
How to detect when player plays fanfire, if he is in position x=100, y=120, z=7
Send player a msg?
if(getCreaturePos(cid) == {x=1234,y=1234,z=7}) then
 

Evil Hero

Legacy Member
Joined
Dec 12, 2007
Messages
1,156
Reaction score
529
Location
Germany
if(getCreaturePos(cid) == {x=1234,y=1234,z=7}) then
You cannot compare position tables, you have to invoke a function like:
Lua:
function comparePosition(p1, p2)
    return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z and true or false
end
depending on tfs version it might have comparePosition(p1, p2) already.
 

Perun

GET SHIT DONE
Premium User
Joined
May 1, 2009
Messages
256
Reaction score
78
You cannot compare position tables, you have to invoke a function like:
Lua:
function comparePosition(p1, p2)
    return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z and true or false
end
depending on tfs version it might have comparePosition(p1, p2) already.
Yea sorry, i forgot that i've edited this in my srv so i can compare table.
__eq
 
OP
newby

newby

Active Member
Joined
Jun 11, 2016
Messages
163
Reaction score
26
Thank you guys!
 
Top