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

Solved Pull lever, get items by voc. Help needed!

RobinFFS

New Member
Joined
Mar 8, 2010
Messages
4
Reaction score
0
Location
Sweden
Hello
I'm new to lua and I could really need some help here.

This is how I want it to work.
New players pull a lever and get items for his vocation.
All vocations pull the same lever, but different rewards.

This is what I accomplished so far;
Code:
function onUse( cid, item, fromPosition, itemEx, toPosition)
  
    if isSorcerer(cid) then
        doPlayerAddItem(cid, 3557, 1)

    elseif isDruid(cid) then
        doPlayerAddItem(cid, 3557, 1)

    elseif isPaladin(cid) then
        doPlayerAddItem(cid, 3557, 1)

    elseif isKnight(cid) then
        doPlayerAddItem(cid, 3557, 1)
    end
end

Is there any better method for doing this?
Can I send multiple itemIDs with "doPlayerAddItem"?
Also, I have no idea how to bind this script to the correct lever ingame...
Should I use a action ID on my lever?

Thanks in advance.
 
if this is for starting items, i recommend using a loginscript to give first items if it is the first login. i can give you a full script for this that I used on my old server.

if you really want to click on a lever, you can just use this code in a action script.

Code:
commonItems = {
    -- ITEMS ALL VOC RECEIVE
    {itemid=2461, count=1}, -- leather helmet
    {itemid=2467, count=1}, -- leather armor
    {itemid=2649, count=1}, -- leather legs
    {itemid=2643, count=1}, -- leather boots
    {itemid=2160, count=1}, -- 1cc
    {itemid=2120, count=1}, -- rope
    {itemid=2168, count=1},-- life ring
    {itemid=2554, count=1}, --shovel
    {itemid=2265, count=100}, --ih rune
    {itemid=2789, count=40} --food
}

firstItems = {
    { -- DRUID ITEMS
        {itemid=2190, count=1}, -- wand
        {itemid=2287, count=50} --lmm
    },
    { -- SORC ITEMS
        {itemid=2190, count=1}, -- wand
        {itemid=2287, count=50} --lmm
    },
    { -- PALADIN ITEMS
        {itemid=2456, count=1}, --bow
        {itemid=2544, count=1} --1 arrow
    },
    { -- KNIGHT ITEMS
        {itemid=2376, count=1}, -- sword
        {itemid=2398, count=1}, -- mace
        {itemid=2388, count=1}, -- hatchet
        {itemid=2512, count=1} -- wooden shield
       
    }
}

function onLogin(cid)
    if getPlayerGroupId(cid) < 2 then
        local hasReceivedFirstItems = getPlayerStorageValue(cid, 908081)
       
        if hasReceivedFirstItems ~= 1 then
            setPlayerStorageValue(cid, 908081, 1)
           
            local giveItems = firstItems[getPlayerVocation(cid)]
           
            if giveItems ~= nil then
                for _, v in ipairs(giveItems) do
                    doPlayerAddItem(cid, v.itemid, v.count)
                end
               
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received your first items depending on your vocation.")
            end
           
            doShowTextDialog(cid, 2110, "You have received first items.")
        end
    end
    return TRUE
end
 
Yes this is for starting items.
People might as well get the items at first log in. That doesn't matter for me.
I want to be able to do it with lever in the future though, but that can wait until I am better at lua.

The code u posted, does it work for "first log in items"?
Where do I add this script? creaturescripts?

Thanks for reply.
 
Thanks I really appreciate this!
Here it comes;

login.lua
Code:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

function onLogin(cid)
    if (getConfigValue("accountManager") == FALSE and getCreatureName(cid) == "Account Manager") then
        return false
    end

    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
    elseif(accountManager == MANAGER_ACCOUNT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end

    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "GuildMotd")
    registerCreatureEvent(cid,'SpellUp')


    registerCreatureEvent(cid, "Idle")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "ReportBug")
    registerCreatureEvent(cid, "AdvanceSave")
    return true
end
 
Code:
local config = {
    loginMessage = getConfigValue('loginMessage'),
    useFragHandler = getBooleanFromString(getConfigValue('useFragHandler'))
}

commonItems = {
    -- ITEMS ALL VOC RECEIVE
    {itemid=2461, count=1}, -- leather helmet
    {itemid=2467, count=1}, -- leather armor
    {itemid=2649, count=1}, -- leather legs
    {itemid=2643, count=1}, -- leather boots
    {itemid=2160, count=1}, -- 1cc
    {itemid=2120, count=1}, -- rope
    {itemid=2168, count=1},-- life ring
    {itemid=2554, count=1}, --shovel
    {itemid=2265, count=100}, --ih rune
    {itemid=2789, count=40} --food
}

firstItems = {
    { -- DRUID ITEMS
        {itemid=2190, count=1}, -- wand
        {itemid=2287, count=50} --lmm
    },
    { -- SORC ITEMS
        {itemid=2190, count=1}, -- wand
        {itemid=2287, count=50} --lmm
    },
    { -- PALADIN ITEMS
        {itemid=2456, count=1}, --bow
        {itemid=2544, count=1} --1 arrow
    },
    { -- KNIGHT ITEMS
        {itemid=2376, count=1}, -- sword
        {itemid=2398, count=1}, -- mace
        {itemid=2388, count=1}, -- hatchet
        {itemid=2512, count=1} -- wooden shield
     
    }
}


function onLogin(cid)
    if (getConfigValue("accountManager") == FALSE and getCreatureName(cid) == "Account Manager") then
        return false
    end

    local loss = getConfigValue('deathLostPercent')
    if(loss ~= nil) then
        doPlayerSetLossPercent(cid, PLAYERLOSS_EXPERIENCE, loss * 10)
    end

    local accountManager = getPlayerAccountManager(cid)
    if(accountManager == MANAGER_NONE) then
        local lastLogin, str = getPlayerLastLoginSaved(cid), config.loginMessage
        if(lastLogin > 0) then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
            str = "Your last visit was on " .. os.date("%a %b %d %X %Y", lastLogin) .. "."
        else
            str = str .. " Please choose your outfit."
            doPlayerSendOutfitWindow(cid)
        end

        doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, str)
    elseif(accountManager == MANAGER_NAMELOCK) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, it appears that your character has been namelocked, what would you like as your new name?")
    elseif(accountManager == MANAGER_ACCOUNT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to manage your account and if you want to start over then type 'cancel'.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Hello, type 'account' to create an account or type 'recover' to recover an account.")
    end

    if(not isPlayerGhost(cid)) then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
    end
   
    if getPlayerGroupId(cid) < 2 then
        local hasReceivedFirstItems = getPlayerStorageValue(cid, 908081)
     
        if hasReceivedFirstItems ~= 1 then
            setPlayerStorageValue(cid, 908081, 1)
         
            local giveItems = firstItems[getPlayerVocation(cid)]
         
            if giveItems ~= nil then
                for _, v in ipairs(giveItems) do
                    doPlayerAddItem(cid, v.itemid, v.count)
                end
             
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You received your first items depending on your vocation.")
            end
         
            doShowTextDialog(cid, 2110, "You have received first items.")
        end
    end

    registerCreatureEvent(cid, "Mail")
    registerCreatureEvent(cid, "GuildMotd")
    registerCreatureEvent(cid,'SpellUp')


    registerCreatureEvent(cid, "Idle")
    if(config.useFragHandler) then
        registerCreatureEvent(cid, "SkullCheck")
    end

    registerCreatureEvent(cid, "ReportBug")
    registerCreatureEvent(cid, "AdvanceSave")
    return true
end
 
Back
Top