• 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 functions.lua & frags.lua-talkaction [0.6.3 - OTH 7.72]

Okke

Retired
Joined
Jul 19, 2015
Messages
1,009
Solutions
23
Reaction score
632
Location
germany
Hello lovely OTLanders,

I implemented a new frag system on my sources a few days ago, it should work like it does on Avesta (Instead of saving frags by Day, Week and Month, it counts a frag, then releases through "timeToDecreaseFrags" and yea, thats it).

The source edit was successful and it is working (counting and decreasing frags). It can just not be shown ingame. Unfortunatelly the repository with the code I implemented on my server had no functions.lua and no frags.lua talkacion, and I've been looking for days without a success to find something that will actually work.

Enough talk, here are my scripts, I hope you guys can help me.

data/functions.lua

Code:
function getPlayerFrags(cid)
local time = os.time()
local times = {today = (time - 86400), week = (time - (7 * 86400))}

--OLD--local contents, result = {day = {}, week = {}, month = {}}, db.getResult("SELECT `pd`.`date`, `pd`.`level`, `p`.`name` FROM `player_killers` pk LEFT JOIN `killers` k ON `pk`.`kill_id` = `k`.`id` LEFT JOIN `player_deaths` pd ON `k`.`death_id` = `pd`.`id` LEFT JOIN `players` p ON `pd`.`player_id` = `p`.`id` WHERE `pk`.`player_id` = " .. getPlayerGUID(cid) .. " AND `k`.`unjustified` = 1 AND `pd`.`date` >= " .. (time - (30 * 86400)) .. " ORDER BY `pd`.`date` DESC")
local contents, result = {day = {}, week = {}, month = {}}, db.getResult("SELECT `pd`.`date`, `pd`.`level`, `p`.`name` FROM `player_killers` pk LEFT JOIN `killers` k ON `pk`.`kill_id` = `k`.`id` LEFT JOIN `player_deaths` pd ON `k`.`death_id` = `pd`.`id` LEFT JOIN `players` p ON `pd`.`player_id` = `p`.`id` WHERE `pk`.`player_id` = " .. getPlayerGUID(cid) .. " AND `pd`.`date` >= " .. (time - (30 * 86400)) .. " ORDER BY `pd`.`date` DESC")
if(result:getID() ~= -1) then
repeat
local content = {date = result:getDataInt("date")}
if(content.date > times.today) then
table.insert(contents.day, content)
elseif(content.date > times.week) then
table.insert(contents.week, content)
else
table.insert(contents.month, content)
end
until not result:next()
result:free()
end

local size = {
day = table.maxn(contents.day),
week = table.maxn(contents.week),
month = table.maxn(contents.month)
}

return size.day + size.week + size.month
end

data/talkactions/scripts/frags.lua

Code:
local config = {
    fragTime = getConfigInfo('timeToDecreaseFrags')
}

function onSay(cid, words, param)
    local amount = getPlayerFrags(cid)
    --if(amount > 0 and config.fragTime > 0) then
        if(getPlayerFrags(cid) > 0 and config.fragTime > 0) then
        local frags = math.floor((amount / config.fragTime) + 1)
        local remainingTime = math.floor(amount - (config.fragTime * (frags - 1)))

        local hours = math.floor(((remainingTime / 1000) / 60) / 60)
        local minutes = math.floor(((remainingTime / 1000) / 60) - (hours * 60))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have " .. frags .. " unjustified frag" .. (frags > 2 and "s" or "") .. ". The amount of unjustified frags will decrease after: " .. hours .. "h and " .. minutes .. "m.")
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You do not have any unjustified frag.")  
    end
    return false
end

If you see it right, there are a few commented lines, I've been testing without success - I'm not good with queries & lua.

A note: the functions.lua getPlayerFrags(cid) worked with the unedited sources (days, weeks, months), so It probably fetches the kill from the right place on my Database, this could help, now that's all I know, I'm helpless.

Thank you in advance and the kindest Regards,

Okke.
 
giphy.gif
 
No it doesn't.

It's probably on functions.lua, since it's using the old script (getPlayerFrags) to fetch data from the database in a wrong format :D

