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

npc bless

Cash22

New Member
Joined
Sep 5, 2019
Messages
14
Solutions
1
Reaction score
1
Hello guys, I needed a help to edit this script pro npc check the bless and say I already have, because it sells all the time.
he also answers my hi far away, basically off screen. I need him to answer me his nearest hi. i used tfs 0.4
Lua:
local focuses = {}
local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end
 
local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end
local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end
local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end
 
local price = 50000
 
function onCreatureSay(cid, type, msg)
    if(not (isFocused(cid)) and (msg == "hi" or msg == "hello")) then
        selfSay("Welcome, ".. getCreatureName(cid) ..". I sell {blessing}.", cid)
        addFocus(cid)
    elseif((isFocused(cid)) and (msg == "bless" or msg == "blessing")) then
        selfSay("Would you like buying blessing per 50000 gold coins?", cid)
    elseif((isFocused(cid)) and (msg == "yes")) then
        if getPlayerMoney(cid) >= price and getPlayerStorageValue(cid, 787878787) == 1 then
            selfSay("Alright.", cid)
            doPlayerRemoveMoney(cid, price)
            doPlayerAddBlessing(cid, 1)
            doPlayerAddBlessing(cid, 2)
            doPlayerAddBlessing(cid, 3)
            doPlayerAddBlessing(cid, 4)
            doPlayerAddBlessing(cid, 5)
            doSendMagicEffect(getCreaturePos(cid), 12)
        else
            selfSay("You don't have enough money or bless scroll.", cid)
        end
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Goodbye!", cid)
        closeShopWindow(cid)
        removeFocus(cid)
    end
end

 
function onThink()
    for i, focus in pairs(focuses) do
        if(not isCreature(focus)) then
            removeFocus(focus)
        else
            local distance = getDistanceTo(focus) or -1
            if((distance > 4) or (distance == -1)) then
                selfSay("Hey, where you going?")
                removeFocus(focus)
            end
        end
    end
    lookAtFocus()
end
 
Solution
Lua:
local focuses = {}
local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end
 
local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end
local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end
local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end
 
local price = 50000
 
function onCreatureSay(cid, type, msg)
    if(not...
Lua:
local focuses = {}
local function isFocused(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            return true
        end
    end
    return false
end
 
local function addFocus(cid)
    if(not isFocused(cid)) then
        table.insert(focuses, cid)
    end
end
local function removeFocus(cid)
    for i, v in pairs(focuses) do
        if(v == cid) then
            table.remove(focuses, i)
            break
        end
    end
end
local function lookAtFocus()
    for i, v in pairs(focuses) do
        if(isPlayer(v)) then
            doNpcSetCreatureFocus(v)
            return
        end
    end
    doNpcSetCreatureFocus(0)
end
 
local price = 50000
 
function onCreatureSay(cid, type, msg)
    if(not (isFocused(cid)) and (msg == "hi" or msg == "hello")) then
        selfSay("Welcome, ".. getCreatureName(cid) ..". I sell {blessing}.", cid)
        addFocus(cid)
    elseif((isFocused(cid)) and (msg == "bless" or msg == "blessing")) then
        selfSay("Would you like buying blessing per 50000 gold coins?", cid)
    elseif((isFocused(cid)) and (msg == "yes")) then
        if getPlayerMoney(cid) >= price and getPlayerStorageValue(cid, 787878787) == 1 then
            if getPlayerBlessing(cid, 1) then
                 selfSay("You already have blessing.", cid)
            else
                 selfSay("Alright.", cid)
                 doPlayerRemoveMoney(cid, price)
                 doPlayerAddBlessing(cid, 1)
                 doPlayerAddBlessing(cid, 2)
                 doPlayerAddBlessing(cid, 3)
                 doPlayerAddBlessing(cid, 4)
                 doPlayerAddBlessing(cid, 5)
                 doSendMagicEffect(getCreaturePos(cid), 12)
            end
        else
            selfSay("You don't have enough money or bless scroll.", cid)
        end
    elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
        selfSay("Goodbye!", cid)
        closeShopWindow(cid)
        removeFocus(cid)
    end
end

 
function onThink()
    for i, focus in pairs(focuses) do
        if(not isCreature(focus)) then
            removeFocus(focus)
        else
            local distance = getDistanceTo(focus) or -1
            if((distance > 4) or (distance == -1)) then
                selfSay("Hey, where you going?")
                removeFocus(focus)
            end
        end
    end
    lookAtFocus()
end
 
Solution
Back
Top