FA
action

Potion Alavanca

Por Faelzdanil, 01 de jun. de 2015 em Scripts

resolvido
script
13
3.4k
FaelzdanilF
01 de junho de 2015 às 09:25

Olá Ekz,

 

Bom eu estou precisando de um script que ao puxar a alavanca ele compre 100 Runas/Potions.

Sim tem alguns scripts aqui no Fórum sobre isso, porém não é o que procuro, pois os que tem, ou compram apenas 1, ou compra por backpack.

Cheguei a pegar esse AQUI:

 

 

 

function getItemCap(itemid, quant) -- function by MatheusMkalo
    return getItemInfo(itemid).weight*(quant or 1)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local configs = {
    [45690] = {itemid = 2160, quantperslot = 10, cost = 5, backpackid = 2002},
    [45691] = {itemid = 2268, quantperslot = 50, cost = 2, backpackid = 2003},
    }
    local coinid = 9971 -- Use o id da gold coin (2148) se voce quizer usar o sistema de dinheiro mesmo. (Caso o itemid for 2148 o cost sera de gps ou seja 30 = 30 gps)
    
    if configs[item.actionid] then
        if getPlayerFreeCap(cid) >= math.ceil((getItemCap(configs[item.actionid].itemid, configs[item.actionid].quantperslot)*20)+getItemCap(configs[item.actionid].backpackid)) then
            if coinid ~= 2148 and getPlayerItemCount(cid, coinid) >= configs[item.actionid].cost or doPlayerRemoveMoney(cid, configs[item.actionid].cost) then
                local backpack = doPlayerAddItem(cid, configs[item.actionid].backpackid)
                for i = 1, 20 do
                    doAddContainerItem(backpack, configs[item.actionid].itemid, configs[item.actionid].quantperslot)
                end
                doPlayerRemoveItem(cid, coinid == 2148 and 0000 or coinid, configs[item.actionid].cost)
            else
                return doPlayerSendCancel(cid, ("You need " .. configs[item.actionid].cost) .. (coinid == 2148 and " gold coins" or (" " .. getItemPluralNameById(coinid):lower())) .. " to buy this item.")
            end
        else
            return doPlayerSendCancel(cid, "You need " .. math.ceil((getItemCap(configs[item.actionid].itemid, configs[item.actionid].quantperslot)*20)+getItemCap(configs[item.actionid].backpackid)) .. " cap for buy that.")
        end
    end
return TRUE
end

 

 

 

Porém ele é com backpack, mesmo eu tirando a parte da backpack ID, ele não funciona.

 

Gostaria se alguém pudesse fazer algum nesse estilo ou configurar esse mesmo pra não ter backpack.

BrunoB
01 de junho de 2015 às 09:50

@@Faelzdanil,

 

Tenta assim:

function getItemCap(itemid, quant) -- function by MatheusMkalo
    return getItemInfo(itemid).weight * (quant or 1)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local configs = {
		[45690] = {itemid = 2160, quant = 100, cost = 5},
		[45691] = {itemid = 2268, quant = 100, cost = 2},
    }
    local coinid = 9971 -- Use o id da gold coin (2148) se voce quizer usar o sistema de dinheiro mesmo. (Caso o itemid for 2148 o cost sera de gps ou seja 30 = 30 gps)
    
    if configs[item.actionid] then
        if getPlayerFreeCap(cid) >= math.ceil(getItemCap(configs[item.actionid].itemid, configs[item.actionid].quant)) then
            if coinid ~= 2148 and getPlayerItemCount(cid, coinid) >= configs[item.actionid].cost or doPlayerRemoveMoney(cid, configs[item.actionid].cost) then
				doPlayerAddItem(cid, configs[item.actionid].itemid, configs[item.actionid].quant)
                doPlayerRemoveItem(cid, coinid, configs[item.actionid].cost)
            else
                return doPlayerSendCancel(cid, ("You need " .. configs[item.actionid].cost) .. (coinid == 2148 and " gold coins" or (" " .. getItemPluralNameById(coinid):lower())) .. " to buy this item.")
            end
        else
            return doPlayerSendCancel(cid, "You need " .. math.ceil(getItemCap(configs[item.actionid].itemid, configs[item.actionid].quant)) .. " cap for buy that.")
        end
    end
	return true
end

Editado Junho 1 por Bruno Minervino

FaelzdanilF
01 de junho de 2015 às 10:22

Bruno, mas eu preciso sem a backpack, que compre e vá direto pra Backpack própria

Natanael BeckmanN
01 de junho de 2015 às 10:31


