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

Change Search Database

xLosT

Member
Joined
Jan 11, 2010
Messages
1,021
Reaction score
13
Location
Brasil, Rio Grande do Sul
need to get the result in
PHP:
('SELECT COUNT(*) as `frags`     
    FROM `killers` k 
    LEFT JOIN `player_killers` pk ON `k`.`id` = `pk`.`kill_id` 
    LEFT JOIN `players` p ON `pk`.`player_id` = `p`.`id` 
    WHERE `player_id` = '.$player->getId())->fetch();

for the skull result of


PHP:
local skulls = {
    [50] = 1, -- Yellow
    [150] = 2, -- Green
    [300] = 3, -- White
    [500] = 4, -- Red
    [800] = 5, -- Black
}
function onKill(cid, target, lastHit)
    if not(isPlayer(target)) then
        return true
    end
    if (getPlayerLevel(cid) - getPlayerLevel(target) < -50) then
        doCreatureSay(cid, getPlayerLevel(cid) - getPlayerLevel(target))
        return true
    end
    if (getPlayerStorageValue(cid, 27534) < 1) then
        setPlayerStorageValue(cid, 27534, 0)
    end
    setPlayerStorageValue(cid, 27534, getPlayerStorageValue(cid, 27534) + 1)
    local sku = 0
    local kills = getPlayerStorageValue(cid, 27534)
    for i, v in pairs(skulls) do
        if (kills >= i) and (i >= sku) then
            print(kills)
            sku = i
        end
    end
    if (sku ~= 0) then
        doCreatureSetSkullType(cid, skulls[sku])
    end
    return true
end
function onLogin(cid)
    local sku = 0
    for i, v in pairs(skulls) do
        if (getPlayerStorageValue(cid, 27534) >= i) and (getPlayerStorageValue(cid, 27534) >= sku) then
            sku = i
        end
    end
    if (sku ~= 0) then
        doCreatureSetSkullType(cid, skulls[sku])
    end
    registerCreatureEvent(cid, "KillSkull")
    return true
end
 
Can you explain where you need it in that script?

Why doesn't setPlayerStorageValue(cid, 27534, getPlayerStorageValue(cid, 27534) + 1) work to count the frags?
 
it works normal but the frags wrong account, see example below the player has 112 frags and this red skull, it should be yellow

PHP:
10:40 You see Payan (Level 149). He is a elder druid
He has Killed: [112] Players.
He has Died: [19] Times.

need to change to get the results it pro code in first post
 
Try this one out:
LUA:
local res = db.getResult("SELECT COUNT(*) as `frags` FROM `killers` k LEFT JOIN `player_killers` pk ON `k`.`id` = `pk`.`kill_id` LEFT JOIN `players` p ON `pk`.`player_id` = `p`.`id` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
if res:getID() ~= -1 then
	local frags = res:getDataInt("frags")
	res:free()
	-- do whatever you want with "frags" variable
else
	print("[Frags]::Could not get result for player '" .. getPlayerName(cid) .. "'")
end
 
I would guess you want it instead of kills so:

Replace:
LUA:
	local kills = getPlayerStorageValue(cid, 27534)
    for i, v in pairs(skulls) do
        if (kills >= i) and (i >= sku) then
            print(kills)
            sku = i
        end
    end

With:
LUA:
	local res = db.getResult("SELECT COUNT(*) as `frags` FROM `killers` k LEFT JOIN `player_killers` pk ON `k`.`id` = `pk`.`kill_id` LEFT JOIN `players` p ON `pk`.`player_id` = `p`.`id` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
	if res:getID() ~= -1 then
		local frags = res:getDataInt("frags")
		res:free()
		for i, v in pairs(skulls) do
			if (frags >= i) and (i >= sku) then
				print(frags)
				sku = i
			end
		end
	else
		print("[Frags]::Could not get result for player '" .. getPlayerName(cid) .. "'")
	end
 
there were some bugs, if you login for the first time and you have example 200 frags remained without skull, you kill someone picks up the skull and Green, but when you die back to the anterior skull would Yellow. and kill you back again to the Green

the bug is in check when the player's login

- - - Updated - - -

possible here

PHP:
function onLogin(cid)
    local sku = 0
    for i, v in pairs(skulls) do
        if (getPlayerStorageValue(cid, 27534) >= i) and (getPlayerStorageValue(cid, 27534) >= sku) then
            sku = i
        end
    end
 
LUA:
local skulls = {
    [50] = 1, -- Yellow
    [150] = 2, -- Green
    [300] = 3, -- White
    [500] = 4, -- Red
    [800] = 5, -- Black
}

function onKill(cid, target, lastHit)
    if not(isPlayer(target)) then
        return true
    end
    if (getPlayerLevel(cid) - getPlayerLevel(target) < -50) then
        doCreatureSay(cid, getPlayerLevel(cid) - getPlayerLevel(target))
        return true
    end
    if (getPlayerStorageValue(cid, 27534) < 1) then
        setPlayerStorageValue(cid, 27534, 0)
    end
    setPlayerStorageValue(cid, 27534, getPlayerStorageValue(cid, 27534) + 1)
    local sku = 0
    local kills = getPlayerStorageValue(cid, 27534)
    for i, v in pairs(skulls) do
        if (kills >= i) and (i >= sku) then
            print(kills)
            sku = i
        end
    end
    if (sku ~= 0) then
        doCreatureSetSkullType(cid, skulls[sku])
    end
    return true
end

function onLogin(cid)
	local sku = 0
    local frags = 0
	local res = db.getResult("SELECT COUNT(*) as `frags` FROM `killers` k LEFT JOIN `player_killers` pk ON `k`.`id` = `pk`.`kill_id` LEFT JOIN `players` p ON `pk`.`player_id` = `p`.`id` WHERE `player_id` = " .. getPlayerGUID(cid) .. ";")
	if res:getID() ~= -1 then
		frags = res:getDataInt("frags")
		res:free()
	else
		print("[Frags]::Could not get result for player '" .. getPlayerName(cid) .. "'")
	end
	
    for i, v in pairs(skulls) do
        if (frags >= i) and (i >= sku) then
            sku = i
        end
    end
	setPlayerStorageValue(cid, 27534, frags)
    if (sku ~= 0) then
        doCreatureSetSkullType(cid, skulls[sku])
    end
    registerCreatureEvent(cid, "KillSkull")
    return true
end
 
Back
Top