Jump to content
Sign in to follow this  
Luck Oake

action Pistol

Recommended Posts

Luck Oake    16
Luck Oake

Hi.

 

Outro pedido de um user, fiz esse script há um bom tempo. É um script de pistola. Você equipa em uma das mãos, usa a arma em algum monster ou player e boa, atira.

 

Script:

 

data/actions/scripts/pistol.lua:

 

local need_target = true -- Precisa de target? (true / false) Se false, o sistema utilizará o Use With.
local bullet_id = 2544 -- ID da munição
local shots_amount = 1 -- Tiros por vez
local exhaustion_time = 1 -- Segundos de exhaustion
local exhaust = 19301 -- Storage da exhaustion
local dmg_min, dmg_max = -10, -20 -- Dano mínimo, dano máximo
local shot_effect = 3 -- Efeito do tiro
local shot_distance_effect = 1 -- Distance effect do tiro
local damage_type = COMBAT_PHYSICALDAMAGE -- Tipo de dano
local shots_delay = 200 -- Delay dos tiros (em milissegundos)
local slots = {CONST_SLOT_LEFT, CONST_SLOT_RIGHT} -- Constants dos Slots permitidos
local control = 0 -- Não modifique, variável de controle
 
function onUse(cid, item, fromPosition, itemEx, toPosition)
    for a, b in ipairs(slots) do
        if getPlayerSlotItem(cid, .uid ~= item.uid then
            control = control + 1
        end
    end
    if control == slots then
        return doPlayerSendCancel(cid, "Coloque a arma no slot correto.")
    end
    if need_target then
        if getCreatureTarget(cid) <= 0 then
            return doPlayerSendCancel(cid, "Selecione um alvo primeiro.")
        elseif getPlayerItemCount(cid, bullet_id) < shots_amount then
            return doPlayerSendCancel(cid, "Você não possui munição.")
        elseif exhaustion.check(cid, exhaust) then
            return doPlayerSendCancel(cid, "Aguarde "..(exhaustion.get(cid, exhaust)).." segundos para usar a arma novamente.")
        end
        
        exhaustion.set(cid, exhaust, exhaustion_time)
        for i = 0, shots_amount-1 do
            addEvent(function()
                if getCreatureTarget(cid) <= 0 then
                    return true
                elseif getPlayerItemCount(cid, bullet_id) < 1 then
                    return doPlayerSendCancel(cid, "Você não possui munição.")
                end
                doSendDistanceShoot(getCreaturePosition(cid), getCreaturePosition(getCreatureTarget(cid)), shot_distance_effect)
                doTargetCombatHealth(cid, getCreatureTarget(cid), damage_type, dmg_min, dmg_max, shot_effect)
                doPlayerRemoveItem(cid, bullet_id, 1)
            end, shots_delay*i)
        end
    else
        if not isCreature(itemEx.uid) then
            return doPlayerSendCancel(cid, "Selecione um alvo primeiro.")
        elseif getPlayerItemCount(cid, bullet_id) < shots_amount then
            return doPlayerSendCancel(cid, "Você não possui munição.")
        elseif exhaustion.check(cid, exhaust) then
            return doPlayerSendCancel(cid, "Aguarde "..(exhaustion.get(cid, exhaust)).." segundos para usar a arma novamente.")
        end
        
        exhaustion.set(cid, exhaust, exhaustion_time)
        for i = 0, shots_amount-1 do
            addEvent(function()
                if not isCreature(itemEx.uid) then
                    return true
                elseif getPlayerItemCount(cid, bullet_id) < 1 then
                    return doPlayerSendCancel(cid, "Você não possui munição.")
                end
                doSendDistanceShoot(getCreaturePosition(cid), getCreaturePosition(itemEx.uid), shot_distance_effect)
                doTargetCombatHealth(cid, itemEx.uid, damage_type, dmg_min, dmg_max, shot_effect)
                doPlayerRemoveItem(cid, bullet_id, 1)
            end, shots_delay*i)
        end
    end
    return true
end

 

 

 

data/actions/actions.xml:

<action itemid="xxxx" script="pistol.lua" allowfaruse="1"/>

No lugar de xxxx, coloque o id do item que será usado como pistola.

 

Configure aqui:

 

local need_target = true -- Precisa de target? (true / false) Se false, o sistema utilizará o Use With.
local bullet_id = 2544 -- ID da munição
local shots_amount = 1 -- Tiros por vez
local exhaustion_time = 1 -- Segundos de exhaustion
local exhaust = 19301 -- Storage da exhaustion
local dmg_min, dmg_max = -10, -20 -- Dano mínimo, dano máximo
local shot_effect = 3 -- Efeito do tiro
local shot_distance_effect = 1 -- Distance effect do tiro
local damage_type = COMBAT_PHYSICALDAMAGE -- Tipo de dano
local shots_delay = 200 -- Delay dos tiros (em milissegundos)
local slots = {CONST_SLOT_LEFT, CONST_SLOT_RIGHT} -- Constants dos Slots permitidos
local control = 0 -- Não modifique, variável de controle

 

Bom uso, até.

Edited by Luck Oake

Share this post


Link to post
Caronte    0
Caronte

Eu fiz um sistema parecido para um pedido, tem um problema ao usar essa action nas hotkeys...

void Game::showHotkeyUseMessage(Player* player, Item* item)
{
	const ItemType& it = Item::items[item->getID()];
	uint32_t count = player->__getItemTypeCount(item->getID(), item->isFluidContainer() ? item->getFluidType() : -1);

	std::stringstream ss;
	if(count == 1)
		ss << "Using the last " << it.name.c_str() << "...";
	else
		ss << "Using one of " << count << " " << it.pluralName.c_str() << "...";

	player->sendTextMessage(MSG_INFO_DESCR, ss.str());
}

vai ficar dando mensagem idiota de Using the last pistol...

Share this post


Link to post
Guest
This topic is now closed to further replies.
Sign in to follow this  
  • Recently Browsing   0 members

    No registered users viewing this page.

×