• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

The Forgotten Server v0.2 (Mystic Spirit)

Status
Not open for further replies.
Has the NPC module for giving a player addons changed? My addon NPC ignores players who are trying to buy the first and second addons.

check the problem maybe is here

By Talaturen

Code:
if(npcHandler.focus ~= cid) then
with:
Code:
if(not npcHandler:isFocused(cid)) then

Replace all:
Code:
selfSay('text')
with:
Code:
npcHandler:say('text', cid)
 
check the problem maybe is here

By Talaturen

Code:
if(npcHandler.focus ~= cid) then
with:
Code:
if(not npcHandler:isFocused(cid)) then
Replace all:
Code:
selfSay('text')
with:
Code:
npcHandler:say('text', cid)

Not only this, the "talkState method" isn't working properly with the new system.
 
Where would I find these to check?

people on my server keep complaining cause of no addons it's annoying as hell lol
I've updated to patch 6 I figured it was fixed in there.. but i guess not yet.
 
Not only this, the "talkState method" isn't working properly with the new system.

talkstate works perfect for me.

Code:
if talkState == 1 then
		if msgcontains(msg, 'yes') and doPlayerRemoveMoney(cid, 300000) == TRUE then
			npcHandler:say("I hereby grant you access to use both addons.", cid)
			setPlayerStorageValue(cid, questID, 2)
			doPlayerAddOutfit(cid,132,1)
			doPlayerAddOutfit(cid,132,2)
			doPlayerAddOutfit(cid,140,1)
			doPlayerAddOutfit(cid,140,2)
			talkState = 0
		else
			npcHandler:say("Come back with 300,000 gold coins.", cid)
			talkState = 0
		end
	else
		if msgcontains(msg, 'addon') then
			if questState1 == -1 then
				npcHandler:say("Bring me 300,000 gold coins and I will grant you access to wear both nobleman addons.", cid)
				setPlayerStorageValue(cid, questID, 1)
			elseif questState1 == 1 then
				npcHandler:say("You brought me 300,000 gold coins?", cid)
				talkState = 1
			end
		end
	end

try it yourself
 
talkstate works perfect for me.

Code:
if talkState == 1 then
        if msgcontains(msg, 'yes') and doPlayerRemoveMoney(cid, 300000) == TRUE then
            npcHandler:say("I hereby grant you access to use both addons.", cid)
            setPlayerStorageValue(cid, questID, 2)
            doPlayerAddOutfit(cid,132,1)
            doPlayerAddOutfit(cid,132,2)
            doPlayerAddOutfit(cid,140,1)
            doPlayerAddOutfit(cid,140,2)
            talkState = 0
        else
            npcHandler:say("Come back with 300,000 gold coins.", cid)
            talkState = 0
        end
    else
        if msgcontains(msg, 'addon') then
            if questState1 == -1 then
                npcHandler:say("Bring me 300,000 gold coins and I will grant you access to wear both nobleman addons.", cid)
                setPlayerStorageValue(cid, questID, 1)
            elseif questState1 == 1 then
                npcHandler:say("You brought me 300,000 gold coins?", cid)
                talkState = 1
            end
        end
    end
try it yourself

Talaturen's commit @ SVN said:
* Fixed some issues in bless.lua (talkState could cause conflicts when more than 1 player was talking to NPC).

:confused:
 
I'm still getting this error.

[14/08/2008 16:14:36] Lua Script Error: [Npc interface]
[14/08/2008 16:14:36] data/npc/scripts/addons.lua:onCreatureSay

[14/08/2008 16:14:36] data/npc/lib/npcsystem/npchandler.lua:563: table index is nil
[14/08/2008 16:14:36] stack traceback:
[14/08/2008 16:14:36] data/npc/lib/npcsystem/npchandler.lua:563: in function 'say'
[14/08/2008 16:14:36] data/npc/scripts/addons.lua:674: in function 'callback'
[14/08/2008 16:14:36] data/npc/lib/npcsystem/npchandler.lua:365: in function 'onCreatureSay'
[14/08/2008 16:14:36] data/npc/scripts/addons.lua:7: in function <data/npc/scripts/addons.lua:7>

And I did exactly what you told me to do:

You are using:
npcHandler:say('text')
instead of:
npcHandler:say('text', cid)

That's why it's happening, it needs cid parameter to know to which player it will talk.

And it still brings up errors.




The script is here:
PS: Saved it as .txt because it won't upload .lua files.
 

