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

doPlayerSendTextMessage

ConAn Edujawa

Member
Joined
Feb 23, 2015
Messages
457
Reaction score
17
hello guys i want send text show only storage +1
local power1= getCreatureStorage(cid, 16000)
local power2= getCreatureStorage(cid, 16001)
local power3= getCreatureStorage(cid, 16002)
local power4= getCreatureStorage(cid, 16004)
need msg come in storage >=1
example
if player have power1 = 1 get msg
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Storage: power1 = 12 .")
if player have power 1 and pwoer 2 >= 1get msg
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Storage: power1 = 12, power2 = 10 .")
0.4
 
Solution
compile done but in game don't work (don't show items ml)

Are you sure?
I tested and it works
C++:
setField(L, "magiclevelpoints", item->abilities.stats[STAT_MAGICLEVEL]);

Lua:
function getMagicPoints(cid)
    local magicPoints = 0
    local slotItem = getPlayerSlotItem(cid, CONST_SLOT_RING)
    if slotItem.uid > 0  then
        local itemInfo = getItemInfo(slotItem.itemid)
        magicPoints = magicPoints + (itemInfo.abilities.magiclevelpoints or 0)
    end
    return magicPoints
end

XML:
<attribute key="magiclevelpoints" value="3" />

note: Make sure to register the item in movements.xml
If I understood you, this might be what you're looking for:

Lua:
local storageKeys = {16000, 16001, 16002, 16003, 16004}

local message = ""
for i = 1, #storageKeys do
    local storageValue = getPlayerStorageValue(cid, storageKeys[i])
    if storageValue and storageValue >= 1 then
        if #message > 0 then
            message = message .. ","
        end
        message = message .. "\nPower" .. i .. " = " .. storageValue
    end
end

if #message > 0 then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Storage: " .. message .. ".")
end

Result:
Code:
22:46 Storage:
Power1 = 1,
Power2 = 1,
Power3 = 1,
Power4 = 1,
Power5 = 1.
 
If I understood you, this might be what you're looking for:

Lua:
local storageKeys = {16000, 16001, 16002, 16003, 16004}

local message = ""
for i = 1, #storageKeys do
    local storageValue = getPlayerStorageValue(cid, storageKeys[i])
    if storageValue and storageValue >= 1 then
        if #message > 0 then
            message = message .. ","
        end
        message = message .. "\nPower" .. i .. " = " .. storageValue
    end
end

if #message > 0 then
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Storage: " .. message .. ".")
end

Result:
Code:
22:46 Storage:
Power1 = 1,
Power2 = 1,
Power3 = 1,
Power4 = 1,
Power5 = 1.
work fine how i can make something like this with function
like this
Lua:
function getDef(cid)
   local defense = 0
   for i = CONST_SLOT_RIGHT,CONST_SLOT_LEFT do
     if getPlayerSlotItem(cid, i).uid > 0  then
       if getItemInfo(getPlayerSlotItem(cid,i).itemid).defense then
         defense = defense + getItemInfo(getPlayerSlotItem(cid,i).itemid).defense
       end
     end
     if getPlayerSlotItem(cid, i).uid > 0 then
       if getItemInfo(getPlayerSlotItem(cid, i).itemid).extraDefense > 0 then
         defense = defense + getItemInfo(getPlayerSlotItem(cid, i).itemid).extraDefense
       end
     end
   end
   return defense
end

function getArm(cid)
   local armor = 0
   for i = CONST_SLOT_FIRST,CONST_SLOT_LAST do
     if getPlayerSlotItem(cid, i).uid > 0 then
       if getItemInfo(getPlayerSlotItem(cid,i).itemid).armor > 0 then
         armor = armor + getItemInfo(getPlayerSlotItem(cid,i).itemid).armor
       end
     end
   end
   return armor > 0 and armor or 1
end

and attack and speed
 
🤔 Not sure what you are asking..

Lua:
-- for testing
-- replace these functions with your own
function getDef(cid)   return  10 end
function getArm(cid)   return   5 end
function getAtk(cid)   return  43 end
function getSpeed(cid) return  34 end

local functions = {
    ["Defense"] = getDef,
    ["Armor"]   = getArm,
    ["Attack"]  = getAtk,
    ["Speed"]   = getSpeed
}

local message = ""
for slot, func in pairs(functions) do
    if func then
        message = message .. "- " .. slot .. ": " .. func(cid) .. "\n"
    end
end

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Stats:\n" .. message)

Result:
Code:
Stats:
- Armor: 5
- Defense: 10
- Speed: 34
- Attack: 43
 
🤔 Not sure what you are asking..

