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

qruczu

New Member
Joined
Jan 8, 2012
Messages
104
Reaction score
0
Hi, how can I add a loop in this script to make it not so big ?

i use tfs 0.3.6

Code:
function onSay(cid, words, param, channel)

local pos = getPlayerPosition(cid)
local players2 = getPlayersOnline()
local strings = {""}
local str2 = ""
local str3 = ""


for _, pid2 in ipairs(players2) do      
       
    if getPlayerStorageValue(pid2, 8000) == 1 then
            str2 = str2 .. getCreatureName(pid2) ..",  "
end  
end  
   
for _, pid3 in ipairs(players2) do      
       
    if getPlayerStorageValue(pid3, 8000) == 2 then
            str3 = str3 .. getCreatureName(pid3) ..",  "
end  
end  
   
if getPlayerStorageValue(cid,8000) == 1 then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Bring me sword")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str2)

elseif getPlayerStorageValue(cid,8000) == 2 then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Bring me shield")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str3)
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Nothing")
end
return true
end
 
Solution
yes but if player have quest 1 looks all who have quest 1 not quest 2 or 3
Lua:
local config = {
[1] = "sword", -- here are storage 8000,1 and msg "sword"
[2] = "shield" -- storage 8000,2 and msg "shield"
}

function onSay(cid, words, param, channel)
    local onlinePlayers = getPlayersOnline()
    local playerSto = getPlayerStorageValue(cid, 8000)   

    for _, pid2 in ipairs(onlinePlayers) do
        local targetStor = getPlayerStorageValue(pid2, 8000)
        local check = config[targetStor]
        if check and targetStor == playerSto then
            local msg = "".. getCreatureName(pid2) .." bring me ".. check .."."
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, msg)
        end
    end
   
    return true...
Hi, how can I add a loop in this script to make it not so big ?

i use tfs 0.3.6

Code:
function onSay(cid, words, param, channel)

local pos = getPlayerPosition(cid)
local players2 = getPlayersOnline()
local strings = {""}
local str2 = ""
local str3 = ""


for _, pid2 in ipairs(players2) do     
      
    if getPlayerStorageValue(pid2, 8000) == 1 then
            str2 = str2 .. getCreatureName(pid2) ..",  "
end 
end 
  
for _, pid3 in ipairs(players2) do     
      
    if getPlayerStorageValue(pid3, 8000) == 2 then
            str3 = str3 .. getCreatureName(pid3) ..",  "
end 
end 
  
if getPlayerStorageValue(cid,8000) == 1 then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Bring me sword")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str2)

elseif getPlayerStorageValue(cid,8000) == 2 then
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Bring me shield")
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str3)
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Nothing")
end
return true
end
what this script does?
 
show quest and players who have this quest
Lua:
local config = {
[1] = "sword", -- here are storage 8000,1 and msg "sword"
[2] = "shield" -- storage 8000,2 and msg "shield"
}

function onSay(cid, words, param, channel)
    local check = config[getPlayerStorageValue(cid, 8000)]
    if check then
        local msg = "".. getCreatureName(cid) .." bring me ".. check .."."
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, msg)
    else
        doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "Nothing")
    end
    
    return true
end
 
almost because it doesn't show players who have the same quest

you didn't say you wanted to check everyone online, try
Lua:
local config = {
[1] = "sword", -- here are storage 8000,1 and msg "sword"
[2] = "shield" -- storage 8000,2 and msg "shield"
}

function onSay(cid, words, param, channel)
    local onlinePlayers = getPlayersOnline()   
    for _, pid2 in ipairs(onlinePlayers) do
        local check = config[getPlayerStorageValue(pid2, 8000)]
        if check then
            local msg = "".. getCreatureName(pid2) .." bring me ".. check .."."
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, msg)
        end
    end
   
    return true
end
 
yes but if player have quest 1 looks all who have quest 1 not quest 2 or 3
Lua:
local config = {
[1] = "sword", -- here are storage 8000,1 and msg "sword"
[2] = "shield" -- storage 8000,2 and msg "shield"
}

function onSay(cid, words, param, channel)
    local onlinePlayers = getPlayersOnline()
    local playerSto = getPlayerStorageValue(cid, 8000)   

    for _, pid2 in ipairs(onlinePlayers) do
        local targetStor = getPlayerStorageValue(pid2, 8000)
        local check = config[targetStor]
        if check and targetStor == playerSto then
            local msg = "".. getCreatureName(pid2) .." bring me ".. check .."."
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, msg)
        end
    end
   
    return true
end
 
Solution
so close :D
now it is like this:
name bring me item < this is me
name bring me item < this is other player with the same quest
but i need:
bring me item
name, name, name
 
Back
Top