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

Make Npc

Scorpvm 101

Active Member
Joined
Feb 23, 2010
Messages
460
Solutions
3
Reaction score
28
Location
Spain
Hi boys,
Anyone know make one npc what. Dont make Trade.
Example:
Player says:
Hi
Npc Says:
Hello [playername] Really you change you 50 yellow eggs for me 50 red eggs?
Player Says:
yes
Npc Says:
Okay, thanks for change it.
BYE

~~~~~~~~~~~~
NPC SAYS: Sorry you dont have 50 yellow eggs.
 
Test this i just made it fast so if any errors post here

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Egg Trader" script="eggs.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="212" head="20" body="30" legs="40" feet="50" corpse="6054"/>
    <parameters>
      <parameter key="message_greet" value="Greetings |PLAYERNAME|. Really you change you 50 {yellow eggs} for me 50 red eggs?." />
    </parameters>
  </npc>


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 eggchange(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    if isPremium(cid) then
        if getPlayerItemCount(cid, [COLOR="yellow"]ID of YELLOW EGG[/COLOR]) >= 50 then
        if doPlayerRemoveItem(cid,[COLOR="yellow"]ID of YELLOW EGG[/COLOR],50) then
            selfSay(cid, Here you go!)
             
            doSendMagicEffect(getCreaturePosition(cid), 13)
            doPlayerAddItem(cid, [COLOR="red"]ID OF RED EGG[/COLOR], 1)
        end
        else
            selfSay(cid, Sorry, you dont have 50 Yellow eggs)
    end
    end
end
end

keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "I change yellow eggs for red eggs!"})

 node1 = keywordHandler:addKeyword({'yellow eggs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'if you got 50 yellow i ill trade for 50 red'})
    node1:addChildKeyword({'yes'}, eggchange, {})
    node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then. Come back when you got 50 yellow eggs.', reset = true}) 
	npcHandler:addModule(FocusModule:new())
 
Dont function :/


[28/10/2010 17:02:09] [Error - Npc interface]
[28/10/2010 17:02:09] (Unknown script file)
[28/10/2010 17:02:09] Description:
[28/10/2010 17:02:09] attempt to call a nil value
[28/10/2010 17:02:09] stack traceback:
 
LUA:
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 eggchange(cid, message, keywords, parameters, node)
	if(not npcHandler:isFocused(cid)) then
		return false
	elseif doPlayerRemoveItem(cid, 6541, 50) then
		selfSay(cid, 'Here you go!')
		doSendMagicEffect(getThingPos(cid), 13)
		doPlayerAddItem(cid, 6542, 50)
	else
		selfSay(cid, 'Sorry, you don\'t have 50 yellow eggs.')
	end
end

node1 = keywordHandler:addKeyword({'yellow eggs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to change 50 yellow eggs for 50 red eggs?'})
	node1:addChildKeyword({'yes'}, eggchange)
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then. Come back when you got 50 yellow eggs.', reset = true})
	npcHandler:addModule(FocusModule:new())
 
LUA:
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 eggchange(cid, message, keywords, parameters, node)
	if(not npcHandler:isFocused(cid)) then
		return false
	elseif doPlayerRemoveItem(cid, 6541, 50) then
		selfSay(cid, 'Here you go!')
		doSendMagicEffect(getThingPos(cid), 13)
		doPlayerAddItem(cid, 6542, 50)
	else
		selfSay(cid, 'Sorry, you don\'t have 50 yellow eggs.')
	end
end

node1 = keywordHandler:addKeyword({'yellow eggs'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to change 50 yellow eggs for 50 red eggs?'})
	node1:addChildKeyword({'yes'}, eggchange)
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then. Come back when you got 50 yellow eggs.', reset = true})
	npcHandler:addModule(FocusModule:new())

Parameter "cid" should be the second param on the function "selfSay".. right?
 
Last edited:
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

 
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 red_eggs = xxxx ----- ID OF RED EGG
local yellow_eggs = xxxx ----- ID OF YELLOW EGG

function creatureSayCallback(cid, type, msg)
if (msgcontains(msg, 'eggs') or msgcontains(msg, 'trade')) then
   npcHandler:say('Really you change you 50 yellow eggs for me 50 red eggs?', cid)
                           Topic[cid] = 1

if msgcontains(msg, 'yes') and getPlayerItemCount(cid,yellow_eggs) >= 50 and Topic[cid] == 1 then
       npcHandler:say('Okay, here you go!', cid)
       doPlayerRemoveItem(cid,yellow_eggs,50)
       doPlayerAddItem(cid,red_eggs, 1)
                           Topic[cid] = 0
       else
           npcHandler:say('You do not have the required eggs for this trade', cid)
       end

elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
       npcHandler:say('Then leave', cid)
                            Topic[cid] = 0
       return true
end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Dont function :S

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}


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 red_eggs = 6542 ----- ID OF RED EGG
local yellow_eggs = 6541 ----- ID OF YELLOW EGG

function creatureSayCallback(cid, type, msg)
if (msgcontains(msg, 'eggs') or msgcontains(msg, 'trade')) then
npcHandler:say('Really you change you 50 yellow eggs for me 50 red eggs?', cid)
Topic[cid] = 1

if msgcontains(msg, 'yes') and getPlayerItemCount(cid,yellow_eggs) >= 50 and Topic[cid] == 1 then
npcHandler:say('Okay, here you go!', cid)
doPlayerRemoveItem(cid,yellow_eggs,50)
doPlayerAddItem(cid,red_eggs, 1)
Topic[cid] = 0
else
npcHandler:say('You do not have the required eggs for this trade', cid)
end

elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
npcHandler:say('Then leave', cid)
Topic[cid] = 0
return true
end
end

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

NPC TALK EVERY TIME: Egg Trader: You do not have the required eggs for this trade
 
Try now
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}


function onCreatureAppear(cid) npcHandlernCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandlernCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandlernCreatureSay(cid, type, msg) end
function onThink() npcHandlernThink() end

local red_eggs = 6542 ----- ID OF RED EGG
local yellow_eggs = 6541 ----- ID OF YELLOW EGG

function creatureSayCallback(cid, type, msg)
         if (msgcontains(msg, 'eggs') or msgcontains(msg, 'trade')) then
            npcHandler:say('Really you change you 50 yellow eggs for me 50 red eggs?', cid)
                                   Topic[cid] = 1

elseif msgcontains(msg, 'yes') and getPlayerItemCount(cid,yellow_eggs) >= 50 and Topic[cid] == 1 then
       npcHandler:say('Okay, here you go!', cid)
                             doPlayerRemoveItem(cid,yellow_eggs,50)
                             doPlayerAddItem(cid,red_eggs, 1)
                                    Topic[cid] = 0

elseif  msgcontains(msg, 'yes') and getPlayerItemCount(cid,yellow_eggs) < 50 and Topic[cid] == 1 then
        npcHandler:say('You do not have the required eggs for this trade', cid)
                                    Topic[cid] = 0

elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
       npcHandler:say('Then leave', cid)
                                  Topic[cid] = 0
       return true
end
end


npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
[09/12/2010 16:32:15] [Error - Npc interface]
[09/12/2010 16:32:15] data/npc/scripts/eggs.lua: onThink
[09/12/2010 16:32:15] Description:
[09/12/2010 16:32:15] data/npc/scripts/eggs.lua:10: attempt to call global 'npcHandlernThink' (a nil value)
[09/12/2010 16:32:15] stack traceback:
[09/12/2010 16:32:15] data/npc/scripts/eggs.lua:10: in function <data/npc/scripts/eggs.lua:10>
 
Lol, all functions were spelled wrong, what the heck.
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
 
 
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 red_eggs = 6542 ----- ID OF RED EGG
local yellow_eggs = 6541 ----- ID OF YELLOW EGG
 
function creatureSayCallback(cid, type, msg)
         if (msgcontains(msg, 'eggs') or msgcontains(msg, 'trade')) then
            npcHandler:say('Really you change you 50 yellow eggs for me 50 red eggs?', cid)
                                   Topic[cid] = 1
 
elseif msgcontains(msg, 'yes') and getPlayerItemCount(cid,yellow_eggs) >= 50 and Topic[cid] == 1 then
       npcHandler:say('Okay, here you go!', cid)
                             doPlayerRemoveItem(cid,yellow_eggs,50)
                             doPlayerAddItem(cid,red_eggs, 1)
                                    Topic[cid] = 0
 
elseif  msgcontains(msg, 'yes') and getPlayerItemCount(cid,yellow_eggs) < 50 and Topic[cid] == 1 then
        npcHandler:say('You do not have the required eggs for this trade', cid)
                                    Topic[cid] = 0
 
elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
       npcHandler:say('Then leave', cid)
                                  Topic[cid] = 0
       return true
end
end
 
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top