• 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 Can somebody tell me how to convert this script from tfs 0.4 to 1.5?

johnsamir

Advanced OT User
Joined
Oct 13, 2009
Messages
960
Solutions
6
Reaction score
164
Location
Nowhere
As title says. can someone tell me how do i convert this script from 0.4 to 1.5?
this is the normal script
Lua:
local storage = 54321
function onKill(cid, target)
    local frags = getPlayerStorageValue(cid, storage)
    if(isPlayer(target)) then
        setPlayerStorageValue(cid, storage, frags+1)
        if(frags == 1) then
            doCreatureSetSkullType(cid, SKULL_YELLOW)
        elseif(frags >= 2 and frags <= 4) then
            doCreatureSetSkullType(cid, SKULL_GREEN)
        elseif(frags >= 5 and frags <= 6) then
            doCreatureSetSkullType(cid, SKULL_WHITE)
        elseif(frags => 7) then
            doCreatureSetSkullType(cid, SKULL_RED)
        end
    end
    return true
end
know that cid isn't used anymore altough tfs 1.5 can handle it, changed cid to player but it hasn't worked either
also i saw this but it's not much explainatory


thank
 
First thing you want to do is find the new onKill parameters
Lua:
local killevent = CreatureEvent("onKill_EventName")

function killevent.onKill(player, target)

	return true
end

killevent:register()
After that, you just start plugging in your stuff that needs converting.
Which essentially is these couple of lines
Lua:
local storage = 54321
local frags = getPlayerStorageValue(cid, storage)
if(isPlayer(target)) then
setPlayerStorageValue(cid, storage, frags+1)
doCreatureSetSkullType(cid, SKULL_YELLOW)
Lua:
local storage = 54321
local frags = player:getStorageValue(storage)
if target:isPlayer() then
player:setStorageValue(storage, frags + 1)
creature:setSkull(SKULL_YELLOW)

and then you just plug it into the code.
Lua:
local storage = 54321

local killevent = CreatureEvent("onKill_EventName")

function killevent.onKill(player, target)
	local frags = player:getStorageValue(storage)
	if target:isPlayer() then
		player:setStorageValue(storage, frags + 1)
		if frags == 1 then
			player:setSkull(SKULL_YELLOW)
		elseif frags >= 2 and frags <= 4 then
			player:setSkull(SKULL_GREEN)
		elseif frags >= 5 and frags <= 6 then
			player:setSkull(SKULL_WHITE)
		elseif frags >= 7 then
			player:setSkull(SKULL_RED)
		end
	end
	return true
end

killevent:register()

And cuz I'm extra nice, here's how you'd do it with a table.
Lua:
local storage = 54321
local fragSkulls = {
	[{1, 1}] = SKULL_YELLOW,
	[{2, 4}] = SKULL_GREEN,
	[{5, 6}] = SKULL_WHITE,
	[{7, 999}] = SKULL_RED
}

local killevent = CreatureEvent("onKill_EventName")

function killevent.onKill(player, target)
	if target:isPlayer() then
		local frags = player:getStorageValue(storage)
		player:setStorageValue(storage, frags + 1)
		for v, k in pairs(fragSkulls) do
			if frags >= v[1] and frags <= v[2] then
				player:setSkull(k)
				break
			end
		end
	end
	return true
end

killevent:register()
 
Thank you a lot. have placed the script inside data/scripts/creatureevents but players are not gaining skull at the first frags and ain't recieving no errors in console. it should be placed somewhere else?
 
Thank you a lot. have placed the script inside data/scripts/creatureevents but players are not gaining skull at the first frags and ain't recieving no errors in console. it should be placed somewhere else?
data/scripts

I converted it to revscript
 
