• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved changegold index nil value tfs 1.0

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
923
Location
Chile
Hello guys, i searched in the forums before posting this but no one have the exact problem
this problem seems to be because of not defining the new coins into const.h, but i already did, this is what i have

error:
Code:
Lua Script Error: [Test Interface]
data/actions/scripts/other/changegold.lua
data/actions/scripts/other/changegold.lua:5: table index is nil
stack traceback:
        [C]: in function '__newindex'
        data/actions/scripts/other/changegold.lua:5: in main chunk
        [C]: in function 'reload'
        data/talkactions/scripts/reload.lua:75: in function <data/talkactions/scripts/reload.lua:59>
[Warning - Event::checkScript] Can not load script: scripts/other/changegold.lua


changegold.lua

LUA:
local config = {
    [ITEM_GOLD_COIN] = {changeTo = ITEM_PLATINUM_COIN},
    [ITEM_PLATINUM_COIN] = {changeBack = ITEM_GOLD_COIN, changeTo = ITEM_CRYSTAL_COIN},
    [ITEM_CRYSTAL_COIN] = {changeBack = ITEM_PLATINUM_COIN, changeTo = ITEM_BLOOD_COIN},
    [ITEM_BLOOD_COIN] = {changeBack = ITEM_CRYSTAL_COIN, changeTo = ITEM_ULTIMATE_COIN},
    [ITEM_ULTIMATE_COIN] = {changeBack = ITEM_BLOOD_COIN}
}

function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    local coin = config[item.itemid]
    if not coin then
        return false
    end

    if coin.changeTo and item.type == 100 then
        item:remove()
        player:addItem(coin.changeTo, 1)
    elseif coin.changeBack then
        item:transform(item.itemid, item.type - 1)
        player:addItem(coin.changeBack, 100)
    else
        return false
    end
    return true
end


and const.h
Code:
ITEM_GOLD_COIN = 2148,
    ITEM_PLATINUM_COIN = 2152,
    ITEM_CRYSTAL_COIN = 2160,
    ITEM_BLOOD_COIN = 28797,
    ITEM_ULTIMATE_COIN = 28838,

plz help guys, i don't know what to do :/
 
Solution
you need to use registerEnum(ITEM_ULTIMATE_COIN) and the same for blood coin in luascript.cpp so it's available to use in the lua environment
ctrl+f and put it under where registerEnum(ITEM_CRYSTAL_COIN) is
you need to use registerEnum(ITEM_ULTIMATE_COIN) and the same for blood coin in luascript.cpp so it's available to use in the lua environment
ctrl+f and put it under where registerEnum(ITEM_CRYSTAL_COIN) is
 
Solution
LUA:
function onUse(cid, item, frompos, item2, topos)
   if item.itemid == 2148 and item.type == 100 then
   doRemoveItem(item.uid,item.type)
   doPlayerAddItem(cid,2152,1)
   doPlayerSendTextMessage(cid,22,"You have changed 100 gp to 1 platnium coin")
   elseif item.itemid == 2148 and item.type < 100 then
   doPlayerSendTextMessage(cid,22,"You have to have 100 gp's to change for platinum coin")
   end
  end

Code:
<action itemid="2148" event="script" value="other/changegold.lua"/>
I dont know tfs 1.0 but this one works on 0.3.5
@Thorn
 
you need to use registerEnum(ITEM_ULTIMATE_COIN) and the same for blood coin in luascript.cpp so it's available to use in the lua environment
ctrl+f and put it under where registerEnum(ITEM_CRYSTAL_COIN) is
it worked thanks! now the money tramsforms great, but is there something missing? because check this
903df5f3b02a41dcdc242e17bcf5b8de.png

100 crystal is 1 red coin, 100 red coins is one green/blue coin, so i clearly have the money to buy those items but they are unavailable for lack of money :/
 
Back
Top