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

Only show text if is in local.

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hey,

I got a question about how to make this string only work if the local exists.

LUA:
doPlayerSendTextMessage(cid,27,'Loot of '..r.article..' '..r.name..': '..getItemNameById(r.loot[1])..','..getItemNameById(r.loot[2])..','..getItemNameById(r.loot[3])..'.')

That's the string i'm using but I want it only to send '..getItemNameById(r.loot[~])..' if it exists.

so if r.loot[2] doesn't exist it should send '.' instead of 'getItemNameById(r.loot[2])'.

Thanks in advance,
unknown666
 
I donno how it goes or what you doing but this may be usful example.

Code:
local item = {2466,2470}
local loot = {}
for i = 1,#item do
  table.insert(loot,getItemNameById(item[i]) )
 end
doPlayerSendTextMessage(cid,19,table.concat(loot,", ").."")

So you can change the item table to the r.loot.
 
Last edited:
Well that's not really a use of me because I guess that would require me to script every itemid I'm going to use and that's going to be alot.

But here's my script so far, it's unfinished so don't mind unused locals.

LUA:
local butchloot = {
    [2905] = {
        chance = {65,20,25,40},
        loot = {2671,11230,2666},
        name = 'sheep',
        article = 'a'
        }
    }

local allowedCorpses = {5991,2905}
function onUse(cid,item,fromPosition,itemEx,toPosition)
local v = getThingPos(cid)
    if getPlayerVocation(cid) == 1 then
        if isInArray(allowedCorpses,getTileThingByPos(toPosition).itemid) then
        local r = butchloot[getTileThingByPos(toPosition).itemid]
            if math.random(1,100) <= r.chance[1] then
                if math.random(1,100) <= r.chance[2] then
                    for i = 1,#loot do
                        doPlayerAddItem(cid,r.loot[i],1)
                    end
                    doPlayerSendTextMessage(cid,27,'Loot of '..r.article..' '..r.name..': '..getItemNameById(r.loot[1])..','..getItemNameById(r.loot[2])..','..getItemNameById(r.loot[3])..'.')
                    doSendMagicEffect(toPosition,12)
                end
            else
                doSendMagicEffect(v,2)
            end
        else
            doSendMagicEffect(v,2)
        end
    else
        doPlayerSendTextMessage(cid,19,'You don\'t have any butching experience!')
    end
    return true
end

now I want it to send the text message with the loot, as posted in my first post, but if the local doesn't exist it should say '.' instead of the itemname.
 
isnt that what i made ?

maybe this will be more clear to you

so you will just change evry "item" to your r.loot table
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local item = {2446,2466}
local loot = {}

for i = 1,#item do
  table.insert(loot,getItemNameById(item[i]) )
 end
doPlayerSendTextMessage(cid,19," There is ".. ( #item > 0 and table.concat(loot,", ") or "nothng.")..".")
	 
return true
end
 
Last edited:
and this should be an edit on your script to make more clearer :
The table.concat if it dont have nothng or is empty it will send nothng so just put that "." at the end of the doPlayerSendText...

Code:
local butchloot = {
    [2905] = {
        chance = {65,20,25,40},
        loot = {2671,11230,2666},
        name = 'sheep',
        article = 'a'
        }
    }
 
local allowedCorpses = {5991,2905}
function onUse(cid,item,fromPosition,itemEx,toPosition)
local v = getThingPos(cid)
    if getPlayerVocation(cid) == 1 then
        if isInArray(allowedCorpses,getTileThingByPos(toPosition).itemid) then
        local r = butchloot[getTileThingByPos(toPosition).itemid]
		
            if math.random(1,100) <= r.chance[1] then
                if math.random(1,100) <= r.chance[2] then
				  local loot = {}
                    for i = 1,#r.loot do
                        doPlayerAddItem(cid,r.loot[i],1)
						  table.insert(loot,getItemNameById(r.loot[i]) )
                    end
					
					 
                    doPlayerSendTextMessage(cid,27,'Loot of '..r.article..' '..r.name..': '..table.concat(loot,", ")..'.')
                    doSendMagicEffect(toPosition,12)
                end
            else
                doSendMagicEffect(v,2)
            end
        else
            doSendMagicEffect(v,2)
        end
    else
        doPlayerSendTextMessage(cid,19,'You don\'t have any butching experience!')
    end
    return true
end

Ah and in your script in the "for" you say [ i have fixed in the example i gave you ]
Code:
 for i = 1,#loot do
                        doPlayerAddItem(cid,r.loot[i],1)
						
                    end
must be
Code:
 for i = 1,#r.loot do
                        doPlayerAddItem(cid,r.loot[i],1)
						
                    end
 
Last edited:
I got this, before seeing your post, but thanks again :).

LUA:
local butchloot = {
    [2905] = {
        chance = {65,20,25,40},
        loot = {2671,11230,2666},
        name = 'sheep',
        article = 'a'
        }
    }

local allowedCorpses = {5991,2905}
function onUse(cid,item,fromPosition,itemEx,toPosition)
local v,lootlist = getThingPos(cid),{}
    if getPlayerVocation(cid) == 1 then
        if isInArray(allowedCorpses,getTileThingByPos(toPosition).itemid) then
        local r = butchloot[getTileThingByPos(toPosition).itemid]
            if math.random(1,100) <= r.chance[1] then
                if math.random(1,100) <= r.chance[2] then
                    for i = 1,#loot do
                        doPlayerAddItem(cid,r.loot[i],1)
                        table.insert(loot,getItemNameById(r.loot[i]))
                    end
                    doPlayerSendTextMessage(cid,27,'Loot of '..r.article..' '..r.name..': '..table.concat(lootlist,',')..'.')
                    doSendMagicEffect(toPosition,12)
                elseif math.random (1,100) <= r.chance[3] then
                    for i = 1,2 do
                        doPlayerAddItem(cid,r.loot[i],1)
                    end
                    doPlayerSendTextMessage(cid,27,'')
            else
                doSendMagicEffect(v,2)
            end
        else
            doSendMagicEffect(v,2)
        end
    else
        doPlayerSendTextMessage(cid,19,'You don\'t have any butching experience!')
    end
    return true
end
 
Back
Top