• 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 Gain X% Attributes When Equiped.[Creaturescript]

LightTenshimaru

LightTenshimaru
Joined
Mar 15, 2014
Messages
28
Reaction score
1
I'm making a script that when equipping [Wand + Shield], [Sword, Axe, Mace + Shield], [Crossbow] have an attribute bonus in [ML], [SWORD, AXE, MACE], [DISTANCE] respectively.

But I have a lot of problems, the first is that activation message
Lua:
creature: say ("Damage Bonus", TALKTYPE_MONSTER_SAY
keeps repeating without stopping on the screen, the second is that when an attribute is applied when putting the item, when removed the stats do not return to normal, and the third is that I can not combine more than one item to work, I can only with one.
I also have no idea how to include two-handed weapons using the tag [slotType = "two-handed"]

I would be extremely grateful if anyone could help.

Lua:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORDPERCENT, 500)

    function onThink(creature, cid)
    if creature:isPlayer() and creature:getWeaponType() == WEAPON_SHIELD then
  
    creature:say("Damage Bonus", TALKTYPE_MONSTER_SAY, 36)
    creature:addCondition(condition)
  
    else
    creature:removeCondition(condition)
    creature:say("Bonus Removed", TALKTYPE_MONSTER_SAY, 36)
    return true  
end
end
 
Last edited:
The message will show up over and over because the conditions is always true. I'd say that it could be done using onEquip function.
 
Check for the condition to be false and also for the shield to be true
 
I suck with tfs 1.x, so if this doesn't work, don't be surprised.

The basic idea is proper though. I just don't know how to use the functions properly.

Lua:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORDPERCENT, 500)

function onThink(creature, cid)
    if not creature:isPlayer() then
        return true
    end
   
    if creature:getWeaponType() == WEAPON_SHIELD then
        if not creature:getCondition(CONDITION_ATTRIBUTES) then
            creature:say("Damage Bonus", TALKTYPE_MONSTER_SAY, 36)
            creature:addCondition(condition)
        end
    else
        if creature:getCondition(CONDITION_ATTRIBUTES) then
            creature:removeCondition(condition)
            creature:say("Bonus Removed", TALKTYPE_MONSTER_SAY, 36)
        end
    end
    return true
end
 
Get weaponType needs to be from an item.
If you want to check the weaponType the creature has, do it like this.

Code:
local weapon = creature:getSlotItem(CONST_SLOT_LEFT).itemid
local it = ItemType(weapon)

I'd write the whole code, but im on mobile!

If you cant do it with that, ill do it all later.
 
I suck with tfs 1.x, so if this doesn't work, don't be surprised.

The basic idea is proper though. I just don't know how to use the functions properly.

Lua:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORDPERCENT, 500)

function onThink(creature, cid)
    if not creature:isPlayer() then
        return true
    end
 
    if creature:getWeaponType() == WEAPON_SHIELD then
        if not creature:getCondition(CONDITION_ATTRIBUTES) then
            creature:say("Damage Bonus", TALKTYPE_MONSTER_SAY, 36)
            creature:addCondition(condition)
        end
    else
        if creature:getCondition(CONDITION_ATTRIBUTES) then
            creature:removeCondition(condition)
            creature:say("Bonus Removed", TALKTYPE_MONSTER_SAY, 36)
        end
    end
    return true
end

Lua:
local weapon = creature:getSlotItem(CONST_SLOT_LEFT).itemid
local it = ItemType(weapon)

Gonna test this, thank you!.
EDIT: I can't make this work without link to a especific item. :/
 
Last edited:
Code:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORDPERCENT, 500)

function onEquip(player, item, slot)
      
if player:getSlotItem(CONST_SLOT_LEFT) then
    weaponside = CONST_SLOT_LEFT
    elseif player:getSlotItem(CONST_SLOT_RIGHT) then
    weaponside = CONST_SLOT_RIGHT
    end

    if (player:getSlotItem(CONST_SLOT_LEFT) == WEAPON_SHIELD and player:getSlotItem(CONST_SLOT_RIGHT) ==(WEAPON TO COMBINE WITH SHIELD)) or (player:getSlotItem(CONST_SLOT_RIGHT) == WEAPON_SHIELD and player:getSlotItem(CONST_SLOT_LEFT) ==(WEAPON TO COMBINE WITH SHIELD))  then
        if not player:getCondition(CONDITION_ATTRIBUTES) then
            player:say("Damage Bonus", TALKTYPE_MONSTER_SAY)
            player:addCondition(condition)
        end
   end
