• 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 setfrags error

Amiroslo

Excellent OT User
Joined
Jul 28, 2009
Messages
6,801
Solutions
6
Reaction score
809
Code:
[19:46:32.485] [Error - CreatureScript Interface]
[19:46:32.485] data/creaturescripts/scripts/login.lua:onLogin
[19:46:32.485] Description:
[19:46:32.486] data/lib/050-function.lua:3: attempt to call global 'getPlayerFra
gs' (a nil value)
[19:46:32.486] stack traceback:
[19:46:32.486]  data/lib/050-function.lua:3: in function 'setFrags'
[19:46:32.486]  data/creaturescripts/scripts/login.lua:67: in function <data/cre
aturescripts/scripts/login.lua:6>

050-function.lua
LUA:
function setFrags(cid)
if not isCreature(cid) then return LUA_ERROR end
setPlayerStorageValue(cid, 824544, getPlayerFrags(cid))
return doPlayerSave(cid)
end

login.lua
brefore return true i added this
LUA:
	registerCreatureEvent(cid, "Rankfrags")
	setFrags(cid)
 
LUA:
function setFrags(cid, amount) -- Ex. setFrags(cid, 5)
	if not isCreature(cid) then return LUA_ERROR end
		setPlayerStorageValue(cid, 824544, amount)
	return doPlayerSave(cid)
end
 
add in lib/050-function

LUA:
function getPlayerFrags(cid)
    local time = os.time()
    local times = {today = (time - 86400), week = (time - (7 * 86400))}
    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")
    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
 
@up

Code:
[21:19:56.963] [Error - CreatureScript Interface]
[21:19:56.964] data/creaturescripts/scripts/login.lua:onLogin
[21:19:56.964] Description:
[21:19:56.964] data/creaturescripts/scripts/login.lua:67: attempt to call global
 'setFrags' (a nil value)
[21:19:56.965] stack traceback:
[21:19:56.965]  data/creaturescripts/scripts/login.lua:67: in function <data/cre
aturescripts/scripts/login.lua:6>
 
In data/lib/050-function.lua add this too:

Code:
function setFrags(cid)
if not isCreature(cid) then return LUA_ERROR end
setPlayerStorageValue(cid, 824544, getPlayerFrags(cid))
return doPlayerSave(cid)
end
 
Back
Top