LeOnArd0
Member
- Joined
- Jan 24, 2010
- Messages
- 76
- Reaction score
- 14
Hello guys!
I need help with an revscript for TFS 1.5, @Nekiro downgrade.
The idea is to put together a script that follows this line of reasoning:
1- When logging in, check if the player has account_storage X, if not, add it but with a value of 0.
I put this:
But i receive this error:
2- After using an item x, check the account_storage (account_id, key, value) and add the value (ex: it was 0 goes to 1).
3-After that, a creaturescripts checks if the player has account_storage with value 1 and adds 1 of melee skill to all characters of the account if he is a knight, 1 of ml if he is a druid/sorcerer, 1 of distance if he is a paladin, considering this table:
Account Storage - 1000, 1 - +1 skills
Account Storage - 1000, 3 - +1 skills
Account Storage - 1000, 5 - +1 skills
Account Storage - 1000, 8 - +1 skills
Account Storage - 1000, 12 - +1 skills
Account Storage - 1000, 18 - +1 skills
Account Storage - 1000, 24 - +1 skills
Account Storage - 1000, 30 - +1 skills
Account Storage - 1000, 36 - +1 skills
Account Storage - 1000, 42 - +1 skills
Adding the skill to each storage, when he has the account storage at 42, he will have +10 skill.
I tested this script and it worked, but it adds 1 skill per player key, today it doesn't respect the table above, I would like to adapt it and consider account_storage not player storage.
I use this function in lib/core/player.lua
Somebody to give me a light?
@Xikini, if you have a little time xD
Tks
Leo
I need help with an revscript for TFS 1.5, @Nekiro downgrade.
The idea is to put together a script that follows this line of reasoning:
1- When logging in, check if the player has account_storage X, if not, add it but with a value of 0.
I put this:
Code:
if Player.getAccountStorageValue(1000) == -1 then
Player.setAccountStorageValue(1000, 0)
end
But i receive this error:
Code:
2023-04-20_16-21-25.023561 Lua Script Error: [CreatureScript Interface]
2023-04-20_16-21-25.023649 data/creaturescripts/scripts/login.lua:onLogin
2023-04-20_16-21-25.023717 data/creaturescripts/scripts/login.lua:42: attempt to call field 'getAccountStorageValue' (a nil value)
2023-04-20_16-21-25.023763 stack traceback:
2023-04-20_16-21-25.023802 [C]: in function 'getAccountStorageValue'
2023-04-20_16-21-25.023860 data/creaturescripts/scripts/login.lua:42: in function <data/creaturescripts/scripts/login.lua:1>
2- After using an item x, check the account_storage (account_id, key, value) and add the value (ex: it was 0 goes to 1).
Code:
if Player.getAccountStorageValue(1000) == 0 then
player:setStorageValue(1000, 1)
3-After that, a creaturescripts checks if the player has account_storage with value 1 and adds 1 of melee skill to all characters of the account if he is a knight, 1 of ml if he is a druid/sorcerer, 1 of distance if he is a paladin, considering this table:
Account Storage - 1000, 1 - +1 skills
Account Storage - 1000, 3 - +1 skills
Account Storage - 1000, 5 - +1 skills
Account Storage - 1000, 8 - +1 skills
Account Storage - 1000, 12 - +1 skills
Account Storage - 1000, 18 - +1 skills
Account Storage - 1000, 24 - +1 skills
Account Storage - 1000, 30 - +1 skills
Account Storage - 1000, 36 - +1 skills
Account Storage - 1000, 42 - +1 skills
Adding the skill to each storage, when he has the account storage at 42, he will have +10 skill.
I tested this script and it worked, but it adds 1 skill per player key, today it doesn't respect the table above, I would like to adapt it and consider account_storage not player storage.
Code:
function onLogin(player)
local skillpercent = player:getStorageValue(1000)
local melee = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
melee:setParameter(CONDITION_PARAM_SUBID, 1)
melee:setParameter(CONDITION_PARAM_TICKS, -1)
melee:setParameter(CONDITION_PARAM_SKILL_MELEE, skillpercent)
melee:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
local distance = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
distance:setParameter(CONDITION_PARAM_SUBID, 1)
distance:setParameter(CONDITION_PARAM_TICKS, -1)
distance:setParameter(CONDITION_PARAM_SKILL_DISTANCE, skillpercent)
distance:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
local magic = Condition(CONDITION_ATTRIBUTES, CONDITIONID_DEFAULT)
magic:setParameter(CONDITION_PARAM_SUBID, 1)
magic:setParameter(CONDITION_PARAM_TICKS, -1)
magic:setParameter(CONDITION_PARAM_STAT_MAGICPOINTS, skillpercent)
magic:setParameter(CONDITION_PARAM_BUFF_SPELL, true)
if player:getStorageValue(skillpercent) then
if player:isKnight() then
player:addCondition(melee)
elseif player:isPaladin() then
player:addCondition(distance)
elseif player:isDruid() or player:isSorcerer() then
player:addCondition(magic)
end
end
return true
end
I use this function in lib/core/player.lua
Lua:
function Player.getAccountStorageValue(self, key)
if type(key) ~= "number" then
return false
end
local query = db.storeQuery("SELECT `value` FROM `account_storage` WHERE `account_id` = ".. self:getAccountId() .." AND `key` = ".. key)
if not query then
return false
end
local value = result.getDataInt(query, "value")
result.free(query)
return value
end
function Player.setAccountStorageValue(self, key, value)
if type(key) ~= "number" then
return false
end
local query = ""
if self:getAccountStorageValue(key) then
query = ("UPDATE `account_storage` SET `value` = %d WHERE `account_id` = %d AND `key` = %d"):format(value, self:getAccountId(), key)
else
query = ("INSERT INTO `account_storage` (`account_id`, `key`, `value`) VALUES (%d, %d, %d)"):format(self:getAccountId(), key, value)
end
return db.query(query)
end
Somebody to give me a light?
@Xikini, if you have a little time xD
Tks
Leo