• 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 Npc Script

Tjay

Retired Hoster
Joined
Nov 25, 2009
Messages
588
Reaction score
69
Location
Behind you. Look out!
Is There a way to make a npc that you need 100 metal spikes(id 11208) and can trade them in for a health stone{id 11220} or mana skull(id 2229)
Thanks,
Tjay
 
Lua:
if getPlayerItemCount(cid, 11208) >= 100 then
	doPlayerRemoveItem(cid, 11208, 100)
	doPlayerAddItem(cid, 11220, 1) -- Or doPlayerAddItem(cid, 2229, 1)
end

Something like that (the function)
 
Basicly but i ended up changing it to just a npc that will add health or mana for 100 metal spikes but for some reason its not adding mana or health..

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 buyMana(cid, message, keywords, parameters, node)
		if doPlayerRemoveItem(cid, 11208, 100) then
		setCreatureMaxMana(cid, getCreatureMaxMana(cid)+1000)
		npcHandler:say("Thank you.", cid)
		npcHandler:releaseFocus(cid)
	else
		npcHandler:say("You don't have items required yet...", cid)
		npcHandler:releaseFocus(cid)
	end
	return true
end
 
function buyHealth(cid, message, keywords, parameters, node)
		if doPlayerRemoveItem(cid, 11208, 100) then
		setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+1000)
		npcHandler:say("Thank you.", cid)
		npcHandler:releaseFocus(cid)
	else
		npcHandler:say("You don't have items required yet..", cid)
		npcHandler:releaseFocus(cid)
	end
	return true
end
 
local node1 = keywordHandler:addKeyword({'mana'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Do you want to buy 1000 mana for 100 metal spikes?"})
	node1:addChildKeyword({'yes'}, buyMana, {npcHandler = npcHandler, onlyFocus = true, reset = true})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ok then.', reset = true})
 
local node2 = keywordHandler:addKeyword({'health'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Do you want to buy 1000 health for 100 metal spikes?"})
	node2:addChildKeyword({'yes'}, buyMana, {npcHandler = npcHandler, onlyFocus = true, reset = true})
	node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ok then.', reset = true})
 
npcHandler:addModule(FocusModule:new())

I have this im not getting any errors in console. But its not working it will take the spikes away but it does add to ur mana or ur hp
 
Try this:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local Topic = 0 
 
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 greetCallback(cid)
	Topic = 0
	return true
end 

npcHandler:setMessage(MESSAGE_GREET, "Greetings, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "How rude!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Bye.")
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback) 
 
if msgcontains(msg, "mana") then
	npcHandler:say("Do you want to buy 1000 mana for 100 metal spikes?.", cid)
		Topic = 1
	
elseif msgcontains(msg, "health") then
	npcHandler:say("Do you want to buy 1000 health for 100 metal spikes?.", cid)
		Topic = 2


	elseif Topic == 1 then
		if msgcontains(msg, 'yes') then
			if getPlayerItemCount(cid, 11208) >= 100 then
				doPlayerRemoveItem(cid, 11208, 100)
				setCreatureMaxMana(cid, getCreatureMaxMana(cid)+1000)
				npcHandler:say("Thank you.", cid)
				npcHandler:releaseFocus(cid)
				Topic = 0
			else
				npcHandler:say("You don't have items required yet...", cid)
				npcHandler:releaseFocus(cid)
                                Topic = 0
			end
		end	

	elseif Topic == 2 then
		if msgcontains(msg, 'yes') then
			if getPlayerItemCount(cid, 11208) >= 100 then
				doPlayerRemoveItem(cid, 11208, 100)
				setCreatureMaxMana(cid, getCreatureMaxHealth(cid)+1000)
				npcHandler:say("Thank you.", cid)
				npcHandler:releaseFocus(cid)
				Topic = 0
			else
				npcHandler:say("You don't have items required yet...", cid)
				npcHandler:releaseFocus(cid)
                                Topic = 0
			end
		end			
			
			

		end
	return TRUE
end

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

in data/npc make file exchanger.lua and paste in this

PHP:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Exchanger" script="data/npc/scripts/exchange.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="22" head="0" body="0" legs="0" feet="0" addons="0"/>
<parameters>
        <parameter key="message_greet" value="! Welcume ' Player.."/>
        <parameter key="message_farewell" value="Good bye!."/>
    </parameters>
</npc>

in data/npc/scripts make file exchange.lua and paste in this

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

-- XVX FORGER START --

function amulet(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
        if getPlayerItemCount(cid,11208) >= 1 then
        if doPlayerRemoveItem(cid,11208,100) and ) then
            npcHandler:say('Here is your item!', cid)
            doPlayerAddItem(cid,11220,1)
        end
        else
            npcHandler:say('You don\'t have these items!', cid)
    end
end

function obsidian(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
        if getPlayerItemCount(cid,11208) >= 1
        if doPlayerRemoveItem(cid,11208,100) and 
            npcHandler:say('Here is your item!', cid)
            doPlayerAddItem(cid,2229,1)
        end
        else
            npcHandler:say('You don\'t have these items!', cid)
    end
end	


local node1 = keywordHandler:addKeyword({'health stone'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to trade 100 metal spikes for a health stone?'})
    node2:addChildKeyword({'yes'}, obsidian, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then. Come back when you got the neccessary items.', reset = true})



local node2 = keywordHandler:addKeyword({'mana skull'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to trade 100 metal spikes for a mana skull?'})
    node2:addChildKeyword({'yes'}, obsidian, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then. Come back when you got the neccessary items.', reset = true})

npcHandler:addModule(FocusModule:new())
 
Last edited:
If you look at the #6 post by me ull see i ended up changing the script. I got the trading npc working one my buddies ended up helping me with it. but the one im using its suppose to just add 1000 to your max mana and or max health for 100 metal spikes.
 
Back
Top