return  true
end

function onDeEquip(player, item, slot)

        if player:getCondition(CONDITION_ATTRIBUTES) then
            player:removeCondition(condition)
            player:say("Bonus Removed", TALKTYPE_MONSTER_SAY)
        end
    return true
end

This is the best way to do what you want in my opinion. Use it on movements and register it to the weapons you want.
 
Code:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
setConditionParam(condition, CONDITION_PARAM_SKILL_SWORDPERCENT, 500)

function onEquip(player, item, slot)
     
if player:getSlotItem(CONST_SLOT_LEFT) then
    weaponside = CONST_SLOT_LEFT
    elseif player:getSlotItem(CONST_SLOT_RIGHT) then
    weaponside = CONST_SLOT_RIGHT
    end

    if (player:getSlotItem(CONST_SLOT_LEFT) == WEAPON_SHIELD and player:getSlotItem(CONST_SLOT_RIGHT) ==(WEAPON TO COMBINE WITH SHIELD)) or (player:getSlotItem(CONST_SLOT_RIGHT) == WEAPON_SHIELD and player:getSlotItem(CONST_SLOT_LEFT) ==(WEAPON TO COMBINE WITH SHIELD))  then
        if not player:getCondition(CONDITION_ATTRIBUTES) then
            player:say("Damage Bonus", TALKTYPE_MONSTER_SAY)
            player:addCondition(condition)
        end
   end
return  true
end

function onDeEquip(player, item, slot)

        if player:getCondition(CONDITION_ATTRIBUTES) then
            player:removeCondition(condition)
            player:say("Bonus Removed", TALKTYPE_MONSTER_SAY)
        end
    return true
end

This is the best way to do what you want in my opinion. Use it on movements and register it to the weapons you want.

But i really need to be any shield or any spellbook, also crossbow that is two-hand alonside with some two-handed Swords, Axes and Mace.
Do this on movements will not archieve my objetive.

The code is nearly perfect on creaturescripts, the only problem is when the unequip of the itens is done, the attributes are not removed too.
 
Yes it will achieve your achievements, but you need to register the script on ALL you objects. Can be done really easy with copy paste replace.

There's a better way to do it probably. If you want to do it onThink would be way harder.
 
one really easy with copy paste replace.
Ok.

There's something wrong?
HTML:
<movevent event="Equip" itemid="8931;8905" slot="hand" function="onEquipItem" script="WeaponBonus.lua"/>
<movevent event="DeEquip" itemid="8931;8905" slot="hand" function="onDeEquipItem" script="WeaponBonus.lua"/>

No console erros and nothing change in game when equip this two itens.
 
I dont know if its possible to register more than one item at once on movements.

If its possible the way should be as in items fromid="8931" toid="8905".
Also, you dont need funciton="onEquipItem" since you are using script="weaponbonus" which already is using that function inside.

TFS has a bug that when using scripts, function onEquipItem and onDeEquipItem doesnt work. I think there was a source fix somewhere or in this forum or on github from theforgottenserver.
 
I dont know if its possible to register more than one item at once on movements.

If its possible the way should be as in items fromid="8931" toid="8905".
Also, you dont need funciton="onEquipItem" since you are using script="weaponbonus" which already is using that function inside.

TFS has a bug that when using scripts, function onEquipItem and onDeEquipItem doesnt work. I think there was a source fix somewhere or in this forum or on github from theforgottenserver.


HTML:
<movevent event="Equip" fromid="8905" toid="8931" slot="hand" script="WeaponBonus.lua"/>

Same problem.
No erros.

Maybe something on the code preventing?
 
Lua:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
        setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
        setConditionParam(condition, CONDITION_PARAM_SKILL_DISTANCEPERCENT, 500)
        setConditionParam(condition, CONDITION_PARAM_BUFF_SPELL, 1)
      
local voc = {
    {
        id = 3, -- Paladin
        spellname = "Bow/Crossbow [Distance Bonus]",
       
    },
}

