• 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 FirstItems script error

Progenosis

Member
Joined
Sep 6, 2011
Messages
131
Reaction score
18
I got this script:

Code:
local commonItems = {
  -- ITEMS ALL VOCS RECEIVE          [COLOR="Lime"]-- all vocs will recive this items[/COLOR]
  {itemid=2481, count=1},
  {itemid=2465, count=1},
  {itemid=2478, count=1},
  {itemid=2643, count=1},
  {itemid=2120, count=1},
  {itemid=2160, count=10},
  {itemid=2789, count=100},
}

local firstItems = {
  { -- SORC ITEMS           [COLOR="Blue"]--sorc items[/COLOR]
    {itemid=2190, count=1},
    {itemid=2529, count=1},
  },
  { -- DRUID ITEMS              [COLOR="Blue"]--druid items[/COLOR]
    {itemid=2182, count=1},
    {itemid=2529, count=1}, 
  },
  { -- PALADIN ITEMS    [COLOR="Blue"]--pala items[/COLOR]
    {itemid=2456, count=1},
    {itemid=2544, count=100}, 
  },
  { -- KNIGHT ITEMS      [COLOR="Blue"]--knight items[/COLOR]
    {itemid=2529, count=1},
    {itemid=8602, count=1},
    {itemid=3966, count=1},
    {itemid=8601, count=1},
  }
}

for _, items in ipairs(firstItems) do
  for _, item in ipairs(commonItems) do
    table.insert(items, item)
  end
end

function onLogin(cid)
  if getPlayerGroupId(cid) < 4 then
    local hasReceivedFirstItems = getPlayerStorageValue(cid, 6771408)

    if hasReceivedFirstItems ~= 1 then
      --[[local backpack = ]]doPlayerAddItem(cid, 1988, 1)

      local giveItems = firstItems[getPlayerVocation(cid)]

      if giveItems ~= nil then
        for _, v in ipairs(giveItems) do
          --doAddContainerItem(backpack, v.itemid, v.count or 1)
          doPlayerAddItem(cid, v.itemid, v.count or 1)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have received your first items!")
      end
      setPlayerStorageValue(cid, 67708, 1)
    end
  end
  return TRUE
end

But everytime the characters logs in, it receives the first items again. I want that the characer receives the first items once when it's newly created not everytime he logs in, what should I do?

This is the creaturescripts.xml line:

Code:
<event type="login" name="FirstItems" event="script" value="firstitems.lua"/>

Help please!
 
Code:
function onLogin(cid)
  if getPlayerGroupId(cid) < 4 then
    local hasReceivedFirstItems = getPlayerStorageValue(cid, 6771408)

    if hasReceivedFirstItems ~= 1 then
      --[[local backpack = ]]doPlayerAddItem(cid, 1988, 1)

      local giveItems = firstItems[getPlayerVocation(cid)]

      if giveItems ~= nil then
        for _, v in ipairs(giveItems) do
          --doAddContainerItem(backpack, v.itemid, v.count or 1)
          doPlayerAddItem(cid, v.itemid, v.count or 1)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have received your first items!")
      end
      setPlayerStorageValue(cid, 67708, 1)
    end
  end
  return TRUE
end

You are not checking for first login, in this script.. If you want first items to work properly it should be looking for first login, after character was created.
Not to mention, you don't need to use storage for this. Because when someone has never logged in they have the "Never logged in" status.

I prefer using this mod because its so well made.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="First Items" version="2.0" author="J.Dre" contact="[email protected]" enabled="yes">
    <config name="firstitems_config"><![CDATA[
        commonItems = {
            {itemid=6103, count=1, useMessage=true}, -- a book (or whatever) with a message
            {itemid=2789, count=100, inContainer = true}, -- 100 brown mushrooms
            {itemid=2160, count=20, inContainer = true}, -- 10 crystal coins
            {itemid=2173, count=1}, -- Aol
            {itemid=2195}, -- BOH
            {itemid=2270}, -- First Manarune
            {itemid=2272}, -- Super UH
            {itemid=2205}, -- life ring
        }
        firstItems = {
            { -- Sorcerer
                {itemid=1988}, -- backpack
                {itemid=2520}, -- Demon Shield
                {itemid=2190}, -- wand of vortex
                {itemid=2494}, -- Demon Armor
                {itemid=2493}, -- Demon Helmet
                {itemid=2495}, -- Demon Legs
            },
            { -- Druid
                {itemid=1988}, -- backpack
                {itemid=2520}, -- Demon Shield
                {itemid=2182}, -- snakebite rod
                {itemid=2494}, -- Demon Armor
                {itemid=2493}, -- Demon Helmet
                {itemid=2495}, -- Demon Legs
            },
            { -- Paladin
                {itemid=1988}, -- backpack
                {itemid=2520, count=1, useSlot=true, slotType=CONST_SLOT_RIGHT}, -- Demon Shield
                {itemid=2399, count=1, useSlot=true, slotType=CONST_SLOT_LAST}, --  star
                {itemid=2494}, -- Demon Armor
                {itemid=2493}, -- Demon Helmet
                {itemid=2495}, -- Demon Legs
            },
            { -- Knight
                {itemid=1988}, -- backpack
                {itemid=2520}, -- Demon Shield
                {itemid=8602}, -- jagged sword
                {itemid=8601, inContainer=true}, -- steel axe
                {itemid=2439, inContainer=true}, -- daramanian mace
                {itemid=2494}, -- Demon Armor
                {itemid=2493}, -- Demon Helmet
                {itemid=2495}, -- Demon Legs
            },
        }
    ]]></config>
    <event type="login" name="FirstItems" event="script"><![CDATA[
        domodlib('firstitems_config')

        for _, items in ipairs(firstItems) do
            for _, item in ipairs(commonItems) do
                table.insert(items, item)
            end
        end

        function onLogin(cid)
            if(getPlayerAccess(cid) < 3 and (getPlayerLastLoginSaved(cid) < 1) and firstItems[getPlayerVocation(cid)]) then
                for _, v in ipairs(firstItems[getPlayerVocation(cid)]) do
                    if isItemContainer(v.itemid) then
                        backpack = doPlayerAddItem(cid, v.itemid, 1, false)
                    elseif v.inContainer then
                        doAddContainerItem(backpack, v.itemid, v.count or 1)
                    elseif v.useSlot then
                        doPlayerAddItem(cid, v.itemid, v.count, false, v.slotType)
                    elseif v.useMessage then
                        local t, k = {
                            writer = "CHANGE ME", date = os.time(),
                            text = "Welcome.\n\nOur community would like to welcome you to " .. getConfigValue('serverName') .. ". If you need help with anything, please refer to the help channel.\n\nEnjoy your time!"
                        }, doPlayerAddItem(cid, v.itemid, v.count or 1, false)
                        doSetItemText(k, t.text, t.writer, t.date)
                    else
                        doPlayerAddItem(cid, v.itemid, v.count or 1)
                    end
                end
            end

            return true
        end
    ]]></event>
</mod>

Remember to change the item ids :p

Also remember to post in Support next time :)
 
Last edited:
Back
Top