not working sadly dont know what could be wrong skull sending to the client were removed from player.cpp
https://ghostbin.com/6YTBk and plaed the newer script inside data/scripts
i didn't removed frags counting
Lua:
void Player::addUnjustifiedDead(const Player* attacked)
{
    if (hasFlag(PlayerFlag_NotGainInFight) || attacked == this || g_game.getWorldType() == WORLD_TYPE_PVP_ENFORCED) {
        return;
    }

    sendTextMessage(MESSAGE_EVENT_ADVANCE, "Warning! The murder of " + attacked->getName() + " was not justified.");

    skullTicks += g_config.getNumber(ConfigManager::FRAG_TIME);

    /*if (getSkull() != SKULL_BLACK) {
        if (g_config.getNumber(ConfigManager::KILLS_TO_BLACK) != 0 && skullTicks > (g_config.getNumber(ConfigManager::KILLS_TO_BLACK) - 1) * static_cast<int64_t>(g_config.getNumber(ConfigManager::FRAG_TIME))) {
            setSkull(SKULL_BLACK);
and im even recieving the frag count
Code:
21:23 Warning! The murder of Cangaceiiiro was not justified.
but still haven't recivied skull nor error in console.
EDIT: TRIED CHANGING PVP TYPE to pvp-enforced and nothing either, ideas?
 
Last edited:
not working sadly dont know what could be wrong skull sending to the client were removed from player.cpp
https://ghostbin.com/6YTBk and plaed the newer script inside data/scripts
i didn't removed frags counting
Lua:
void Player::addUnjustifiedDead(const Player* attacked)
{
    if (hasFlag(PlayerFlag_NotGainInFight) || attacked == this || g_game.getWorldType() == WORLD_TYPE_PVP_ENFORCED) {
        return;
    }

    sendTextMessage(MESSAGE_EVENT_ADVANCE, "Warning! The murder of " + attacked->getName() + " was not justified.");

    skullTicks += g_config.getNumber(ConfigManager::FRAG_TIME);

    /*if (getSkull() != SKULL_BLACK) {
        if (g_config.getNumber(ConfigManager::KILLS_TO_BLACK) != 0 && skullTicks > (g_config.getNumber(ConfigManager::KILLS_TO_BLACK) - 1) * static_cast<int64_t>(g_config.getNumber(ConfigManager::FRAG_TIME))) {
            setSkull(SKULL_BLACK);
and im even recieving the frag count
Code:
21:23 Warning! The murder of Cangaceiiiro was not justified.
but still haven't recivied skull nor error in console.
EDIT: TRIED CHANGING PVP TYPE to pvp-enforced and nothing either, ideas?
Oh I see.

So the problem is probably that you haven't registered the script the player.

So let's rectify that.

Lua:
local storage = 54321
local fragSkulls = {
	[{1, 1}] = SKULL_YELLOW,
	[{2, 4}] = SKULL_GREEN,
	[{5, 6}] = SKULL_WHITE,
	[{7, 999}] = SKULL_RED
}

local killevent = CreatureEvent("onKill_EventName")

function killevent.onKill(player, target)
	if target:isPlayer() then
		local frags = player:getStorageValue(storage)
		player:setStorageValue(storage, frags + 1)
		for v, k in pairs(fragSkulls) do
			if frags >= v[1] and frags <= v[2] then
				player:setSkull(k)
				break
			end
		end
	end
	return true
end

killevent:register()



local login = CreatureEvent("onLogin_EventName")

function login.onLogin(player)
	player:registerEvent("onKill_EventName")	
	return true
end

login:register()
 
Oh I see.

So the problem is probably that you haven't registered the script the player.

So let's rectify that.

Lua:
local storage = 54321
local fragSkulls = {
    [{1, 1}] = SKULL_YELLOW,
    [{2, 4}] = SKULL_GREEN,
    [{5, 6}] = SKULL_WHITE,
    [{7, 999}] = SKULL_RED
}

local killevent = CreatureEvent("onKill_EventName")

function killevent.onKill(player, target)
    if target:isPlayer() then
        local frags = player:getStorageValue(storage)
        player:setStorageValue(storage, frags + 1)
        for v, k in pairs(fragSkulls) do
            if frags >= v[1] and frags <= v[2] then
                player:setSkull(k)
                break
            end
        end
    end
    return true
end

killevent:register()



local login = CreatureEvent("onLogin_EventName")

function login.onLogin(player)
    player:registerEvent("onKill_EventName")  
    return true
end

login:register()
this should work even with pvp-enforced worldtype on right? because i'm still get no skull
tested with clean datapack /clean sources it won't work
also tested with clean daptack + pvp worldtype but skull sending removed from sources(player.cpp)
still doesn't work and get no source, might be something missing?
tfs 1.x is super different than than tfs 0.4


thank xikini for your help
Post automatically merged:

i figured out that maybe should register fragskull storages at data/lib/core/storages.lua
it looks like this now:
Lua:
--[[
Reserved storage ranges:
- 300000 to 301000+ reserved for achievements
- 20000 to 21000+ reserved for achievement progress
- 10000000 to 20000000 reserved for outfits and mounts on source
]]--
PlayerStorageKeys = {
    fragSkulls = 67541. --agregado war skulls
    annihilatorReward = 30015,
    promotion = 30018,
    delayLargeSeaShell = 30019,
    firstRod = 30020,
    delayWallMirror = 30021,
    madSheepSummon = 30023,
    crateUsable = 30024,
    afflictedOutfit = 30026,
    afflictedPlagueMask = 30027,
    afflictedPlagueBell = 30028,
    nailCaseUseCount = 30031,
    swampDigging = 30032,
    insectoidCell = 30033,
    vortexTamer = 30034,
    mutatedPumpkin = 30035,
    achievementsBase = 300000,
    achievementsCounter = 20000,
}

GlobalStorageKeys = {
}

no luck yet, help!
 
Last edited:
Back
Top