function onThink(creature, interval)
    if config.enabled then
        if creature:isPlayer() then
                    local vocation = creature:getVocation():getBase():getId()
                    for i=1, #voc do
                        if vocation == voc[i].id then
                            local level = creature:getLevel()
                            local min = 0
                            local max = 0
                            if vocation == 3 then
                                local weapontype = nil
                                local slotItem = creature:getSlotItem(CONST_SLOT_LEFT)
                                if    slotItem then
                                weaponType = slotItem:getType():getWeaponType()
                                end
                                if weaponType == 5 then
                                creature:addCondition(condition)
                                end
                            end

This code is working on creaturescripts, mas still the problem when unequip the bonus still.
Can help?
 
Last edited:
Why don't you post the whole script?

Also I think you should rewrite your config table:
Lua:
local voc = {
    {
        id = 3, -- Paladin
        spellname = "Bow/Crossbow [Distance Bonus]",
      
    },
}

for i=1, #voc do
 if vocation == voc[i].id then

To something like this:
Lua:
local voc = {
    [3] = { -- Paladin
        spellname = "Bow/Crossbow [Distance Bonus]"
    }
}

local vocation = voc[creature:getVocation():getBase():getId()]
if vocation then
   --
end
 
Here's the entire code:
Lua:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
        setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
        setConditionParam(condition, CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, 150)
        setConditionParam(condition, CONDITION_PARAM_BUFF_SPELL, 1)

local condition2 = createConditionObject(CONDITION_ATTRIBUTES)
        setConditionParam(condition2, CONDITION_PARAM_TICKS, -1)
        setConditionParam(condition2, CONDITION_PARAM_SKILL_DISTANCEPERCENT, 150)
        setConditionParam(condition2, CONDITION_PARAM_BUFF_SPELL, 1)  

local condition3 = createConditionObject(CONDITION_ATTRIBUTES)
        setConditionParam(condition3, CONDITION_PARAM_TICKS, -1)
        setConditionParam(condition3, CONDITION_PARAM_SKILL_MELEEPERCENT, 150)
        setConditionParam(condition3, CONDITION_PARAM_BUFF_SPELL, 1)          
      
local voc = {
    {
        id = 1, -- Sorcerer
    },
    {
        id = 2, -- Druid       
    },
    {
        id = 3, -- Paladin
    },
    {
        id = 4, -- Knight
    },
}

function onThink(creature, interval)
    if creature:isPlayer() then
       local vocation = creature:getVocation():getBase():getId()
            for i=1, #voc do
                if vocation == voc[i].id then
                    print(creature:getWeaponType())
                        if vocation == 1 or vocation == 2 then
                            local weapontype = nil
                            local slotItem = creature:getSlotItem(CONST_SLOT_LEFT) or creature:getSlotItem(CONST_SLOT_RIGHT)
                            if    slotItem then
                            weaponType = slotItem:getType():getWeaponType()
                            end
                            if weaponType == WEAPON_SHIELD then
                            creature:addCondition(condition)
                            creature:say("MAGIC!", TALKTYPE_MONSTER_SAY)
                            end
                            end
                          
                        if vocation == 3 then
                            local weapontype = nil
                            local slotItem = creature:getSlotItem(CONST_SLOT_LEFT)
                            if    slotItem then
                            weaponType = slotItem:getType():getWeaponType()
                            end
                            if weaponType == 5 then
                            creature:addCondition(condition2)
                            creature:say("DISTANCE!", TALKTYPE_MONSTER_SAY)
                            end
                            end
                          
                        if vocation == 4 then
                            local weapontype = nil
                            local slotItem = creature:getSlotItem(CONST_SLOT_LEFT) or creature:getSlotItem(CONST_SLOT_RIGHT)
                            if slotItem then
                            weaponType = slotItem:getType():getWeaponType()
                            end                              
                            if weaponType == WEAPON_SHIELD then
                            creature:addCondition(condition3)
                            creature:say("BERSERKER!", TALKTYPE_MONSTER_SAY)
                            end
                        end
                    end
                end
            end
        end

Just need to figure how to identify "slotType="two-handed" and how to remove de condition of attribute bonus after the item is unequiped.
 
