• 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 Need to modify blessing npc script!

richux

Tibera.org
Joined
Aug 18, 2008
Messages
3,666
Reaction score
26
Location
---------
Hello! cause of some reason my blessing npc doesn't work. When I buy blessings from him the death loos % is the same as before. So I died and loose tons of lvls. Also I would like to make it possible buy all 5 blessings by saying "all". Here is my blessing npc script1:

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

function creatureSayCallback(cid, type, msg)
	--- TODO: bless function in modules.lua
	if(npcHandler.focus ~= cid) then
		return FALSE
	end

	if msgcontains(msg, 'blessing') or msgcontains(msg, 'blessings') or msgcontains(msg, 'help') or msgcontains(msg, 'offer') then
		npcHandler:say("I can provide you with five blessings... the 'first bless', 'second bless', 'third bless', 'fourth bless' and the 'fifth bless', they cost 10000 gold coins each.")
		talkState = 0
	elseif msgcontains(msg, 'first bless') then
		npcHandler:say("Do you want to buy the first blessing for 10000 gold?")
		talkState = 1
	elseif msgcontains(msg, 'second bless') then
		npcHandler:say("Do you want to buy the second blessing for 10000 gold?")
		talkState = 2
	elseif msgcontains(msg, 'third bless') then
		npcHandler:say("Do you want to buy the third blessing for 10000 gold?")
		talkState = 3
	elseif msgcontains(msg, 'fourth bless') then
		npcHandler:say("Do you want to buy the fourth blessing for 10000 gold?")
		talkState = 4
	elseif msgcontains(msg, 'fifth bless') then
		npcHandler:say("Do you want to buy the fifth blessing for 10000 gold?")
		talkState = 5
		if msgcontains(msg, 'yes') then
			if getPlayerBlessing(cid, talkState) then
				npcHandler:say("A god has already blessed you with this blessing.")
			elseif isPremium(cid) == TRUE then
				if doPlayerRemoveMoney(cid, 10000) == TRUE then
					doPlayerAddBlessing(cid, talkState)
					npcHandler:say("You have been blessed by one of the five gods!")
				else
					npcHandler:say("You don't have enough money.")
				end
			else
				npcHandler:say("You need a premium account to buy blessings.")
			end
		elseif msgcontains(msg, 'no') then
			npcHandler:say("Then not.")
		end
		talkState = 0
	end
	return TRUE
end

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

and other one:

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 10000 gold?'})
	node1:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 1, premium = false, cost = 10000})
	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 10000 gold?'})
	node2:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 2, premium = false, cost = 10000})
	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 10000 gold?'})
	node3:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 3, premium = false, cost = 10000})
	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 10000 gold?'})
	node4:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 4, premium = false, cost = 10000})
	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 10000 gold?'})
	node5:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 5, premium = false, cost = 10000})
	node5:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})	

local node6 = keywordHandler:addKeyword({'all'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy all blessings for 50000 gold?'})
	node6:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 5, bless = 1, bless = 4, bless = 3, bless = 2, premium = false, cost = 50000})
	node6:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})	

npcHandler:addModule(FocusModule:new())

I tried to modify them by myself but I failed. Help me please! Its Easter :D

Thank you and Happy easter!
 
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 10000 gold?'})
	node1:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 1, premium = false, cost = 10000})
	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 10000 gold?'})
	node2:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 2, premium = false, cost = 10000})
	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 10000 gold?'})
	node3:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 3, premium = false, cost = 10000})
	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 10000 gold?'})
	node4:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 4, premium = false, cost = 10000})
	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 10000 gold?'})
	node5:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 5, premium = false, cost = 10000})
	node5:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})	

local node6 = keywordHandler:addKeyword({'all bless'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the fifth blessing for 50000 gold?'})
	node6:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 5, bless = 1, bless = 4, bless = 3, bless = 2, premium = false, cost = 50000})
	node6:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})	

npcHandler:addModule(FocusModule:new())

And a NPC:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="[COLOR="Red"]HELLO OTLAND[/COLOR]" script="data/npc/scripts/[COLOR="Red"]xxxxxx[/COLOR].lua" walkinterval="2000" speed="1" floorchange="0" access="5" level="1" maglevel="1">
	<health now="150" max="150"/>
	<look type="138" head="55" body="68" legs="96" feet="32" corpse="2212"/>
	<parameters>
	<parameter key="message_greet" value="Hello,  |PLAYERNAME|. I sell 'first', 'second', 'third', 'fourth' and 'fifth' bless for 10.000 gold coins each." />	
	</parameters>
</npc>
 
Last edited:
Hello! cause of some reason my blessing npc doesn't work. When I buy blessings from him the death loos % is the same as before. So I died and loose tons of lvls. Also I would like to make it possible buy all 5 blessings by saying "all". Here is my blessing npc script1:

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