And I suck at lua with DB-Queries.
 
I think on my sources they're called skullTicks.

And no, I haven't got any I guess, I implemented it from avesta sources.

Edit: btw I think I added this:

Code:
void Player::checkRedSkullTicks(int32_t ticks)
{
if(redSkullTicks - ticks > 0)
redSkullTicks = redSkullTicks - ticks;

if(redSkullTicks < 1000 && !hasCondition(CONDITION_INFIGHT) && skull != SKULL_NONE){
setSkull(SKULL_NONE);
g_game.updateCreatureSkull(this);
}
}
 
I think on my sources they're called skullTicks.

And no, I haven't got any I guess, I implemented it from avesta sources.
Avesta got redSkullTicks, TFS call them skullTicks instead.
You should write a function to read redskullticks, it is important for the talkaction part.
I doubt you have commands.cpp/h?

Edit:
You should be able to use something like..
Code:
case PlayerInfoRedSkullTicks:
{
lua_pushnumber(L, player->redSkullTicks());
return 1;
}
later you can use:
Code:
frags = (getRedSkullTicks(cid) /fragTime ) + 1;
(taken from source part from avesta, not sure if 100%)
 
I think I added that aswell, I'll take a detailed look @ my sources tonight.

I found this aswell:

Code:
function onSay(player, words, param)
   local fragTime = configManager.getNumber(configKeys.FRAG_TIME)
   if fragTime <= 0 then
     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have any unjustified kill.")
     return false
   end

   local skullTime = player:getSkullTime()
   if skullTime <= 0 then
     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have any unjustified kill.")
     return false
   end

   local kills = math.ceil(skullTime / fragTime)
   local remainingSeconds = math.floor((skullTime % fragTime) / 1000)

   local hours = math.floor(remainingSeconds / 3600)
   local minutes = math.floor((remainingSeconds % 3600) / 60)
   local seconds = remainingSeconds % 60

   local message = "You have " .. kills .. " unjustified kill" .. (kills > 1 and "s" or "") .. ". The amount of unjustified kills will decrease after: "
   if hours ~= 0 then
     if hours == 1 then
       message = message .. hours .. " hour, "
     else
       message = message .. hours .. " hours, "
     end
   end

   if hours ~= 0 or minutes ~= 0 then
     if minutes == 1 then
       message = message .. minutes .. " minute and "
     else
       message = message .. minutes .. " minutes and "
     end
   end

   if seconds == 1 then
     message = message .. seconds .. " second."
   else
     message = message .. seconds .. " seconds."
   end

   player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
   return false
end
 
I think I added that aswell, I'll take a detailed look @ my sources tonight.

I found this aswell:

Code:
function onSay(player, words, param)
   local fragTime = configManager.getNumber(configKeys.FRAG_TIME)
   if fragTime <= 0 then
     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have any unjustified kill.")
     return false
   end

   local skullTime = player:getSkullTime()
   if skullTime <= 0 then
     player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You do not have any unjustified kill.")
     return false
   end

   local kills = math.ceil(skullTime / fragTime)
   local remainingSeconds = math.floor((skullTime % fragTime) / 1000)

   local hours = math.floor(remainingSeconds / 3600)
   local minutes = math.floor((remainingSeconds % 3600) / 60)
   local seconds = remainingSeconds % 60

   local message = "You have " .. kills .. " unjustified kill" .. (kills > 1 and "s" or "") .. ". The amount of unjustified kills will decrease after: "
   if hours ~= 0 then
     if hours == 1 then
       message = message .. hours .. " hour, "
     else
       message = message .. hours .. " hours, "
     end
   end

   if hours ~= 0 or minutes ~= 0 then
     if minutes == 1 then
       message = message .. minutes .. " minute and "
     else
       message = message .. minutes .. " minutes and "
     end
   end

   if seconds == 1 then
     message = message .. seconds .. " second."
   else
     message = message .. seconds .. " seconds."
   end

   player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, message)
   return false
end

Useless, since you do not use meta's or even have functions such as getSkullTime (doubt you got this)

Your code is very well so far, I have been using one that is similar to yours, I'm using getRedSkullTicks instead to read out the frags.
 
Back
Top