• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction [MoveEvents] [CreatureEvent] Attribute System

Shinmaru

エロルアー Scripter!
Joined
Aug 20, 2007
Messages
1,988
Reaction score
88
Location
Puerto Rico
Attribute System
By:375311
I want to share here a basic attribute system, that lets you further empower
your character beyond than what you thought it would've been.
So here is my script:
Warning: This is not an advanced script in no way, if you have
the skill to make it better then feel free to do so.

Script Name: attributes.lua
Type: Talkaction
Location: data/talkactions/scripts/
Lua Code:
Lua:
local attr =  {
    stock = 2800,
    str = 2801,
    agi = 2802,
    hth = 2803,
    ene = 2804,
    mlpool = 2805
}
local v = {
    [1] = {st = 1, ag = 2, ht = 3, en = 5, mlReq = 4},
    [2] = {st = 1, ag = 2, ht = 3, en = 5, mlReq = 4},
    [3] = {st = 3, ag = 3, ht = 3, en = 3, mlReq = 6},
    [4] = {st = 5, ag = 3, ht = 4, en = 1, mlReq = 8},
    [5] = {st = 2, ag = 4, ht = 6, en = 10, mlReq = 2},
    [6] = {st = 2, ag = 4, ht = 6, en = 10, mlReq = 2},
    [7] = {st = 6, ag = 6, ht = 6, en = 6, mlReq = 3},
    [8] = {st = 10, ag = 6, ht = 8, en = 2, mlReq = 4}
}
function onSay(cid, words, param)
    local stockPoints = getPlayerStorageValue(cid, attr.stock)
    local MLpool = getPlayerStorageValue(cid, attr.mlpool)
    local weaponTypes = {1, 2, 3, 5, 6}
    local rightHand = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
    local leftHand = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
    local strength = getPlayerStorageValue(cid, attr.str)
    local agility = getPlayerStorageValue(cid, attr.agi)
    local energy = getPlayerStorageValue(cid, attr.ene)
    local health = getPlayerStorageValue(cid, attr.hth)
    for voc, info in pairs(v) do   
        if isNumber(param) then
            if tonumber(param) <= stockPoints then
                plrl = "points"
                        if words == "!addStr" then
                            if getPlayerVocation(cid) == voc then
                                doPlayerSetStorageValue(cid, attr.str, strength+param)
                                doPlayerSetStorageValue(cid, attr.stock, stockPoints-param)
                                doPlayerSendTextMessage(cid, 25, "You added "..param.." "..plrl.." to Strength.")
                                local strength2 = getPlayerStorageValue(cid, attr.str)
                                local strfrm = strength2*info.st
                                if isInArray(weaponTypes, getItemWeaponType(rightHand.uid)) then
                                    setItemExtraAttack(rightHand.uid, strfrm)
                                elseif isInArray(weaponTypes, getItemWeaponType(leftHand.uid)) then    
                                    setItemExtraAttack(leftHand.uid, strfrm)
                                end
                            end    
                        end
                        if words == "!addAgi" then
                            if getPlayerVocation(cid) == voc then
                                doPlayerSetStorageValue(cid, attr.agi, agility+param)
                                doPlayerSetStorageValue(cid, attr.stock, stockPoints-param)
                                doPlayerSendTextMessage(cid, 25, "You added "..param.." "..plrl.." to Agility.")
                                local agility2 = getPlayerStorageValue(cid, attr.agi)
                                local agifrm = agility2*info.ag
                                if isInArray(weaponTypes, getItemWeaponType(rightHand.uid)) or getItemWeaponType(rightHand.uid) == 4 then
                                    setItemExtraDefense(rightHand.uid, agifrm)
                                    if getItemAttackSpeed(rightHand.uid) > 0 then
                                        setItemAttackSpeed(rightHand.uid, agifrm)
                                    end
                                end    
                                if isInArray(weaponTypes, getItemWeaponType(leftHand.uid)) or getItemWeaponType(leftHand.uid) == 4 then
                                    setItemExtraDefense(leftHand.uid, agifrm)
                                    if getItemAttackSpeed(leftHand.uid) > 0 then
                                        setItemAttackSpeed(leftHand.uid, agifrm)
                                    end    
                                end    
                            end    
                        end
                        if words == "!addHealth" then
                            if getPlayerVocation(cid) == voc then
                                doPlayerSetStorageValue(cid, attr.hth, health+param)
                                doPlayerSetStorageValue(cid, attr.stock, stockPoints-param)
                                doPlayerSendTextMessage(cid, 25, "You added "..param.." "..plrl.." to Health.")
                                local health2 = getPlayerStorageValue(cid, attr.hth)
                                local hthfrm = health2*info.ht
                                setCreatureMaxHealth(cid, getCreatureMaxHealth(cid)+hthfrm)
                                doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
                            end    
                        end
                        if words == "!addEnergy" then
                            if getPlayerVocation(cid) == voc then
                                doPlayerSetStorageValue(cid, attr.ene, energy+param)
                                doPlayerSetStorageValue(cid, attr.stock, stockPoints-param)
                                doPlayerSendTextMessage(cid, 25, "You added "..param.." "..plrl.." to Energy.")
                                local energy2 = getPlayerStorageValue(cid, attr.ene)
                                local enefrm = energy2*info.en
                                setCreatureMaxMana(cid, getCreatureMaxMana(cid)+enefrm)
                                doCreatureAddMana(cid, getCreatureMaxMana(cid))
                            end    
                        end    
                        if words == "!addML" then
                            if getPlayerVocation(cid) == voc then
                                if tonumber(param) == info.mlReq then
                                    doPlayerSetStorageValue(cid, attr.stock, stockPoints-param)
                                    doPlayerSetStorageValue(cid, attr.mlpool, MLpool+1)
                                    doPlayerAddSkill(cid, SKILL__MAGLEVEL, 1)
                                    doPlayerAddSpentMana(cid, 50)
                                    doPlayerSendTextMessage(cid, 25, "Magic Level +1.")
                                    doCreatureAddMana(cid, getCreatureMaxMana(cid))
                                else
                                    doPlayerSendCancel(cid, "You need "..info.mlReq.." points to get 1 Magic Level.")
                                end    
                            end
                        end    
            else
                doPlayerSendCancel(cid, "You don't have enough points to add.")
            end
        else
            doPlayerSendCancel(cid, "Please specify a number.")
        end
    end    
