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

Script not working :(

  • Thread starter Thread starter Deleted member 49793
  • Start date Start date
D

Deleted member 49793

Guest
Its suppose to, when you turn in 10 of 2670 (Shrimp) give you 10k hp, I want it in tables so i can add differnet items for differnet experience. Can someone help?

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

local Topic = {}
local items = {
	[{2670,10}] = 10000
}

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)
	for v, x in ipairs(items) do
		if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
			if getPlayerItemCount(cid, v[1]) >= v[2] then
				npcHandler:say("Hello " .. getCreatureName(cid) .. ". Would you like to {exchange} 10 shrimp for some experience?", cid)
				Topic[cid] = 1
			else
				npcHandler:say("Hmm...don't think I can help you.", cid)
				Topic[cid] = 0
			end
			npcHandler:addFocus(cid)
		elseif(not npcHandler:isFocused(cid)) then
			return false
		elseif Topic[cid] == 1 then
			if msgcontains(msg, "exchange") then
				npcHandler:say("Are you sure you want to exchange " .. v[2] .. "x " .. getItemInfo(v[1]).name .. " for " .. x .. " experience points?", cid)
				Topic[cid] = 2
			else
				npcHandler:say("What was that? I don't understand you.", cid)
				Topic[cid] = 1
			end
		elseif Topic[cid] == 2 then
			if msgcontains(msg, "yes") then
				if doPlayerRemoveItem(cid, v[1], v[2] or 1) then
					npcHandler:say("Great! Here you are.", cid)
					doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
					doPlayerAddExperience(cid, x)
					Topic[cid] = 0
				else
					npcHandler:say("You do not have the item with you.", cid)
					Topic[cid] = 0
				end
			elseif msgcontains(msg, "no") then
				npcHandler:say("Well, then leave.", cid)
				Topic[cid] = 0
			end
		elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") and npcHandler:isFocused(cid) then
			npcHandler:say("Good bye.", cid, TRUE)
			Topic[cid] = nil
			npcHandler:releaseFocus(cid)
		end
		
		return true
	end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Have a good day!")
 
its just an exchange npc why make it so dificult o,o if i understand corect then you want to change 10 shrimps for say like 10k exp?

try this and if you want to add new items then just copy from function eggchange till the end and paste it and then just change the eggchange to shrimptoexp and at down at npc node add node2 about shripstoexp.

this is just example of trade
the guy want to trade yellow eggs for red eggs you can change the yellow eggs id to shrimp and the red eggs to exp

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)
            doPlayerAddExperience(cid, 10000)
        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())
 
Last edited:
Back
Top