local Config = {
BuyMoney = 1000,
ItemID = 2268
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if doPlayerRemoveMoney(cid, Config.BuyMoney) then
doSendAnimatedText(fromPosition, "Purchased", TEXTCOLOR_YELLOW)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have purchased a ".. getItemNameById(Config.ItemID) .."s for ".. Config.BuyMoney .." gold.")
doPlayerAddItem(cid, Config.ItemID, 100)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need ".. Config.BuyMoney .." gold coins to buy a "..getItemNameById(Config.ItemID) .."s.")
end
end

Editado Junho 1 por Natanael Beckman

FaelzdanilF
01 de junho de 2015 às 10:33

O problema desse Natanael, é que vou ter que criar um script pra cada alavanca

Natanael BeckmanN
01 de junho de 2015 às 10:39

O problema desse Natanael, é que vou ter que criar um script pra cada alavanca

Exatamente!

L3K0TL
01 de junho de 2015 às 10:39

só com potions:

 

 

 

removido por nem testar!

 


<action uniqueid="1002" event="script" value="alavanca.lua"/>
1002 uniqueid que vai na alavanca

 

agora com runa e potions:

 

 

removido por nem testar!

<action uniqueid="1002" event="script" value="alavanca.lua"/>
1002 uniqueid que vai na alavanca

Editado Junho 1 por leleke

FaelzdanilF
01 de junho de 2015 às 10:50

 

local Config = {
        BuyMoney = 1000,
        ItemID = 2268
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if doPlayerRemoveMoney(cid, Config.BuyMoney) then
                doSendAnimatedText(fromPosition, "Purchased", TEXTCOLOR_YELLOW)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have purchased a ".. getItemNameById(Config.ItemID) .."s for ".. Config.BuyMoney .." gold.")
                doPlayerAddItem(cid, Config.ItemID, 100)
        else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need ".. Config.BuyMoney .." gold coins to buy a "..getItemNameById(Config.ItemID) .."s.")
        end
end

 

Dinheiro baseado em gold? Platinum? Crystal ?

BrunoB
01 de junho de 2015 às 11:13
Melhor resposta

Bruno, mas eu preciso sem a backpack, que compre e vá direto pra Backpack própria

Amigo, eu só esqueci de tirar a variavel da backpack, porém já fiz da forma que você queria, você ao menos testou?

 

Vou editar o meu post.

Se você usou a do Natanael e funcionou da forma que você quis, aqui está uma forma sem você precisar adicionar um script para cada alavanca:

 

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local Config = {
			[45690] = {itemid = 2268, quant = 100, cost = 1000}
	}
	if doPlayerRemoveMoney(cid, Config[item.actionid].cost) then
			doSendAnimatedText(fromPosition, "Purchased", TEXTCOLOR_YELLOW)
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have purchased a ".. getItemNameById(Config[item.actionid].itemid) .."s for ".. Config[item.actionid].cost .." gold.")
			doPlayerAddItem(cid, Config[item.actionid].itemid, Config[item.actionid].quant)
	else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need ".. Config[item.actionid].cost .." gold coins to buy a ".. Config[item.actionid].itemid .."s.")
	end
end
FaelzdanilF
01 de junho de 2015 às 12:08

O correto de fazer outros seria com virgula no final, certo ?

[45690] = {itemid = 2268, quant = 100, cost = 1000},
[45690] = {itemid = 2268, quant = 100, cost = 1000},
[45690] = {itemid = 2268, quant = 100, cost = 1000},
[45690] = {itemid = 2268, quant = 100, cost = 1000}
BrunoB
01 de junho de 2015 às 12:35

 

O correto de fazer outros seria com virgula no final, certo ?

[45690] = {itemid = 2268, quant = 100, cost = 1000},
[45690] = {itemid = 2268, quant = 100, cost = 1000},
[45690] = {itemid = 2268, quant = 100, cost = 1000},
[45690] = {itemid = 2268, quant = 100, cost = 1000}

Isso mesmo!

Deu certo?

FaelzdanilF
01 de junho de 2015 às 12:53

Obrigado Bruno, funcionando 100%

Só uma coisa, teria como colocar algum delay pra comprar ?

BrunoB
01 de junho de 2015 às 13:59

Tópico movido para a seção de dúvidas e pedidos resolvidos.

Obrigado Bruno, funcionando 100%

Só uma coisa, teria como colocar algum delay pra comprar ?

Tenta assim:

local exaust = 3 -- 3 segundos
local storage = 9501 -- alguma storage que não esteja em uso

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local Config = {
			[45690] = {itemid = 2268, quant = 100, cost = 1000}
	}
	if exhaustion.get(cid, storage) then
		if doPlayerRemoveMoney(cid, Config[item.actionid].cost) then
				doSendAnimatedText(fromPosition, "Purchased", TEXTCOLOR_YELLOW)
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have purchased a ".. getItemNameById(Config[item.actionid].itemid) .."s for ".. Config[item.actionid].cost .." gold.")
				doPlayerAddItem(cid, Config[item.actionid].itemid, Config[item.actionid].quant)
				exhaustion.set(cid, storage, exaust)
		else
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You need ".. Config[item.actionid].cost .." gold coins to buy a ".. Config[item.actionid].itemid .."s.")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You are exhausted.")
	end
end