• 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 I can't get this script to work TFS 0.4, RME

bedlamos

New Member
Joined
Dec 11, 2018
Messages
24
Solutions
1
Reaction score
1
Location
USA
[20:12:18.359] [Error - Action Interface]
[20:12:18.359] data/actions/scripts/bag.lua:<putting space here because emote> onUse
[20:12:18.359] Description:
[20:12:18.359] data/actions/scripts/bag.lua:2: attempt to call global 'Player' (a nil value)
[20:12:18.359] stack traceback:
[20:12:18.359] data/actions/scripts/bag.lua:2: in function <data/actions/scripts/bag.lua:1>

When I right click the tree to receive the quest loot I get the error above.

In the scripts folder I have 'bag.lua' saved.

bag.lua:
Code:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)        --This is mostly used to state the script executes onUse (right-clicking an object)
local player = Player(cid)
local storage = 1500    --This is a variable, it contains the prefix 'local' so that it doesn't interfere in another script, this is a value we will set into the player once he receives the reward, as we don't them to keep receiving it after the first time
    if player:getStorageValue(storage) == -1 then    --Here we just check if the Player has the storage value we mentioned before, -1 means that the player DOESN'T have the value
        local backpack = player:addItem(1987, 1)    --This variable contains a function, 'addItem', I named it backpack just to remember i'm refering to a container. 1987 stands for the ID of the item, in this case, a bag, the 1 stands for the amount of items (Or charges if you select a rune)
        backpack:addItem(2120, 1)    --Self explanatory, adds item id 2120 (Rope) to the container 'backpack'
        backpack:addItem(2643, 1)    --Leather boots
        backpack:addItem(1950, 1):setAttribute(ITEM_ATTRIBUTE_TEXT, 'Here lies the text.')    --Here we give an item, in this case a book, containing an ATTRIBUTE, in this case, TEXT.
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have found a mysterious bag...")    --This is just a message so the player knows something happened.
        player:setStorageValue(storage, 1)    --We set the storage value to 1
    else    --What happens if the value is already assigned to that player (He already received the reward)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There's nothing of interest here.")    --Only shows this message
    end
return true
end

In the actions.xml I have:
Code:
<action uniqueid="1500" script="bag.lua"/>

And in RME I have the tree set to UID = 1500.

I can't get it to work! Please help!
 
[8.60] The Forgotten Server 1.2

That is a good start, I'm pretty sure thats the best TFS 1.2 downgraded to 8.60.

Edit:
Just to point out:

onUse functions in 1.x+ already pass the first argument as the player itself and not his ID so you don't need to instantiate it.

You can change it from:
Lua:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)        --This is mostly used to state the script executes onUse (right-clicking an object)
local player = Player(cid)

To:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)        --This is mostly used to state the script executes onUse (right-clicking an object)

As you can see I just changed the first arguments name of the function from cid to player, the name here is not what matters, its just to clearify that we already have a player object and not it's ID. Also removed the declaration of the local variable player as its already being passed as an argument.
It's a small change but its something I'd consider changing on my scripts when I had time, since you are starting right now, its good to know.
 
Last edited:
Back
Top