• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua When Player Attack

alejandro762

Well-Known Member
Joined
Sep 6, 2021
Messages
225
Reaction score
63
Hello,
This script made by Sarah Wesker, i wish to know how to convert it 'when a player attacks, has 2% chance to create a summon for 20s and get the condition'.
Since i made a mistake on the last thread saying i want it onEquip, but I was wrong, it was when the object is equipped and the player attacks, he has a 2% chance of summon monster and get the condition.


Lua:
local config = {
    chance = 2,
    summon = 'rat',
    bonus = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,
    bonusPercent = 2,
    duration = 20
}

local summons = {}

local summonTest = MoveEvent()

function summonTest.onEquip(player, item, slot, isCheck)
    if isCheck then
        return true
    end

    if math.random(100) <= config.chance then
        local monster = Game.createMonster(config.summon, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            summons[player:getId()] = monster:getId()
            local bonus = Condition(CONDITION_ATTRIBUTES)
            bonus:setParameter(CONDITION_PARAM_TICKS, config.duration * 1000)
            bonus:setParameter(config.bonus, config.bonusPercent)
            player:addCondition(bonus)
            return true
        end
    end

    player:getPosition():sendMagicEffect(CONST_ME_POFF)
    return true
end

summonTest:id(10300)
summonTest:register()

local summonTest = MoveEvent()

function summonTest.onDeEquip(player, item, slot)
    local playerId = player:getId()
    if summons[playerId] then
        local monster = Monster(summons[playerId])
        if monster then
            monster:remove()
            summons[playerId] = nil
        end
    end
    return true
end

summonTest:id(10300)
summonTest:register()
 
Solution
Rofl, i start doing changes, but from this otservbr to tfs, some functions are very different hard to understand where add it, players.lua looks different.
Well.
Did was the same doing this method onCast spell ( like doing exevo gran mas vis 2% chance to summon and get the bonus ? ), it was with eventcallback also ?

Anyway thanks, tested on Tfs and was working like a charm, i will look in further to pass the server on Tfs.
Try add:
Lua:
if target then
    target:registerEvent("WhenPlayerAttackHealth")
    target:registerEvent("WhenPlayerAttackMana")
end
HERE in your otbr datapack

remember to remove this from your script:
Lua:
local ec = EventCallback

function ec.onTargetCombat(creature, target)...
There is currently no Lua method to monitor when a weapon is used.
but this is where the call to this Lua function you need should be.

events.h
HERE
C++:
int32_t playerOnUseWeapon = -1;
HERE
Lua:
void eventPlayerOnUseWeapon(Player* player, Creature* target, Item* weapon, CombatDamage& damage)

events.cpp
HERE
C++:
else if (methodName == "onUseWeapon") {
    info.playerOnUseWeapon = event;
}
HERE
C++:
void Events::eventPlayerOnUseWeapon(Player* player, Creature* target, Item* weapon, CombatDamage& damage)
{
    // Player:onUseWeapon(target, weapon, primaryDamage, primaryType, secondaryDamage, secondaryType)
    if (info.playerOnUseWeapon == -1) {
        return;
    }

    if (!scriptInterface.reserveScriptEnv()) {
        std::cout << "[Error - Events::eventPlayerOnUseWeapon] Call stack overflow" << std::endl;
        return;
    }

    ScriptEnvironment* env = scriptInterface.getScriptEnv();
    env->setScriptId(info.playerOnUseWeapon, &scriptInterface);

    lua_State* L = scriptInterface.getLuaState();
    scriptInterface.pushFunction(info.playerOnUseWeapon);

    LuaScriptInterface::pushUserdata<Player>(L, player);
    LuaScriptInterface::setMetatable(L, -1, "Player");
    if (target) {
        LuaScriptInterface::pushUserdata(L, target);
        LuaScriptInterface::setCreatureMetatable(L, -1, target);
    } else {
        lua_pushnil(L);
    }

    LuaScriptInterface::pushThing(L, weapon);
    LuaScriptInterface::pushCombatDamage(L, damage);

    if (scriptInterface.protectedCall(L, 8, 4) != 0) {
        LuaScriptInterface::reportError(nullptr, LuaScriptInterface::popString(L));
    } else {
        damage.primary.value = std::abs(LuaScriptInterface::getNumber<int32_t>(L, -4));
        damage.primary.type = LuaScriptInterface::getNumber<CombatType_t>(L, -3);
        damage.secondary.value = std::abs(LuaScriptInterface::getNumber<int32_t>(L, -2));
        damage.secondary.type = LuaScriptInterface::getNumber<CombatType_t>(L, -1);

        lua_pop(L, 4);
        if (damage.primary.type != COMBAT_HEALING) {
            damage.primary.value = -damage.primary.value;
            damage.secondary.value = -damage.secondary.value;
        }
    }

    scriptInterface.resetScriptEnv();
}

weapons.cpp
HERE
C++:
#include "events.h"
HERE
C++:
extern Events* g_events;
AFTER HERE
C++:
g_events->eventPlayerOnUseWeapon(player, target, item, damage);

add to data/events/events.xml
XML:
<event class="Player" method="onUseWeapon" enabled="1" />

and add to data/events/scripts/player.lua
on the last line
Lua:
local config = {
    chance = 2,
    summon = 'rat',
    bonus = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,
    bonusPercent = 2,
    duration = 20
}

function Player:onUseWeapon(target, weapon, primaryDamage, primaryType, secondaryDamage, secondaryType)
    if math.random(100) <= config.chance then
        local monster = Game.createMonster(config.summon, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            addEvent(function (cid)
                local monster = Monster(cid)
                if monster then
                    monster:remove()
                end
            end, config.duration * 1000, monster:getId())
            local bonus = Condition(CONDITION_ATTRIBUTES)
            bonus:setParameter(CONDITION_PARAM_TICKS, config.duration * 1000)
            bonus:setParameter(config.bonus, config.bonusPercent)
            player:addCondition(bonus)
            return true
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
This script will be executed every time you try to use the weapon to damage another creature.
I don't know if it's the correct way to monitor when the weapon is used, but it's an advance.
 
There is currently no Lua method to monitor when a weapon is used.
but this is where the call to this Lua function you need should be.

events.h
HERE
C++:
int32_t playerOnUseWeapon = -1;
HERE
Lua:
void eventPlayerOnUseWeapon(Player* player, Creature* target, Item* weapon, CombatDamage& damage)

events.cpp
HERE
C++:
else if (methodName == "onUseWeapon") {
    info.playerOnUseWeapon = event;
}
HERE
C++:
void Events::eventPlayerOnUseWeapon(Player* player, Creature* target, Item* weapon, CombatDamage& damage)
{
    // Player:onUseWeapon(target, weapon, primaryDamage, primaryType, secondaryDamage, secondaryType)
    if (info.playerOnUseWeapon == -1) {
        return;
    }

    if (!scriptInterface.reserveScriptEnv()) {
        std::cout << "[Error - Events::eventPlayerOnUseWeapon] Call stack overflow" << std::endl;
        return;
    }

    ScriptEnvironment* env = scriptInterface.getScriptEnv();
    env->setScriptId(info.playerOnUseWeapon, &scriptInterface);

    lua_State* L = scriptInterface.getLuaState();
    scriptInterface.pushFunction(info.playerOnUseWeapon);

    LuaScriptInterface::pushUserdata<Player>(L, player);
    LuaScriptInterface::setMetatable(L, -1, "Player");
    if (target) {
        LuaScriptInterface::pushUserdata(L, target);
        LuaScriptInterface::setCreatureMetatable(L, -1, target);
    } else {
        lua_pushnil(L);
    }

    LuaScriptInterface::pushThing(L, weapon);
    LuaScriptInterface::pushCombatDamage(L, damage);

    if (scriptInterface.protectedCall(L, 8, 4) != 0) {
        LuaScriptInterface::reportError(nullptr, LuaScriptInterface::popString(L));
    } else {
        damage.primary.value = std::abs(LuaScriptInterface::getNumber<int32_t>(L, -4));
        damage.primary.type = LuaScriptInterface::getNumber<CombatType_t>(L, -3);
        damage.secondary.value = std::abs(LuaScriptInterface::getNumber<int32_t>(L, -2));
        damage.secondary.type = LuaScriptInterface::getNumber<CombatType_t>(L, -1);

        lua_pop(L, 4);
        if (damage.primary.type != COMBAT_HEALING) {
            damage.primary.value = -damage.primary.value;
            damage.secondary.value = -damage.secondary.value;
        }
    }

    scriptInterface.resetScriptEnv();
}

weapons.cpp
HERE
C++:
#include "events.h"
HERE
C++:
extern Events* g_events;
AFTER HERE
C++:
g_events->eventPlayerOnUseWeapon(player, target, item, damage);

add to data/events/events.xml
XML:
<event class="Player" method="onUseWeapon" enabled="1" />

and add to data/events/scripts/player.lua
on the last line
Lua:
local config = {
    chance = 2,
    summon = 'rat',
    bonus = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,
    bonusPercent = 2,
    duration = 20
}

function Player:onUseWeapon(target, weapon, primaryDamage, primaryType, secondaryDamage, secondaryType)
    if math.random(100) <= config.chance then
        local monster = Game.createMonster(config.summon, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            addEvent(function (cid)
                local monster = Monster(cid)
                if monster then
                    monster:remove()
                end
            end, config.duration * 1000, monster:getId())
            local bonus = Condition(CONDITION_ATTRIBUTES)
            bonus:setParameter(CONDITION_PARAM_TICKS, config.duration * 1000)
            bonus:setParameter(config.bonus, config.bonusPercent)
            player:addCondition(bonus)
            return true
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
This script will be executed every time you try to use the weapon to damage another creature.
I don't know if it's the correct way to monitor when the weapon is used, but it's an advance.

Is it not possible by onTargetCombat?
He didnt say anything about a weapon? :eek:
 
Is it not possible by onTargetCombat?
He didnt say anything about a weapon? :eek:
Well i was not thinking it will need a Sources changes.
When a player attacks, yeah i mean using weapon or using a spell.
Is a simple example than Diablo Immortal, when you attack a monster and have a legendary gems, then you got 10% that the resonance gem it will make an explosion and hit all monsters around.

We start to recreate some tips from Diablo in to Tibia with @alexv45 on a open source server, already posted on forum, but anyway i will try this after the next update with the new vocation.

There is currently no Lua method to monitor when a weapon is used.
but this is where the call to this Lua function you need should be.

events.h
HERE
C++:
int32_t playerOnUseWeapon = -1;
HERE
Lua:
void eventPlayerOnUseWeapon(Player* player, Creature* target, Item* weapon, CombatDamage& damage)

events.cpp
HERE
C++:
else if (methodName == "onUseWeapon") {
    info.playerOnUseWeapon = event;
}
HERE
C++:
void Events::eventPlayerOnUseWeapon(Player* player, Creature* target, Item* weapon, CombatDamage& damage)
{
    // Player:onUseWeapon(target, weapon, primaryDamage, primaryType, secondaryDamage, secondaryType)
    if (info.playerOnUseWeapon == -1) {
        return;
    }

    if (!scriptInterface.reserveScriptEnv()) {
        std::cout << "[Error - Events::eventPlayerOnUseWeapon] Call stack overflow" << std::endl;
        return;
    }

    ScriptEnvironment* env = scriptInterface.getScriptEnv();
    env->setScriptId(info.playerOnUseWeapon, &scriptInterface);

    lua_State* L = scriptInterface.getLuaState();
    scriptInterface.pushFunction(info.playerOnUseWeapon);

    LuaScriptInterface::pushUserdata<Player>(L, player);
    LuaScriptInterface::setMetatable(L, -1, "Player");
    if (target) {
        LuaScriptInterface::pushUserdata(L, target);
        LuaScriptInterface::setCreatureMetatable(L, -1, target);
    } else {
        lua_pushnil(L);
    }

    LuaScriptInterface::pushThing(L, weapon);
    LuaScriptInterface::pushCombatDamage(L, damage);

    if (scriptInterface.protectedCall(L, 8, 4) != 0) {
        LuaScriptInterface::reportError(nullptr, LuaScriptInterface::popString(L));
    } else {
        damage.primary.value = std::abs(LuaScriptInterface::getNumber<int32_t>(L, -4));
        damage.primary.type = LuaScriptInterface::getNumber<CombatType_t>(L, -3);
        damage.secondary.value = std::abs(LuaScriptInterface::getNumber<int32_t>(L, -2));
        damage.secondary.type = LuaScriptInterface::getNumber<CombatType_t>(L, -1);

        lua_pop(L, 4);
        if (damage.primary.type != COMBAT_HEALING) {
            damage.primary.value = -damage.primary.value;
            damage.secondary.value = -damage.secondary.value;
        }
    }

    scriptInterface.resetScriptEnv();
}

weapons.cpp
HERE
C++:
#include "events.h"
HERE
C++:
extern Events* g_events;
AFTER HERE
C++:
g_events->eventPlayerOnUseWeapon(player, target, item, damage);

add to data/events/events.xml
XML:
<event class="Player" method="onUseWeapon" enabled="1" />

and add to data/events/scripts/player.lua
on the last line
Lua:
local config = {
    chance = 2,
    summon = 'rat',
    bonus = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,
    bonusPercent = 2,
    duration = 20
}

function Player:onUseWeapon(target, weapon, primaryDamage, primaryType, secondaryDamage, secondaryType)
    if math.random(100) <= config.chance then
        local monster = Game.createMonster(config.summon, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            addEvent(function (cid)
                local monster = Monster(cid)
                if monster then
                    monster:remove()
                end
            end, config.duration * 1000, monster:getId())
            local bonus = Condition(CONDITION_ATTRIBUTES)
            bonus:setParameter(CONDITION_PARAM_TICKS, config.duration * 1000)
            bonus:setParameter(config.bonus, config.bonusPercent)
            player:addCondition(bonus)
            return true
        end
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
This script will be executed every time you try to use the weapon to damage another creature.
I don't know if it's the correct way to monitor when the weapon is used, but it's an advance.
Thanks sarah again, i will try it!
 
I misunderstood, I'm sorry for confusing you. @alejandro762
data/scripts/file.lua
Lua:
local config = {
    chance = 20,
    summon = 'rat',
    bonus = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,
    bonusPercent = 2,
    duration = 20,
    minDetectableDamage = 100, -- 100 hit points
    onlyWeapons = false
}

local function whenPlayerAttack(player, damage)
    if damage >= config.minDetectableDamage and math.random(100) <= config.chance then
        local monster = Game.createMonster(config.summon, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            addEvent(function (cid)
                local monster = Monster(cid)
                if monster then
                    monster:getPosition():sendMagicEffect(CONST_ME_POFF)
                    monster:remove()
                end
            end, config.duration * 1000, monster:getId())
            local bonus = Condition(CONDITION_ATTRIBUTES)
            bonus:setParameter(CONDITION_PARAM_TICKS, config.duration * 1000)
            bonus:setParameter(config.bonus, config.bonusPercent)
            player:addCondition(bonus)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You feel a bit more skillful.')
        end
    end
end

local creatureEvent = CreatureEvent("WhenPlayerAttackHealth")

function creatureEvent.onHealthChange(creature, player, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not player then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    if primaryType == COMBAT_HEALING or not player:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    if not config.onlyWeapons or table.contains({ORIGIN_WAND, ORIGIN_MELEE, ORIGIN_RANGED}, origin) then
        whenPlayerAttack(player, primaryDamage + secondaryDamage)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

creatureEvent:register()

local creatureEvent = CreatureEvent("WhenPlayerAttackMana")

function creatureEvent.onManaChange(creature, player, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if not player then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    if primaryType == COMBAT_MANADRAIN or not player:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    if not config.onlyWeapons or table.contains({ORIGIN_WAND, ORIGIN_MELEE, ORIGIN_RANGED}, origin) then
        whenPlayerAttack(player, primaryDamage + secondaryDamage)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

creatureEvent:register()

local ec = EventCallback

function ec.onTargetCombat(creature, target)
    target:registerEvent("WhenPlayerAttackHealth")
    target:registerEvent("WhenPlayerAttackMana")
    return RETURNVALUE_NOERROR
end

ec:register(--[[0]])
 
Last edited:
I misunderstood, I'm sorry for confusing you. @alejandro762
data/scripts/file.lua
Lua:
local config = {
    chance = 20,
    summon = 'rat',
    bonus = CONDITION_PARAM_SPECIALSKILL_CRITICALHITCHANCE,
    bonusPercent = 2,
    duration = 20,
    minDetectableDamage = 100, -- 100 hit points
    onlyWeapons = false
}

local function whenPlayerAttack(player, damage)
    if damage >= config.minDetectableDamage and math.random(100) <= config.chance then
        local monster = Game.createMonster(config.summon, player:getPosition())
        if monster then
            monster:setMaster(player)
            monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            addEvent(function (cid)
                local monster = Monster(cid)
                if monster then
                    monster:getPosition():sendMagicEffect(CONST_ME_POFF)
                    monster:remove()
                end
            end, config.duration * 1000, monster:getId())
            local bonus = Condition(CONDITION_ATTRIBUTES)
            bonus:setParameter(CONDITION_PARAM_TICKS, config.duration * 1000)
            bonus:setParameter(config.bonus, config.bonusPercent)
            player:addCondition(bonus)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You feel a bit more skillful.')
        end
    end
end

local creatureEvent = CreatureEvent("WhenPlayerAttackHealth")

function creatureEvent.onHealthChange(creature, player, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType == COMBAT_HEALING or not player:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    if not config.onlyWeapons or table.contains({ORIGIN_WAND, ORIGIN_MELEE, ORIGIN_RANGED}, origin) then
        whenPlayerAttack(player, primaryDamage + secondaryDamage)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

creatureEvent:register()

local creatureEvent = CreatureEvent("WhenPlayerAttackMana")

function creatureEvent.onManaChange(creature, player, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if primaryType == COMBAT_MANADRAIN or not player:isPlayer() then
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
    if not config.onlyWeapons or table.contains({ORIGIN_WAND, ORIGIN_MELEE, ORIGIN_RANGED}, origin) then
        whenPlayerAttack(player, primaryDamage + secondaryDamage)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

creatureEvent:register()

local ec = EventCallback

function ec.onTargetCombat(creature, target)
    target:registerEvent("WhenPlayerAttackHealth")
    target:registerEvent("WhenPlayerAttackMana")
    return RETURNVALUE_NOERROR
end

ec:register(--[[0]])
Great!
I test it after add the EventCallback, since we start the project on wrong tfs that doesn't have ec :)

This are the full changes ?
 
Great!
I test it after add the EventCallback, since we start the project on wrong tfs that doesn't have ec :)

This are the full changes ?
 
Rofl, i start doing changes, but from this otservbr to tfs, some functions are very different hard to understand where add it, players.lua looks different.
Well.
Did was the same doing this method onCast spell ( like doing exevo gran mas vis 2% chance to summon and get the bonus ? ), it was with eventcallback also ?

Anyway thanks, tested on Tfs and was working like a charm, i will look in further to pass the server on Tfs.
 
Rofl, i start doing changes, but from this otservbr to tfs, some functions are very different hard to understand where add it, players.lua looks different.
Well.
Did was the same doing this method onCast spell ( like doing exevo gran mas vis 2% chance to summon and get the bonus ? ), it was with eventcallback also ?

Anyway thanks, tested on Tfs and was working like a charm, i will look in further to pass the server on Tfs.
Try add:
Lua:
if target then
    target:registerEvent("WhenPlayerAttackHealth")
    target:registerEvent("WhenPlayerAttackMana")
end
HERE in your otbr datapack

remember to remove this from your script:
Lua:
local ec = EventCallback

function ec.onTargetCombat(creature, target)
    target:registerEvent("WhenPlayerAttackHealth")
    target:registerEvent("WhenPlayerAttackMana")
    return RETURNVALUE_NOERROR
end

ec:register(--[[0]])
 
Solution
Try add:
Lua:
if target then
    target:registerEvent("WhenPlayerAttackHealth")
    target:registerEvent("WhenPlayerAttackMana")
end
HERE in your otbr datapack

remember to remove this from your script:
Lua:
local ec = EventCallback

function ec.onTargetCombat(creature, target)
    target:registerEvent("WhenPlayerAttackHealth")
    target:registerEvent("WhenPlayerAttackMana")
    return RETURNVALUE_NOERROR
end

ec:register(--[[0]])

Is working, removing ec part, then add it as action. Very impressive.

Is only doing an error as "player" ( not god ),
Line 40,
if primaryType == COMBAT_HEALING or not player:isPlayer() then
Attempt to index local 'player' (a nil value), i think such same for line 54
if primaryType == COMBAT_MANADRAIN or not player:isPlayer() then
 
before of:
Lua:
if primaryType == COMBAT_MANADRAIN or not player:isPlayer() then
add:
Lua:
if not player then
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

Adding this part of code before COMBAT_MANADRAIN and before COMBAT_HEALING, is working.

Since i know what is doing this, maybe you can know what is 'interfering', we are using a condition system on maps, like diablo, malus / bonus, in this case we got Dazzled Condition, others, curse, poison etc.. then a player with 1-2 malus conditions, while attacking using the Action registered item id, is giving this error on console a player nil value, here is the script for map condition, maybe there is something interfering.. i know some scripts are not compatible both,

Without any condition on player, ( and without adding the last part code you sent ) it was working without errors, with a condition and without the last part if not player, was givin an error. I just try now, adding it before manadrain & healing, and is working with player getting 4 differents conditions.

Here is the code if you wish check,


Lua:
local topLeftCorner = Position(29535, 32426, 10)
local bottomRightCorner = Position(29652, 32533, 10)

local condition = Condition(CONDITION_POISON, CONDITIONID_COMBAT)
condition:setParameter(CONDITION_PARAM_DELAYED, true)
condition:setParameter(CONDITION_PARAM_MINVALUE, 20)
condition:setParameter(CONDITION_PARAM_MAXVALUE, 70)
condition:setParameter(CONDITION_PARAM_STARTVALUE, 50)
condition:setParameter(CONDITION_PARAM_TICKINTERVAL, 5000)
condition:setParameter(CONDITION_PARAM_FORCEUPDATE, true)

local riftCond = GlobalEvent("riftCondMap1")

function riftCond.onThink(interval)
    for _, player in pairs(Game.getPlayers()) do
        local position = player:getPosition()
        if position:isInRange(topLeftCorner, bottomRightCorner) then
            condition:addDamage(20, 5000, -20)
            player:addCondition(condition)
        end
    end
    return true
end

riftCond:interval(5000)
riftCond:register()

The script works while attack, with any kind of weapon or fist fighting, now is possible to add this to a specific item ?
Since whenplayerattacking is not like onUse, onAttack, just like local playerAttack = Action() , playerAttack:id(2175) ?

I'll try add and player:getItembyId / player:getItemCount / player:getItemId , but doesnt work, it spawns monster without having the item.
 
Last edited:
Do not hesitate to share the answer, this can be useful to many people.
Oh sorry,

On the function,
Lua:
local function whenPlayerAttack(.....)
When if start before then adding and player:getItemCount(2175) > 0 then
If you got item 2175, spellbook on backpack it will work, if not, it doesnt work.

Awesome!
Post automatically merged:

Do not hesitate to share the answer, this can be useful to many people.
Arg..
I found only one problem.
Using and equipping items, not problem, but if anyone attack with no weapon as fist fighting...
Is returning an error about "attempt to index a nil value".

I just copy 2x in same script same functions with differents names in order to add this on 2 differents items.

attempt to index a nil value, :17 in function 'whenPlayerAttack'
 
Last edited:
Back
Top