• 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 Frag Remove

Esbuma

New Member
Joined
Apr 19, 2017
Messages
21
Reaction score
1
I have these script to when you use a item remove your frags and skull(only work for red and black skull)

Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)

    if isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
        player:setSkull(SKULL_NONE)
        player:setSkullTime(0)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your skull has been removed!")
        db.query("UPDATE `player_deaths` SET `unjustified` = 0 WHERE `unjustified` = 1 AND `killed_by` = " .. db.escapeString(player:getName()))
        item:remove(1)
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only remove red or black skulls!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
  
    return true
end

The problem is, if you are black skull or red skull and use the item, you lose your skull, but if afther that you kill 1 player you go to black/red skull again?

How can i fix that? Because if the script remove the frags you should need to kill 12 player(is how my confg.lua is setup)

These is my config.lua on the kill part
Code:
timeToDecreaseFrags = 4 * 60 * 60 * 1000
whiteSkullTime = 15 * 60 * 1000
experienceByKillingPlayers = false
expFromPlayersLevelRange = 75
dayKillsToRedSkull = 8
dayKillsToBlackSkull = 12
blackSkulledDeathHealth = 40
blackSkulledDeathMana = 0
useBlackSkull = true
redSkullDuration = 30
blackSkullDuration = 45
orangeSkullDuration = 7
 
Last edited:
So..i tested here the frag remove works fine..he removes the unjistified kills from the player_deth table....

the problem is that...in some other place(idk where) the daily kills keep geting storege so after i kill again after using the skull remove, even if in the table players_deth show that i got 0 kill, it counts that i have passed the daily limit of kills and gave me the skulls back.

So the question is...where is that the dailykills is storage?where is that file?

These is just a teory...idk if is true...but it was the only thing i could find.

Other thing some ppl say something about a creaturscript/frags.lua...i dont have these file...could be it?The places i found about the file was for showing frags when you look the player
 
Sorry, where i do that?
Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    if isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
        player:setSkull(SKULL_NONE)
        player:setSkullTime(0)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your skull has been removed!")
        db.query("UPDATE `player_deaths` SET `unjustified` = 0 WHERE `unjustified` = 1 AND `killed_by` = " .. db.escapeString(player:getName()))
        item:remove(1)
        player:remove()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only remove red or black skulls!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return true
end

The player will logout and save
 
Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    if isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
        player:setSkull(SKULL_NONE)
        player:setSkullTime(0)
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your skull has been removed!")
        db.query("UPDATE `player_deaths` SET `unjustified` = 0 WHERE `unjustified` = 1 AND `killed_by` = " .. db.escapeString(player:getName()))
        item:remove(1)
        player:remove()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only remove red or black skulls!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return true
end

The player will logout and save

I did that and still heve the same problem...after i log back in...1 kill and go to red skull again
 

If we look at the schema we got this;
SQL:
CREATE TABLE `player_deaths` (
  `player_id` int(11) NOT NULL,
  `time` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
  `level` int(11) NOT NULL DEFAULT '1',
  `killed_by` varchar(255) NOT NULL,
  `is_player` tinyint(1) NOT NULL DEFAULT '1',
  `mostdamage_by` varchar(100) NOT NULL,
  `mostdamage_is_player` tinyint(1) NOT NULL DEFAULT '0',
  `unjustified` tinyint(1) NOT NULL DEFAULT '0',
  `mostdamage_unjustified` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Unjustified is set to 0 and thats the only thing we "should" change if we still want the kills on our website.
So we move on to the source code (where we give the player the red skull).
There we find this; forgottenserver/player.cpp at 5ba1ef3926695237a8da3d969bd99e779a0ae7f1 · otland/forgottenserver · GitHub
C++:
} else if (getSkull() != SKULL_RED && g_config.getNumber(ConfigManager::KILLS_TO_RED) != 0 && skullTicks > (g_config.getNumber(ConfigManager::KILLS_TO_RED) - 1) * static_cast<int64_t>(g_config.getNumber(ConfigManager::FRAG_TIME))) {
     setSkull(SKULL_RED);
}