Attachments

I'm still getting this error.



And I did exactly what you told me to do:



And it still brings up errors.




The script is here:
PS: Saved it as .txt because it won't upload .lua files.

Again, that script is far from exactly patched with what I told you.
 
Hey is there a Banker npc that will work for this server? or what?
 
So I have to make a new one with the new patch?
And this one can be deleted?

I don't get exactly what you mean.


for examle u have to change it also: npcHandler:say(addon_have_not_items)

on npcHandler:say((addon_have_not_items) ,cid)
more:
from npcHandler:say(addon_have_already) to npcHandler:say((addon_have_already), cid)
and all rest!
U have a lot of changing, but as Talaturen said, every decent txt program have replacing function, gl
 
for examle u have to change it also: npcHandler:say(addon_have_not_items)

on npcHandler:say((addon_have_not_items) ,cid)
more:
from npcHandler:say(addon_have_already) to npcHandler:say((addon_have_already), cid)
and all rest!
U have a lot of changing, but as Talaturen said, every decent txt program have replacing function, gl

Well, if you read the script a lot more carefully.

At line 23 (before the script):
addon_have_not_items = 'Sorry, you don\'t have these items.', cid

and:

npcHandler:say('Sorry, you don\'t have these items.', cid)

is the same as:

npcHandler:say(addon_have_not_items)
 
Very good, but this version has no items or monsters 8.20, commands do not work, someone help me with the commands?
Ty so much
 
commands are working, u have to set in char group_id 3
and in account Type 5 and group_id 3
 
OMG!

I'm dumb, and connot make this NPCs works normaly... =O
I trided to do everything, but nothing has worked. =S

Premium, Addon and Banker don't work...
If anybody can help me, I've gonna happy. =P
Sorry for my bad english, one day I will be better. =P

Look the scripts:

-> Addons
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


function buyAddons(cid, message, keywords, parameters, node)
	--TODO: buyAddons function in modules.lua
	if(cid ~= npcHandler.focus) then
		return false
	end

	local addon = parameters.addon
	local cost = parameters.cost
	local premium = (parameters.premium ~= nil and parameters.premium ~= false)

	if isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or premium == true then
		if doPlayerRemoveMoney(cid, cost) == TRUE then
			doPlayerAddAddons(cid, addon)
			npcHandler:say('There, you are now able to use all addons!')
		else
			npcHandler:say('Sorry, you do not have enough money.')
		end
	else
		npcHandler:say('I only serve customers with premium accounts.')
	end

	keywordHandler:moveUp(1)
	return true
end

local node1 = keywordHandler:addKeyword({'first addon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy the first addons set for 100000 gold coins?'})
	node1:addChildKeyword({'yes'}, buyAddons, {addon = 1, cost = 100000, premium = true})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'Too expensive, eh?'})

local node2 = keywordHandler:addKeyword({'second addon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to buy the second addons set for 200000 gold coins?'})
	node2:addChildKeyword({'yes'}, buyAddons, {addon = 2, cost = 200000, premium = true})
	node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'Too expensive, eh?'})

