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

Request: Npc

Scurzo

New Member
Joined
Aug 23, 2008
Messages
66
Reaction score
0
Hi, I dont know how to make this npcs so if anyone here could help me I would be very glad...

1. An npc that sells skills (for money) but with a skill limit (Example: If you have 100 at shielding it wont sell you shield skill anymore) -SOLVED-

2. An npc that adds "x" hp/mana to your max limit if you give him "x" items (not money)
 
Last edited:
Should work(tested on tfs 0.3.6)
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
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 msgcontains(msg, 'help') then
selfSay('Write "shielding", "sword", "axe", "club", "distance" or "magic" to get skills.')
elseif msgcontains(msg, 'magic') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get magic skill for 1 Crystal coin ?')
talk_state = 2
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end

elseif msgcontains(msg, 'yes') and talk_state == 2 then
talk_state = 0
	if(getPlayerMagLevel(cid) >= 100) then
	selfSay('You have max amount of this skill.')
	return 0
		elseif getPlayerItemCount(cid, 2160) >= 1 then
				if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
				doPlayerAddSpentMana(cid, 15000)
				selfSay('Here u are.')
		end
	else
selfSay('You must have 20 lvl.')
end

elseif msgcontains(msg, 'shielding') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get shielding skill for 1 Crystal coin ?')
talk_state = 1
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end

elseif msgcontains(msg, 'yes') and talk_state == 1 then
talk_state = 0
	if(getPlayerSkillLevel(cid, 5) >= 100) then
	selfSay('You have max amount of this skill.')
	return 0
		elseif getPlayerItemCount(cid, 2160) >= 1 then
				if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
				doPlayerAddSkillTry(cid, 5, 150)
				selfSay('Here u are.')
		end
	else
selfSay('You must have 20 lvl.')
end
elseif msgcontains(msg, 'sword') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get sword skill for 1 Crystal coin ?')
talk_state = 3
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end

elseif msgcontains(msg, 'yes') and talk_state == 3 then
talk_state = 0
	if(getPlayerSkillLevel(cid, 2) >= 100) then
	selfSay('You have max amount of this skill.')
	return 0
		elseif getPlayerItemCount(cid, 2160) >= 1 then
				if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
				doPlayerAddSkillTry(cid, 2, 20)
				selfSay('Here u are.')
		end
end
elseif msgcontains(msg, 'axe') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get axe skill for 1 Crystal coin ?')
talk_state = 4
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end

elseif msgcontains(msg, 'yes') and talk_state == 4 then
talk_state = 0
	if(getPlayerSkillLevel(cid, 3) >= 100) then
	selfSay('You have max amount of this skill.')
	return 0
		elseif getPlayerItemCount(cid, 2160) >= 1 then
				if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
				doPlayerAddSkillTry(cid, 3, 20)
				selfSay('Here u are.')
		end
end
elseif msgcontains(msg, 'club') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get club skill for 1 Crystal coin ?')
talk_state = 5
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end

elseif msgcontains(msg, 'yes') and talk_state == 5 then
talk_state = 0
	if(getPlayerSkillLevel(cid, 1) >= 100) then
	selfSay('You have max amount of this skill.')
	return 0
		elseif getPlayerItemCount(cid, 2160) >= 1 then
				if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
				doPlayerAddSkillTry(cid, 1, 20)
				selfSay('Here u are.')
		end
end

elseif msgcontains(msg, 'distance') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get distance skill for 1 Crystal coin ?')
talk_state = 6
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end

elseif msgcontains(msg, 'yes') and talk_state == 6 then
talk_state = 0
	if(getPlayerSkillLevel(cid, 4) >= 100) then
	selfSay('You have max amount of this skill.')
	return 0
		elseif getPlayerItemCount(cid, 2160) >= 1 then
				if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
				doPlayerAddSkillTry(cid, 4, 100)
				selfSay('Here u are.')
		end
end


elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
selfSay('Ok than.')
talk_state = 0
end
-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

But I couldn't find function like addskill(doPlayerAddSkill(cid, 1)adds skill only at once:S), I found only Addskilltries, so write in lines like
Code:
	doPlayerAddSkillTry(cid, 4, [COLOR="Red"]100[/COLOR])
Your value(tries)
Rep if I helped :)
 
Here ya go. Be sure to edit top.
Edit: couple syntax errors, fixed em.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local health_amount = --edit
local currency_item = --edit
local x = getCreatureMaxHealth(cid)
local total = x + health_amount
local cancel_message = "" --edit
local purchase_message = "" --edit

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[cid] = 0
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, "health") then
		npcHandler:say("Would you like to add" .. health_amount .. 'for 1' .. currency_item .. "?", cid)
		doPlayerSetStorageValue(cid, 1001, 1)
	elseif msgcontains(msg, "yes") and getPlayerStorageValue(cid, 1001) == 1 and getPlayerItemById(cid, true, currency_item) == true then
		doPlayerRemoveItem(cid, currency_item, 1)
		setCreatureMaxHealth(cid, total)
		doPlayerSendTextMessage(cid, 17, purchase_message)
	else
		doPlayerSendCancel(cid, cancel_message)
	end
end

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