• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Give All Blessings

Pening

Pingwin :P
Joined
Nov 25, 2008
Messages
152
Reaction score
6
Location
Poland/Płock
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    bless2 = getPlayerBlessing(cid,2)
    tbless = 'Sorry, but you already have this blessing.'
    tbless2 = 'Sorry, but you already have one blessing, and u cant buy all others.'
    obless = 'I will give to you all blessings, but you will have to make a sacrifice. Are you prepared to pay 200.000 gold for the blessings?'
    mbless = 'Oh. You do not have enough money.' 
    gbless = 'Now the Gods blessed you.'
    price = 60000
    player_gold = getPlayerItemCount(cid,2148)
    player_plat = getPlayerItemCount(cid,2152)*100
    player_crys = getPlayerItemCount(cid,2160)*10000
    player_money = player_gold + player_plat + player_crys

    if msgcontains(msg, 'all blessings') then
        if isPremium(cid) then
            if player_money >= price then
                selfSay(obless, cid)
                talkState[talkUser] = 2
            else
                selfSay(mbless, cid)
                talkState[talkUser] = 0
            end
        else
            selfSay(pbless, cid)
            talkState[talkUser] = 0
        end

    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
        talkState[talkUser] = 0
         if bless2 then
            selfSay(tbless, cid)
        else
            if doPlayerRemoveMoney(cid, price) == TRUE then
                doPlayerAddBlessing(cid, 1)
                doPlayerAddBlessing(cid, 2)
                doPlayerAddBlessing(cid, 3)
                doPlayerAddBlessing(cid, 4)
                doPlayerAddBlessing(cid, 5)
                selfSay(gbless, cid)
            else
                selfSay(mbless, cid)
            end
        end

------------------------------------------------ confirm no ------------------------------------------------
    elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
        selfSay('Ok than.', cid)
        talkState[talkUser] = 0
    end
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Thank you very much,
been looking for something similar to this


Rep++

Zer0xe.
 
I do not try, but possible errors.

**************************
1ººº
In..


Code:
 if isPremium(cid) then
.
.
.
.
        else
            selfSay(pbless, cid)
            talkState[talkUser] = 0
        end

pbless = ???

**************************
2ººº
In..

Code:
if msgcontains(msg, 'all blessings') then
        if isPremium(cid) then
            if player_money >= price then
                selfSay(obless, cid)
                talkState[talkUser] = 2


*** Perfect, the function checks if the player has money.

*** But if the player leaving your money down and say YES???

Code:
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
        talkState[talkUser] = 0
         if bless2 then
            selfSay(tbless, cid)
        else
            if doPlayerRemoveMoney(cid, price) == TRUE then
                doPlayerAddBlessing(cid, 1)


*** Now the function will not check whether the player has money, maybe error!

*** To replace:

Code:
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
        talkState[talkUser] = 0
         if bless2 then
            selfSay(tbless, cid)
        else
            if player_money >= price then
                doPlayerRemoveMoney(cid, price) == TRUE then
                doPlayerAddBlessing(cid, 1)

**************************
3ººº
In..

price = 60000
and
Are you prepared to pay 200.000 gold for the blessings?

=/

**************************
 
Last edited by a moderator:
Wouldnt it be the same to modify the default bless.lua by defining a "local" for all blessings and adding a new node to buy them?

(not trying to be rude, I suck at lua anyways lol)

Like this:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
local full = {1, 2, 3, 4, 5}

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'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the first blessing for 15k gold?'})
	node1:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 1, premium = true, cost = 15000})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you?'})

local node2 = keywordHandler:addKeyword({'second'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the second blessing for 15k gold?'})
	node2:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 2, premium = true, cost = 15000})
	node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you?'})

local node3 = keywordHandler:addKeyword({'third'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the third blessing for 15k gold?'})
	node3:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 3, premium = true, cost = 15000})
	node3:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you?'})

local node4 = keywordHandler:addKeyword({'fourth'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the fourth blessing for 15k gold?'})
	node4:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 4, premium = true, cost = 15000})
	node4:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you?'})

local node5 = keywordHandler:addKeyword({'fifth'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the fifth blessing for 15k gold?'})
	node5:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 5, premium = true, cost = 15000})
	node5:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you?'})
	
local node6 = keywordHandler:addKeyword({'full'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy ALL five blessings for 100k gold? If you buy them separately one by one it will be 75k total.'})
	node6:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = full, premium = true, cost = 100000})
	node6:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you? You can get them cheaper if you buy them separately, it would be 75k total.'})

