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

Script Problem

Dorianek

Member
Joined
Nov 29, 2018
Messages
252
Reaction score
10
Location
Poland
How to add a line here that the lever will start only when the player has eg lvl 120 ??


local nazwyPotworow = {"Pirate Corsair"} -- Nazwy potworów, jakie skrypt może robić
local exh = 2 -- Ile sekund exhaused
local storage = 10016
function onUse(cid, item, frompos, item2, topos)
local monster = nazwyPotworow[math.random(1,#nazwyPotworow)]

if(getPlayerStorageValue(cid,storage) <= os.time()) then
local summon = doSummonCreature(monster,getPlayerPosition(cid))
doChallengeCreature(cid, summon)
doChallengeCreature(summon, cid)
setPlayerStorageValue(cid,storage,os.time()+exh)
doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"Czeka cie walka z ".. monster .."!")
else
doPlayerSendCancel(cid,"You are exhausted.")
end
return TRUE
end
 
Code:
local nazwyPotworow = {"Pirate Corsair"} -- Nazwy potworów, jakie skrypt może robić
local exh = 2 -- Ile sekund exhaused
local storage = 10016
local playerLevel = 120  --Level the player needs

function onUse(cid, item, frompos, item2, topos)
local monster = nazwyPotworow[math.random(1,#nazwyPotworow)]

    if(getPlayerStorageValue(cid,storage) <= os.time()) then  
        if getPlayerLevel(cid) >= 120 then
            local summon = doSummonCreature(monster,getPlayerPosition(cid))
            doChallengeCreature(cid, summon)
            doChallengeCreature(summon, cid)
            setPlayerStorageValue(cid,storage,os.time()+exh)
            doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"Czeka cie walka z ".. monster .."!")
        else
            doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You need level 120 or higher.")
        end
    else
        doPlayerSendCancel(cid,"You are exhausted.")
    end
return true
end
 
Code:
local nazwyPotworow = {"Pirate Corsair"} -- Nazwy potworów, jakie skrypt może robić
local exh = 2 -- Ile sekund exhaused
local storage = 10016
local playerLevel = 120  --Level the player needs

function onUse(cid, item, frompos, item2, topos)
local monster = nazwyPotworow[math.random(1,#nazwyPotworow)]

    if(getPlayerStorageValue(cid,storage) <= os.time()) then
        if getPlayerLevel(cid) >= 120 then
            local summon = doSummonCreature(monster,getPlayerPosition(cid))
            doChallengeCreature(cid, summon)
            doChallengeCreature(summon, cid)
            setPlayerStorageValue(cid,storage,os.time()+exh)
            doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"Czeka cie walka z ".. monster .."!")
        else
            doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,"You need level 120 or higher.")
        end
    else
        doPlayerSendCancel(cid,"You are exhausted.")
    end
return true
end
Should break that nested if habit.
With longer code, those nested if's can get really long and confusing, when it doesn't need to be.

example, using above code.

LUA:
local nazwyPotworow = {"Pirate Corsair"} -- Nazwy potworów, jakie skrypt może robić
local exh = 2 -- Ile sekund exhaused
local storage = 10016
local playerLevel = 120  --Level the player needs

function onUse(cid, item, frompos, item2, topos)
    if getPlayerLevel(cid) >= 120 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need level 120 or higher.")
        return true
    end
  
    if getPlayerStorageValue(cid,storage) <= os.time() then
        doPlayerSendCancel(cid,"You are exhausted.")
        return true
    end
    setPlayerStorageValue(cid, storage, os.time() + exh)
  
    local monster = nazwyPotworow[math.random(1,#nazwyPotworow)]
    local summon = doSummonCreature(monster, getPlayerPosition(cid))
    doChallengeCreature(cid, summon)
    doChallengeCreature(summon, cid)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Czeka cie walka z ".. monster .."!")
  
    return true
end

On a side note, keep up the good work helping people. <3
 
Should break that nested if habit.
With longer code, those nested if's can get really long and confusing, when it doesn't need to be.

example, using above code.

LUA:
local nazwyPotworow = {"Pirate Corsair"} -- Nazwy potworów, jakie skrypt może robić
local exh = 2 -- Ile sekund exhaused
local storage = 10016
local playerLevel = 120  --Level the player needs

function onUse(cid, item, frompos, item2, topos)
    if getPlayerLevel(cid) >= 120 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need level 120 or higher.")
        return true
    end
 
    if getPlayerStorageValue(cid,storage) <= os.time() then
        doPlayerSendCancel(cid,"You are exhausted.")
        return true
    end
    setPlayerStorageValue(cid, storage, os.time() + exh)
 
    local monster = nazwyPotworow[math.random(1,#nazwyPotworow)]
    local summon = doSummonCreature(monster, getPlayerPosition(cid))
    doChallengeCreature(cid, summon)
    doChallengeCreature(summon, cid)
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Czeka cie walka z ".. monster .."!")
 
    return true
end

On a side note, keep up the good work helping people. <3
Never thought of it Xikini, most of the time I end up nesting the ifs! Old habits die hard, I'm not good by any means in scripting, but this type of advices always help, thank you very much! (L
 
Back
Top