What we wanna look at is this;
Lua:
skullTicks > (g_config.getNumber(ConfigManager::KILLS_TO_RED) - 1) * static_cast<int64_t>(g_config.getNumber(ConfigManager::FRAG_TIME)
We see that the server is trying to compare the skullTicks to the amount we need to set the red skull.

So to fix the problem we need to set that value (skullTicks / skullTime, located in the player table) to 0
SQL:
  `skulltime` int(11) NOT NULL DEFAULT '0',

Add this below the other query;
Lua:
db.query("UPDATE `players` SET `skulltime` = 0 WHERE `id` = " .. player:getGuid())
 
does not work using the unjustified points system, just remove the red or black skull.
and if you kill 1 player returns red or black skull
 
I just did and nothing.

I just send u PM

Missed that there already was a reset for the skullTime, but give this a try, check the database if the player has any unjusts or if the skullTime is over 0
Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    if isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your skull has been removed!")

        player:setSkull(SKULL_NONE)
        db.query("UPDATE `player_deaths` SET `unjustified` = 0 WHERE `unjustified` = 1 AND `killed_by` = " .. db.escapeString(player:getName()))
        player:setSkullTime(0)
        item:remove(1)
        player:save()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only remove red or black skulls!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return true
end
 
Missed that there already was a reset for the skullTime, but give this a try, check the database if the player has any unjusts or if the skullTime is over 0
Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    if isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your skull has been removed!")

        player:setSkull(SKULL_NONE)
        db.query("UPDATE `player_deaths` SET `unjustified` = 0 WHERE `unjustified` = 1 AND `killed_by` = " .. db.escapeString(player:getName()))
        player:setSkullTime(0)
        item:remove(1)
        player:save()
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only remove red or black skulls!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return true
end


So these is what i did...set the killtoredskull to 3(config.lua)
create 2 new characters.....
so i got 1 character kill the toher...after 2 kills(unjustified) the skulltime of that character in the database was still 0.
when i killd for 3 time.......i got to redskull...but in the database my skulltime and skull was still 0.

so i used the /save command in the god accont.
After that the skulltime has changed to a number and the skull to 4.
after that i used the item and my skulltime and skull got to 0.(like it was doing before)
after that i killed again, just 1, and got redskull again.

So everything is the same
 
First try this:

Lua:
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    if isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
       player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your skull has been removed!")

       player:setSkull(SKULL_NONE)
       db.query("UPDATE `player_deaths` SET `unjustified` = 0 WHERE `unjustified` = 1 AND `killed_by` = " .. db.escapeString(player:getName()))
       db.query("UPDATE `player_kills` SET `time` = 0 WHERE `player_id` = " .. player:getGuid())
       player:setSkullTime(0)
       item:remove(1)
       player:save()
    else
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only remove red or black skulls!")
       player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return true
end

And later try:

Lua:
db.query("DELETE FROM `player_kills` WHERE `player_id` = " .. player:getGuid())


Instead of:

Lua:
db.query("UPDATE `player_kills` SET `time` = 0 WHERE `player_id` = " .. player:getGuid())
 
Last edited:
Try this:

  1. Lua:
    function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
        if isInArray({SKULL_RED, SKULL_BLACK}, player:getSkull()) then
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your skull has been removed!")
    
            player:setSkull(SKULL_NONE)
            db.query("UPDATE `player_deaths` SET `unjustified` = 0 WHERE `unjustified` = 1 AND `killed_by` = " .. db.escapeString(player:getName()))
            db.query("UPDATE `player_kills` SET `time` = 0 WHERE `player_id` = " .. player:getGuid())
            player:setSkullTime(0)
            item:remove(1)
            player:save()
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only remove red or black skulls!")
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
        return true
    end

Or try:

Lua:
db.query("DELETE FROM `player_kills` WHERE `player_id` = " .. player:getGuid())


Instead of:

Lua:
db.query("UPDATE `player_kills` SET `time` = 0 WHERE `player_id` = " .. player:getGuid())

tryed both, and the problem is the same
 
Back
Top