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

Lua I can't close the ends

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
380
Solutions
1
Reaction score
89
Hi Otlanders,

I'm not able to close the ends, I'm a beginner on the lua.
Lua:
function onUse(cid, item, frompos, item2, topos)
jailroom = {x=1031, y=1034, z=8}
jailtime = 10

time = getPlayerStorageValue(cid,1533)
now = os.time()

access = 6
access2 = 2

if getPlayerAccess(cid) >= access then
    if getPlayerName(item2.uid) == getPlayerName(cid) then
        doPlayerSendTextMessage(cid,22,""..jailtime.." seconds of prison system.")
        setPlayerStorageValue(cid,1533,jailtime)
        doPlayerSay(cid,"/B Jail System: The player "..getPlayerName(item2.uid).." was arrested for " ..jailtime.." seconds.", 16)
    end
if getPlayerAccess(item2.uid) < access2 then
    if getPlayerStorageValue(item2.uid,1444) == -1 then
        doPlayerSendTextMessage(item2.uid,22,"You are arrested for "..time.." seconds! Any word that you say now can be used against you later.")
        doTeleportThing(item2.uid,jailroom)
        setPlayerStorageValue(item2.uid,1445,time)
        setPlayerStorageValue(item2.uid,1444,now)
    else
        doPlayerSendTextMessage(cid,22,""..getPlayerName(item2.uid).." is already arrested.")
    end
else
    doPlayerSendCancel(cid,"You cannot make this player a prisioner.")
end
else
    doPlayerSendCancel(cid,"You can only use this rune on a person.")
else
    doPlayerSendCancel(cid,"You do not have the needed access to use this rune.")
end
return 1
end

data/actions/scripts/jail/jailkey.lua:31: `end' expected (to close `if' at line 11) near `else'
 
Lua:
function onUse(cid, item, frompos, item2, topos)
    jailroom = {x = 1031, y = 1034, z = 8}
    jailtime = 10
    time = getPlayerStorageValue(cid, 1533)
    now = os.time()
    access = 6
    access2 = 2
    if getPlayerAccess(cid) >= access then
        if getPlayerName(item2.uid) == getPlayerName(cid) then
            doPlayerSendTextMessage(cid, 22, "" .. jailtime .. " seconds of prison system.")
            setPlayerStorageValue(cid, 1533, jailtime)
            doPlayerSay(cid, "/B Jail System: The player " .. getPlayerName(item2.uid) .. " was arrested for " .. jailtime .. " seconds.", 16)
            if getPlayerAccess(item2.uid) < access2 then
                if getPlayerStorageValue(item2.uid, 1444) == -1 then
                    doPlayerSendTextMessage(
                        item2.uid,
                        22,
                        "You are arrested for " .. time .. " seconds! Any word that you say now can be used against you later."
                    )
                    doTeleportThing(item2.uid, jailroom)
                    setPlayerStorageValue(item2.uid, 1445, time)
                    setPlayerStorageValue(item2.uid, 1444, now)
                else
                    doPlayerSendTextMessage(cid, 22, "" .. getPlayerName(item2.uid) .. " is already arrested.")
                end
            else
                doPlayerSendCancel(cid, "You cannot make this player a prisioner.")
            end
        else
            doPlayerSendCancel(cid, "You can only use this rune on a person.")
        end
    else
        doPlayerSendCancel(cid, "You do not have the needed access to use this rune.")
    end
    return 1
end
 
Here's an alternative way of coding this, so you don't have 30 nested if statements.
Lua:
local access = 6
local access2 = 2
local jailroom = {x = 1031, y = 1034, z = 8}
local jailtime = 10

function onUse(cid, item, frompos, item2, topos)
    
    local time = getPlayerStorageValue(cid, 1533)
    local now = os.time()
    local target = item2.uid
    
    -- check that only gods can use it.
    if getPlayerAccess(cid) < access then
        doPlayerSendCancel(cid, "You do not have the needed access to use this rune.")
        return true
    end
    
    -- check it is being used on a player
    if not isPlayer(target) then
        doPlayerSendCancel(cid, "You can only use this rune on a player.")
        return true
    end
    
    -- Ensure it's not used on a GM / CM / GOD
    if getPlayerAccess(target) < access2 then
        doPlayerSendCancel(cid, "You cannot make this player a prisoner.")
        return true
    end
    
    -- Jail the player -- I don't fully understand how this bottom section is supposed to work.. so just leaving it as-is.
    doPlayerSendTextMessage(cid, 22, "" .. jailtime .. " seconds of prison system.")
    setPlayerStorageValue(cid, 1533, jailtime)
    doPlayerSay(cid, "/B Jail System: The player " .. getPlayerName(target) .. " was arrested for " .. jailtime .. " seconds.", 16)
    
    if getPlayerStorageValue(target, 1444) == -1 then
        doPlayerSendTextMessage(target, 22, "You are arrested for " .. time .. " seconds! Any word that you say now can be used against you later.")
        doTeleportThing(target, jailroom)
        setPlayerStorageValue(target, 1445, time)
        setPlayerStorageValue(target, 1444, now)
    end
    
    return true
end
 
Here's an alternative way of coding this, so you don't have 30 nested if statements.
Lua:
local access = 6
local access2 = 2
local jailroom = {x = 1031, y = 1034, z = 8}
local jailtime = 10

