MikeOT
Well-Known Member
- Joined
- Jan 22, 2017
- Messages
- 232
- Solutions
- 2
- Reaction score
- 86
Ok, so I'm trying to make a woodcutting script work. I had this fixed before, and was so kindly helped by a few members here. That was a year ago, and I haven't touched it since.
I'm now working with a different distro (still tfs 1.2, but a new project). I tried moving these scripts to the new distro, and I can't get it to work for the life of me... and I have no idea why it is giving me a nil value error.
So here is what I've got:
I created a file called "woodcutting" in my actions scripts folder.
I then registered the woodcutting axe in actions.xml
I then created an exp table in my data/lib folder:
and in lib.lua, added:
and in global.lua, added:
I feel like this should work. When I use the axe on the tree, nothing happens ingame, and my console tells me that it is attempting to index a nil value with my exp table.
Why is this nil? I thought that by doing this:
That it would eliminate this problem.
Apparently not.
Thank you.
I'm now working with a different distro (still tfs 1.2, but a new project). I tried moving these scripts to the new distro, and I can't get it to work for the life of me... and I have no idea why it is giving me a nil value error.
So here is what I've got:
I created a file called "woodcutting" in my actions scripts folder.
Code:
--Locals that can be set before the action is done should be outside the function itself. This way the code doesnt have to redefine them everytime it runs--
local exhaust = Condition(CONDITION_EXHAUST_WEAPON)
exhaust:setParameter(CONDITION_PARAM_TICKS, (2000))
local logsIds = {3083}
local STORAGE_SKILL_LEVEL = 20020
local STORAGE_SKILL_TRY = 20021
function onUse(cid, item, fromPosition, itemEx, toPosition)
--These locals require the script to be ran so they are here.--
local player = Player(cid)
local target = Item(itemEx.uid)
--Its always good to make sure locals we set are read--
if not target then return false end
--Check if the itemid is in the logIds table first so the script wont read much before stopping here (optimization)--
if not isInArray(logsIds, itemEx.itemid) then return false end
--Check exhaust right away so the code doesn't read much if the player is exhausted (optimization)--
if player:getCondition(CONDITION_EXHAUST_WEAPON) then
return player:sendTextMessage(MESSAGE_STATUS_SMALL, Game.getReturnMessage(RETURNVALUE_YOUAREEXHAUSTED))
end
--This will make sure the players storage value is correct so we can read it in the experience table--
if player:getStorageValue(STORAGE_SKILL_LEVEL) == nil then
player:setStorageValue(STORAGE_SKILL_LEVEL, 1)
player:setStorageValue(STORAGE_SKILL_TRY, 0)
end
local skillLevel = player:getStorageValue(STORAGE_SKILL_LEVEL)
local skillTry = player:getStorageValue(STORAGE_SKILL_TRY)
local quant = configs.experience[skillLevel][1] --------(This is the line that is throwing the nil error)
if not quant then return false end
player:addCondition(exhaust)
player:addItem(3141,1)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE,"You cut some logs.")
toPosition:sendMagicEffect(CONST_ME_BLOCKHIT)
target:remove(1)
player:say("+25 Woodcutting Exp", TALKTYPE_MONSTER_SAY)
player:sendTextMessage(MESSAGE_EXPERIENCE,"You received 25 Woodcutting exp by cutting Logs.")
if itemEx.itemid == 3083 then
Game.createItem(3084, 1, toPosition):decay()
end
if skillLevel >= 1 and skillLevel <= 10 and skillTry >= (quant-25) then
setPlayerStorageValue(cid,STORAGE_SKILL_TRY,skillTry + 25)
setPlayerStorageValue(cid,STORAGE_SKILL_LEVEL,skillLevel + 1)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have advanced from Woodcutting Level ".. skillLevel .." to Woodcutting Level ".. skillLevel + 1 .."")
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_YELLOW)
else
setPlayerStorageValue(cid,STORAGE_SKILL_TRY,skillTry + 25)
end
return true
end
I then registered the woodcutting axe in actions.xml
I then created an exp table in my data/lib folder:
Code:
rateskill = 1
expmax = 13034431
configs = {
experience ={
{83},
{174},
{276},
{388},
{512},
{650},
{801},
{969},
{1154},
{1358}
}
}
and in lib.lua, added:
Code:
dofile('data/lib/experience.lua')
and in global.lua, added:
Code:
dofile('data/lib/experience.lua')
I feel like this should work. When I use the axe on the tree, nothing happens ingame, and my console tells me that it is attempting to index a nil value with my exp table.
Why is this nil? I thought that by doing this:
Code:
if player:getStorageValue(STORAGE_SKILL_LEVEL) == nil then
player:setStorageValue(STORAGE_SKILL_LEVEL, 1)
player:setStorageValue(STORAGE_SKILL_TRY, 0)
end
That it would eliminate this problem.
Apparently not.
Thank you.