What's new

[8.22][SQL][TFS] Ma?y problem

Status
Not open for further replies.

losiek2

User
Joined
Apr 26, 2008
Messages
27
Reaction score
1
siemka, mam nast?puj?cy skrypt do npc:
PHP:
 ---credits to DAcs, and to all guys from OTfans.net forum. I tooked from theirs post scripts, combinning, testing, and from server libraries. I made a lots of tests, so i forgot from who i tooked which part of script.It works on TFS 0.214 Mystic.
 ---Please, try to don`t miss any space, row, because it will give you and error message on server console even if npc will works. Also thanks to guys who made TFS Mystic for keeping a library for guidenance
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 itemWindow = {
      -- Wand of Vortex
      {id=2190, charges=0, buy=500, sell=100},
	  -- Wand of Dragonbreath
      {id=2191, charges=0, buy=1000, sell=200},
      -- wand of decay
      {id=2188, charges=0, buy=5000, sell=1000},
      -- wand of cosmic energy
      {id=2189, charges=0, buy=10000, sell=2000},
      -- Wand of Inferno
      {id=2187, charges=0, buy=15000, sell=5000},
      -- Wand of Starstorm
      {id=8920, charges=0, buy=18000, sell=3600},
      -- Wand of Voodoo
      {id=8922, charges=0, buy=22000, sell=4400},
      -- Snakebite Rod
      {id=2182, charges=0, buy=500, sell=100},
      -- Moonlight Rod
      {id=2186, charges=0, buy=1000, sell=200},
      -- necrotic Rod
      {id=2185, charges=0, buy=5000, sell=1000},
      -- Northwind Rod
      {id=8911, charges=0, buy=7500, sell=1500},
      -- Terra Rod
      {id=2181, charges=0, buy=10000, sell=2000},
      -- Hailstorm Rod
      {id=2183, charges=0, buy=15000, sell=3000},
      -- Springsprout Rod
      {id=8912, charges=0, buy=18000, sell=3600},
      -- Underworld Rod
      {id=8910, charges=0, buy=22000, sell=4400},
      -- Ultimate Healing Rune
      {id=2273, charges=0, buy=400, sell=175},
      -- sudden death
      {id=2268, charges=0, buy=700, sell=325},
      -- Poison Field
      {id=2285, charges=0, buy=1200, sell=50},
      -- Poison Bomb
      {id=2286, charges=0, buy=3000, sell=50},
      -- Poison Wall
      {id=2289, charges=0, buy=200, sell=50},
      -- Fire Field
      {id=2301, charges=0, buy=350, sell=50},
      --Firebomb
      {id=2305, charges=0, buy=50, sell=50},
      --Fire Wall
      {id=2303, charges=0, buy=1200, sell=50},
	   -- Soulfire
      {id=2308, charges=0, buy=1200, sell=50},
	        -- Fireball
      {id=2302, charges=0, buy=1200, sell=50},
	        -- Great Fireball
      {id=2304, charges=0, buy=1200, sell=50},
	  	        -- Mana Rune
      {id=2298, charges=0, buy=12000, sell=5000},
}
 
local items = {}
for _, item in ipairs(itemWindow) do
	items[item.id] = {buyPrice = item.buy, sellPrice = item.sell, subtype = item.subtype}
end
 
local function getPlayerMoney(cid)
	return ((getPlayerItemCount(cid, 2160) * 10000) + 
	(getPlayerItemCount(cid, 2152) * 100) + 
	getPlayerItemCount(cid, 2148))
end
 
local onBuy = function(cid, item, subtype, amount)
	if(items[item] == nil) then
		selfSay("Ehm.. sorry... this shouldn't be there, I'm not selling it.", cid)
		return
	end
 
	if(getPlayerMoney(cid) >= amount*items[item].buyPrice) then
		local itemz, i = doPlayerAddItem(cid, item, subtype, amount)
		if(i < amount) then
			if(i == 0) then
				selfSay("Sorry, but you don't have space to take it.", cid)
			else
				selfSay("I've sold some for you, but it seems you can't carry more than this. I won't take more money than necessary.", cid)
				doPlayerRemoveMoney(cid, i*items[item].buyPrice)
			end
		else
			selfSay("Thanks for the money!", cid)
			doPlayerRemoveMoney(cid, amount*items[item].buyPrice)
		end
	else
		selfSay("Stfu noob, you don't have money.", cid)
	end
end
 
local onSell = function(cid, item, subtype, amount)
	if(items[item] == nil) then
		selfSay("Ehm.. sorry... this shouldn't be there, I'm not buying it.", cid)
	end
 
	if(subtype < 1) then
		subtype = -1
	end
	if(doPlayerRemoveItem(cid, item, amount, subtype) == TRUE) then
		doPlayerAddMoney(cid, items[item].sellPrice*amount)
		selfSay("Here you are.", cid)
	else
		selfSay("No item, no deal.", cid)
	end
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)
	if((msg == "hi") and not (isFocused(cid))) then
		selfSay("Welcome, ".. getCreatureName(cid) .."I sell and buy all magic items. Want to trade anything?", cid, TRUE)
		selfSay("Do you want to see my {magic items}?", cid)
		addFocus(cid)
	elseif((isFocused(cid)) and (msg == "magic items" or msg == "trade")) then
		selfSay("Pretty nice, right?", cid)
		openShopWindow(cid, itemWindow, onBuy, onSell)
	elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
		selfSay("Goodbye!", 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
i nie wiem jak mam zrobi? by gracze mogli kupowa? po kilka item?w naraz oraz by pobierana by?a op?ata gdy si? kupuje co?. b?d? wdzi?czny gdy kto? pomo?e. :)


@down: tak dzia?a, na tym kt?ry sam dawa?es na forum. ;D
 
Last edited:

Matre

Nie b?dzie ciszy...
Joined
Sep 12, 2008
Messages
789
Reaction score
143
Odp: [8.22][SQL][TFS] Ma?y problem

Ten skrypt Ci dziala w ogole na nowym tfsie? dziwne
 

losiek2

User
Joined
Apr 26, 2008
Messages
27
Reaction score
1
Odp: [8.22][SQL][TFS] Ma?y problem

Refresh, pom??cie prosz?.
 

Matre

Nie b?dzie ciszy...
Joined
Sep 12, 2008
Messages
789
Reaction score
143
Odp: [8.22][SQL][TFS] Ma?y problem

hmm jak to, przeciez wybiera sie tam "Amount" od 1 do 100 itemow naraz mozna kupic :>

edit: chyba jednak ten skrypt nie dziala :)
za kazdym razem gdy chce cos kupic mimo ze mam miejsce:
Sorry, but you don't have space to take it.
 
Last edited:

Kamil

Wielki powr?t
Joined
Apr 10, 2008
Messages
1,730
Reaction score
243
Age
32
Odp: [8.22][SQL][TFS] Ma?y problem

Masz data\npc\Malak.xml

<npc name="Malak" script="data/npc/scripts/runes.lua" walkinterval="2000" floorchange="0" access="5" level="1" maglevel="1">
<health now="150" max="150"/>
<look type="130" head="132" body="116" legs="116" feet="76" corpse="2212"/>
<parameters>
<parameter key="message_greet" value="Witaj |PLAYERNAME|. Sprzedaje runes, fluids, wands and rods." />
<parameter key="message_needmoremoney" value="Nie masz pieniedzy." />
<parameter key="message_decline" value=" |TOTALCOST| gold coins ok?" />
</parameters>
</npc>

data\npc\scripts\runes.lua

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



-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:eek:nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:eek:nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:eek:nCreatureSay(cid, type, msg) end
function onThink() npcHandler:eek:nThink() end
-- OTServ event handling functions end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:addBuyableItem({'light wand', 'lightwand'}, 2163, 500, 'magic light wand')

shopModule:addBuyableItem({'manapotion', 'manapotion'}, 7620, 100, 'mana potion')
shopModule:addBuyableItem({'healthpotion', 'healthpotion'}, 7618, 100, 'health potion')
shopModule:addBuyableItem({'strong mana potion', 'strong mana potion'}, 7589, 300, 'strong mana potion')
shopModule:addBuyableItem({'strong health potion', 'strong health potion'}, 7588, 300, 'strong health potion')
shopModule:addBuyableItem({'great mana potion', 'great mana potion'}, 7590, 500, 'great mana potion')
shopModule:addBuyableItem({'great health potion', 'great health potion'}, 7591, 500, 'great health potion')


shopModule:addBuyableItem({'heavy magic missile', 'hmm'}, 2311, 3000, 100, 'heavy magic missile rune')
shopModule:addBuyableItem({'great fireball', 'gfb'}, 2304, 1500, 100, 'great fireball rune')
shopModule:addBuyableItem({'explo', 'xpl'}, 2313, 2500, 100, 'explosion rune')
shopModule:addBuyableItem({'ultimate healing', 'uh'}, 2273, 4000, 100, 'ultimate healing rune')
shopModule:addBuyableItem({'sudden death', 'sd'}, 2268, 8000, 100, 'sudden death rune')
shopModule:addBuyableItem({'blank', 'rume'}, 2260, 1, 'blank rume')
shopModule:addBuyableItem({'manarune', 'mr'}, 2270, 10000, 100, 'manarune rune')


shopModule:addBuyableItem({'wand of inferno', 'inferno'}, 2187, 15000, 'wand of inferno')
shopModule:addBuyableItem({'wand of plague', 'plague'}, 2188, 5000, 'wand of plague')
shopModule:addBuyableItem({'wand of cosmic energy', 'cosmic energy'}, 2189, 10000, 'explosion rune')
shopModule:addBuyableItem({'wand of vortex', 'vortex'}, 2190, 500, 'wand of cosmic energy')
shopModule:addBuyableItem({'wand of dragonbreath', 'dragonbreath'}, 2191, 1000, 'wand of dragonbreath')

shopModule:addBuyableItem({'quagmire rod', 'quagmire'}, 2181, 10000, 'quagmire rod')
shopModule:addBuyableItem({'snakebite rod', 'snakebite'}, 2182, 500, 'snakebite rod')
shopModule:addBuyableItem({'tempest rod', 'tempest'}, 2183, 15000, 'tempest rod')
shopModule:addBuyableItem({'volcanic rod', 'volcanic'}, 2185, 3000, 'volcanic rod')
shopModule:addBuyableItem({'moonlight rod', 'moonlight'}, 2186, 500, 'moonlight rod')

npcHandler:addModule(FocusModule:new())

powinno dzia?a?.
 

Matre

Nie b?dzie ciszy...
Joined
Sep 12, 2008
Messages
789
Reaction score
143
Odp: [8.22][SQL][TFS] Ma?y problem

Kamil ja mam dzialajacego npc, losiek2 mysle ze tez ma, ale tu chodzi o ten konkretny skrypt, zobacz jak on dziala, jednym slowen jest zaje**sty, szkoda tylko ze do konca nie dziala.
 

losiek2

User
Joined
Apr 26, 2008
Messages
27
Reaction score
1
Odp: [8.22][SQL][TFS] Ma?y problem

~~Refresh~~


hmm jak to, przeciez wybiera sie tam "Amount" od 1 do 100 itemow naraz mozna kupic :>

edit: chyba jednak ten skrypt nie dziala :)
za kazdym razem gdy chce cos kupic mimo ze mam miejsce:
Sorry, but you don't have space to take it.

Hmm wybierasz niby te amount 1 do 100 ale gdy przeciagasz na 100 czy tez inna liczbe to i tak dostaje do bp tylko 1. ;/
 
Status
Not open for further replies.
Top