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

[Function] getPlayersOnline()

scorpionfight

New Member
Joined
Sep 21, 2008
Messages
111
Reaction score
1
Location
Brazil
I need a function that comes with TFS 0.3.4, but it is copiled, and now I'm using TFS 0.2.5,
is the function getPlayersOnline() it returns all the names of the players that are online.

Thanks.
 
Try this.. (this function return the name)
Lua:
function getPlayersOnline()
	local players = {}
	local result = db.getResult("SELECT `name` FROM `players` WHERE `online` = 1;")
	if(result:getID() ~= -1) then
		while(true) do
			table.insert(players, result:getDataString("name"))
			if not(result:next())then break end
		end
		result:free()
	end
	return players
end
 
Try this one, it return the players not the names ;).
Lua:
function getPlayersOnline()
	local players = {}
        local player_names = {}
        local result = db.getResult("SELECT `name` FROM `players` WHERE `online` = 1;")
        if(result:getID() ~= -1) then
                while(true) do
                        table.insert(player_names, result:getDataString("name"))
                        if not(result:next())then 
				break 
			end
                end
                result:free()
        end
	for i = 1, #players do
		table.insert(players, getPlayerByName(player_names[i])
	end
        return players
end

Regards,
Shawak
 
Oh really? Dont you know, let me call you retard, that TFS 0.2.5 also has this function and its name is in my previous post?

Learn to read source files, then post your crap, thanks.

How bout you calm da fuck down, and yes actually I did read the DOCs in the latest WebSVN and unless its out of date it says nowhere about that function. So since he needed it and he personally uses 0.2.5 which I don't, and it wasn't in the DOC I presume its not there. So suck it and quit crying.

Code:
[ TODO - Info, example use
        setPlayerGroupId(cid, newGroupId)
        playerLearnInstantSpell(cid, name)
        canPlayerLearnInstantSpell(cid, name)
        getPlayerLearnedInstantSpell(cid, name)
        getPlayerInstantSpellCount(cid)
        getPlayerInstantSpellInfo(cid, index)
        getInstantSpellInfoByName(cid, name)
        getInstantSpellWords(name)
        setPlayerStorageValue(uid, valueid, newvalue)
        getGlobalStorageValue(valueid)
        setGlobalStorageValue(valueid, newvalue)
        getTilePzInfo(pos)
        getTileHouseInfo(pos)
        getItemRWInfo(uid)
        getThingfromPos(pos)
        getThing(uid)
        queryTileAddThing(uid, pos, <optional> flags)
        getThingPos(uid)
        doRemoveItem(uid, <optional> n)
        doPlayerFeed(cid, food)

        doPlayerSendDefaultCancel(cid, ReturnValue)
        doTeleportThing(cid, newpos, <optional> pushmove)
        doTransformItem(uid, toitemid, <optional> count/subtype)
        doCreatureSay(cid, text, type)
        doSendMagicEffect(pos, type)
        doSendDistanceShoot(frompos, topos, type)
        doChangeTypeItem(uid, newtype)
        doSetItemActionId(uid, actionid)
        doSetItemText(uid, text)
        doSetItemSpecialDescription(uid, desc)
        doSendAnimatedText(pos, text, color)
        doPlayerAddSkillTry(cid, skillid, n)
        doCreatureAddHealth(cid, health)
        doPlayerAddMana(cid, mana)
        doPlayerAddManaSpent(cid, mana)
        doPlayerAddSoul(cid, soul)
        doPlayerAddItem(uid, itemid, <optional> count/subtype)
        doPlayerAddItemEx(cid, uid, <optional: default: 0> useCidPosOnFail)
        doPlayerSendTextMessage(cid, MessageClasses, message)
        doPlayerRemoveMoney(cid, money)
        doShowTextDialog(cid, itemid, text)
        doDecayItem(uid)
        doCreateItem(itemid, type/count, pos)
        doCreateItemEx(itemid, <optional> count/subtype)
        doTileAddItemEx(pos, uid)
        doCreateTeleport(itemid, topos, createpos)
        doSummonCreature(name, pos)
        doConvinceCreature(cid, target)
        doRemoveCreature(cid)
        doMoveCreature(cid, direction)
        doPlayerSetTown(cid, townid)
        doPlayerSetVocation(cid,voc)
        doPlayerRemoveItem(cid,itemid,count)
        doPlayerAddExp(cid,exp)
        doPlayerSetGuildId(cid, id)
        doPlayerSetGuildRank(cid, rank)
        doPlayerSetGuildNick(cid, nick)
        doPlayerAddOutfit(cid,looktype,addons)
        doPlayerRemOutfit(cid,looktype,addons)
        doSetCreatureLight(cid, lightLevel, lightColor, time)
        doSetCreatureDropLoot(cid, doDrop)
        getCreatureCondition(cid, condition)
        isPlayer(cid)
        isCreature(cid)
        isContainer(uid)
        isMoveable(uid)
        getPlayerByName(name)
        getPlayerGUIDByName(name)
        registerCreatureEvent(uid, eventName)
        getContainerSize(uid)
        getContainerCap(uid)
        getContainerItem(uid, slot)
        doAddContainerItem(uid, itemid, <optional> count/subtype)
        getHouseOwner(houseid)
        getHouseName(houseid)
        getHouseEntry(houseid)
        getHouseRent(houseid)
        getHouseTown(houseid)
        getHouseAccessList(houseid, listid)
        getHouseByPlayerGUID(playerGUID)
        setHouseAccessList(houseid, listid, listtext)
        setHouseOwner(houseid, ownerGUID)
        getWorldType()
        getWorldTime()
        getWorldLight()
        getWorldCreatures(type)
        getWorldUpTime()
        broadcastMessage(message, type)
        getGuildId(guild_name)
        getPlayerSex(cid)
        doPlayerSetSex(cid, newSex)
        createCombatArea( {area}, <optional> {extArea} )
        createConditionObject(type)
        setCombatArea(combat, area)
        setCombatCondition(combat, condition)
        setCombatParam(combat, key, value)
        setConditionParam(condition, key, value)
        addDamageCondition(condition, rounds, time, value)
        addOutfitCondition(condition, lookTypeEx, lookType, lookHead, lookBody, lookLegs, lookFeet)
        setCombatCallBack(combat, key, function_name)
        setCombatFormula(combat, type, mina, minb, maxa, maxb)
        setConditionFormula(combat, mina, minb, maxa, maxb)
        doCombat(cid, combat, param)
        createCombatObject()
        doAreaCombatHealth(cid, type, pos, area, min, max, effect)
        doTargetCombatHealth(cid, target, type, min, max, effect)
        doAreaCombatMana(cid, pos, area, min, max, effect)
        doTargetCombatMana(cid, target, min, max, effect)
        doAreaCombatCondition(cid, pos, area, condition, effect)
        doTargetCombatCondition(cid, target, condition, effect)
        doAreaCombatDispel(cid, pos, area, type, effect)
        doTargetCombatDispel(cid, target, type, effect)
        doChallengeCreature(cid, target)
        numberToVariant(number)
        stringToVariant(string)
        positionToVariant(pos)
        targetPositionToVariant(pos)
        variantToNumber(var)
        variantToString(var)
        variantToPosition(var)
        doChangeSpeed(cid, delta)
        doSetMonsterOutfit(cid, name, time)
        doSetItemOutfit(cid, item, time)
        doSetCreatureOutfit(cid, outfit, time)
        getCreatureOutfit(cid)
        getCreaturePosition(cid)
        getCreatureName(cid)
        getCreatureSpeed(cid)
        getCreatureBaseSpeed(cid)
        getCreatureTarget(cid)
        isItemStackable(itemid)
        isItemRune(itemid)
        isItemDoor(itemid)
        isItemContainer(itemid)
        isItemFluidContainer(itemid)
        getItemName(itemid)
        getItemWeight(itemid, count)
        debugPrint(text)
        isInArray(array, value)
        addEvent(callback, delay, parameter)
        stopEvent(eventid)
        doPlayerPopupFYI(cid, message)
        mayNotLogout(cid, value)
        mayNotMove(cid, value)
        doPlayerAddPremiumDays(cid, days)
        doPlayerRemovePremiumDays(cid, days)
        getPlayerPremiumDays(cid)
        getPlayerSkullType(cid)
        getPromotedVocation(vocation)
        getPlayerBlessing(cid, blessing)
        doPlayerAddBlessing(cid, blessing)
        saveData()
        escapeString(str)

ALSO, I looked through the latest global.lua for any function of the sort, and found none
Lua:
function doPlayerGiveItem(cid, itemid, count, charges)
        local hasCharges = (isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE)
        if(hasCharges and charges == nil) then
                charges = 1
        end
        while count > 0 do
                local tempcount = 1
                if(isItemStackable(itemid) == TRUE) then
                        tempcount = math.min (100, count)
                end
                local ret = doPlayerAddItem(cid, itemid, tempcount, charges)
                if(ret == LUA_ERROR) then
                        ret = doCreateItem(itemid, tempcount, getPlayerPosition(cid))
                end
                if(ret ~= LUA_ERROR) then
                        if(hasCharges) then
                                count = count - 1
                        else
                                count = count - tempcount
                        end
                else
                        return LUA_ERROR
                end
        end
        return LUA_NO_ERROR
end

function doPlayerTakeItem(cid, itemid, count)
        if(getPlayerItemCount(cid,itemid) >= count) then
                while count > 0 do
                        local tempcount = 0
                        if(isItemStackable(itemid) == TRUE) then
                                tempcount = math.min (100, count)
                        else
                                tempcount = 1
                        end
                        local ret = doPlayerRemoveItem(cid, itemid, tempcount)
                        if(ret ~= LUA_ERROR) then
                                count = count-tempcount
                        else
                                return LUA_ERROR
                        end
                end
                if(count == 0) then
                        return LUA_NO_ERROR
                end
        else
                return LUA_ERROR
        end
end

function doPlayerBuyItem(cid, itemid, count, cost, charges)
        if(doPlayerRemoveMoney(cid, cost) == TRUE) then
                return doPlayerGiveItem(cid, itemid, count, charges)
        end
        return LUA_ERROR
end

function doPlayerSellItem(cid, itemid, count, cost)
        if(doPlayerTakeItem(cid, itemid, count) == LUA_NO_ERROR) then
                if doPlayerAddMoney(cid, cost) ~= TRUE then
                        error('Could not add money to ' .. getPlayerName(cid) .. '(' .. cost .. 'gp)')
                end
                return LUA_NO_ERROR
        end
        return LUA_ERROR
end

function isInRange(pos, fromPos, toPos)
        if pos.x >= fromPos.x and pos.y >= fromPos.y and pos.z >= fromPos.z and pos.x <= toPos.x and pos.y <= toPos.y and pos.z <= toPos.z then
                return TRUE
        end
        return FALSE
end

function isPremium(cid)
        return (isPlayer(cid) == TRUE and (getPlayerPremiumDays(cid) > 0 or getConfigInfo('freePremium') == "yes")) and TRUE or FALSE
end

function rows(connection, sql_statement)
        local cursor = assert(connection:execute(sql_statement))
        return function ()
                return cursor:fetch()
        end
end

function getMonthDayEnding(day)
        if day == "01" or day == "21" or day == "31" then
                return "st"
        elseif day == "02" or day == "22" then
                return "nd"
        elseif day == "03" or day == "23" then
                return "rd"
        else
                return "th"
        end
end

function getMonthString(m)
        return os.date("%B", os.time{year = 1970, month = m, day = 1})
end

function getArticle(str)
        return str:find("[AaEeIiOoUuYy]") == 1 and "an" or "a"
end

function isNumber(str)
        return tonumber(str) ~= nil and TRUE or FALSE
end

function getDistanceBetween(firstPosition, secondPosition)
        local xDif = math.abs(firstPosition.x - secondPosition.x)
        local yDif = math.abs(firstPosition.y - secondPosition.y)

        local posDif = math.max(xDif, yDif)
        if(firstPosition.z ~= secondPosition.z) then
                posDif = posDif + 9 + 6
        end
        return posDif
end

function doPlayerAddAddons(cid, addon)
        for i = 0, table.maxn(maleOutfits) do
                doPlayerAddOutfit(cid, maleOutfits[i], addon)
        end

        for i = 0, table.maxn(femaleOutfits) do
                doPlayerAddOutfit(cid, femaleOutfits[i], addon)
        end
end

function numRows(cursor)
        local row = cursor:fetch()
        local rows = 0
        while row do
                rows = rows + 1
                row = cursor:fetch()
        end
        cursor:close()
        return rows
end

function isSorcerer(cid)
        if(isPlayer(cid) == FALSE) then
                debugPrint("isSorcerer: Player not found.")
                return false
        end

        return (isInArray({1,5}, getPlayerVocation(cid)) == TRUE)
end

function isDruid(cid)
        if(isPlayer(cid) == FALSE) then
                debugPrint("isDruid: Player not found.")
                return false
        end

        return (isInArray({2,6}, getPlayerVocation(cid)) == TRUE)
end

function isPaladin(cid)
        if(isPlayer(cid) == FALSE) then
                debugPrint("isPaladin: Player not found.")
                return false
        end

        return (isInArray({3,7}, getPlayerVocation(cid)) == TRUE)
end

function isKnight(cid)
        if(isPlayer(cid) == FALSE) then
                debugPrint("isKnight: Player not found.")
                return false
        end

        return (isInArray({4,8}, getPlayerVocation(cid)) == TRUE)
end

function getConfigInfo(info)
        if (type(info) ~= 'string') then return nil end

        dofile('config.lua')
        return _G[info]
end

function getPlayerMoney(cid)
        return ((getPlayerItemCount(cid, ITEM_CRYSTAL_COIN) * 10000) + (getPlayerItemCount(cid, ITEM_PLATINUM_COIN) * 100) + getPlayerItemCount(cid, ITEM_GOLD_COIN))
end

function table.find(table, value)
        for i,v in pairs(table) do
                if (v == value) then
                        return i
                end
        end
        return nil
end

function doPlayerBuyItemContainer(cid, containerid, itemid, count, cost, charges)
        if doPlayerRemoveMoney(cid, cost) == TRUE then
                for i = 1, count do
                        local container = doCreateItemEx(containerid, 1)
                        for x = 1, getContainerCapById(containerid) do
                                doAddContainerItem(container, itemid, charges)
                        end
                        doPlayerAddItemEx(cid, container, 1)
                end
                return LUA_NO_ERROR
        end
        return LUA_ERROR
end

EDIT2:
//getOnlinePlayers()
lua_register(m_luaState, "getOnlinePlayers", LuaScriptInterface::luaGetOnlinePlayers);

Found it, hardcoded -.- Really should post it in DOCs
 
Last edited:
How bout you calm da fuck down, and yes actually I did read the DOCs in the latest WebSVN and unless its out of date it says nowhere about that function. So since he needed it and he personally uses 0.2.5 which I don't, and it wasn't in the DOC I presume its not there. So suck it and quit crying.

It looks for me more like you're crying :(:(:(
I have said SOURCE files, does global.lua or docs have anything to do with them? Go read some luascript.cpp/h
Code:
//line 1183-1184
//getOnlinePlayers()
lua_register(m_luaState, "getOnlinePlayers", LuaScriptInterface::luaGetOnlinePlayers);

.i.
 
^.^ I really could care less, but you're attitude sucks. And yes global.lua and docs have alot todo with sources, but thats another thing entirely. I already posted above that I found it, I assumed since he was searching for it and the function was not documented that it did not exist. So go masturbate to Emma Watson's ugly ass and get a real forum name. ^.^

@topic: its solved, and getting out of hand, close please :)
 
Back
Top