function creatureSayCallback(cid, type, msg)
	--- TODO: bless function in modules.lua
	if(npcHandler.focus ~= cid) then
		return FALSE
	end

	if msgcontains(msg, 'blessing') or msgcontains(msg, 'blessings') or msgcontains(msg, 'help') or msgcontains(msg, 'offer') then
		npcHandler:say("I can provide you with five blessings... the 'first bless', 'second bless', 'third bless', 'fourth bless' and the 'fifth bless', they cost 10000 gold coins each.")
		talkState = 0
	elseif msgcontains(msg, 'first bless') then
		npcHandler:say("Do you want to buy the first blessing for 10000 gold?")
		talkState = 1
	elseif msgcontains(msg, 'second bless') then
		npcHandler:say("Do you want to buy the second blessing for 10000 gold?")
		talkState = 2
	elseif msgcontains(msg, 'third bless') then
		npcHandler:say("Do you want to buy the third blessing for 10000 gold?")
		talkState = 3
	elseif msgcontains(msg, 'fourth bless') then
		npcHandler:say("Do you want to buy the fourth blessing for 10000 gold?")
		talkState = 4
	elseif msgcontains(msg, 'fifth bless') then
		npcHandler:say("Do you want to buy the fifth blessing for 10000 gold?")
		talkState = 5
		if msgcontains(msg, 'yes') then
			if getPlayerBlessing(cid, talkState) then
				npcHandler:say("A god has already blessed you with this blessing.")
			elseif isPremium(cid) == TRUE then
				if doPlayerRemoveMoney(cid, 10000) == TRUE then
					doPlayerAddBlessing(cid, talkState)
					npcHandler:say("You have been blessed by one of the five gods!")
				else
					npcHandler:say("You don't have enough money.")
				end
			else
				npcHandler:say("You need a premium account to buy blessings.")
			end
		elseif msgcontains(msg, 'no') then
			npcHandler:say("Then not.")
		end
		talkState = 0
	end
	return TRUE
end

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

To make that one work, make sure you have this in your modules.lua
Code:
		if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium == false) then
			if getPlayerBlessing(cid, parameters.bless) then
				npcHandler:say("Gods have already blessed you with this blessing!", cid)
			elseif doPlayerRemoveMoney(cid, parameters.cost) == FALSE then
				npcHandler:say("You don't have enough money for blessing.", cid)
			else
				npcHandler:say("You have been blessed by one of the five gods!", cid)
				doPlayerAddBlessing(cid, parameters.bless)
			end
		else
			npcHandler:say('You need a premium account in order to be blessed.', cid)
		end
		npcHandler:resetNpc()
		return true
	end
 
It works when I buy first bless, than second bless and so on. But when I buy "all bless" Im not getting blessed. I rlly want so its possible to get it work by only saying only 1 command. Can you do that? I can also add u on msn, it would be more comfortable to talk there, or you can add me [email protected]
 
Last edited:
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 10000 gold?'})
	node1:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 1, premium = false, cost = 10000})
	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 10000 gold?'})
	node2:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 2, premium = false, cost = 10000})
	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 10000 gold?'})
	node3:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 3, premium = false, cost = 10000})
	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 10000 gold?'})
	node4:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 4, premium = false, cost = 10000})
	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 10000 gold?'})
	node5:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 5, premium = false, cost = 10000})
	node5:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})	

local node6 = keywordHandler:addKeyword({'all bless'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the fifth blessing for 50000 gold?'})
	node6:addChildKeyword({'yes'}, StdModule.bless, {npcHandler = npcHandler, bless = 5, bless = 1, bless = 4, bless = 3, bless = 2, premium = false, cost = 50000})
	node6:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})	

npcHandler:addModule(FocusModule:new())

And a NPC:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="[COLOR="Red"]HELLO OTLAND[/COLOR]" script="data/npc/scripts/[COLOR="Red"]xxxxxx[/COLOR].lua" walkinterval="2000" speed="1" floorchange="0" access="5" level="1" maglevel="1">
	<health now="150" max="150"/>
	<look type="138" head="55" body="68" legs="96" feet="32" corpse="2212"/>
	<parameters>
	<parameter key="message_greet" value="Hello,  |PLAYERNAME|. I sell 'first', 'second', 'third', 'fourth' and 'fifth' bless for 10.000 gold coins each." />	
	</parameters>
</npc>

ExibeR forgot to change last node to 6
This should work

Credits to ExibeR
 
Last edited:
It doesnt work btw, buying all bless it takes the money off you, like it should, but then gives you no blessings (or possibly one, but i cant tell), anyone know how to fix?
 
@up
ye


PS. If you see this and ur a scripter we would be very thankfull if you edited the script so It would be possible to buy all 5 blessings with 1 command.

Thank you!
 
@up
ye


PS. If you see this and ur a scripter we would be very thankfull if you edited the script so It would be possible to buy all 5 blessings with 1 command.

Thank you!

Meanwhile you can use the talkaction script I have.
Go to /data/talkactions/scripts/ and create a new .lua file called bless.lua
Insert
Code:
function onSay(cid, words, param)
    if getPlayerBlessing(cid, 1) or getPlayerBlessing(cid, 2) or getPlayerBlessing(cid, 3) or getPlayerBlessing(cid, 4) or getPlayerBlessing(cid, 5) then
        doPlayerSendCancel(cid,'You have already got one or more blessings!')
    else
        if doPlayerRemoveMoney(cid, 50000) == TRUE then
            doPlayerAddBlessing(cid, 1)
            doPlayerAddBlessing(cid, 2)
            doPlayerAddBlessing(cid, 3)
            doPlayerAddBlessing(cid, 4)
            doPlayerAddBlessing(cid, 5)
			doSendMagicEffect(getPlayerPosition(cid), CONST_ME_HOLYDAMAGE)
            doPlayerSendTextMessage(cid,MESSAGE_EVENT_ADVANCE,'You have been blessed by the gods!')
        else
            doPlayerSendCancel(cid, "You need 70k to get blessed!")
        end
    end    
    return 1
end
Then go back and open talkactions.xml
Add this line
Code:
	<talkaction access="0" log="no" filter="word" words="!bless" script="bless.lua" />

Then just make the npc say etc.
"To buy all blessings, write !bless and you shall be blessed by all five gods."

Use this as a temp solution
 
Back
Top