return true         
end
XML Code:
PHP:
<talkaction words="!addStr;!addAgi;!addHealth;!addEnergy;!addML" event="script" value="attributes.lua"/>
XML Location: data/talkactions/talkactions.xml
Description:
This script is used to add attribute points earned by leveling up.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Script Name: getattributes.lua
Type: Talkaction
Location: data/talkactions/scripts/
Lua Code:
Lua:
local attr =  {
    stock = 2800,
    str = 2801,
    agi = 2802,
    hth = 2803,
    ene = 2804,
    mlpool = 2805
}
function onSay(cid, words)
local stockPoints = getPlayerStorageValue(cid, attr.stock)
local MLpool = getPlayerStorageValue(cid, attr.mlpool)
local strength = getPlayerStorageValue(cid, attr.str)
local agility = getPlayerStorageValue(cid, attr.agi)
local energy = getPlayerStorageValue(cid, attr.ene)
local health = getPlayerStorageValue(cid, attr.hth)
    
    if words == "!attpoints" then
        if stockPoints > 1 then
            P = "points"
            doPlayerSendTextMessage(cid, 25, "You have "..stockPoints.." attribute "..P.." to use on your self.")
        else
            P = "point"
            doPlayerSendTextMessage(cid, 25, "You have "..stockPoints.." attribute "..P.." to use on your self.")
        end
        if stockPoints == 0 then
            doPlayerSendTextMessage(cid, 25, "You have "..stockPoints.." attribute point to use on your self.")
        end    
    end
    if words == "!strength" then
        if strength > 1 then
            P = "points"
            doPlayerSendTextMessage(cid, 25, "You have "..strength.." attribute "..P.." in Strength.")
        else
            P = "point"
            doPlayerSendTextMessage(cid, 25, "You have "..strength.." attribute "..P.." in Strength.")
        end
    end
    if words == "!agility" then
        if agility > 1 then
            P = "points"
            doPlayerSendTextMessage(cid, 25, "You have "..agility.." attribute "..P.." in Agility.")
        else
            P = "point"
            doPlayerSendTextMessage(cid, 25, "You have "..agility.." attribute "..P.." in Agility.")
        end
    end
    if words == "!health" then
        if health > 1 then
            P = "points"
            doPlayerSendTextMessage(cid, 25, "You have "..health.." attribute "..P.." in Health.")
        else
            P = "point"
            doPlayerSendTextMessage(cid, 25, "You have "..health.." attribute "..P.." in Health.")
        end
    end
    if words == "!energy" then
        if energy > 1 then
            P = "points"
            doPlayerSendTextMessage(cid, 25, "You have "..energy.." attribute "..P.." in Energy.")
        else
            P = "point"
            doPlayerSendTextMessage(cid, 25, "You have "..energy.." attribute "..P.." in Energy.")
        end
    end
    if words == "!magic" then
        if MLpool > 1 then
            P = "points"
            doPlayerSendTextMessage(cid, 25, "You have "..MLpool.." Magic Level "..P..".")
        else
            P = "point"
            doPlayerSendTextMessage(cid, 25, "You have "..MLpool.." Magic Level "..P..".")
        end
    end
