• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua init-start-record lua

Onizuka

Member
Joined
Jul 5, 2008
Messages
2,291
Reaction score
14
LUA:
data/globalevents/scripts/start.lua:2: attempt to call field 'query' (a nil value)

LUA:
data/globalevents/scripts/start.lua:2: attempt to call field 'executeQuery' (a nil value)


tried both but no luck.
Any ideas what needs to be changed or source edited?
tfs 0.4 3671
 
it is low case ;l
LUA:
function onStartup()
	db.query("UPDATE `players` SET `online` = 0 WHERE `world_id` = " .. getConfigValue('worldId') .. ";")

and still error :(
 
IMO this script isn't important, at least my server was good without it :D

Set it to this
LUA:
function onStartup()
	db.query("UPDATE `players` SET `online` = 0 WHERE `world_id` = 0;")
(Change last 0 to world id, if you've got 1 server then it's probably 0)
 
How did you do? help me please!!

Code:
[Error - GlobalEvent Interfac]
data/globalevents/scripts/init.lua:OnStartup
Description:
data/globalevents/scripts/init.lua:78: attempt to call field 'executeQuery' <a nil value>
stack traceback:
data/globalevents/scripts/init.lua:78: in function <data/globalevents/scripts/init.lua:8>

This is my Init.Lua:
PHP:
local config = {
	creationTime = 7 * 86400,
	checkTime = 7 * 86400,
	viceCount = 4,
	memberCount = 10
}

function onStartup()
	local data, time, result = {}, os.time(), db.getResult("SELECT `id`, `ownerid`, `creationdata`, `checkdata` FROM `guilds` WHERE `world_id` = " .. getConfigValue('worldId') .. ";")
	if(result:getID() ~= -1) then
		repeat
			data[result:getDataInt("id")] = {result:getDataInt("ownerid"), result:getDataInt("creationdata"), result:getDataInt("checkdata")}
		until not(result:next())
		result:free()
	end

	for id, v in ipairs(data) do
		local owner, created, check = v[1], v[2], v[3]
		if(created < (time - config.creationTime)) then
			result = db.getResult("SELECT `id`, `level` FROM `guild_ranks` WHERE `guild_id` = " .. id .. ";")
			if(result:getID() ~= -1) then
				local rank, ranks = 0, {}
				repeat
					ranks[result:getDataInt("id")] = result:getDataInt("level")
					if(result:getDataInt("level") == 1) then
						rank = result:getDataInt("id")
					end
				until not(result:next())
				result:free()

				local members = {0, 0, 0, 0}
				for k, v in ipairs(ranks) do
					result = db.getResult("SELECT COUNT(`id`) AS `count` FROM `players` WHERE `rank_id` = " .. k .. ";")
					if(result:getID() ~= -1) then
						members[v] = members[v] + result:getDataInt("count")
						result:free()
					end

					if(v == 2) then
						result = db.getResult("SELECT `p`.`id` FROM `players` p LEFT JOIN `accounts` a ON `p`.`account_id` = `a`.`id` WHERE `p`.`rank_id` = " .. k .. " AND (`a`.`premdays` = 0 OR (`a`.`lastday` + (`a`.`premdays` * 86400) <= 0));")
						if(result:getID() ~= -1) then
							local demote = ""
							repeat
								demote = demote .. result:getDataInt("id") .. ","
								members[2] = members[2] - 1
								members[1] = members[1] + 1
							until not(result:next())
							result:free()

							if(demote ~= "" and rank ~= 0) then
								db.executeQuery("UPDATE `players` SET `rank_id` = " .. rank .. " WHERE `id` IN (" .. demote:sub(1, -2) .. ");")
							end
						end
					end
				end

				for i = 1, 3 do
					members[4] = members[4] + members[i]
				end

				if(members[2] < config.viceCount or members[4] < config.memberCount) then
					if(check == 0) then
						db.executeQuery("UPDATE `guilds` SET `checkdata` = " .. (time + config.checkTime) .. " WHERE `id` = " .. id .. ";")
					elseif(check < time) then
						local tmp = ""
						for rank, _ in ipairs(ranks) do
							tmp = tmp .. rank .. ","
						end

						db.executeQuery("UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (" .. tmp:sub(1, -2) .. ");")
						db.executeQuery("DELETE FROM `guilds` WHERE `id` = " .. id .. ";")
					end
				end
			end
		end
	end

	db.executeQuery("UPDATE `players` SET `online` = 0 WHERE `world_id` = 0;")
	return true
end

function onGlobalSave()
	if(getGameState() ~= GAMESTATE_CLOSING) then
		return onStartup()
	end

	return true
end
 
use this one
LUA:
local config = {
    creationTime = 7 * 86400,
    checkTime = 7 * 86400,
    viceCount = 4,
    memberCount = 10
}

function onStartup()
    local data, time, result = {}, os.time(), db.getResult("SELECT `id`, `ownerid`, `creationdata`, `checkdata` FROM `guilds` WHERE `world_id` = " .. getConfigValue('worldId') .. ";")
    if(result:getID() ~= -1) then
        repeat
            data[result:getDataInt("id")] = {result:getDataInt("ownerid"), result:getDataInt("creationdata"), result:getDataInt("checkdata")}
        until not(result:next())
        result:free()
    end

    for id, v in ipairs(data) do
        local owner, created, check = v[1], v[2], v[3]
        if(created < (time - config.creationTime)) then
            result = db.getResult("SELECT `id`, `level` FROM `guild_ranks` WHERE `guild_id` = " .. id .. ";")
            if(result:getID() ~= -1) then
                local rank, ranks = 0, {}
                repeat
                    ranks[result:getDataInt("id")] = result:getDataInt("level")
                    if(result:getDataInt("level") == 1) then
                        rank = result:getDataInt("id")
                    end
                until not(result:next())
                result:free()

                local members = {0, 0, 0, 0}
                for k, v in ipairs(ranks) do
                    result = db.getResult("SELECT COUNT(`id`) AS `count` FROM `players` WHERE `rank_id` = " .. k .. ";")
                    if(result:getID() ~= -1) then
                        members[v] = members[v] + result:getDataInt("count")
                        result:free()
                    end

                    if(v == 2) then
                        result = db.getResult("SELECT `p`.`id` FROM `players` p LEFT JOIN `accounts` a ON `p`.`account_id` = `a`.`id` WHERE `p`.`rank_id` = " .. k .. " AND (`a`.`premdays` = 0 OR (`a`.`lastday` + (`a`.`premdays` * 86400) <= 0));")
                        if(result:getID() ~= -1) then
                            local demote = ""
                            repeat
                                demote = demote .. result:getDataInt("id") .. ","
                                members[2] = members[2] - 1
                                members[1] = members[1] + 1
                            until not(result:next())
                            result:free()

                            if(demote ~= "" and rank ~= 0) then
                                db.Query("UPDATE `players` SET `rank_id` = " .. rank .. " WHERE `id` IN (" .. demote:sub(1, -2) .. ");")
                            end
                        end
                    end
                end

                for i = 1, 3 do
                    members[4] = members[4] + members[i]
                end

                if(members[2] < config.viceCount or members[4] < config.memberCount) then
                    if(check == 0) then
                        db.Query("UPDATE `guilds` SET `checkdata` = " .. (time + config.checkTime) .. " WHERE `id` = " .. id .. ";")
                    elseif(check < time) then
                        local tmp = ""
                        for rank, _ in ipairs(ranks) do
                            tmp = tmp .. rank .. ","
                        end

                        db.Query("UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (" .. tmp:sub(1, -2) .. ");")
                        db.Query("DELETE FROM `guilds` WHERE `id` = " .. id .. ";")
                    end
                end
            end
        end
    end

    db.Query("UPDATE `players` SET `online` = 0 WHERE `world_id` = 0;")
    return true
end

function onGlobalSave()
    if(getGameState() ~= GAMESTATE_CLOSING) then
        return onStartup()
    end

    return true
end
 
Didint worked..

[Error - GlobalEvent Interfac]
data/globalevents/scripts/init.lua:OnStartup
Description:
data/globalevents/scripts/init.lua:78: attempt to call field 'executeQuery' <a nil value>
stack traceback:
data/globalevents/scripts/init.lua:78: in function <data/globalevents/scripts/init.lua:8>
 
Last edited:
use this one:

LUA:
local config = {
    creationTime = 7 * 86400,
    checkTime = 7 * 86400,
    viceCount = 4,
    memberCount = 10
}
 
function onStartup()
    local data, time, result = {}, os.time(), db.getResult("SELECT `id`, `ownerid`, `creationdata`, `checkdata` FROM `guilds` WHERE `world_id` = " .. getConfigValue('worldId') .. ";")
    if(result:getID() ~= -1) then
        repeat
            data[result:getDataInt("id")] = {result:getDataInt("ownerid"), result:getDataInt("creationdata"), result:getDataInt("checkdata")}
        until not(result:next())
        result:free()
    end
 
    for id, v in ipairs(data) do
        local owner, created, check = v[1], v[2], v[3]
        if(created < (time - config.creationTime)) then
            result = db.getResult("SELECT `id`, `level` FROM `guild_ranks` WHERE `guild_id` = " .. id .. ";")
            if(result:getID() ~= -1) then
                local rank, ranks = 0, {}
                repeat
                    ranks[result:getDataInt("id")] = result:getDataInt("level")
                    if(result:getDataInt("level") == 1) then
                        rank = result:getDataInt("id")
                    end
                until not(result:next())
                result:free()
 
                local members = {0, 0, 0, 0}
                for k, v in ipairs(ranks) do
                    result = db.getResult("SELECT COUNT(`id`) AS `count` FROM `players` WHERE `rank_id` = " .. k .. ";")
                    if(result:getID() ~= -1) then
                        members[v] = members[v] + result:getDataInt("count")
                        result:free()
                    end
 
                    if(v == 2) then
                        result = db.getResult("SELECT `p`.`id` FROM `players` p LEFT JOIN `accounts` a ON `p`.`account_id` = `a`.`id` WHERE `p`.`rank_id` = " .. k .. " AND (`a`.`premdays` = 0 OR (`a`.`lastday` + (`a`.`premdays` * 86400) <= 0));")
                        if(result:getID() ~= -1) then
                            local demote = ""
                            repeat
                                demote = demote .. result:getDataInt("id") .. ","
                                members[2] = members[2] - 1
                                members[1] = members[1] + 1
                            until not(result:next())
                            result:free()
 
                            if(demote ~= "" and rank ~= 0) then
                                db.query("UPDATE `players` SET `rank_id` = " .. rank .. " WHERE `id` IN (" .. demote:sub(1, -2) .. ");")
                            end
                        end
                    end
                end
 
                for i = 1, 3 do
                    members[4] = members[4] + members[i]
                end
 
                if(members[2] < config.viceCount or members[4] < config.memberCount) then
                    if(check == 0) then
                        db.query("UPDATE `guilds` SET `checkdata` = " .. (time + config.checkTime) .. " WHERE `id` = " .. id .. ";")
                    elseif(check < time) then
                        local tmp = ""
                        for rank, _ in ipairs(ranks) do
                            tmp = tmp .. rank .. ","
                        end
 
                        db.query("UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (" .. tmp:sub(1, -2) .. ");")
                        db.query("DELETE FROM `guilds` WHERE `id` = " .. id .. ";")
                    end
                end
            end
        end
    end
 
    db.query("UPDATE `players` SET `online` = 0 WHERE `world_id` = 0;")
    return true
end
 
function onGlobalSave()
    if(getGameState() ~= GAMESTATE_CLOSING) then
        return onStartup()
    end
 
    return true
end

sorry i forgot one part
 
use this one:

LUA:
local config = {
    creationTime = 7 * 86400,
    checkTime = 7 * 86400,
    viceCount = 4,
    memberCount = 10
}
 
function onStartup()
    local data, time, result = {}, os.time(), db.getResult("SELECT `id`, `ownerid`, `creationdata`, `checkdata` FROM `guilds` WHERE `world_id` = " .. getConfigValue('worldId') .. ";")
    if(result:getID() ~= -1) then
        repeat
            data[result:getDataInt("id")] = {result:getDataInt("ownerid"), result:getDataInt("creationdata"), result:getDataInt("checkdata")}
        until not(result:next())
        result:free()
    end
 
    for id, v in ipairs(data) do
        local owner, created, check = v[1], v[2], v[3]
        if(created < (time - config.creationTime)) then
            result = db.getResult("SELECT `id`, `level` FROM `guild_ranks` WHERE `guild_id` = " .. id .. ";")
            if(result:getID() ~= -1) then
                local rank, ranks = 0, {}
                repeat
                    ranks[result:getDataInt("id")] = result:getDataInt("level")
                    if(result:getDataInt("level") == 1) then
                        rank = result:getDataInt("id")
                    end
                until not(result:next())
                result:free()
 
                local members = {0, 0, 0, 0}
                for k, v in ipairs(ranks) do
                    result = db.getResult("SELECT COUNT(`id`) AS `count` FROM `players` WHERE `rank_id` = " .. k .. ";")
                    if(result:getID() ~= -1) then
                        members[v] = members[v] + result:getDataInt("count")
                        result:free()
                    end
 
                    if(v == 2) then
                        result = db.getResult("SELECT `p`.`id` FROM `players` p LEFT JOIN `accounts` a ON `p`.`account_id` = `a`.`id` WHERE `p`.`rank_id` = " .. k .. " AND (`a`.`premdays` = 0 OR (`a`.`lastday` + (`a`.`premdays` * 86400) <= 0));")
                        if(result:getID() ~= -1) then
                            local demote = ""
                            repeat
                                demote = demote .. result:getDataInt("id") .. ","
                                members[2] = members[2] - 1
                                members[1] = members[1] + 1
                            until not(result:next())
                            result:free()
 
                            if(demote ~= "" and rank ~= 0) then
                                db.query("UPDATE `players` SET `rank_id` = " .. rank .. " WHERE `id` IN (" .. demote:sub(1, -2) .. ");")
                            end
                        end
                    end
                end
 
                for i = 1, 3 do
                    members[4] = members[4] + members[i]
                end
 
                if(members[2] < config.viceCount or members[4] < config.memberCount) then
                    if(check == 0) then
                        db.query("UPDATE `guilds` SET `checkdata` = " .. (time + config.checkTime) .. " WHERE `id` = " .. id .. ";")
                    elseif(check < time) then
                        local tmp = ""
                        for rank, _ in ipairs(ranks) do
                            tmp = tmp .. rank .. ","
                        end
 
                        db.query("UPDATE `players` SET `rank_id` = 0, `guildnick` = '', `guildjoin` = 0 WHERE `rank_id` IN (" .. tmp:sub(1, -2) .. ");")
                        db.query("DELETE FROM `guilds` WHERE `id` = " .. id .. ";")
                    end
                end
            end
        end
    end
 
    db.query("UPDATE `players` SET `online` = 0 WHERE `world_id` = 0;")
    return true
end
 
function onGlobalSave()
    if(getGameState() ~= GAMESTATE_CLOSING) then
        return onStartup()
    end
 
    return true
end

sorry i forgot one part

I tried this but it still dont work, do you got any new helpfull tips?
 
Back
Top