function onUse(cid, item, frompos, item2, topos)
   
    local time = getPlayerStorageValue(cid, 1533)
    local now = os.time()
    local target = item2.uid
   
    -- check that only gods can use it.
    if getPlayerAccess(cid) < access then
        doPlayerSendCancel(cid, "You do not have the needed access to use this rune.")
        return true
    end
   
    -- check it is being used on a player
    if not isPlayer(target) then
        doPlayerSendCancel(cid, "You can only use this rune on a player.")
        return true
    end
   
    -- Ensure it's not used on a GM / CM / GOD
    if getPlayerAccess(target) < access2 then
        doPlayerSendCancel(cid, "You cannot make this player a prisoner.")
        return true
    end
   
    -- Jail the player -- I don't fully understand how this bottom section is supposed to work.. so just leaving it as-is.
    doPlayerSendTextMessage(cid, 22, "" .. jailtime .. " seconds of prison system.")
    setPlayerStorageValue(cid, 1533, jailtime)
    doPlayerSay(cid, "/B Jail System: The player " .. getPlayerName(target) .. " was arrested for " .. jailtime .. " seconds.", 16)
   
    if getPlayerStorageValue(target, 1444) == -1 then
        doPlayerSendTextMessage(target, 22, "You are arrested for " .. time .. " seconds! Any word that you say now can be used against you later.")
        doTeleportThing(target, jailroom)
        setPlayerStorageValue(target, 1445, time)
        setPlayerStorageValue(target, 1444, now)
    end
   
    return true
end
my source is yurots 0.9.4f, this script didn't work.
Post automatically merged:

@Xikini My original script is the one below.
However I wanted to remove the "choose" and leave a fixed time.
but I'm not able to remove the "choose" from the script.

Lua:
function onUse(cid, item, frompos, item2, topos)


cadeia = {x=1031, y=1034, z=8} ---coordenadas da cadeia

now = os.time()


-----tempos das penas de prisão em segundos-------

time1 = 10
time2 = 30
time3 = 60

---------------------------------------

time = getPlayerStorageValue(cid,1533)
choose = getPlayerStorageValue(cid,1532)


access = 6 ---acesso para usar a rune
access2 = 2 --- a partir deste acesso nao e preso


if getPlayerAccess(cid) >= access then
    aux = getPlayerAccess(cid)
if item2.itemid == cid then
if getPlayerName(item2.uid) == getPlayerName(cid) then
if choose == -1 then
doPlayerSendTextMessage(cid,22,""..time1.." seconds of prison system.")
setPlayerStorageValue(cid,1532,0)
setPlayerStorageValue(cid,1533,time1)
-- doPlayerSay(cid,"hit! hit! fresh beer!!",16)
doPlayerSay(cid,"/B Jail System: The player "..getPlayerName(item2.uid).." was arrested for " ..time1.." seconds.", 16)
elseif choose == 0 then
doPlayerSendTextMessage(cid,22,""..time2.." seconds of prison system.")
setPlayerStorageValue(cid,1532,1)
setPlayerStorageValue(cid,1533,time2)
doPlayerSay(cid,"/B Jail System: The player "..getPlayerName(item2.uid).." was arrested for " ..time1.." seconds.", 16)
elseif choose == 1 then
doPlayerSendTextMessage(cid,22,""..time3.." seconds of prison system.")
setPlayerStorageValue(cid,1532,-1)
setPlayerStorageValue(cid,1533,time3)
doPlayerSay(cid,"/B Jail System: The player "..getPlayerName(item2.uid).." was arrested for " ..time1.." seconds.", 16)
end
else
if getPlayerAccess(item2.uid) < access2 then
if getPlayerStorageValue(item2.uid,1444) == -1 then
doPlayerSendTextMessage(item2.uid,22,"You are arrested for "..time.." seconds! Any word that you say now can be used against you later.")
doTeleportThing(item2.uid,cadeia)
setPlayerStorageValue(item2.uid,1445,time)
setPlayerStorageValue(item2.uid,1444,now)
else
doPlayerSendTextMessage(cid,22,""..getPlayerName(item2.uid).." is already arrested.")
end
else
doPlayerSendCancel(cid,"You cannot make this player a prisioner.")
end
end
else
doPlayerSendCancel(cid,"You can only use this rune on a person.")
end
else
doPlayerSendCancel(cid,"You do not have the needed access to use this rune.")
end

return 1
end
 
1607537968225.png
you would notice a problem if you had proper indentation. You have two else statements next to each other and two lines left out my bad, they close "function" statement

the if statement structure is:
Code:
if (condition is met) then
-- instructions
elseif (condition is met) then -- optional, any amount of these can be made
-- this will execute when condition from if or previous elseif wasn't met
else -- optional, zero or one can be in your "if" statement
-- this will execute when condition from above statement wasn't met
end

also please use "local" when declaring variables if you don't want them to leak to other script (lua variables are global by default unless you specify it's a local variable)
 
View attachment 52259
you would notice a problem if you had proper indentation. You have two else statements next to each other and two lines left out my bad, they close "function" statement

the if statement structure is:
Code:
if (condition is met) then
-- instructions
elseif (condition is met) then -- optional, any amount of these can be made
-- this will execute when condition from if or previous elseif wasn't met
else -- optional, zero or one can be in your "if" statement
-- this will execute when condition from above statement wasn't met
end

also please use "local" when declaring variables if you don't want them to leak to other script (lua variables are global by default unless you specify it's a local variable)
I'm learning, so the difficulty, thanks for the tips.
 

Similar threads

Back
Top