return true
end
XML Code:
PHP:
<talkaction words="!attpoints;!strength;!agility;!health;!energy;!magic" event="script" value="getattributes.lua"/>
XML Location: data/talkactions/talkactions.xml
Description:
This script tells the Player how many points has he added to his attributes.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Script Name: attributeAdvance.lua
Type: CreatureEvent
Location: data/creaturescripts/scripts/
Lua Code:
Lua:
local v = {
    [0] = {amount = 1},
    [1] = {amount = 5},
    [2] = {amount = 5},
    [3] = {amount = 5},
    [4] = {amount = 5},
    [5] = {amount = 7},
    [6] = {amount = 7},
    [7] = {amount = 7},
    [8] = {amount = 7}
    }
function onAdvance(cid, skill, oldLevel, newLevel)
local stock = 2800
    for voc, info in pairs(v) do
        if skill == SKILL__LEVEL then
            if getPlayerVocation(cid) == voc then
            local points = (newLevel-oldLevel)*info.amount
                doPlayerSetStorageValue(cid, stock, getPlayerStorageValue(cid, stock)+points)
                doPlayerSendTextMessage(cid, 25, "You got "..points.." points on your level up.")
            end
        end    
    end
return true
end
XML Code:
PHP:
<event type="advance" name="AttributeAdvance" event="script" value="attributeAdvance.lua"/>
XML Location: data/creaturescripts/creaturescripts.xml
Description:
This script allows Players to earn their respective points according to their vocation.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Script Name: attributeLogin.lua
Type: CreatureEvent
Location: data/creaturescripts/scripts/
Lua Code:
Lua:
local attr = {
    stock = 2800,
    str = 2801,
    agi = 2802,
    hth = 2803,
    ene = 2804,
    mlpool = 2805
    }
function onLogin(cid)
    if stockPoints == -1 then
        doPlayerSetStorageValue(cid, attr.stock, 0)    
    end    
    if MLpool == -1 then
        doPlayerSetStorageValue(cid, attr.mlpool, 0)    
    end    
    if strength == -1 then
        doPlayerSetStorageValue(cid, attr.str, 0)    
    end
    if agility == -1 then
        doPlayerSetStorageValue(cid, attr.agi, 0)    
    end
    if energy == -1 then
        doPlayerSetStorageValue(cid, attr.ene, 0)    
    end
    if health == -1 then
        doPlayerSetStorageValue(cid, attr.hth, 0)    
    end
return true
end
XML Code:
PHP:
<event type="login" name="AttributeLogin" event="script" value="attributeLogin.lua"/>
XML Location: data/creaturescripts/creaturescripts.xml
Description:
This script sets the storage values to new players allowing them to use the Attribute System.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Script Name: attributeEquip.lua
Type: MoveEvent
Location: data/movements/scripts
Lua Code:
Lua:
local attr = {
    stock = 2800,
    str = 2801,
    agi = 2802,
    hth = 2803,
    ene = 2804,
    mlpool = 2805
    }
local v = {
    [1] = {st = 1, ag = 2, ht = 3, en = 5},
    [2] = {st = 1, ag = 2, ht = 3, en = 5},
    [3] = {st = 3, ag = 3, ht = 3, en = 3},
    [4] = {st = 5, ag = 3, ht = 4, en = 1},
    [5] = {st = 2, ag = 4, ht = 6, en = 10},
    [6] = {st = 2, ag = 4, ht = 6, en = 10},
    [7] = {st = 6, ag = 6, ht = 6, en = 6},
    [8] = {st = 10, ag = 6, ht = 8, en = 2}
    }
