• 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 Script] Entry in TP then add player name in a list

StormRusher

New Member
Joined
Dec 23, 2009
Messages
138
Reaction score
0
Well,

I need a script (I think a moveevent) to do that:
When a player with group < 3, walk in a certain tp (unique id) add his name in a certain list, the list could be seen with a certain talkaction.

If you dont understand, i am trying to make a way to know how many (and which) players have entered in an area.

Hope you can help me :)
Thanks
 
@Cykotitan
Using global tables doesn't means that you'll have a memory leak.
Anyways, if you want to waste time seeing performance in everything, quit Lua, high level languages are slow.
 
@Cykotitan
Using global tables doesn't means that you'll have a memory leak.
Anyways, if you want to waste time seeing performance in everything, quit Lua, high level languages are slow.
Not necessarily that it'll occur in practice, but it still counts as a potential memory leak in this case.
 
i had some ideas...
does it possible to make a talkaction like !online, but show only players with GlobalStorageValue(5) == 1 ?
Yes, but it would only return a list of players who are both online and have the (player, not global) storage set to 1.
 
ok, its exactly what i want, i have this "!online" script, but i dont know how to edit it to show only players with storage value(5) 1...

can you help me?

LUA:
local config = {
	showGamemasters = getBooleanFromString(getConfigValue('displayGamemastersWithOnlineCommand'))
}

function onSay(cid, words, param, channel)
	local players = getPlayersOnline()
	local strings = {""}

	local i, position = 1, 1
	local added = false
	for _, pid in ipairs(players) do
		if(added) then
			if(i > (position * 7)) then
				strings[position] = strings[position] .. ","
				position = position + 1
				strings[position] = ""
			else
				strings[position] = i == 1 and "" or strings[position] .. ", "
			end
		end

		if((config.showGamemasters or getPlayerCustomFlagValue(cid, PlayerCustomFlag_GamemasterPrivileges) or not getPlayerCustomFlagValue(pid, PlayerCustomFlag_GamemasterPrivileges)) and (not isPlayerGhost(pid) or getPlayerGhostAccess(cid) >= getPlayerGhostAccess(pid))) then
			strings[position] = strings[position] .. getCreatureName(pid) .. " [" .. getPlayerLevel(pid) .. "]"
			i = i + 1
			added = true
		else
			added = false
		end
	end

	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, (i - 1) .. " player(s) online:")
	for i, str in ipairs(strings) do
		if(str:sub(str:len()) ~= ",") then
			str = str .. "."
		end

		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str)
	end

	return true
end
 
Very easy:
Code:
local storage = 5
function onSay(cid, words, param, channel)
	local first, str = true, ""
	for _, pid in ipairs(getPlayersOnline()) do
		str = str .. (getPlayerStorageValue(pid, storage) == 1 and (not first and ", " or "") .. getCreatureName(pid) or "")
		first = false
	end
	return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, str)
end

I've used this to verify that code will work:
Code:
table.find = function (table, value)
	for i, v in pairs(table) do
		if(v == value) then
			return i
		end
	end

	return nil
end
function getPlayersOnline() return {100, 101, 102} end
function getPlayerStorageValue(cid) return table.find({100, 102}, cid) and 1 or 0 end
function getCreatureName(cid) return cid == 100 and "Frank" or cid == 101 and "KURWA" or cid == 102 and "Farmer" end
local first, str = true, ""
for _, pid in ipairs(getPlayersOnline()) do
	str = str .. (getPlayerStorageValue(pid, storage) == 1 and (not first and ", " or "") .. getCreatureName(pid) or "")
	first = false
end
return str
Output:
Code:
Frank, Farmer
 
Last edited:
strange... i am getting this error:

PHP:
[13/01/2010 04:09:07] Lua Script Error: [TalkAction Interface] 
[13/01/2010 04:09:07] data/talkactions/scripts/open.lua:onSay

[13/01/2010 04:09:07] data/talkactions/scripts/open.lua:5: attempt to concatenate a boolean value
[13/01/2010 04:09:07] stack traceback:
[13/01/2010 04:09:07] 	data/talkactions/scripts/open.lua:5: in function <data/talkactions/scripts/open.lua:2>
 
Back
Top