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

getPlayerWorldId

klekSu

Stroke my ego.
Joined
Nov 4, 2008
Messages
1,285
Reaction score
18
Could anyone make this function for me, please? If so, let the function display number of his world, for example 0, or 1, or 2, the number of world set in config. I haven't seen any function showing player world_id actually. So, anyone?
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
Code:
function getPlayerWorldId(cid)
	if not(isPlayer(cid)) then
		return false
	end

	local pid = getPlayerGUID(cid)
	local worldPlayer = 0
	
	local result_plr = db.getResult("SELECT * FROM `players` WHERE `id` = "..pid..";")
    if(result_plr:getID() ~= -1) then
		worldPlayer = tonumber(result_plr:getDataInt("world_id"))
		result_plr:free()
	else
		return false
    end
	
	return worldPlayer
end

Repp?
 
Last edited:
Umm, how do i display it in function onThink in doBroadcastMessage? Ofc gave you rep.
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
I keep getting this:
Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/lottery.lua:onThink

data/globalevents/scripts/lottery.lua:22: attempt to concatenate local 'world' (a boolean value)
stack traceback:
        data/globalevents/scripts/lottery.lua:22: in function <data/globalevents/scripts/lottery.lua:8>
[Error - GlobalEvents::onThink] Couldn't execute event: lottery
Line 22:
doBroadcastMessage('.. world ..')

local world = getPlayerWorldId(cid)
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
Oh sorry x.D. My fail.

function getPlayerWorldId(cid)
if not(isPlayer(cid)) then
return false
end

local pid = getPlayerGUID(cid)
local worldPlayer = 0

local result_plr = db.getResult("SELECT * FROM `players` WHERE `id` = "..pid..";")
if(result_plr:getID() ~= -1) then
worldPlayer = tonumber(result_plr:getDataInt("world_id"))
result_plr:free()
else
return false
end

return worldPlayer
end

And broadcast...
local world = getPlayerWorldId(cid)

doBroadcastMessage('blablalbal '..world ..' balbalbla')
 
But nothing has changed except you added end, i already did it myself :p and it's still not working yet, error with 'world' a boolean value.
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
Yea... works... i just did like it.

local world = tonumber(getPlayerWorldId(cid))
doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR,world)

and while using it said my world id which is 1. Why isn't working with broadcast then?

Actually i'm trying to do a query
db.executeQuery("INSERT INTO `lottery` (`name`, `przedmiot`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")

But it's saying local 'world' has a nil value
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
I don't know really. Maybe add to function the broadcast?

Like this:
Code:
function getPlayerWorldId(cid)
if not(isPlayer(cid)) then
return false
end

local pid = getPlayerGUID(cid)
local worldPlayer = 0

local result_plr = db.getResult("SELECT * FROM `players` WHERE `id` = "..pid..";")
if(result_plr:getID() ~= -1) then
worldPlayer = tonumber(result_plr:getDataInt("world_id"))
result_plr:free()
else
return false
end

return doBroadcastMessage('blablalbal '..worldPlayer..' balbalbla')
end
 
Remember, that `world` is integer!

db.executeQuery("INSERT INTO `lottery` (`name`, `przedmiot`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', ".. world ..");")

Next. Do you have the world_id field in players table?

What is the world's id?
 
0, 1 and 2. Yea, i have world_id field. Either ".. world ..", '".. world .."', '".. getPlayerWorldId(cid) .."' or ".. getPlayerWorldId(cid) .." works, none of it.

EDIT: When done 'world' it doesn't show any error but instert in db world_id 0, when the real world_id is 1.
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
Oh! It's our fail :P

db.executeQuery("INSERT INTO `lottery` (`name`, `przedmiot`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', ".. world ..");")

NO CID, WINNER! x.D

local world = tonumber(getPlayerWorldId(winner))
 
Owww lol yea, hehe. Now it's works as a charm.

local world = tonumber(getPlayerWorldId(winner))
'".. world .."'

You are soooo cool! Gna rep you again was soon as i can ;)
__________________
klekSu.png

You are welcome on kleksoria.com!
Please visit new open tibia forum with it's own ots list. otservers.net!
 
Last edited:
Back
Top