function onEquip(cid, item, slot)
local stockPoints = getPlayerStorageValue(cid, attr.stock)
local MLpool = getPlayerStorageValue(cid, attr.mlpool)
local weaponTypes = {1, 2, 3, 5, 6}
local helmet = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
local armor = getPlayerSlotItem(cid, CONST_SLOT_ARMOR)
local legs = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
local boots = getPlayerSlotItem(cid, CONST_SLOT_FEET)
local rightHand = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
local leftHand = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
local strength = getPlayerStorageValue(cid, attr.str)
local agility = getPlayerStorageValue(cid, attr.agi)
local energy = getPlayerStorageValue(cid, attr.ene)
local health = getPlayerStorageValue(cid, attr.hth)
    for voc, info in pairs(v) do
        if getPlayerVocation(cid) == voc then
            if rightHand.itemid > 0 then
                local strength2 = getPlayerStorageValue(cid, attr.str)
                local strfrm = strength2*info.st
                if isInArray(weaponTypes, getItemWeaponType(rightHand.uid)) then
                    setItemExtraAttack(rightHand.uid, strfrm)
                end
            end    
            if leftHand.itemid > 0 then
                local strength2 = getPlayerStorageValue(cid, attr.str)
                local strfrm = strength2*info.st
                if isInArray(weaponTypes, getItemWeaponType(leftHand.uid)) then    
                    setItemExtraAttack(leftHand.uid, strfrm)
                end
            end
            local agility2 = getPlayerStorageValue(cid, attr.agi)
            local agifrm = agility2*info.ag
            if rightHand.itemid > 0 then
                if isInArray(weaponTypes, getItemWeaponType(rightHand.uid)) or getItemWeaponType(rightHand.uid) == 4 then
                    setItemExtraDefense(rightHand.uid, agifrm)
                    if getItemAttackSpeed(rightHand.uid) > 0 then
                        setItemAttackSpeed(rightHand.uid, agifrm)
                    end
                end    
            end
            if leftHand.itemid > 0 then
                if isInArray(weaponTypes, getItemWeaponType(leftHand.uid)) or getItemWeaponType(leftHand.uid) == 4 then    
                    setItemExtraDefense(leftHand.uid, agifrm)
                    if getItemAttackSpeed(leftHand.uid) > 0 then
                        setItemAttackSpeed(leftHand.uid, agifrm)
                    end    
                end
            end
        end
    end    
return true
end    
function onDeEquip(cid, item, slot)
local stockPoints = getPlayerStorageValue(cid, attr.stock)
local MLpool = getPlayerStorageValue(cid, attr.mlpool)
local weaponTypes = {1, 2, 3, 5, 6}
local helmet = getPlayerSlotItem(cid, CONST_SLOT_HEAD)
local armor = getPlayerSlotItem(cid, CONST_SLOT_ARMOR)
local legs = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
local boots = getPlayerSlotItem(cid, CONST_SLOT_FEET)
local rightHand = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
local leftHand = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
local strength = getPlayerStorageValue(cid, attr.str)
local agility = getPlayerStorageValue(cid, attr.agi)
local energy = getPlayerStorageValue(cid, attr.ene)
local health = getPlayerStorageValue(cid, attr.hth)
    for voc2, info2 in pairs(v) do
        if getPlayerVocation(cid) == voc2 then
            if item.itemid > 0 then
                local strength2 = getPlayerStorageValue(cid, attr.str)
                local strfrm = strength2*info2.st
                setItemExtraAttack(item.uid, 0)
            end    
            if item.itemid > 0 then
                local strength2 = getPlayerStorageValue(cid, attr.str)
                local strfrm = strength2*info2.st
                setItemExtraAttack(item.uid, 0)
            end
            local agility2 = getPlayerStorageValue(cid, attr.agi)
            local agifrm = agility2*info2.ag
            if item.itemid > 0 then
                setItemExtraDefense(item.uid, 0)
                if getItemAttackSpeed(item.uid) > 0 then
                    setItemAttackSpeed(item.uid, 0)
                end    
            end
            if item.itemid > 0 then
                setItemExtraDefense(item.uid, 0)
                if getItemAttackSpeed(item.uid) > 0 then
                    setItemAttackSpeed(item.uid, 0)
                end
            end    
        end
    end    
