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

Compiling show duration item.cpp

beenii

Well-Known Member
Joined
Jul 26, 2010
Messages
580
Solutions
1
Reaction score
57
hi i want adapted this function:

Code:
function timeString(timeDiff)
  local dateFormat = {
    {"day", timeDiff / 60 / 60 / 24},
    {"hour", timeDiff / 60 / 60 % 24},
    {"minut", timeDiff / 60 % 60},
    {"second", timeDiff % 60}
  }

  local out = {}
    for k, t in ipairs(dateFormat) do
      local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #dateFormat and (#out > 0 and ', ' or '') or ' y ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
  local ret = table.concat(out)
    if ret:len() < 16 and ret:find("second") then
      local a, b = ret:find(" y ")
      ret = ret:sub(b+1)
    end
  return ret
end



here on item.cpp:

Code:
    if(it.showDuration)
    {
        if(item && item->hasIntegerAttribute("duration"))
        {
            int32_t duration = item->getDuration() / 1000;
            s << " that has energy for ";

            if(duration >= 120)
                s << duration / 60 << " minutes left";
            else if(duration > 60)
                s << "1 minute left";
            else
                s << " less than a minute left";
        }
        else
            s << " that is brand-new";
    }

any have idea?
 
First you need to decide what you want to do.

actuality items with long duration show here:
18:34 You see a private spawn ticket that has energy for 2762 minutes left.
It weighs 1.00 oz.

want show here:
18:34 You see a private spawn ticket that has energy for 1 day, 20 hours, 10 minutes and 40 sec left.
It weighs 1.00 oz.
 
That's why I ask for help, because I do not know convert that code to C ++ -.-
That's not what you asked for.
Anyway, it shouldnt be hard to find someone to help you, all you need is some basics and math, I am on mobile atm so I cant help you much..
 
could do it in pure lua by creating your own onLook format
check for duration attribute and if it has one, add it to description
 
Code:
    if (it.showDuration) {
        if (item && item->hasIntegerAttribute("duration")) { 
            uint32_t duration = item->getDuration() / 1000;
            s << " that will expire in ";

            if (duration >= 86400) {
                uint16_t days = duration / 86400;
                uint16_t hours = (duration % 86400) / 3600;
                s << days << " day" << (days != 1 ? "s" : "");

                if (hours > 0) {
                    s << " and " << hours << " hour" << (hours != 1 ? "s" : "");
                }
            } else if (duration >= 3600) {
                uint16_t hours = duration / 3600;
                uint16_t minutes = (duration % 3600) / 60;
                s << hours << " hour" << (hours != 1 ? "s" : "");

                if (minutes > 0) {
                    s << " and " << minutes << " minute" << (minutes != 1 ? "s" : "");
                }
            } else if (duration >= 60) {
                uint16_t minutes = duration / 60;
                s << minutes << " minute" << (minutes != 1 ? "s" : "");
                uint16_t seconds = duration % 60;

                if (seconds > 0) {
                    s << " and " << seconds << " second" << (seconds != 1 ? "s" : "");
                }
            } else {
                s << duration << " second" << (duration != 1 ? "s" : "");
            }
        } else {
            s << " that is brand-new";
        }
    }
 
Code:
    if (it.showDuration) {
        if (item && item->hasIntegerAttribute("duration")) {
            uint32_t duration = item->getDuration() / 1000;
            s << " that will expire in ";

            if (duration >= 86400) {
                uint16_t days = duration / 86400;
                uint16_t hours = (duration % 86400) / 3600;
                s << days << " day" << (days != 1 ? "s" : "");

                if (hours > 0) {
                    s << " and " << hours << " hour" << (hours != 1 ? "s" : "");
                }
            } else if (duration >= 3600) {
                uint16_t hours = duration / 3600;
                uint16_t minutes = (duration % 3600) / 60;
                s << hours << " hour" << (hours != 1 ? "s" : "");

                if (minutes > 0) {
                    s << " and " << minutes << " minute" << (minutes != 1 ? "s" : "");
                }
            } else if (duration >= 60) {
                uint16_t minutes = duration / 60;
                s << minutes << " minute" << (minutes != 1 ? "s" : "");
                uint16_t seconds = duration % 60;

                if (seconds > 0) {
                    s << " and " << seconds << " second" << (seconds != 1 ? "s" : "");
                }
            } else {
                s << duration << " second" << (duration != 1 ? "s" : "");
            }
        } else {
            s << " that is brand-new";
        }
    }

2dui7ar.png


It works perfectly, I'm very grateful to you.
 

Similar threads

Back
Top