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

REQUEST: NPC Help

MadMOOK

Hoo
Joined
Apr 20, 2011
Messages
802
Reaction score
44
Heres the NPC. You gain attribute points per level that you can trade with this NPC. Its WAY to slow!!!
I say Hi, atrribute points, the NPC says vitality or mana. I pick one and npc gives you what you ask for like it should, but it says bye.....

Can someone make this work better?
If i have 64 attribute points and want 30 points put into vitality(hp) I would like to say 30 vitality and get the hp for 30 points and have it take the 30 attribute points away.
Anyone feel me? lol




LUA:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Rootehs Attributes" script="data/npc/scripts/attribute.lua" walkinterval="2000" floorchange="0">
	<health now="150" max="150"/>
  <look type="131" head="95" body="95" legs="95" feet="95" corpse="6080"/>
	<parameters>
		<parameter key="module_shop" value="1"/>
	</parameters>
</npc>
LUA:
local focuses = {}
local function isFocused(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			return true
		end
	end
	return false
end

local function addFocus(cid)
	if(not isFocused(cid)) then
		table.insert(focuses, cid)
	end
end
local function removeFocus(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			table.remove(focuses, i)
			break
		end
	end
end
local function lookAtFocus()
	for i, v in pairs(focuses) do
		if(isPlayer(v) == TRUE) then
			doNpcSetCreatureFocus(v)
			return
		end
	end
	doNpcSetCreatureFocus(0)
end

local function doPlayerAddAttributePoint(cid, amount)
-- Function made by Rooteh
-- doPlayerAddAttributePoint(cid, amount)
local storagevalue = 47061
local current = getPlayerStorageValue(cid, storagevalue)
local new = (current+amount)
setPlayerStorageValue(cid, storagevalue, new)
return LUA_NO_ERROR
end

local function doPlayerCheckAttributePoint(cid)
-- Function made by Rooteh
-- doPlayerCheckAttributePoint(cid)
local storagevalue = 47061
local amt = getPlayerStorageValue(cid, storagevalue)
return amt
end

function onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		removeFocus(cid)
		if(isPlayer(cid) == TRUE) then --Be sure he's online
			closeShopWindow(cid)
		end
	end
end

function onCreatureSay(cid, type, msg)
local Vitality = 
{				[1] = {name = 'Sorcerer', cost = 1, amount = 5},   ---[1] = Vocation,  Name = Vocation Name, Cost = Amount of Attribute Points Needed, Amount = MaxHp Added
				[2] = {name = 'Druid', cost = 1, amount = 5},
				[3] = {name = 'Paladin', cost = 1, amount = 5},
				[4] = {name = 'Knight', cost = 1, amount = 5},
				[5] = {name = 'Master Sorcerer', cost = 1, amount = 5},
				[6] = {name = 'Elder Druid', cost = 1, amount = 5},
				[7] = {name = 'Royal Paladin', cost = 1, amount = 10},
				[8] = {name = 'Elite Knight', cost = 1, amount = 15},

}

local Energy = 
{				[1] = {name = 'Sorcerer', cost = 1, amount = 5},   ---[1] = Vocation,  Name = Vocation Name, Cost = Amount of Attribute Points Needed, Amount = MaxMana Added
				[2] = {name = 'Druid', cost = 1, amount = 5},
				[3] = {name = 'Paladin', cost = 1, amount = 5},
				[4] = {name = 'Knight', cost = 1, amount = 5},
				[5] = {name = 'Master Sorcerer', cost = 1, amount = 10},
				[6] = {name = 'Elder Druid', cost = 1, amount = 10},
				[7] = {name = 'Royal Paladin', cost = 1, amount = 5},
				[8] = {name = 'Elite Knight', cost = 1, amount = 5},
}

	if((msg == "hi") and not (isFocused(cid))) then
		selfSay("Welcome "..getCreatureName(cid)..", would you like to learn about {Attribute Points}? You currently have "..doPlayerCheckAttributePoint(cid).." attribute points.", cid)
		addFocus(cid)
		talk_state = 1
	elseif((isFocused(cid)) and (msg == "attribute" or msg == "points" or msg == "help" or msg == "job" or msg == "attribute point" or msg == "attribute points")) and talk_state == 1 then
		selfSay("When you gain levels, you recieve attribute points. You can spend the attribute points on {vitality} or {energy} to improve your character.", cid)
	elseif((isFocused(cid)) and (msg == "energy")) and talk_state == 1 then
		selfSay("As a "..(Energy[getPlayerVocation(cid)].name).." you can increase your max mana by "..(Energy[getPlayerVocation(cid)].amount)..".  It will cost you "..(Energy[getPlayerVocation(cid)].cost).." attribute points.", cid)
		selfSay("Do you want to spend your attribute points on energy?", cid)
		talk_state = 2
	elseif((isFocused(cid)) and (msg == "yes" or msg == "ye")) and talk_state == 2 then
		if doPlayerCheckAttributePoint(cid) >= Energy[getPlayerVocation(cid)].amount then
			local maxmana = getCreatureMaxMana(cid)
			setCreatureMaxMana(cid, (maxmana+Energy[getPlayerVocation(cid)].amount))
			local mana = (getCreatureMaxMana(cid)-getCreatureMana(cid))
			doCreatureAddMana(cid, mana)
			doPlayerAddAttributePoint(cid, -(Energy[getPlayerVocation(cid)].cost))
			selfSay("Your max mana has increased by "..(Energy[getPlayerVocation(cid)].amount).."!", cid)
			selfSay("Goodbye, come back and see me soon!", cid)
			talk_state = 0
			removeFocus(cid)
		else
			selfSay("You do not have enough attribute points!", cid)
			selfSay("Come back after you level.", cid)
			talk_state = 0
			removeFocus(cid)
		end
	elseif((isFocused(cid)) and (msg == "vitality")) and talk_state == 1 then
		selfSay("As a "..(Vitality[getPlayerVocation(cid)].name).." you can increase your max health by "..(Vitality[getPlayerVocation(cid)].amount)..".  It will cost you "..(Vitality[getPlayerVocation(cid)].cost).." attribute points.", cid)
		selfSay("Do you want to spend your attribute points on vitality?", cid)
		talk_state = 3
	elseif((isFocused(cid)) and (msg == "yes" or msg == "ye")) and talk_state == 3 then
		if doPlayerCheckAttributePoint(cid) >= Vitality[getPlayerVocation(cid)].cost then
			local maxhp = getCreatureMaxHealth(cid)
			setCreatureMaxHealth(cid, (maxhp+Vitality[getPlayerVocation(cid)].amount))
			local health = (getCreatureMaxHealth(cid)-getCreatureHealth(cid))
			doCreatureAddHealth(cid, health)
			doPlayerAddAttributePoint(cid, -(Vitality[getPlayerVocation(cid)].cost))
			selfSay("Your max health has increased by "..(Vitality[getPlayerVocation(cid)].amount).."!", cid)
			selfSay("Goodbye, come back and see me soon!", cid)
			talk_state = 0
			removeFocus(cid)	
		else
			selfSay("You do not have enough attribute points!", cid)
			selfSay("Come back after you level.", cid)
			talk_state = 0
			removeFocus(cid)
		end
	elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
		selfSay("cya!", cid, TRUE)
		closeShopWindow(cid)
		removeFocus(cid)
	end
end

function onPlayerCloseChannel(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		closeShopWindow(cid)
		removeFocus(cid)
	end
end

function onPlayerEndTrade(cid)
	selfSay("It was a pleasure doing business with you.", cid)
end

function onThink()
	for i, focus in pairs(focuses) do
		if(isCreature(focus) == FALSE) then
			removeFocus(focus)
		else
			local distance = getDistanceTo(focus) or -1
			if((distance > 4) or (distance == -1)) then
				selfSay("Hmph!")
				closeShopWindow(focus)
				removeFocus(focus)
			end
		end
	end
	lookAtFocus()
end
 
Back
Top