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

Action script not working

klekSu

Stroke my ego.
Joined
Nov 4, 2008
Messages
1,285
Reaction score
18
Hi there I've got a problem. The script stops at function for, what's wrong with it?

Lua:
local items = {
[40001] = {2166, 1, 6527, 200},
[40002] = {5785, 1, 6527, 1000},
[40003] = {2217, 1, 6527, 6000}
}

function onUse(cid, item, frompos, item2, topos)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "1")
for i=1, #items do
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "2")
    if(item.actionid == items[i]) and (item.itemid == 1512) then
        if(getPlayerItemCount(cid, items[i][3]) <= items[i][4]) then
            doPlayerAddItem(cid,items[i][1],items[i][2])
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Here you are.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You don\'t have enough tokens.")
        return TRUE
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Wrong aid.")
    end
end
return TRUE
end
doPlayerSendTextMessage 1 and 2 are for checking where does the script stops, and it displays only "1" so something must be wrong with function for, but what?
 
try this
Code:
local items = {
[40001] = {2166, 1, 6527, 200},
[40002] = {5785, 1, 6527, 1000},
[40003] = {2217, 1, 6527, 6000}
}
 
function onUse(cid, item, frompos, item2, topos)
    if(item.actionid == items[1]) and (item.itemid == 1512) then
        if(getPlayerItemCount(cid, items[1][3]) <= items[1][4]) then
            doPlayerAddItem(cid,items[1][1],items[1][2])
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Here you are.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You don\'t have enough tokens.")
        return TRUE
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Wrong aid.")
    end
return TRUE
end
 
It says "Wrong aid." but the aid is correct because it reads it.

XML:
<action fromaid="40001" toaid="40003" event="script" value="tokens/getitems.lua"/>
Lua:
local items = {
[40001] = {id = 2496, count = 1, idCount = 6527, tokens = 700},
[40002] = {id = 10569, count = 1, idCount = 6527, tokens = 700},
[40003] = {id = 2474, count = 1, idCount = 6527, tokens = 700}
}

function onUse(cid, item, frompos, item2, topos)
    if(item.actionid == items[i]) then
        if(getPlayerItemCount(cid, items[i].idCount) <= items[i].tokens) then
            doPlayerAddItem(cid, items[i].id, items[i].count)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Here you are.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You don\'t have enough tokens.")
        return TRUE
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Wrong aid.")
    end
return TRUE
end
 
Lua:
local items = {
[40001] = {id = 2496, count = 1, idCount = 6527, tokens = 700},
[40002] = {id = 10569, count = 1, idCount = 6527, tokens = 700},
[40003] = {id = 2474, count = 1, idCount = 6527, tokens = 700}
}
 
function onUse(cid, item, frompos, item2, topos)
    v = items[item.actionid]
    if v then
        if(getPlayerItemCount(cid, items[i].idCount) <= items[i].tokens) then
            doPlayerAddItem(cid, items[i].id, items[i].count)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Here you are.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You don\'t have enough tokens.")
        return TRUE
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Wrong aid.")
    end
return
 
getitem.lua:10: attempt to index field (?) a nil value
stack traceback:
getitems.lua:10: in function getitems.lua:7
 
Try
PHP:
local items = {
[40001] = {id = 2496, count = 1, idCount = 6527, tokens = 700},
[40002] = {id = 10569, count = 1, idCount = 6527, tokens = 700},
[40003] = {id = 2474, count = 1, idCount = 6527, tokens = 700}
}
 
function onUse(cid, item, frompos, item2, topos)
    v = items[item.actionid]
    if v then
        if(getPlayerItemCount(cid, v.idCount) <= v.tokens) then
            doPlayerAddItem(cid, v.id, v.count)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Here you are.")
        else
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "You don\'t have enough tokens.")
        return TRUE
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Wrong aid.")
    end
return true
end
 
Back
Top