siemka, mam nast?puj?cy skrypt do npc:
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
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
@down: tak dzia?a, na tym kt?ry sam dawa?es na forum. ;D
Last edited: