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

Lua First Items

Wezza

lua nOOb
Joined
May 31, 2008
Messages
2,278
Reaction score
31
The script shows no errors at the console, however it adds no items to the player.
Its a bit custom, let me explain how it is supposed to work.

On player first login, he is unable to move and supposed to receive his first items, server sends him a "not possible msg", the server automatically
pop up a message regarding info about the OT. Now the server push the new player 1 SQM to North, then another 1 SQM to North automatically, and pop-up a new Message which explains further more about the OT itself.


so now what is working?
Everything, except for the Items, the new player receives nothing.

Code:
local function secondMovePlayer(q)
local cid = q.cid
    if isPlayer(cid) == TRUE then
        doMoveCreature(cid, NORTH)
        doCreatureSetNoMove(cid, FALSE)
        doShowTextDialog(cid, 8931, "xxx")
    end
end

local function moveNewPlayer(p)
local cid = p.cid
    if isPlayer(cid) == TRUE then
        doMoveCreature(cid, NORTH)
        addEvent(secondMovePlayer, 900, {cid = cid})
    end
end

function onLogin(cid)
    if getPlayerGroupId(cid) < 2 then
        local hasReceivedFirstItems = getPlayerStorageValue(cid, 908081)
       
        if hasReceivedFirstItems ~= 1 then
           
            if not comparePos(getPlayerPosition(cid), {x=831,y=702,z=7}) then
                doTeleportThing(cid, {x=831,y=702,z=7}, false)
            end
       
            setPlayerStorageValue(cid, _STORAGES.CHARGES.manapotion, 100)
            setPlayerStorageValue(cid, _STORAGES.CHARGES.reflection, 3)
            setPlayerStorageValue(cid, _STORAGES.CHARGES.namescroll, 0)
            setPlayerStorageValue(cid, _STORAGES.CHARGES.deathavenger, 0)
            setPlayerStorageValue(cid, 908081, 1)
           
           
--[[    local giveItems = firstItems[getPlayerVocation(cid)]
           
        if giveItems ~= nil then
                for _, v in ipairs(giveItems) do
                    if getPlayerItemCount(cid, v.itemid) >= v.count then
                        break
                    doPlayerAddItem(cid, v.itemid, v.count)
                end
               
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received your first items depending on your vocation.")
            end
           
            for _, v in ipairs(commonItems) do
                if getPlayerItemCount(cid, v.itemid) >= v.count then
                    break
                doPlayerAddItem(cid, v.itemid, v.count)
            end
]]           
           
            doShowTextDialog(cid, 2110, "xxx")
            doCreatureSetNoMove(cid, TRUE)
            addEvent(moveNewPlayer, 10100, {cid = cid})
           
        elseif getCreatureNoMove(cid) == TRUE then
            doCreatureSetNoMove(cid, FALSE)
        end
    end
    return true
end
 
I did remove the quote before, the whole script stopped working, about the firstItems and commonItems, I didn't do this yet, any further info regarding this specific thing?
 
You can replace that part for the part of the script I made for someone in that link.
Code:
  local x = vocitems[getPlayerVocation(cid)]
       if x then
           for e = 1, #x.eq do
               doPlayerAddItem(cid, x.eq[e].id, x.eq[e].count)
           end
           local bag = doPlayerAddItem(cid, 2000, 1)
           for c = 1, #x.container do
               doAddContainerItem(bag, x.container[c].id, x.container[c].count)
           end
       end
   end

Then add that table.
Code:
local vocitems = {
   [1] = { -- sorcerer
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2190, count = 1},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   },
   [2] = { -- druid
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2182, count = 1},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   },
   [3] = { -- paladin
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2389, count = 5},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   },
   [4] = { -- knight
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2409, count = 1},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   }
}
 
I added that, not working; makes me unable to login into the server, however it shows the MSG but on the clients background and not the OT.
 
in lib folder, constant.lua , have a look;

Code:
commonItems = {
    -- ITEMS ALL VOC RECEIVE
    {itemid=2461, count=1}, -- leather helmet
    {itemid=2467, count=1}, -- leather armor
    {itemid=2512, count=1}, -- wooden shield
    {itemid=2649, count=1}, -- leather legs
    {itemid=2643, count=1}, -- leather boots
    {itemid=2152, count=30}, -- 30pc
    {itemid=2120, count=1}, -- rope
    {itemid=2168, count=1},-- life ring
    {itemid=2554, count=1}, --shovel
    {itemid=2265, count=100}, --ih rune
    {itemid=7620, count=1}, --mana pot
    {itemid=2789, count=40} --food
}

firstItems = {
    { -- MAGE ITEMS
        {itemid=1988, count=1}, -- backpack
        {itemid=2190, count=1}, -- wand
        {itemid=2287, count=50} --lmm
    },
    { -- PALADIN ITEMS
        {itemid=1988, count=1}, -- backpack
        {itemid=2456, count=1}, --bow
        {itemid=2544, count=1} --1 arrow
    },
    { -- WARRIOR ITEMS
        {itemid=1988, count=1}, -- backpack   
        {itemid=2376, count=1}, -- sword
        {itemid=2398, count=1}, -- mace
        {itemid=2388, count=1} -- hatchet   
    }


Here are the common and first items, how do I link it with the firstitems.lua
 
You can just use what I posted, alot of things are wrong in the itemsadd part you have.
If you use what I posted, it will be the same thing but then correct.
 
Okay look; I added it after the quote

Code:
--[[    local giveItems = firstItems[getPlayerVocation(cid)]
          
        if giveItems ~= nil then
                for _, v in ipairs(giveItems) do
                    if getPlayerItemCount(cid, v.itemid) >= v.count then
                        break
                    doPlayerAddItem(cid, v.itemid, v.count)
                end
              
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received your first items depending on your vocation.")
            end
          
            for _, v in ipairs(commonItems) do
                if getPlayerItemCount(cid, v.itemid) >= v.count then
                    break
                doPlayerAddItem(cid, v.itemid, v.count)
            end
]]          

local x = vocitems[getPlayerVocation(cid)]
       if x then
           for e = 1, #x.eq do
               doPlayerAddItem(cid, x.eq[e].id, x.eq[e].count)
           end
           local bag = doPlayerAddItem(cid, 2000, 1)
           for c = 1, #x.container do
               doAddContainerItem(bag, x.container[c].id, x.container[c].count)
           end
       end
   end
 
   local vocitems = {
   [1] = { -- sorcerer
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2190, count = 1},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   },
   [2] = { -- druid
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2182, count = 1},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   },
   [3] = { -- paladin
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2389, count = 5},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   },
   [4] = { -- knight
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2409, count = 1},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   }
}

I pasted it under the quote..

no error in console but, player keeps logging in and out
Code:
[03/07/2014 20:19:43] Rxzor has logged in.
[03/07/2014 20:19:43] Rxzor has logged out.
[03/07/2014 20:19:44] Sdasdas has logged in.
[03/07/2014 20:19:44] Sdasdas has logged out.
[03/07/2014 20:25:55] Sdasdas has logged in.
[03/07/2014 20:25:55] Sdasdas has logged out.
[03/07/2014 20:25:57] Sdasdas has logged in.
 
The table has to be at the top of the script (outside the function or above where it's used).
It can't be under where it's used, it reads the script from the top to the bottom, if you add it under it in the function, it won't find the table before it finds the rest, so then it's nil.

If you have problems with scripts, always post the errors.
 
error code;

Code:
[03/07/2014 20:42:45] data/creaturescripts/scripts/firstitems.lua:77: attempt to index global 'q' (a nil value)
[03/07/2014 20:42:45] [Warning - Event::loadScript] Cannot load script (data/creaturescripts/scripts/firstitems.lua)


.lua;

Code:
local cid = q.cid
    if isPlayer(cid) == TRUE then
        doMoveCreature(cid, NORTH)
        doCreatureSetNoMove(cid, FALSE)
        doShowTextDialog(cid, 8931, "xxxxxxxxxxx")
    end
 
Code:
local function secondMovePlayer(q)
local vocitems = {
   [1] = { -- sorcerer
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2190, count = 1},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   },
   [2] = { -- druid
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2182, count = 1},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   },
   [3] = { -- paladin
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2389, count = 5},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   },
   [4] = { -- knight
     container = {
       {id = 2120, count = 1},
       {id = 2554, count = 1},
       {id = 2674, count = 1}
     },
     eq = {
       {id = 2525, count = 1},
       {id = 2409, count = 1},
       {id = 2457, count = 1},
       {id = 2463, count = 1},
       {id = 2647, count = 1},
       {id = 2643, count = 1}
     }
   }
}
local x = vocitems[getPlayerVocation(cid)]
       if x then
           for e = 1, #x.eq do
               doPlayerAddItem(cid, x.eq[e].id, x.eq[e].count)
           end
           local bag = doPlayerAddItem(cid, 2000, 1)
           for c = 1, #x.container do
               doAddContainerItem(bag, x.container[c].id, x.container[c].count)
           end
       end
   end
  

local cid = q.cid
    if isPlayer(cid) == TRUE then
        doMoveCreature(cid, NORTH)
        doCreatureSetNoMove(cid, FALSE)
        doShowTextDialog(cid, 8931, "Here you will find 3 hunting grounds made for beginners!\n\nIf you walk north, you will find a Rune-Seller and a Loot-Buyer. 2 depots are also located north.\n\nNow go and enjoy your time on Grand-Ot")
    end



local function moveNewPlayer(p)
local cid = p.cid
    if isPlayer(cid) == TRUE then
        doMoveCreature(cid, NORTH)
        addEvent(secondMovePlayer, 900, {cid = cid})
    end
end

function onLogin(cid)
    if getPlayerGroupId(cid) < 2 then
        local hasReceivedFirstItems = getPlayerStorageValue(cid, 908081)
        end
       
        if hasReceivedFirstItems ~= 1 then
           
            if not comparePos(getPlayerPosition(cid), {x=831,y=702,z=7}) then
                doTeleportThing(cid, {x=831,y=702,z=7}, false)
            end
       
            setPlayerStorageValue(cid, _STORAGES.CHARGES.manapotion, 100)
            setPlayerStorageValue(cid, _STORAGES.CHARGES.reflection, 3)
            setPlayerStorageValue(cid, _STORAGES.CHARGES.namescroll, 0)
            setPlayerStorageValue(cid, _STORAGES.CHARGES.deathavenger, 0)
            setPlayerStorageValue(cid, 908081, 1)
           
           
--[[    local giveItems = firstItems[getPlayerVocation(cid)]
           
        if giveItems ~= nil then
                for _, v in ipairs(giveItems) do
                    if getPlayerItemCount(cid, v.itemid) >= v.count then
                        break
                    doPlayerAddItem(cid, v.itemid, v.count)
                end
               
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received your first items depending on your vocation.")
            end
           
            for _, v in ipairs(commonItems) do
                if getPlayerItemCount(cid, v.itemid) >= v.count then
                    break
                doPlayerAddItem(cid, v.itemid, v.count)
            end
]]           




           
            doShowTextDialog(cid, 2110, "Welcome to Grand-Ot.\n\nYou have received your first items!\n\nWe have a special room only for new players! You will automatically be moved to this room so you can start your journey at Grand-Ot")
            doCreatureSetNoMove(cid, TRUE)
            addEvent(moveNewPlayer, 10100, {cid = cid})
           
        elseif getCreatureNoMove(cid) == TRUE then
            doCreatureSetNoMove(cid, FALSE)
        end
    end
    return true
 
You closed function secondMovePlayer above local cid = q.cid, so now q isn't a parameter of that fuction anymore what makes it nil.
Add the items part instead of the part you quoted, so inside function onLogin and add the table at the top (outside any function).
The table doesn't have any of the functions parameter so it can just be added outside any function.
 
Back
Top