• logo_cipsoft
    Nowe serwery zostały otwarte 19 Lut 2025:
    Noctalia (Open PvP) Ignitera (Open PvP) us_logo Xybra (Open PvP)

NPC [TFS z priv npc] Soft Man(naprawa soft?w)

Status
Zamknięty.

Miziak

Advanced User
Dołączył
Wrzesień 16, 2008
Posty
175
Liczba reakcji
27
Witam,
przegl?daj?c fora i og?lnie szukaj?c w sieci npc naprawiaj?cego softy widz? ich wiele ale zwykle nie s? uniwersalne tylko spreparowane pod dan? wersj? tibii wi?c postanowi?em napisa? co? w miar? uniwersalnego :)
Wi?c tak w data/npc tworzymy plik soft.xml i wlkejamy do niego:
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Soft" script="soft.lua" walkinterval="2000" floorchange="0">
	<health now="150" max="150"/>
	<look type="134" head="57" body="59" legs="40" feet="76" corpse="2212"/>
</npc>
A w data/npc/scripts tworzymy plik soft.lua i w nim umieszczamy:
Kod:
local items = {
						stare = 10021, -- id zepsutych soft?w
						nowe = {2640, 6132}, -- id nowych soft?w
						cena = 20000 -- w gp
					}
local focuses = {}
local talkStates = {}
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)) then
			doNpcSetCreatureFocus(v)
			return
		end
	end
	doNpcSetCreatureFocus(0)
end
local function isTalkState(cid)
	for _, v in pairs(talkStates) do
		if(v[1] == cid) then
			return true
		end
	end
	return false
end
local function setTalkState(cid, state)
	if(not isTalkState(cid)) then
		table.insert(talkStates, {cid, state})
	else
		for _, v in pairs(talkStates) do
			if(v[1] == cid) then
				v[2] = state
				break
			end
		end
	end
end
local function removeTalkState(cid)
	for i, v in pairs(talkStates) do
		if(v[1] == cid) then
			table.remove(talkStates, i)
			break
		end
	end
end
local function getTalkState(cid)
	for _, v in pairs(talkStates) do
		if(v[1] == cid) then
			return v[2]
		end
	end
	return 0
end
function onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		removeFocus(cid)
		removeTalkState(cid)
		if(isPlayer(cid)) then --Be sure he's online
			closeShopWindow(cid)
		end
	end
end
function onCreatureSay(cid, type, msg)
	if((msg == "hi") and not (isFocused(cid))) then
		selfSay("Witaj, ".. getCreatureName(cid) ..".", cid, true)
		selfSay("I can {rapair} if u have full used boots or {renew} if u have some minutes left!", cid)
		addFocus(cid)
	elseif((isFocused(cid)) and (msg == "rapair" or msg == "repair boots" or msg == "soft boots") and getTalkState(cid) ~= 2) then
		setTalkState(cid, 1)
		selfSay("Do you want me to rapair your soft boots for 20k?", cid)
	elseif((isFocused(cid)) and msg == "renew" and getTalkState(cid) ~= 1) then
		setTalkState(cid, 2)
		selfSay("Do you want me to renew your soft boots for 20k?", cid)
	elseif((isFocused(cid)) and msg == "yes" and getTalkState(cid) ~= 0) then
		if((getPlayerItemCount(cid, items.stare) >= 1 or getPlayerItemCount(cid, items.nowe[1]) >= 1 or getPlayerItemCount(cid, items.nowe[2]) >= 1) and getPlayerMoney(cid) >= items.cena)then
			if(getTalkState(cid) == 1)then
				if(not doPlayerRemoveItem(cid, items.stare, 1))then
					selfSay("You haven't soft boots to rapair!", cid)
					removeTalkState(cid)
					return
				end
			else
				if(not doPlayerRemoveItem(cid, items.nowe[1], 1) and not doPlayerRemoveItem(cid, items.nowe[2], 1))then
					selfSay("You haven't soft boots to renew!", cid)
					removeTalkState(cid)
					return
				end
			end
			doPlayerRemoveMoney(cid, items.cena)
			doPlayerAddItem(cid, items.nowe[1], 1)
			selfSay("Here you are!", cid)
		else
			selfSay((getPlayerMoney(cid) < items.cena and "Sorry, you dont have money!" or (getTalkState(cid) == 1 and "Sorry, you dont have worn soft boots!" or "Sorry, you dont have soft boots!")), cid)
		end
		removeTalkState(cid)
	elseif((isFocused(cid)) and msg == "no" and getTalkState(cid) ~= 0) then
		selfSay("Ok Man!", cid)
		removeTalkState(cid)
	elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
		selfSay("Goodbye!", cid, true)
		closeShopWindow(cid)
		removeFocus(cid)
		removeTalkState(cid)
	end
end
function onPlayerCloseChannel(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		closeShopWindow(cid)
		removeFocus(cid)
		removeTalkState(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(not isCreature(focus)) then
			removeFocus(focus)
		else
			local distance = getDistanceTo(focus) or -1
			if((distance > 4) or (distance == -1)) then
				selfSay("Hmph!")
				closeShopWindow(focus)
				removeFocus(focus)
				removeTalkState(focus)
			end
		end
	end
	lookAtFocus()
end
I gotowe!
Pozdrawiam,
Miziak ;)
 
Status
Zamknięty.
Do góry