• 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 script return true and false...

milbradt

New Member
Joined
Dec 25, 2011
Messages
177
Solutions
1
Reaction score
4
Code:
local summons = getCreatureSummons(cid)
local monster = "Orc"
for k = 1, #summons do
      if getCreatureName(summons[k]):lower() == monster:lower() then
         doCreatureSay(cid,"true",19)
       else
         doCreatureSay(cid,"false",19)
       end
end

By that returning the two when I have more than 2 summons?
 
If you have more summons and 1 of them is an orc it will give both messages since the for loop repeats it with same amount as the amount of summons.
 
Aaaa Okay.. '-'

You know a way to do this?

Code:
local summons = getCreatureSummons(cid)
local monsterOrc = "Orc"
local monsterTroll = "Troll"
local allMonster = {monsterOrc, monsterTroll}

if #getCreatureSummons(cid) == 0 then
    for _, all in pairs(allMonster) do
        local mysummon = doCreateMonster(all, getPlayerPosition(cid))
    end
end

for k = 1, #summons do
    if not getCreatureName(summons[k]):lower() == monsterOrc:lower() then
        local summon = doCreateMonster(monsterOrc, getPlayerPosition(cid))
    end
    if not getCreatureName(summons[k]):lower() == monsterTroll:lower() then
        local summon = doCreateMonster(monsterTroll, getPlayerPosition(cid))
    end   
end
 
If just 1 result should match you can add return true in the loop which will stop the loop (and the rest under it) so it won't create another troll if the player has 2 orcs.
Code:
for k = 1, #summons do
     if getCreatureName(summons[k]):lower() == "orc" then
         doCreateMonster("Troll", getPlayerPosition(cid))
         return true
     end
end

If it should check for more things, for example all summons, you can use variables and change these variables in the loop.
For example amount of orcs.
Code:
local a = 0
for k = 1, #summons do
     if getCreatureName(summons[k]):lower() == "orc" then
         a = a + 1
     end
end
if a == 2 then
     -- blabla
end


Or different summons.
Code:
local orc, troll = 0, 0
for k = 1, #summons do
     if getCreatureName(summons[k]):lower() == "orc" then
         orc = 1
     elseif getCreatureName(summons[k]):lower() == "troll" then
         troll = 1
     end
end
if orc == 1 and troll == 0 then
     -- blabla
end
 
Back
Top