• 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!

Lua TFS 1.x - player:getStorageValue not working with this script?

Extrodus

|| Blazera.net ||
Joined
Dec 22, 2008
Messages
2,750
Solutions
7
Reaction score
552
Location
Canada
So I'm trying to create a script that checks if the player has all the storages from Act I in order to start Act II but currently, all it does is tell me I have already started Act II even though I don't have the storages.

Here's the code, I'm sure I have a small error somewhere.

Code:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
   local player = Player(cid)
     if not Player(player) then
  return false
  end
  if item:getActionId(6001) and player:getStorageValue(37113) and player:getStorageValue(37114) and player:getStorageValue(37115) and player:getStorageValue(37116) and player:getStorageValue(37117) and player:getStorageValue(37118) then
       player:sendTextMessage(MESSAGE_INFO_DESCR, "You have unlocked the Temporal Shrine of [Act II]!")
       player:setStorageValue(37121, 1)
       player:setStorageValue(37122, 1)
     else
       player:sendTextMessage(MESSAGE_INFO_DESCR, "You need to activate all the shrines of [Act I] before continuing!")
       return false
     end
   if item:getActionId(6001) and player:getStorageValue(37121,1) then
     player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already started [Act II]! Say !travel to continue.")
     return true
   end
  return true
end

Thanks in advance!
 
Last edited:
Also you can't do a check in the getStorageValue function (last if statment).
The correct way is to compare it to an integer ex.
Code:
player:getStorageValue(37121) == 1
 
On TFS 1.2, (maybe 1.1 too?) you should remove lines:
Code:
local player = Player(cid)
if not Player(player) then
return false
end

And change function declaration to:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
 
Thanks a ton guys! The fix was clarifying the storages like @WibbenZ suggested, also thanks @hellboy for the tip on change the onUse function; cleans the script up :) Rep++

Here's what it looks like now thanks to your help, and also if anyone needs a script like this for other purposes ;D Little bit cleaner now, and re-organized to work properly.

Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
     if item:getActionId(6001) and player:getStorageValue(37121) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have already started [Act II]! Say !travel to continue.")
     elseif player:getStorageValue(37113) == 1 and player:getStorageValue(37114) == 1 and player:getStorageValue(37115) == 1 and player:getStorageValue(37116) == 1 and player:getStorageValue(37117) == 1 and player:getStorageValue(37118) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have unlocked the Temporal Shrine of [Act II]!")
        player:setStorageValue(37121, 1)
        player:setStorageValue(37122, 1)
     else
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You need to activate all the shrines of [Act I] before continuing!")
     end
  return true
end
 
Last edited:

Similar threads

Back
Top