keywordHandler:addKeyword({'addon'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sell the first addons set for 10cc and the second addons set for 20cc.'})

npcHandler:addModule(FocusModule:new())

-> Premium
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({'promotion'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
	node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Allright then. Come back when you are ready.', reset = true})
 
local node2 = keywordHandler:addKeyword({'premium'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'How many days of premium do you want to buy? I offer 7 days for 5k, 30 days for 20k, 60 days for 35k, and 90 days for 55k.'})
	node2:addChildKeyword({'7'}, StdModule.premiumPlayer, {npcHandler = npcHandler, cost = 5000, text = 'You now have 7 more days of premium'})
	node2:addChildKeyword({'30'}, StdModule.premiumPlayer, {npcHandler = npcHandler, cost = 20000, text = 'You now have 30 more days of premium'})
	node2:addChildKeyword({'60'}, StdModule.premiumPlayer, {npcHandler = npcHandler, cost = 35000, text = 'You now have 60 more days of premium'})
	node2:addChildKeyword({'90'}, StdModule.premiumPlayer, {npcHandler = npcHandler, cost = 55000, text = 'You now have 90 more days of premium'})
 
npcHandler:addModule(FocusModule:new())

-> Banker
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
local stan = 0
local stan_two = 0
local player_pattern = '^[a-zA-Z0-9 -]+$'
local number_pattern = '%d'
local target_cid = 0
local number_pattern_two = '%d+'
local b, e = 0
local count = 0
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end
function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    if getPlayerStorageValue(cid,8996) <= 0 then
        setPlayerStorageValue(cid,8996,0)
    end
        
    if msgcontains(msg, 'deposit') or msgcontains(msg, 'wplac') then
        if string.find(msg, number_pattern) then
            b, e = string.find(msg, number_pattern_two)
            count = tonumber(string.sub(msg, b, e))
            if pay(cid,count) then
		        stan = getPlayerStorageValue(cid,8996) + count
		        setPlayerStorageValue(cid,8996,stan)
		        doPlayerRemoveMoney(cid,count)
		        selfSay('Money was deposited!')
		        talk_state = 0
		    else
			    selfSay('You dont have enough money!')
			    talk_state = 0
		    end
        else
            selfSay('How much money you want deposit?')
            talk_state = 1
        end
    elseif msgcontains(msg, 'withdraw') or msgcontains(msg, 'wyplac') then
        if string.find(msg, number_pattern) then
            b, e = string.find(msg, number_pattern_two)
            count = tonumber(string.sub(msg, b, e))
            if getPlayerStorageValue(cid,8996) - count >= 0 then
		        stan = getPlayerStorageValue(cid,8996) - count
		        setPlayerStorageValue(cid,8996,stan)
		        doPlayerAddMoney(cid,count)
		        selfSay('Money was withdrawed!')
		        talk_state = 0
			else
				selfSay('You do not have anought money on account!')
				talk_state = 0
		    end
        else
            selfSay('How much money you want withdraw?')
            talk_state = 2
        end
    elseif msgcontains(msg, 'transfer') or msgcontains(msg, 'transferuj') then
        selfSay('Want you for who transfer money?')
        talk_state = 3
    elseif msgcontains(msg, 'balance') or msgcontains(msg, 'stan') then
        selfSay('Your account have ' ..  getPlayerStorageValue(cid,8996) .. 'gp.')
        talk_state = 4		  	
	elseif talk_state == 1 then
	   if string.find(msg, number_pattern) then
		   if pay(cid,msg) then
		      stan = getPlayerStorageValue(cid,8996) + msg
		      setPlayerStorageValue(cid,8996,stan)
		      doPlayerRemoveMoney(cid,msg)
		      selfSay('Money was deposited!')
		      talk_state = 0
		   else
			  selfSay('You dont have anought money!')
			  talk_state = 0
		   end
		else
		    selfSay('There is not number!')
		    talk_state = 0
	    end
	elseif talk_state == 2 then
	    stan = getPlayerStorageValue(cid,8996)
		if string.find(msg, number_pattern) then
		    if getPlayerStorageValue(cid,8996) - msg >= 0 then
		        stan = getPlayerStorageValue(cid,8996) - msg
		        setPlayerStorageValue(cid,8996,stan)
		        doPlayerAddMoney(cid,msg)
		        selfSay('Money was withdrawed!')
		        talk_state = 0
			else
				selfSay('You do not have anought money on account!')
				talk_state = 0
		    end
		else
		    selfSay('There is not number!')
		    talk_state = 0
		end
	elseif talk_state == 3 then
		if string.find(msg, player_pattern) then
		    target_cid = getPlayerByName(msg)
		    if isPlayer(target_cid) == 1 then		        		    
		        talk_state = 4
		        selfSay('How much i must transfer?')
		    else
			    talk_state = 0
		        selfSay('Player is not online or this player dont exists.')    
		    end
		else
		    selfSay('It isnt nick!')
		    talk_state = 0
		end
	elseif talk_state == 4 then
	    stan = getPlayerStorageValue(cid,8996)
		if string.find(msg, number_pattern) then
		    if stan - msg >= 0 then
		        stan_two = getPlayerStorageValue(target_cid,8996) + msg
                    stan = getPlayerStorageValue(cid,8996) - msg
                    setPlayerStorageValue(target_cid,8996,stan_two)
                    setPlayerStorageValue(cid,8996,stan)
                    doPlayerRemoveMoney(cid,msg)
                    talk_state = 0
                    selfSay('Money transfered.')
		    else
		        selfSay('You do not have anought money on account!')
		        talk_state = 0
		    end
		else
		    selfSay('There is not number!')
		    talk_state = 0
	    end
	elseif talk_state == 5 then				
	end
		   
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Status
Not open for further replies.
Back
Top