Rooteh
New Member
- Joined
- Jul 24, 2008
- Messages
- 95
- Reaction score
- 0
What will these scripts do?
They will allow your players to increase their mana / hitpoints using attribute points which are gained when they level.
This script was made for TFS 0.3.4PL2
What to do?
Create file attribute.xml file in data/npc
Create file attribute.lua in data/npc/scripts
You must edit the red text to fit your server. My examples are given.
Open data/creaturescripts/scripts/login.lua
Above
add
Open data/creaturescripts/creaturescripts.xml
Above
add
Create file attribute_points.lua in data/creaturescripts/scripts
Then you are done..
The attribute points will be stored in playerstoragevalue 47061.
Rep me if you enjoyed it.
They will allow your players to increase their mana / hitpoints using attribute points which are gained when they level.
This script was made for TFS 0.3.4PL2
What to do?
Create file attribute.xml file in data/npc
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Rootehs Attributes" script="data/npc/scripts/attribute.lua" walkinterval="2000" floorchange="0">
<health now="150" max="150"/>
<look type="131" head="95" body="95" legs="95" feet="95" corpse="6080"/>
<parameters>
<parameter key="module_shop" value="1"/>
</parameters>
</npc>
Create file attribute.lua in data/npc/scripts
Code:
--Made By Rooteh--
local focuses = {}
local function isFocused(cid)
for i, v in pairs(focuses) do
if(v == cid) then
return true
end
end
return false
end
local function addFocus(cid)
if(not isFocused(cid)) then
table.insert(focuses, cid)
end
end
local function removeFocus(cid)
for i, v in pairs(focuses) do
if(v == cid) then
table.remove(focuses, i)
break
end
end
end
local function lookAtFocus()
for i, v in pairs(focuses) do
if(isPlayer(v) == TRUE) then
doNpcSetCreatureFocus(v)
return
end
end
doNpcSetCreatureFocus(0)
end
local function doPlayerAddAttributePoint(cid, amount)
-- Function made by Rooteh
-- doPlayerAddAttributePoint(cid, amount)
local storagevalue = 47061
local current = getPlayerStorageValue(cid, storagevalue)
local new = (current+amount)
setPlayerStorageValue(cid, storagevalue, new)
return LUA_NO_ERROR
end
local function doPlayerCheckAttributePoint(cid)
-- Function made by Rooteh
-- doPlayerCheckAttributePoint(cid)
local storagevalue = 47061
local amt = getPlayerStorageValue(cid, storagevalue)
return amt
end
function onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
removeFocus(cid)
if(isPlayer(cid) == TRUE) then --Be sure he's online
closeShopWindow(cid)
end
end
end
function onCreatureSay(cid, type, msg)
local Vitality =
{ [COLOR="Red"][1] = {name = 'Amazon', cost = 1, amount = 3},[/COLOR] ---[1] = Vocation, Name = Vocation Name, Cost = Amount of Attribute Points Needed, Amount = MaxHp Added
[COLOR="Red"][2] = {name = 'Assassin', cost = 1, amount = 3},
[3] = {name = 'Necromancer', cost = 1, amount = 2},
[4] = {name = 'Barbarian', cost = 1, amount = 4},
[5] = {name = 'Fire Sorcerer', cost = 1, amount = 2},
[6] = {name = 'Ice Sorcerer', cost = 1, amount = 2},
[7] = {name = 'Energy Sorcerer', cost = 1, amount = 2},
[8] = {name = 'Druid', cost = 1, amount = 2},
[9] = {name = 'Paladin', cost = 1, amount = 3}[/COLOR]
}
local Energy =
{ [COLOR="Red"][1] = {name = 'Amazon', cost = 2, amount = 3},[/COLOR] ---[1] = Vocation, Name = Vocation Name, Cost = Amount of Attribute Points Needed, Amount = MaxMana Added
[COLOR="Red"][2] = {name = 'Assassin', cost = 4, amount = 7},
[3] = {name = 'Necromancer', cost = 1, amount = 2},
[4] = {name = 'Barbarian', cost = 1, amount = 1},
[5] = {name = 'Fire Sorcerer', cost = 1, amount = 2},
[6] = {name = 'Ice Sorcerer', cost = 1, amount = 2},
[7] = {name = 'Energy Sorcerer', cost = 1, amount = 2},
[8] = {name = 'Druid', cost = 1, amount = 2},
[9] = {name = 'Paladin', cost = 2, amount = 3}[/COLOR]
}
if((msg == "hi") and not (isFocused(cid))) then
selfSay("Welcome "..getCreatureName(cid)..", would you like to learn about {Attribute Points}? You currently have "..doPlayerCheckAttributePoint(cid).." attribute points.", cid)
addFocus(cid)
talk_state = 1
elseif((isFocused(cid)) and (msg == "attribute" or msg == "points" or msg == "help" or msg == "job" or msg == "attribute point" or msg == "attribute points")) and talk_state == 1 then
selfSay("When you gain levels, you recieve attribute points. You can spend the attribute points on {vitality} or {energy} to improve your character.", cid)
elseif((isFocused(cid)) and (msg == "energy")) and talk_state == 1 then
selfSay("As a "..(Energy[getPlayerVocation(cid)].name).." you can increase your max mana by "..(Energy[getPlayerVocation(cid)].amount)..". It will cost you "..(Energy[getPlayerVocation(cid)].cost).." attribute points.", cid)
selfSay("Do you want to spend your attribute points on energy?", cid)
talk_state = 2
elseif((isFocused(cid)) and (msg == "yes" or msg == "ye")) and talk_state == 2 then
if doPlayerCheckAttributePoint(cid) >= Energy[getPlayerVocation(cid)].amount then
local maxmana = getCreatureMaxMana(cid)
setCreatureMaxMana(cid, (maxmana+Energy[getPlayerVocation(cid)].amount))
local mana = (getCreatureMaxMana(cid)-getCreatureMana(cid))
doCreatureAddMana(cid, mana)
doPlayerAddAttributePoint(cid, -(Energy[getPlayerVocation(cid)].cost))
selfSay("Your max mana has increased by "..(Energy[getPlayerVocation(cid)].amount).."!", cid)
selfSay("Goodbye, come back and see me soon!", cid)
talk_state = 0
removeFocus(cid)
else
selfSay("You do not have enough attribute points!", cid)
selfSay("Come back after you level.", cid)
talk_state = 0
removeFocus(cid)
end
elseif((isFocused(cid)) and (msg == "vitality")) and talk_state == 1 then
selfSay("As a "..(Vitality[getPlayerVocation(cid)].name).." you can increase your max health by "..(Vitality[getPlayerVocation(cid)].amount)..". It will cost you "..(Vitality[getPlayerVocation(cid)].cost).." attribute points.", cid)
selfSay("Do you want to spend your attribute points on vitality?", cid)
talk_state = 3
elseif((isFocused(cid)) and (msg == "yes" or msg == "ye")) and talk_state == 3 then
if doPlayerCheckAttributePoint(cid) >= Vitality[getPlayerVocation(cid)].cost then
local maxhp = getCreatureMaxHealth(cid)
setCreatureMaxHealth(cid, (maxhp+Vitality[getPlayerVocation(cid)].amount))
local health = (getCreatureMaxHealth(cid)-getCreatureHealth(cid))
doCreatureAddHealth(cid, health)
doPlayerAddAttributePoint(cid, -(Vitality[getPlayerVocation(cid)].cost))
selfSay("Your max health has increased by "..(Vitality[getPlayerVocation(cid)].amount).."!", cid)
selfSay("Goodbye, come back and see me soon!", cid)
talk_state = 0
removeFocus(cid)
else
selfSay("You do not have enough attribute points!", cid)
selfSay("Come back after you level.", cid)
talk_state = 0
removeFocus(cid)
end
elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
selfSay("cya!", cid, TRUE)
closeShopWindow(cid)
removeFocus(cid)
end
end
function onPlayerCloseChannel(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
closeShopWindow(cid)
removeFocus(cid)
end
end
function onPlayerEndTrade(cid)
selfSay("It was a pleasure doing business with you.", cid)
end
function onThink()
for i, focus in pairs(focuses) do
if(isCreature(focus) == FALSE) then
removeFocus(focus)
else
local distance = getDistanceTo(focus) or -1
if((distance > 4) or (distance == -1)) then
selfSay("Hmph!")
closeShopWindow(focus)
removeFocus(focus)
end
end
end
lookAtFocus()
end
You must edit the red text to fit your server. My examples are given.
Open data/creaturescripts/scripts/login.lua
Above
Code:
return TRUE
Code:
registerCreatureEvent(cid, "AttributePoints")
if getPlayerStorageValue(cid, 47061) < 0 then
setPlayerStorageValue(cid,47061,0)
end
Open data/creaturescripts/creaturescripts.xml
Above
Code:
</creaturescripts>
Code:
<event type="advance" name="AttributePoints" event="script" value="attribute_points.lua"/>
Create file attribute_points.lua in data/creaturescripts/scripts
Code:
function onAdvance(cid, skill, oldlevel, newlevel)
if skill == 8 then
if oldlevel < newlevel then
local addmana = getPlayerMaxMana(cid)
local addhp = getCreatureMaxHealth(cid)
local addattribute = (getPlayerStorageValue(cid, 47061)+2)
doSendAnimatedText(getPlayerPosition(cid), "Level UP", 129) -- will show a hovering text of "Level Up"
doSendMagicEffect(getPlayerPosition(cid),math.random(28, 30)) -- will show the range of fireworks
doCreatureAddHealth(cid, addhp) -- will give max Hp after level up
doPlayerAddMana(cid, addmana) -- Will give Max mana after level up
setPlayerStorageValue(cid, 47061, addattribute) -- Will add 2 attribute points after level
end
end
return true
end
Then you are done..
The attribute points will be stored in playerstoragevalue 47061.
Rep me if you enjoyed it.
Last edited: