Shinmaru
エロルアー Scripter!
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.
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
PHP:
<talkaction words="!addStr;!addAgi;!addHealth;!addEnergy;!addML" event="script" value="attributes.lua"/>
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
PHP:
<talkaction words="!attpoints;!strength;!agility;!health;!energy;!magic" event="script" value="getattributes.lua"/>
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
PHP:
<event type="advance" name="AttributeAdvance" event="script" value="attributeAdvance.lua"/>
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
PHP:
<event type="login" name="AttributeLogin" event="script" value="attributeLogin.lua"/>
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
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"/>
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")
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
Please leave comments and post any bug if any!
Tested on TFS 0.3.5 Crying Damson
Last edited: