Signup Now
Results 1 to 10 of 10
  1. #1
    Free User
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    117
    Reputation
    15
    Rep Power
    21

    Advanced player on screen

    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

    SCREEN_CREATURES[player.name].lastSeen = os.time()

    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

    auto(500)

    setfontstyle("Verdana", 8, 100)
    setfontcolor(0xFF0000)
    setfontborder(1, 0x000000)

    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

    setfontcolor(0x2277FF)
    drawtext("And " .. hidden .. " others...", 13, 12 * amount)

    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!
    Last edited by Colandus; 03-18-2014 at 06:00 PM.
    Regards,
    Colandus

  2. #2
    Free User
    Join Date
    May 2014
    Posts
    19
    Reputation
    10
    Rep Power
    0

    Lightbulb

    Great job.. amazing! Its exactly what i was looking for..

  3. #3
    Free User
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    117
    Reputation
    15
    Rep Power
    21
    bump.
    Regards,
    Colandus

  4. #4
    Free User KrusT's Avatar
    Join Date
    Jul 2014
    Posts
    332
    Reputation
    15
    Rep Power
    20
    does'nt work here, dont show any hud for me

  5. #5
    Free User
    Join Date
    Dec 2013
    Location
    Sweden
    Posts
    117
    Reputation
    15
    Rep Power
    21
    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.
    Regards,
    Colandus

  6. #6
    Free User KrusT's Avatar
    Join Date
    Jul 2014
    Posts
    332
    Reputation
    15
    Rep Power
    20
    @Colandus, i tested on depot with lot people, and notting happens bro

  7. #7
    Free User
    Join Date
    Oct 2014
    Posts
    11
    Reputation
    10
    Rep Power
    0
    does this script monitor only people at your hunt location or also at the depot when resupplying?

  8. #8
    Free User KrusT's Avatar
    Join Date
    Jul 2014
    Posts
    332
    Reputation
    15
    Rep Power
    20
    Quote Originally Posted by codyjaymes View Post
    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

  9. #9
    Free User Kamcio's Avatar
    Join Date
    Jan 2014
    Posts
    164
    Reputation
    37
    Rep Power
    21
    Its possible to ignore someppl? safe list or something?
    Sold 435ED to guy on Ventrilo
    Sold 298 EK to NoMercy on iBot Forum Click
    Sold 272 ED to Tomasz on iBot Forum Click
    Bought 360 ED from JayemVps

  10. #10
    Free User
    Join Date
    Apr 2014
    Posts
    74
    Reputation
    7
    Rep Power
    0
    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

    22. if(not SCREEN_CREATURES[player.name]) then

    23. SCREEN_CREATURES[player.name] = {firstSeen=os.time(), longestTime=0, currentTime=0, obj=player}

    24. end

    25.

    26. SCREEN_CREATURES[player.name].lastSeen = os.time()

    27.

    28. local currentTime = SCREEN_CREATURES[player.name].currentTime + 0.5

    29. SCREEN_CREATURES[player.name].currentTime = currentTime

    30.

    31. if(currentTime > SCREEN_CREATURES[player.name].longestTime) then

    32. SCREEN_CREATURES[player.name].longestTime = currentTime

    33. end

    34. end

    35. end

    36.end

    37.

    38.local playAlert = false

    39.for name, player in pairs(SCREEN_CREATURES) do

    40. local lastSeenSeconds = os.time() - player.lastSeen

    41. if(lastSeenSeconds > counterResetTime) then

    42. player.currentTime = 0

    43. end

    44.

    45. if(alert.enabled and player.currentTime >= alert.screenTime and

    46. (not onlySkull or player.obj.skull ~= SKULL_NOSKULL) and

    47. (alert.wptSection == 'any' or alert.wptSection == $wptsection:lower())) then

    48. playAlert = true

    49. end

    50.

    51. -- custom code may be added here, to make e.g. ss when player on screen

    52.end

    53.

    54.if(playAlert) then

    55. playsound('monster.wav')

    56.end

    57.

    58.

    59.--Print, if not using HUD, for testing!

    60.--print()

    61.--for name, v in pairs(SCREEN_CREATURES) do

    62.-- print(name, v.firstSeen, v.lastSeen, v.currentTime, v.longestTime)

    63.--end

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •