Hello. This code will allow you to see which players have been on your screen recently, and optionally alert under certain conditions. The main code is a persistent code, which can be used to build up other codes as well, but my main need was to know who has been on my screen during my hunt...
The HUD is very basic and I would be happy if someone would improve and allow me to share it with the public.
Let's not waste any time, the persistent code:
init start
local counterResetTime = 10 -- How long (in seconds) can creature leave screen before counter is reset?
local waypointSection = 'Spawn' -- Only count while in given waypoint section (or 'any').
local alert = {
enabled = false, -- Alert enabled
screenTime = 5, -- How long does player need to stay on screen to trigger alert?
onlySkull = true, -- Alert only if skull
wptSection = 'Spawn' -- Only play on given waypoint section (or 'any')
}
-- Do not edit below.
waypointSection = waypointSection:lower()
alert.wptSection = alert.wptSection:lower()
init end
auto(500)
SCREEN_CREATURES = SCREEN_CREATURES or {}
foreach creature player 'ps' do
if($id ~= player.id) then
if(waypointSection == 'any' or waypointSection == $wptsection:lower()) then
if(not SCREEN_CREATURES[player.name]) then
SCREEN_CREATURES[player.name] = {firstSeen=os.time(), longestTime=0, currentTime=0, obj=player}
end
local currentTime = SCREEN_CREATURES[player.name].currentTime + 0.5
SCREEN_CREATURES[player.name].currentTime = currentTime
if(currentTime > SCREEN_CREATURES[player.name].longestTime) then
SCREEN_CREATURES[player.name].longestTime = currentTime
end
end
end
end
local playAlert = false
for name, player in pairs(SCREEN_CREATURES) do
local lastSeenSeconds = os.time() - player.lastSeen
if(lastSeenSeconds > counterResetTime) then
player.currentTime = 0
end
if(alert.enabled and player.currentTime >= alert.screenTime and
(not onlySkull or player.obj.skull ~= SKULL_NOSKULL) and
(alert.wptSection == 'any' or alert.wptSection == $wptsection:lower())) then
playAlert = true
end
-- custom code may be added here, to make e.g. ss when player on screen
end
if(playAlert) then
playsound('monster.wav')
end
--Print, if not using HUD, for testing!
--print()
--for name, v in pairs(SCREEN_CREATURES) do
-- print(name, v.firstSeen, v.lastSeen, v.currentTime, v.longestTime)
--end
HUD code:
init start
local timeToDisplay = 20 -- Amount of seconds player has to be on screen max to be displayed
init end
if(SCREEN_CREATURES) then
local hidden = 0
local amount = 0
for name, player in pairs(SCREEN_CREATURES) do
if(player.longestTime >= timeToDisplay) then
drawtext(name, 13, 12 * amount)
drawtext(math.floor(player.currentTime), 170, 12 * amount)
drawtext(math.floor(player.longestTime), 210, 12 * amount)
amount = amount + 1
else
hidden = hidden + 1
end
end
setposition($worldwin.right, $worldwin.bottom - (amount + 1) * 12)
end
timeToDisplay is the amount of seconds the player has to be in your screen to display his name, otherwise he will be shown under "and 4 others" for example.
If you only came for the codes, you may skip below text!
How it works (small intro for scripters who may find other usages of it):
The persistent code will monitor all players that have been on your screen lately, in a table, with the values:
firstSeen - The first time the player was seen on your screen (os.time())
lastSeen - The last time the player was seen on your screen ((os.time())
longestTime - The longest time in seconds the player was on your screen
currentTime - The amount of time in seconds the player has been in your screen (if he's still there)
obj - The players userdata object
To obtain the data for a specific player (on any code, action script or whatever), you can do it as such:
local onScreenInfo = SCREEN_CREATURES[playerName]
if(onScreenInfo ~= nil) then
if(onScreenInfo.currentTime ~= 0) then
print("Player \"" .. playerName .. "\" is currently on your screen for " .. onScreenInfo.currentTime .. " seconds!")
end
local firstOnScreen = os.time() - onScreenInfo.firstSeen
print("Player \"" .. playerName .. "\" was first seen on your screen: " .. firstOnScreen .. " seconds ago.")
local lastOnScreen = os.time() - onScreenInfo.lastSeen
print("Player \"" .. playerName .. "\" was last seen on your screen: " .. lastOnScreen .. " seconds ago.")
else
print("Player \"" .. playerName .. "\" has not been on your screen!")
end
The SCREEN_CREATURES variable will be accessible on all of your codes, so it's not limited to only this persistent code!
Enjoy and good luck!
05-29-2014, 01:37 AM
asp
Great job.. amazing! Its exactly what i was looking for.. :D
08-14-2014, 01:12 PM
Colandus
bump.
10-26-2014, 07:52 PM
KrusT
does'nt work here, dont show any hud for me
10-29-2014, 05:00 PM
Colandus
Probably because no players have been on your screen. The HUD is very basic and was mainly meant to demonstrate the functionality and should be improved, but it does do the job however, it just won't display anything until you have some players on your screen.
11-01-2014, 04:27 PM
KrusT
@Colandus, i tested on depot with lot people, and notting happens bro
01-09-2015, 12:17 AM
codyjaymes
does this script monitor only people at your hunt location or also at the depot when resupplying?
01-11-2015, 02:36 PM
KrusT
Quote:
Originally Posted by codyjaymes
does this script monitor only people at your hunt location or also at the depot when resupplying?
sorry the late.
when i tried your hud he does'nt show nothing for me, i put to check in all i think
03-15-2016, 04:11 PM
Kamcio
Its possible to ignore someppl? safe list or something?
04-20-2016, 03:30 AM
sek
It copy with the line numbers...
I am too high to remove them out.
1.init start
2. local counterResetTime = 10 -- How long (in seconds) can creature leave screen before counter is reset?
3. local waypointSection = 'Spawn' -- Only count while in given waypoint section (or 'any').
4. local alert = {
5. enabled = false, -- Alert enabled
6. screenTime = 5, -- How long does player need to stay on screen to trigger alert?
7. onlySkull = true, -- Alert only if skull
8. wptSection = 'Spawn' -- Only play on given waypoint section (or 'any')
9. }
10.
11. -- Do not edit below.
12. waypointSection = waypointSection:lower()
13. alert.wptSection = alert.wptSection:lower()
14.init end
15.
16.auto(500)
17.
18.SCREEN_CREATURES = SCREEN_CREATURES or {}
19.foreach creature player 'ps' do
20. if($id ~= player.id) then
21. if(waypointSection == 'any' or waypointSection == $wptsection:lower()) then