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

Lua Blessings NPC TFS 1.0

Raggaer

Godly Member
Joined
Jul 25, 2012
Messages
1,557
Solutions
8
Reaction score
957
Location
Spain
Hello, Im very new to LUA and I was creating this simple NPC that sells first blessing but for some reason its not working, any help?

PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


function onCreatureAppear(cid)                                npcHandler:onCreatureAppear(cid)                        end
function onCreatureDisappear(cid)                        npcHandler:onCreatureDisappear(cid)                end
function onCreatureSay(cid, type, msg)                npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                                                        npcHandler:onThink()                                                end

local node1 = keywordHandler:addKeyword({'blessing'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the spiritual shielding blessing for 10000 gold?'})
        node1:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 1, premium = true, cost = 10000, text = 'You are now blessed with spiritual shielding blessing.'})
        node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})

npcHandler:addModule(FocusModule:new())

And the .xml file

Code:
<npc name="Norf" script="Norf.lua" autowalk="1" floorchange="0">
<health now="100" max="100"/>
<look type="57" head="110" body="69" legs="41" feet="91" corpse="2212"/>
</npc>
 
Why you not add one talkaction for add blessings?
Example:
Code:
function onSay(cid, words, param)
    local cost = getBlessingsCost(getPlayerLevel(cid))
    if (isPlayerPzLocked(cid) == FALSE) then
        if (getPlayerBlessing(cid, 1) and getPlayerBlessing(cid, 2) and getPlayerBlessing(cid, 3) and getPlayerBlessing(cid, 4) and getPlayerBlessing(cid, 5)) then
            doPlayerSendCancel(cid,"You have already been blessed by the gods.")
            return false
        end
        if (doPlayerRemoveMoney(cid,cost)) then
            doPlayerAddBlessing(cid, 1)
            doPlayerAddBlessing(cid, 2)
            doPlayerAddBlessing(cid, 3)
            doPlayerAddBlessing(cid, 4)
            doPlayerAddBlessing(cid, 5)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_HOLYAREA)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have been blessed by the 5 gods!")
        else
            doPlayerSendCancel(cid,"You need "..cost.." gold coins to buy all 5 bless.")
        end
    else
        doPlayerSendCancel(cid,"You can't buy bless, when you are in a battle.")
    end
    return false
end

PD: Please i add one post in your repository in github.
 
I can't reproduce your issue :p

LOL the npc is giving you the blessing? for me when I say Yes it stops talkings, nothing happends

Why you not add one talkaction for add blessings?
Example:
Code:
function onSay(cid, words, param)
    local cost = getBlessingsCost(getPlayerLevel(cid))
    if (isPlayerPzLocked(cid) == FALSE) then
        if (getPlayerBlessing(cid, 1) and getPlayerBlessing(cid, 2) and getPlayerBlessing(cid, 3) and getPlayerBlessing(cid, 4) and getPlayerBlessing(cid, 5)) then
            doPlayerSendCancel(cid,"You have already been blessed by the gods.")
            return false
        end
        if (doPlayerRemoveMoney(cid,cost)) then
            doPlayerAddBlessing(cid, 1)
            doPlayerAddBlessing(cid, 2)
            doPlayerAddBlessing(cid, 3)
            doPlayerAddBlessing(cid, 4)
            doPlayerAddBlessing(cid, 5)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_HOLYAREA)
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have been blessed by the 5 gods!")
        else
            doPlayerSendCancel(cid,"You need "..cost.." gold coins to buy all 5 bless.")
        end
    else
        doPlayerSendCancel(cid,"You can't buy bless, when you are in a battle.")
    end
    return false
end

PD: Please i add one post in your repository in github.

I want it to give one by one but thanks anyway

PD: will look into it
 
Something like this?

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)             end
function onCreatureDisappear(cid)             npcHandler:onCreatureDisappear(cid)         end
function onCreatureSay(cid, type, msg)         npcHandler:onCreatureSay(cid, type, msg)     end
function onThink()                             npcHandler:onThink()                         end

local node1 = keywordHandler:addKeyword({'first bless'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the first blessing for 2000 (plus level depending amount) gold?'})
    node1:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, number = 1, premium = true, baseCost = 2000, levelCost = 200, startLevel = 30, endLevel = 120})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})

local node2 = keywordHandler:addKeyword({'second bless'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the second blessing for 2000 (plus level depending amount) gold?'})
    node2:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, number = 2, premium = true, baseCost = 2000, levelCost = 200, startLevel = 30, endLevel = 120})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})

local node3 = keywordHandler:addKeyword({'third bless'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the third blessing for 2000 (plus level depending amount) gold?'})
    node3:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, number = 3, premium = true, baseCost = 2000, levelCost = 200, startLevel = 30, endLevel = 120})
    node3:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})

local node4 = keywordHandler:addKeyword({'fourth bless'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the fourth blessing for 2000 (plus level depending amount) gold?'})
    node4:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, number = 4, premium = true, baseCost = 2000, levelCost = 200, startLevel = 30, endLevel = 120})
    node4:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})

local node5 = keywordHandler:addKeyword({'fifth bless'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the fifth blessing for 2000 (plus level depending amount) gold?'})
    node5:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, number = 5, premium = true, baseCost = 2000, levelCost = 200, startLevel = 30, endLevel = 120})
    node5:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})

npcHandler:addModule(FocusModule:new())
 
Back
Top