Last edited:
Check if the player have the equiped weapons, in your case can be checked with an else statement when you check the weapontypes and then remove the vocation condition if exists.

Lua:
if weaponType == WEAPON_SHIELD then
    -- add condition
else
    -- check conditions then remove if exist
end

Also you should assign subIds into your conditions to make them easier to check/remove.
 
Nearly done, but i'm trying to findo something to identify that the shield is not present, to remove the bonus.
But everything i do remove the bonus even with the shield equiped.



I'm trying things like this, but sometimes i got lost and doing wrong things!
Lua:
local shield = creature:getSlotItem(CONST_SLOT_LEFT) and creature:getSlotItem(CONST_SLOT_RIGHT)
..
elseif    shield ~= WEAPON_SHIELD then
creature:removeCondition(CONDITION_ATTRIBUTES)                              
end


Updated code:
Lua:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
        setConditionParam(condition, CONDITION_PARAM_TICKS, -1)
        setConditionParam(condition, CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, 150)
        setConditionParam(condition, CONDITION_PARAM_BUFF_SPELL, 1)

local condition2 = createConditionObject(CONDITION_ATTRIBUTES)
        setConditionParam(condition2, CONDITION_PARAM_TICKS, -1)
        setConditionParam(condition2, CONDITION_PARAM_SKILL_DISTANCEPERCENT, 150)
        setConditionParam(condition2, CONDITION_PARAM_BUFF_SPELL, 1)   

local condition3 = createConditionObject(CONDITION_ATTRIBUTES)
        setConditionParam(condition3, CONDITION_PARAM_TICKS, -1)
        setConditionParam(condition3, CONDITION_PARAM_SKILL_MELEEPERCENT, 150)
        setConditionParam(condition3, CONDITION_PARAM_BUFF_SPELL, 1)           
       
local voc = {
    {
        id = 1, -- Sorcerer
    },
    {
        id = 2, -- Druid        
    },
    {
        id = 3, -- Paladin
    },
    {
        id = 4, -- Knight
    },
}

function onThink(creature, interval)
    if creature:isPlayer() then
       local vocation = creature:getVocation():getBase():getId()
            for i=1, #voc do
                if vocation == voc[i].id then
                    --print(creature:getWeaponType())
                        if vocation == 1 or vocation == 2 then
                            local weapontype = nil
                            local slotItem = creature:getSlotItem(CONST_SLOT_LEFT) or creature:getSlotItem(CONST_SLOT_RIGHT)
                            if    slotItem then
                               weaponType = slotItem:getType():getWeaponType()
                            end
                            if weaponType == WEAPON_SHIELD then
                               creature:addCondition(condition)
                               --creature:say("MAGIC!", TALKTYPE_MONSTER_SAY)
                            elseif
                               creature:getSlotItem(CONST_SLOT_LEFT) and creature:getSlotItem(CONST_SLOT_RIGHT) == WEAPON_WAND then
                               creature:removeCondition(CONDITION_ATTRIBUTES)                              
                            end
                            end
                            end
                            end
                           
                        if vocation == 3 then
                            local slotItem = creature:getSlotItem(CONST_SLOT_LEFT) or creature:getSlotItem(CONST_SLOT_RIGHT)
                            if    slotItem then
                                  slotPos = slotItem:getType():getSlotPosition()
                                  --print("Slot position: ", slotPos)
                            end
                            if slotPos == 2096 then
                               creature:addCondition(condition2)                           
                               --creature:say("DISTANCE!", TALKTYPE_MONSTER_SAY)
                            elseif
                               slotPos == 48 then                              
                               creature:removeCondition(CONDITION_ATTRIBUTES)                              
                            end
                            end
                           
                        if vocation == 4 then
                            local weapontype = nil
                            local slotItem = creature:getSlotItem(CONST_SLOT_LEFT) or creature:getSlotItem(CONST_SLOT_RIGHT)
                            if slotItem then
                               weaponType = slotItem:getType():getWeaponType()
                            end                               
                            if weaponType == WEAPON_SHIELD then
                               creature:addCondition(condition3)
                                --creature:say("BERSERKER!", TALKTYPE_MONSTER_SAY)
                            else
                               creature:removeCondition(CONDITION_ATTRIBUTES)               
   
                            end
                            end
                        end
                    end
 
Back
Top