return true
end
XML Code:
PHP:
    <movevent type="Equip" itemid="2128-2194;2196-2322;2324-2342;2344-2465;2467-2469;2471;2473;2475;2478-2486;2489-2491;2494-2498;2501-2639;2641-2659;2661-5460;5462-6131;6133-7883;7887-7890;7904-8818;8822-8864;8873-8876;8893-9775;9779-9931" slot="right-hand" event="script" value="attributeEquip.lua"/>
    <movevent type="DeEquip" itemid="2128-2194;2196-2322;2324-2342;2344-2465;2467-2469;2471;2473;2475;2478-2486;2489-2491;2494-2498;2501-2639;2641-2659;2661-5460;5462-6131;6133-7883;7887-7890;7904-8818;8822-8864;8873-8876;8893-9775;9779-9931" slot="right-hand" event="script" value="attributeEquip.lua"/>
    <movevent type="Equip" itemid="2128-2194;2196-2322;2324-2342;2344-2465;2467-2469;2471;2473;2475;2478-2486;2489-2491;2494-2498;2501-2639;2641-2659;2661-5460;5462-6131;6133-7883;7887-7890;7904-8818;8822-8864;8873-8876;8893-9775;9779-9931" slot="left-hand" event="script" value="attributeEquip.lua"/>
    <movevent type="DeEquip" itemid="2128-2194;2196-2322;2324-2342;2344-2465;2467-2469;2471;2473;2475;2478-2486;2489-2491;2494-2498;2501-2639;2641-2659;2661-5460;5462-6131;6133-7883;7887-7890;7904-8818;8822-8864;8873-8876;8893-9775;9779-9931" slot="left-hand" event="script" value="attributeEquip.lua"/>
XML Location: data/movements/movements.xml
Description:
This script will set the extra damage and defense when you equip a weapon and/or shield.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Also to all the CreatureEvents, you need to register this in login.lua, located in 'data/creaturescripts/scripts/login.lua'
and add this in it:
Lua:
    registerCreatureEvent(cid, "AttributeLogin")
    registerCreatureEvent(cid, "AttributeAdvance")
and you will be set.

Well I hope you enjoy this and it helps you make a Fully Custom server.
Please leave comments and post any bug if any!
Tested on TFS 0.3.5 Crying Damson
 
Last edited:
It seems to be cool, but when you level up, you have to add points as you want? Or it is defined?

Maybe some screens and a little introduction to show how it works.
 
And so again you've made something really creative. Let's see if I can configure it to my needs. Anyway, great job.
 
@kito2
when you level up it gives you points according to your vocation.
Example:
if you are a:
Rookie you get 1 Attribute Point
First vocation(from Sorcerer to Knight) you get 5 points.
Second vocation(from Master Sorcerer to Elite Knight) you get 7 points.
(this can be configured to your liking.)

then you may distribute those points between:
Strength
Agility
Health
Energy(Mana)
Magic Level

@Whiskey
Yea I was raking my head a little on this one, but it turned out OK for a
basic script.
 
Ye but its bugged u can got weapon and shield in hands.
u can only choose one.
 
No! it will give extra attack and extra def to weapon and give extra def to shield, also if it gives you any errors post it! And this was tested on TFS 0.3.5 so anything higher might bug in some parts of the script.
 
ye i'm useing tfs 0.3.6pl1 and when i got a wand in hand cant put shield to second
when i want to travel witch gold in backpack and empty hands server crash.
 
I'll have to look at that and see what happens on my server when I equip a
wand, after I do the testing I'll let you know ASAP.
 
Maybe you should change the talkaction into an NPC. It would make it more realistic.
 
@ Collz
Yeah it would! Like the idea! :D
:( but right now I'm tied to some other scripts that we are working with,
anyone is free to make a NPC for it or wait a while for us to make it.
 
Here is an error on TFS 0.3.6

[10/07/2010 00:26:49] [Error - TalkAction Interface]
[10/07/2010 00:26:49] data/talkactions/scripts/attributes.lua:eek:nSay
[10/07/2010 00:26:49] Description:
[10/07/2010 00:26:49] data/talkactions/scripts/attributes.lua:43: attempt to call global 'setItemExtraAttack' (a nil value)
[10/07/2010 00:26:49] stack traceback:
[10/07/2010 00:26:49] data/talkactions/scripts/attributes.lua:43: in function <data/talkactions/scripts/attributes.lua:19>
 
you have to change all setItem[whatever] to (if I'm not mistaking)
doSetItemAttribute(cid, "", value) "" put extraattack, value the amount.
 
Back
Top Bottom