Lua:
-- for testing
-- replace these functions with your own
function getDef(cid)   return  10 end
function getArm(cid)   return   5 end
function getAtk(cid)   return  43 end
function getSpeed(cid) return  34 end

local functions = {
    ["Defense"] = getDef,
    ["Armor"]   = getArm,
    ["Attack"]  = getAtk,
    ["Speed"]   = getSpeed
}

local message = ""
for slot, func in pairs(functions) do
    if func then
        message = message .. "- " .. slot .. ": " .. func(cid) .. "\n"
    end
end

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Stats:\n" .. message)

Result:
Code:
Stats:
- Armor: 5
- Defense: 10
- Speed: 34
- Attack: 43
yes but that show all function like this
  • Armor: 0
  • Defense: 0
  • Speed: 0
  • Attack: 0
i need if speed or def or armor >= 1 show in msg
 
yes but that show all function like this
  • Armor: 0
  • Defense: 0
  • Speed: 0
  • Attack: 0
i need if speed or def or armor >= 1 show in msg

try this
Lua:
for slot, func in pairs(functions) do
    if func then
        local result = func(cid)
        if result > 0 then
            message = message .. "- " .. slot .. ": " .. result .. "\n"
        end
    end
end
 
try this
Lua:
for slot, func in pairs(functions) do
    if func then
        local result = func(cid)
        if result > 0 then
            message = message .. "- " .. slot .. ": " .. result .. "\n"
        end
    end
end
this work fine but how i can add 2 function in one line
like this
["Power"] = getDef,getArm
 
this work fine but how i can add 2 function in one line
like this
["Power"] = getDef,getArm

Try:

Lua:
local functions = {
    ["Power"]  = {getDef, getArm},
    ["Attack"] = getAtk,
    ["Speed"]  = getSpeed
}

local message = ""
for slot, v in pairs(functions) do
    local totalAmount = 0
    if type(v) == 'table' then
        for _, func in pairs(v) do
            totalAmount = totalAmount + func(cid)
        end
        message = message .. "- " .. slot .. ": " .. totalAmount .. "\n"
    else
        local func = v
        if func then
            local result = func(cid)
            if result > 0 then
                message = message .. "- " .. slot .. ": " .. result .. "\n"
            end
        end
    end
end

Result:
Code:
- Speed: 4
- Attack: 3
- Power: 3
 
Try:

Lua:
local functions = {
    ["Power"]  = {getDef, getArm},
    ["Attack"] = getAtk,
    ["Speed"]  = getSpeed
}

local message = ""
for slot, v in pairs(functions) do
    local totalAmount = 0
    if type(v) == 'table' then
        for _, func in pairs(v) do
            totalAmount = totalAmount + func(cid)
        end
        message = message .. "- " .. slot .. ": " .. totalAmount .. "\n"
    else
        local func = v
        if func then
            local result = func(cid)
            if result > 0 then
                message = message .. "- " .. slot .. ": " .. result .. "\n"
            end
        end
    end
end

Result:
Code:
- Speed: 4
- Attack: 3
- Power: 3
work but i want ask on something how i can check manaGain player have in items slots and i want its work like
power: def x , arm x
not collection number
 
work but i want ask on something how i can check manaGain player have in items slots and i want its work like
power: def x , arm x
not collection number

🤔
If you want to check if an item has an attribute, use getItemAttribute(uid, key)

power: def x , arm x

Hmm..
Lua:
local functions = {
    ["Power"] = {
        ["Def"] = getDef,
        ["Arm"] = getArm
    },
    ["Attack"] = getAtk,
    ["Speed"]  = getSpeed
}

local message = ""
for slot, func in pairs(functions) do
    local totalAmount = 0
    if type(func) ~= 'table' then
        if func then
            local result = func(cid)
            if result > 0 then
                message = message .. "- " .. slot .. ": " .. result .. "\n"
            end
        end
    end
end

message = message .. "Powers:\n- - "
for powerSlot, func in pairs(functions["Power"]) do
    if func then
        message = message .. powerSlot .. ": " .. func(cid) .. " | "
    end
end

Code:
- Speed: 1
- Attack: 1
Powers:
- - Arm: 1 | Def: 1 |
 
🤔
If you want to check if an item has an attribute, use getItemAttribute(uid, key)



Hmm..
Lua:
local functions = {
    ["Power"] = {
        ["Def"] = getDef,
        ["Arm"] = getArm
    },
    ["Attack"] = getAtk,
    ["Speed"]  = getSpeed
}

