• 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 get condition ticks

Xagul

deathzot.net
Joined
Jun 30, 2008
Messages
1,295
Solutions
3
Reaction score
1,043
I am trying to get the ticks remaining on a condition and after looking through the lua script it seems "getCreatureCondition" only returns true if you have a condition and false if not. What I am looking for is somthing like this:

Code:
conditionticks = getCreatureCondition(cid, CONDITION_EXHAUST, 2).ticks

message to player: You are still exhausted for 5 seconds.

Is there any way to do this? I am currently using 0.4 r3884.
 
Yea, I kinda wanted to stray away from using storage for exhaust :( was hoping maybe someone had made a function that I could add into the source for example: getConditionTicks(condition, type, subid)
 
[cpp]int32_t LuaScriptInterface::luaGetConditionEnd(lua_State* L)
{
//getConditionEnd(cid, condition[, subId])
int32_t subId = 0, condition = 0;
if(lua_gettop(L) > 2)
subId = popNumber(L);

condition = (ConditionType_t)popNumber(L);
ScriptEnviroment* env = getEnv();
if(Creature* creature = env->getCreatureByUID(popNumber(L))) {
ConditionList tmpList = creature->conditions;
for(ConditionList::iterator it = tmpList.begin(); it != tmpList.end(); ++it)
{
if((*it)->getType() != condition || (subId != -1 && (*it)->getSubId() != (uint32_t)subId))
continue;

if(!(*it)->getEndTime())
lua_pushboolean(L, false);
else
lua_pushnumber(L, (*it)->getEndTime());

return 1;
}
}
else
errorEx(getError(LUA_ERROR_CREATURE_NOT_FOUND));

lua_pushboolean(L, false);
return 1;
}[/cpp]
condition end is unix timestamp in milliseconds matching the time this condition expires, so you'll have to divide it by 1000 and compare with os.time() :p

LUA:
doPlayerSendCancel(cid, 'Seconds left: ' .. getConditionEnd(cid, CONDITION_EXHAUST, EXHAUST_HEALING) / 1000 - os.time())
you might also want to use math.ceil or math.floor on the result because it mostly won't be a whole number
 
Last edited:
Back
Top