npcHandler:addModule(FocusModule:new())

So I added the local "full" being blessing 1, 2, 3, 4 and 5 and just copied+pasted a node making node6 and modifying it accordingly.

Working fine in TFS 0.3.2.

The only difference is that it doesnt check if the player has any other blessings already, it just adds them up.

Maybe you could combine both scripts to make a new cleaner and more organized script for this, but still nice job. +Repped

Cheers.
 
Wouldnt it be the same to modify the default bless.lua by defining a "local" for all blessings and adding a new node to buy them?

(not trying to be rude, I suck at lua anyways lol)

Like this:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
local full = {1, 2, 3, 4, 5}

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'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the first blessing for 15k gold?'})
	node1:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 1, premium = true, cost = 15000})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you?'})

local node2 = keywordHandler:addKeyword({'second'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the second blessing for 15k gold?'})
	node2:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 2, premium = true, cost = 15000})
	node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you?'})

local node3 = keywordHandler:addKeyword({'third'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the third blessing for 15k gold?'})
	node3:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 3, premium = true, cost = 15000})
	node3:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you?'})

local node4 = keywordHandler:addKeyword({'fourth'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the fourth blessing for 15k gold?'})
	node4:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 4, premium = true, cost = 15000})
	node4:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you?'})

local node5 = keywordHandler:addKeyword({'fifth'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the fifth blessing for 15k gold?'})
	node5:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 5, premium = true, cost = 15000})
	node5:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you?'})
	
local node6 = keywordHandler:addKeyword({'full'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy ALL five blessings for 100k gold? If you buy them separately one by one it will be 75k total.'})
	node6:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = full, premium = true, cost = 100000})
	node6:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive for you? You can get them cheaper if you buy them separately, it would be 75k total.'})

npcHandler:addModule(FocusModule:new())

So I added the local "full" being blessing 1, 2, 3, 4 and 5 and just copied+pasted a node making node6 and modifying it accordingly.

Working fine in TFS 0.3.2.

The only difference is that it doesnt check if the player has any other blessings already, it just adds them up.

Maybe you could combine both scripts to make a new cleaner and more organized script for this, but still nice job. +Repped

Cheers.

data/npc/lib/npcsystem/modules.lua:141: attempt to compare nil with number
[08/06/2009 18:59:57] stack traceback:
[08/06/2009 18:59:57] data/npc/lib/npcsystem/modules.lua:141: in function 'callback'
[08/06/2009 18:59:57] data/npc/lib/npcsystem/keywordhandler.lua:40: in function 'processMessage'
[08/06/2009 18:59:57] data/npc/lib/npcsystem/keywordhandler.lua:168: in function 'processNodeMessage'
[08/06/2009 18:59:57] data/npc/lib/npcsystem/keywordhandler.lua:122: in function 'processMessage'
[08/06/2009 18:59:57] data/npc/lib/npcsystem/npchandler.lua:381: in function 'onCreatureSay'
[08/06/2009 18:59:57] data/npc/scripts/bless.lua:10: in function <data/npc/scripts/bless.lua:10>


:(
 
Thanks for Script!

remember People My First ot!

toms.sytes.net !

Is another Mode Playing Tibia, It's Not As all ots!

MNade by me 100% !

Thanks to all People That Help Making Scripts and Good This In Otland. Thank you so Much!
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    local price = 60000

    if msgcontains(msg, 'all blessings') then
        if isPremium(cid) == TRUE then
            if getPlayerMoney(cid) <= price then
                selfSay('I will give to you all blessings, but you will have to make a sacrifice. Are you prepared to pay '.. price ..' gold for the blessings?', cid)
                talkState[talkUser] = 1
            else
                selfSay('Oh. You do not have enough money.', cid)
                talkState[talkUser] = 0
            end
        else
            selfSay('Oh. Only premium players can buy blessings.', cid)
            talkState[talkUser] = 0
        end

    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
        if getPlayerBlessing(cid) < 0 then
            selfSay('Sorry, but you already have one of the blessing.', cid)
			talkState[talkUser] = 0
        else
			if doPlayerRemoveMoney(cid, price) == TRUE then
				for i = 1, 5 then
                doPlayerAddBlessing(cid, i)
                selfSay('Now the Gods blessed you.', cid)
            else
                selfSay('Oh. You do not have enough money.', cid)
            end
        end
		
    elseif msgcontains(msg, 'no') and (talkState[talkUser] == 1) then
        selfSay('Ok, Good Bye Adventurer.', cid)
        talkState[talkUser] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

it should works..
 
Back
Top