local message = ""
for slot, func in pairs(functions) do
    local totalAmount = 0
    if type(func) ~= 'table' then
        if func then
            local result = func(cid)
            if result > 0 then
                message = message .. "- " .. slot .. ": " .. result .. "\n"
            end
        end
    end
end

message = message .. "Powers:\n- - "
for powerSlot, func in pairs(functions["Power"]) do
    if func then
        message = message .. powerSlot .. ": " .. func(cid) .. " | "
    end
end

Code:
- Speed: 1
- Attack: 1
Powers:
- - Arm: 1 | Def: 1 |
wow work good but i want function like this
Lua:
function getDef(cid)
   local defense = 0
   for i = CONST_SLOT_RIGHT,CONST_SLOT_LEFT do
     if getPlayerSlotItem(cid, i).uid > 0  then
       if getItemInfo(getPlayerSlotItem(cid,i).itemid).defense then
         defense = defense + getItemInfo(getPlayerSlotItem(cid,i).itemid).defense
       end
     end
     if getPlayerSlotItem(cid, i).uid > 0 then
       if getItemInfo(getPlayerSlotItem(cid, i).itemid).extraDefense > 0 then
         defense = defense + getItemInfo(getPlayerSlotItem(cid, i).itemid).extraDefense
       end
     end
   end
   return defense
end
to know how many mana reg player have in items slots
 
Here you go;

Lua:
function getManaGain(cid)
    local manaGain = 0
    for i = CONST_SLOT_RIGHT, CONST_SLOT_LEFT do -- only left & right ?
        local slotItem = getPlayerSlotItem(cid, i)
        if slotItem.uid > 0  then
            local itemInfo = getItemInfo(slotItem.itemid)
            if itemInfo.abilities.regeneration and itemInfo.abilities.manaGain then
                manaGain = manaGain + itemInfo.abilities.manaGain
            end
        end
    end
    return manaGain
end

 
Here you go;

Lua:
function getManaGain(cid)
    local manaGain = 0
    for i = CONST_SLOT_RIGHT, CONST_SLOT_LEFT do -- only left & right ?
        local slotItem = getPlayerSlotItem(cid, i)
        if slotItem.uid > 0  then
            local itemInfo = getItemInfo(slotItem.itemid)
            if itemInfo.abilities.regeneration and itemInfo.abilities.manaGain then
                manaGain = manaGain + itemInfo.abilities.manaGain
            end
        end
    end
    return manaGain
end

how i can use getItemInfo for magiclevel its not add in source
 
not work always show me 0 and ring have to add 1 ml

I tested and you are right. magiclevelpoints is added to item.abilities.stats[STAT_MAGICLEVEL]

but this isn't added to the table which is returned by getItemInfo it seems.

Try this.
Compile & test. Let me know if it works.

C++:
setField(L, "magiclevelpoints", item->abilities.stats[STAT_MAGICLEVEL]);
 
I tested and you are right. magiclevelpoints is added to item.abilities.stats[STAT_MAGICLEVEL]

but this isn't added to the table which is returned by getItemInfo it seems.

Try this.
Compile & test. Let me know if it works.

C++:
setField(L, "magiclevelpoints", item->abilities.stats[STAT_MAGICLEVEL]);
compile done but in game don't work (don't show items ml)
 
compile done but in game don't work (don't show items ml)

Are you sure?
I tested and it works
C++:
setField(L, "magiclevelpoints", item->abilities.stats[STAT_MAGICLEVEL]);

Lua:
function getMagicPoints(cid)
    local magicPoints = 0
    local slotItem = getPlayerSlotItem(cid, CONST_SLOT_RING)
    if slotItem.uid > 0  then
        local itemInfo = getItemInfo(slotItem.itemid)
        magicPoints = magicPoints + (itemInfo.abilities.magiclevelpoints or 0)
    end
    return magicPoints
end

XML:
<attribute key="magiclevelpoints" value="3" />

note: Make sure to register the item in movements.xml
 
Solution
Are you sure?
I tested and it works
C++:
setField(L, "magiclevelpoints", item->abilities.stats[STAT_MAGICLEVEL]);

Lua:
function getMagicPoints(cid)
    local magicPoints = 0
    local slotItem = getPlayerSlotItem(cid, CONST_SLOT_RING)
    if slotItem.uid > 0  then
        local itemInfo = getItemInfo(slotItem.itemid)
        magicPoints = magicPoints + (itemInfo.abilities.magiclevelpoints or 0)
    end
    return magicPoints
end

XML:
<attribute key="magiclevelpoints" value="3" />

note: Make sure to register the item in movements.xml
yes yes :D u are the best :D
 
Back
Top