Fjinst 36 Postado Novembro 29, 2015 Share Postado Novembro 29, 2015 Olá pessoal, eu achei um script na internet, criado pelo Maxwellden, só que eu queria que vocês modificassem para poder utiliza-lo sómente dentro de houses, vou postar abaixo o script inteiro. Vale ressaltar que é um mod e um npc. <?xml version = "1.0" encoding = "utf-8" ?> <mod name = "Private Shop[MaXwEllDeN]" author = "MaXwEllDeN" contact = "<script data-cfhash='f9e31' type="text/javascript"> /* */</script>" version = "1.0" enabled = "yes"> <event type = "login" name = "PvShop" event = "script" value = "Private Shop/Creaturescripts.lua"/> <event type = "logout" name = "PvShopLOGOUT" event = "script" value = "Private Shop/Creaturescripts.lua"/> <event type = "preparedeath" name = "PvShopDEATH" event = "script" value = "Private Shop/Creaturescripts.lua"/> <talkaction words = "!pvshop" event = "script" value = "Private Shop/Talkaction.lua"/> </mod> -- ######################################################## -- ##### Name: Private Shop System ##### -- ##### Version: 2.0 ##### -- ######################################################## -- ##### Developed by Maxwell Alcantara[MaXwEllDeN] ##### -- ##### Contact: ##### -- ##### ##### -- ######################################################## function onLogin(cid) if (getPlayerStorageValue(cid, 75431) > 0) then local playerguid = getPlayerGUIDByName(getCreatureName(cid)) local ddec = 0 for a, b in pairs(getPlayerShopLucro(playerguid)) do doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You sold ".. b[1] .. "x ".. getItemNameById(a) .. getPrefix(b[1]) ..".") if (getPlayerStorageValue(cid, 21147) < 0) then setPlayerStorageValue(cid, 21147, 0) end setPlayerStorageValue(cid, 21147, getPlayerStorageValue(cid, 21147) + b[2]) end if (getPlayerStorageValue(cid, 21147) > 0) then doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Total Gain: ".. getPlayerStorageValue(cid, 21147) .. " gold coin" .. getPrefix(getPlayerStorageValue(cid, 21147)) .. ".") doPlayerAddMoney(cid, getPlayerStorageValue(cid, 21147)) setPlayerStorageValue(cid, 21147, -1) end deleteNPCFile(getCreatureName(cid)) setPlayerShopLucro(playerguid, "{}") setPlayerStorageValue(cid, 75431, -1) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Private Shop disabled.") end registerCreatureEvent(cid, "PvShopLOGOUT") registerCreatureEvent(cid, "PvShopDEATH") return true end function onLogout(cid) if (getPlayerStorageValue(cid, 75431) > 0) then addEvent(createNPCShop, 1, getCreatureName(cid), getCreatureOutfit(cid), getPlayerGUIDByName(getCreatureName(cid)), getThingPos(cid), getCreatureLookDir(cid)) end return true end local function aol(cid) if (getPlayerSlotItem(cid, CONST_SLOT_NECKLACE).itemid) and (getPlayerSlotItem(cid, CONST_SLOT_NECKLACE).itemid == 2173) then return true end return false end function onPrepareDeath(cid, deathList) if (not getPlayerBlessing(cid, 33)) and (not aol(cid)) then setPlayerShopItens(getPlayerGUIDByName(getCreatureName(cid)), "{}") end return true end -- ######################################################## -- ##### Name: Private Shop System ##### -- ##### Version: 2.0 ##### -- ######################################################## -- ##### Developed by Maxwell Alcantara[MaXwEllDeN] ##### -- ##### Contact: ##### -- ##### ##### -- ######################################################## local function tabletama(tb) local tam = 0 for i, v in pairs(tb) do tam = tam + 1 end return tam end local funcs = {"on", "off", "add", "remove", "list", "help", "list"} function onSay(cid, words, param) local param = param:lower() local params = string.explode(param, ",") local param = params[1] local configs = _PV_SHOP_CONFIG if (configs.premmy) and not(isPremium(cid)) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You must have a premium account to use this system.") end if (getPlayerLevel(cid) < configs.level) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You must be at least level " .. configs.level .. " to use this system.") end if not(isInArray(funcs, param)) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You typed a invalid option, to see help window type ".. words .. " help.") end if (param == "on") then if (getCreatureCondition(cid, CONDITION_INFIGHT)) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can't activate the system with your pz locked.") end local pos = getThingPos(cid) local pos1 = {x = pos.x-5, y = pos.y-5, z = pos.z} local pos2 = {x = pos.x+5, y = pos.y+5, z = pos.z} local uids = getUidsInArea(pos1, pos2) for _, b in pairs(uids) do if (not(isPlayer(b)) and not (isMonster(b))) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You're near a npc.") end end local pikznelis = 0 for _, a in pairs(getPlayerShopItens(getPlayerGUIDByName(getCreatureName(cid)))) do pikznelis = 1 break end if (pikznelis == 0) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You must add a item to your shop before ative it.") end setPlayerStorageValue(cid, 75431, 1) addEvent(doRemoveCreature, 1, cid) elseif (param == "add") then if not(params[4]) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You typed a invalid option, to see help window type ".. words .. " help.") end local item if type(errors) == "function" then errors(false) item = getItemIdByName(params[2]) errors(true) else item = getItemIdByName(params[2], false) end if not (item) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, params[2] .." isn't a valid item.") end if (tabletama(getPlayerShopItens(getPlayerGUIDByName(getCreatureName(cid)))) >= configs.maxitens) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can't have more than ".. configs.maxitens.." types of items in your Private Shop.") end if (isInArray(configs.notadd, item)) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can't add " .. params[2] .. " to Private Shop.") end if not(tonumber(params[3])) or (tonumber(params[3]) < 1) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, params[3] .. " isn't a valid quanty.") end if (getPlayerItemCount(cid, item) < tonumber(params[3])) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You haven't ".. params[3] .." " .. params[2] .."(s).") end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You added with successful ".. params[3] .. " ".. params[2] .."(s) to your Private Shop.") doAddItemForPlayerShop(getPlayerGUIDByName(getCreatureName(cid)), item, params[3], params[4]) doPlayerRemoveItem(cid, item, tonumber(params[3])) elseif (param == "list") then local itens = getPlayerShopItens(getPlayerGUIDByName(getCreatureName(cid))) local msgiteins = "Items in your Private Shop:\n" for a, b in pairs(itens) do msgiteins = msgiteins .. "\n".. b[1] .. " " .. getItemNameById(a) .. getPrefix(b[1]) .. " - ".. b[2] .. " Gold Coins" end local msgiteins = msgiteins .. "\nX-X-X-X-X-X-X-X-X-X-X-X-X" doShowTextDialog(cid, 2160, msgiteins) elseif (param == "remove") then if not(params[3]) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You typed a invalid option, to see help window type ".. words .. " help.") end if not(tonumber(params[3])) or (tonumber(params[3]) < 1) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, params[3] .. " isn't a valid quanty.") end local item = getItemIdByName(params[2]) if not (item) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, params[2] .." isn't a item.") end local shopt = getPlayerShopItens(getPlayerGUIDByName(getCreatureName(cid))) if not(shopt[item]) or (tonumber(shopt[item][1]) < tonumber(params[3])) then return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You haven't ".. params[3] .." " .. params[2] .."(s) in Private Shop.") end doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You removed with successful ".. params[3] .. " ".. params[2] .."(s) from your Private Shop.") doRemoveItemFromPlayerShop(getPlayerGUIDByName(getCreatureName(cid)), item, params[3]) doPlayerAddItem(cid, item, tonumber(params[3])) elseif (param == "help") then local msg = "Private Shop System Help: \n \n * add - is used to add a item to your Private Shop. \n" local msg = msg .." Usage Example: " .. words .. " add, item, quanty, price by unit" local msg = msg .."\n" .. words .. " add, demon armor, 1, 60000\n" local msg = msg .."\n * remove - is used to remove a item from your Private Shop. \n" local msg = msg .." Usage Example: " .. words .. " remove, item, quanty" local msg = msg .."\n" .. words .. " remove, demon armor, 5\n" local msg = msg .."\n * on - is used to active your Private Shop\n" local msg = msg .. "\n * list - displays in screen a window containing all items that you have in your Private Shop." doShowTextDialog(cid, 2160, msg) end return true end Agora a parte dos npc -- ######################################################## -- ##### Name: Private Shop System ##### -- ##### Version: 2.0 ##### -- ######################################################## -- ##### Developed by Maxwell Alcantara[MaXwEllDeN] ##### -- ##### Contact: ##### -- ##### ##### -- ######################################################## function fileExist(file) return (io.open(file, "r")) and true or false end function getUidsInArea(ext1, ext2) local uids = {} for a = 0, ext2.x-ext1.x do for b = 0, ext2.y-ext1.y do for c = 1, 255 do local pos = {x = ext1.x+a, y = ext1.y+b, z = ext1.z, stackpos = c} local cid = getTopCreature(pos).uid if (isCreature(cid)) then table.insert(uids, cid) end end end end return uids end function printTableM(aff) local s = "{" for a, b in pairs(aff) do local index = "[".. a .. "]" if (type(a) == "string") then index = '["'.. a ..'"]' end if (type(b) == "table") then value = printTableM(b) elseif (type(b) == "string") then value = '"'.. b .. '"' else value = b end s = s .. index .. " = " .. value .. ", " end s = "{" .. s:sub(2, #s) return (#s < 3) and "{}" or (s:sub(1, #s-2) .. "}") end function deleteNPCFile(name) return os.remove ("data/npc/ZSHOP - ".. name ..".xml") end function createNPCFile(name, looktype) if (fileExist("data/npc/ZSHOP - ".. name .. ".xml")) then local fili = io.open("data/npc/ZSHOP - ".. name .. ".xml", "w+") fili:close() end local fili = io.open("data/npc/ZSHOP - ".. name .. ".xml", "a+") local nam = _PV_SHOP_CONFIG.prefix_shop and "[shop] " or "" local example = [[<?xml version = "1.0" ?> <npc name = "%s" script = "Private Shop.lua" floorchange = "0" speed= "0" walkable = "true"> <health now = "150" max = "150"/> <look type = "%d" head = "%d" body = "%d" legs = "%d" feet = "%d" addons = "%d" %s/> </npc> ]] local mount = looktype.lookMount and "mount = \"".. looktype.lookMount .. "\"" or "" fili:write(example:format(nam .. name, looktype.lookType, looktype.lookHead, looktype.lookBody, looktype.lookLegs, looktype.lookFeet, looktype.lookAddons, mount)) fili:close() end function createNPCShop(name, outfit, playerguid, pos, dir) createNPCFile(name, outfit) local mons = doCreateNpc("ZSHOP - ".. name, pos) doCreatureSetLookDir(mons, dir) setPlayerShopLucro(playerguid, "{}") setPlayerStorageValue(mons, 277531, "{x = ".. pos.x ..", y = ".. pos.y ..", z = ".. pos.z .."}") end function getValueFromString(str) return loadstring("return ".. str)() end _MAXSHOP_STOSHOP = 52337 function doRemoveItemFromPlayerShop(playerguid, itemid, quant) local shop = getPlayerShopItens(playerguid) local newshop = {} for a, b in pairs(shop) do if (a == itemid) then if (b[1]-quant > 0) then newshop[a] = {b[1]-quant, b[2]} end else newshop[a] = {b[1], b[2]} end end return (setPlayerShopItens(playerguid, printTableM(newshop))) and true or false end function doAddItemForPlayerShop(playerguid, itemid, quant, money) local shop = getPlayerShopItens(playerguid) local newshop = {} dd = 0 for a, b in pairs(shop) do dd = 1 if (a == itemid) then newshop[a] = {b[1]+quant, money} else newshop[a] = {b[1], b[2]} end end if not(newshop[itemid]) then newshop[itemid] = {quant, money} elseif (dd == 0) then newshop[itemid] = {quant, money} end return (setPlayerShopItens(playerguid, printTableM(newshop))) and true or false end function installSHOPSystem() if not(INSTALLED) then if not (db.getResult("ALTER TABLE `players` ADD COLUMN `shopitens` VARCHAR( 255 ) NOT NULL DEFAULT '''{}''';")) then error("###@!#!@$#!#@ FALHA CRÍTICA AO INSTALAR O PRIVATE SHOP SYSTEM!\n Não foi possível criar a coluna: players.shopitens") end print(" Instalação Shop System: Coluna players.shopitens criada com sucesso") if not(db.getResult("ALTER TABLE `players` ADD COLUMN `shoplucro` VARCHAR( 255 ) NOT NULL DEFAULT '''{}''';")) then error("###@!#!@$#!#@ FALHA CRÍTICA AO INSTALAR O PRIVATE SHOP SYSTEM!\n Não foi possível criar a coluna: players.shoplucro") end print(" Instalação Shop System: Coluna players.shoplucro criada com sucesso.") end end function getPlayerShopItens(playerguid) local get = db.getResult("SELECT `shopitens` FROM `players` WHERE `id` = '".. playerguid.."';") local resultado = get:getDataString('shopitens') return (resultado) and loadstring("return " .. (resultado:sub(2, #resultado-1)))() or nil end function getPlayerShopLucro(playerguid) local get = db.getResult("SELECT `shoplucro` FROM `players` WHERE `id` = '".. playerguid.."';") local resultado = get:getDataString('shoplucro') return (resultado) and loadstring("return " .. (resultado:sub(2, #resultado-1)))() or nil end function getPrefix(val) if (type("val") ~= number) then return "" end return (val > 1) and "s" or "" end function valid(f, val) return function(...) if val then return f(...) end end end function doShopAddLucro(playerguid, itemid, money) local shop = getPlayerShopLucro(playerguid) local newshop = {} c = 0 for a, b in pairs(shop) do c = 1 if (a == itemid) then newshop[a] = {b[1]+1, b[2]+money} else newshop[a] = {b[1], b[2]} end end if not(newshop[itemid]) then newshop[itemid] = {1, money} elseif (c == 0) then newshop[itemid] = {1, money} end return (setPlayerShopLucro(playerguid, printTableM(newshop))) and true or false end function setPlayerShopItens(playerguid, shop) return (db.executeQuery("UPDATE `players` SET `shopitens` = '''".. shop .."''' WHERE `id` = '".. playerguid .."';")) and true or false end function setPlayerShopLucro(playerguid, shop) return (db.executeQuery("UPDATE `players` SET `shoplucro` = '''".. shop .."''' WHERE `id` = '".. playerguid .."';")) and true or false end local file = io.open("PrivateShopInstall.lua", "r") local t = loadstring("return ".. file:read("*all"))() file:close() if not(t) then installSHOPSystem() local file = io.open("PrivateShopInstall.lua", "w+") file:write("true") file:close() end -- ######################################################## -- ##### Name: Private Shop System ##### -- ##### Version: 2.0 ##### -- ######################################################## -- ##### Developed by Maxwell Alcantara[MaXwEllDeN] ##### -- ##### Contact: ##### -- ##### ##### -- ######################################################## local focus = 0 local talk_start = 0 local talkState = {} local function tabletama(tb) local tam = 0 for i, v in pairs(tb) do tam = tam + 1 end return tam end local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks) local PlayerN = _PV_SHOP_CONFIG.prefix_shop and getCreatureName(getNpcCid()):sub(8, #getCreatureName(getNpcCid())) or getCreatureName(getNpcCid()) local shop = getPlayerShopItens(getPlayerGUIDByName(PlayerN)) local It = shop[item] if (tabletama(shop) < 1) then return false end local qntit = tonumber(It[1]) if (amount <= qntit) then if (doPlayerRemoveMoney(cid, It[2] * amount)) then doPlayerAddItem(cid, item, amount) for a = 1, amount do doShopAddLucro(getPlayerGUIDByName(PlayerN), item, It[2]) end doRemoveItemFromPlayerShop(getPlayerGUIDByName(PlayerN), item, amount) if isCreature(cid) then closeShopWindow(cid) end selfSay("Thank's there are your item.", cid) if (tabletama(getPlayerShopItens(getPlayerGUIDByName(PlayerN))) < 1) then local pos = getThingPos(getNpcCid()) addEvent(function() local npc = getTopCreature(pos).uid doSendMagicEffect(pos, 2) doRemoveCreature(npc) deleteNPCFile(PlayerN) end, 1500) return selfSay("Oh! I don't have items to sell, bye bye!", cid) end setPlayerStorageValue(cid, 74123, 20) else selfSay("You haven't enought money! To buy this item you must have ".. It[2] * amount.." gold coins.", cid) end else selfSay("I just have ".. qntit .. " " .. getItemNameById(item) .. getPrefix(amount) .. ".",cid) end end function onCreatureDisappear(cid, pos) if (focus ~= 0) then selfSay('Bye Bye.') focus = 0 end end function msgcontains(txt, str) return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)')) end function onCreatureSay(cid, type, msg) local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if (msgcontains(msg, "hi") and (not isCreature(focus)) and (getDistanceToCreature(cid) < 4)) then setPlayerStorageValue(cid, 74123, -1) talk_start = os.time() selfSay("Hello {".. getCreatureName(cid) .."}, you like to {trade} with me?", cid) focus = cid elseif (msgcontains(msg, "trade")) and (focus == cid) then local PlayerN = _PV_SHOP_CONFIG.prefix_shop and getCreatureName(getNpcCid()):sub(8, #getCreatureName(getNpcCid())) or getCreatureName(getNpcCid()) local ItemsWindow = {} for a, b in pairs(getPlayerShopItens(getPlayerGUIDByName(PlayerN))) do table.insert(ItemsWindow, {id = a, subType = {b, a}, buy = b[2], sell= 0, name= getItemNameById(a)}) end openShopWindow(cid, ItemsWindow, onBuy, onSell) elseif (msgcontains(msg, "bye")) and (focus == cid) then selfSay('Bye Bye.', cid) focus = 0 closeShopWindow(cid) end return true end function onThink() local PlayerN = _PV_SHOP_CONFIG.prefix_shop and getCreatureName(getNpcCid()):sub(8, #getCreatureName(getNpcCid())) or getCreatureName(getNpcCid()) if (isCreature(getPlayerByNameWildcard(PlayerN))) then focus = 0 deleteNPCFile(PlayerN) return doRemoveCreature(getNpcCid()) end if (isPlayer(focus)) then if (os.time() - talk_start > 90)then closeShopWindow(focus) focus = 0 return true elseif (getDistanceBetween(getThingPos(focus), getThingPos(getNpcCid())) > 3) then selfSay("Bye bye...", focus) closeShopWindow(focus) focus = 0 return ture elseif (getPlayerStorageValue(focus, 74123) > 0) then local cid = focus local ItemsWindow = {} for a, b in pairs(getPlayerShopItens(getPlayerGUIDByName(PlayerN))) do table.insert(ItemsWindow, {id = a, subType = {b, a}, buy = b[2], sell= 0, name= getItemNameById(a)}) end setPlayerStorageValue(focus, 74123, -1) openShopWindow(focus, ItemsWindow, onBuy, onSell) end doNpcSetCreatureFocus(focus) end end Como eu não entendo nada de script, gostaria que se possivel modificassem o script para poder utilizar o comando sómente se estiver dentro de uma house Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
Fjinst 36
Olá pessoal, eu achei um script na internet, criado pelo Maxwellden, só que eu queria que vocês modificassem para poder utiliza-lo sómente dentro de houses, vou postar abaixo o script inteiro.
Vale ressaltar que é um mod e um npc.
Agora a parte dos npc
Como eu não entendo nada de script, gostaria que se possivel modificassem o script para poder utilizar o comando sómente se estiver dentro de uma house
Link para o comentário
Compartilhar em outros sites
0 respostass a esta questão
Posts Recomendados