Wazzap
Killing Elite
actions.xml
ownbp.lua:<action actionid="1567" event="script" value="ownbp.lua"/>
NPC to buy own bpfunction onUse(cid, item, fromPos, itemEx, toPos)
if (getItemAttribute(item.uid, "aid") == 1567) then
if (getItemAttribute(item.uid, "uid") ~= (getPlayerGUID(cid) + 1000)) then
doPlayerSendTextMessage(cid, 22, "This is not your backpack.")
return true
end
end
return false
end
Cost of own bplocal focuses = {}
local talkState = {}
local cost = 50000
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
function onCreatureSay(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local msg = string.lower(msg)
if((msg == "hi") and not (isFocused(cid))) then
selfSay("Hello my friend. How can I help you?", cid)
addFocus(cid)
elseif(isFocused(cid) and(msg == "special backpack" or msg == "backpack" or msg == "own backpack")) then
selfSay("Yes I have it, but it really expensive item. Do you want to buy it for "..cost.." gold coins?", cid)
talkState[talkUser] = 1
elseif(isFocused(cid) and msg == "yes" and talkState[talkUser] == 1) then
if (doPlayerRemoveMoney(cid, cost) == true) then
local item = doPlayerAddItem(cid, 1988)
doItemSetAttribute(item, "aid", 1567)
doItemSetAttribute(item, "uid", (getPlayerGUID(cid) + 1000))
doItemSetAttribute(item, "description", "It is "..getCreatureName(cid).." own backpack.")
selfSay("Here you are", cid)
else
selfSay("You don\'t have enough money.", cid)
end
elseif(isFocused(cid) and msg == "yes" and talkState[talkUser] == 1) then
selfSay("Ohh, ok.", cid)
elseif(isFocused(cid) and (msg == "bb" or msg == "bye")) then
selfSay("Bye!", cid)
removeFocus(cid)
else
selfSay("I cannot understand what you say, reapeat please.", cid)
end
return true
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("")
removeFocus(focus)
end
end
end
lookAtFocus()
end