1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. We need your help nominating resources for or next YouTube video. Post here now.
    Dismiss Notice
  3. Cast your vote for the best created hero from the Hive Workshop! [POLL] +100 REP Team Contest - Hive Member
    Dismiss Notice
  4. The Terraining Mini Contest Reload #1 - Mist has began! Create a scene laden in thick fog, with only 20 doodads!
    Dismiss Notice
  5. Full steam ahead! Choose the best steampunk song at our Music Contest #9 - Poll
    Dismiss Notice
  6. Join us in our custom games night next Saturday, January 27th. We'll see you on Battle.net and Discord!
    Dismiss Notice

[System] PlayerManager

Discussion in 'Graveyard' started by Nestharus, Sep 2, 2009.

  1. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,143
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    This resource has moved here.

    --

    gone
     
    Last edited by a moderator: Jan 17, 2018
  2. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,301
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    You don't need a force containing all the players - it already exists as native.

    Any public names should be capitalised - it's convention.

    The library names are too short and generic. Change please.

    Other than that, it looks OK. A quite simple library, but useful nonetheless.
     
  3. aznricepuff

    aznricepuff

    Joined:
    Feb 22, 2006
    Messages:
    749
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    I agree with EoW on the library names. Other than that I don't see any problems.
     
  4. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,143
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Sure thing.. I'll add my customary N to the end of the libraries ^_^.
     
  5. Element of Water

    Element of Water

    Joined:
    Aug 3, 2008
    Messages:
    2,301
    Resources:
    5
    Spells:
    3
    Tutorials:
    1
    JASS:
    1
    Resources:
    5
    Still quite short. What I meant was, call them PlayerTracking and HostTracking.
     
  6. MapperMalte

    MapperMalte

    Joined:
    Nov 4, 2007
    Messages:
    326
    Resources:
    5
    Maps:
    2
    Spells:
    2
    JASS:
    1
    Resources:
    5
    Code (vJASS):

        private function GetHost takes nothing returns player
            call StoreInteger(getTheHost, "missionKey", "key", GetPlayerId(GetLocalPlayer()) + 1)
            call TriggerSyncStart()
            call SyncStoredInteger(getTheHost, "missionKey", "key")
            call TriggerSyncReady()
            return Player(GetStoredInteger(getTheHost, "missionKey", "key") - 1)
        endfunction
     


    This function was stolen!
     
  7. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,143
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    I actually wrote that myself mate -.-. Syncing data up between players is pretty common knowledge... someone used this technique to get the delay of players.
     
  8. Yixx

    Yixx

    Joined:
    Oct 12, 2008
    Messages:
    1,492
    Resources:
    3
    Spells:
    3
    Resources:
    3
    Something that might be handy to add:
    the GET_PLAYER, GET_COMPUTER and GET_ALL take the integer you assign to it, right? Make versions of those that take a player or global player Id (meaning the one generated by GetPlayerId()), because i might not have those integers somewhere where i actually do need this function. I know it seems unlikely but it shouldnt be hard and might actually come in hand i think. Or just GetPlayerCustomId or whatever that returns the ID you assigned to it.

    for the rest, this seems like a nice system, good job.
     
  9. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,143
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Yixx, originally there were things in this for getting a player using an id... but there's already a native for that =).

    If you're going to loop, then just use the regular player array. If you want to attach data to a player, use the player's id. When you are looping, do GetPlayerId(PTN_GET_PLAYER(x)) to access you arrays =).
     
  10. MapperMalte

    MapperMalte

    Joined:
    Nov 4, 2007
    Messages:
    326
    Resources:
    5
    Maps:
    2
    Spells:
    2
    JASS:
    1
    Resources:
    5
    I've got a system that does pretty much the same thing, but is able to do more things (I didn't post it in forums, just use it for me and myself):
    It is able to return the highest number of all players.
    And it is able to return how many players are still playing.

    You should add these things.
     
  11. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,143
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Mine is also able to return how many players are playing and it can even get the highest player in the game (computer, player, or combination)

    The key words are through out, meaning the variables are updated during the game.
    Code (vJASS):
    PTN_GET_PLAYER_COUNT()
    will always return the proper total count of all players =).

    As for getting the highest player in the game, the player arrays in the background are indexed in the most efficient way meaning that the players get scrambled after one player leaves.

    If you can come up with a really good reason, I'll add it in =). It'd only be 2 lines of code for lowest and biggest.
     
  12. MapperMalte

    MapperMalte

    Joined:
    Nov 4, 2007
    Messages:
    326
    Resources:
    5
    Maps:
    2
    Spells:
    2
    JASS:
    1
    Resources:
    5
    Reason? Ok.
    I want to do sth. for all players.
    Player 4 left.
    Player count is 5.
    Highest Player number is 6.

    So I loop to the highest ID, and it does everything correct.
    I loop to the player count and player 6 isn't used.
     
  13. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,143
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Fixed

    loop
    exitwhen x == PTN_GET_PLAYER_COUNT()
    //do stuff
    set x = x + 1
    endloop

    that should work now after players leave. The indexing was messed up for pointing the ids to the new index slots ^^.
     
    Last edited: Sep 6, 2009
  14. MapperMalte

    MapperMalte

    Joined:
    Nov 4, 2007
    Messages:
    326
    Resources:
    5
    Maps:
    2
    Spells:
    2
    JASS:
    1
    Resources:
    5
    And what if sb wants to split up respoueces to all players and max player ID is 10, but 3 players play, really, you need two vars.
    Also your function/variable naming is always horribly none-saying.
    Please think clearly before starting to make a system, that really makes it less complicated and maybe it's designed better then.
    This Is not bad, but I won't use it, because it's not very complex.
     
  15. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,143
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    You don't need a max player id... it's all indexed into an array...

    PTN_GET_PLAYER(0)
    PTN_GET_PLAYER(1)

    Those aren't necessarily player 0 and player 1..

    If you want to loop thru all players in the map, then just use 0 thru PTN_GET_PLAYER_COUNT()

    if you want to get player via id, then use the GetPlayerId() native.

    I don't know how you are using it, but GET_PLAYER does not take a player id =), it takes an internal index because it's kept sequential so that it can be used in loops. It's not meant to be used on specific players, it's meant to be used for all players =).

    Again, there is absolutely no need for tracking the highest player id, lol...
     
  16. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,143
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Found a bug in this ; o. It caused leaving players to not be registered except for Player 0. It was 1 line fix.

    Increased the ini loop speed, so it should be faster.

    Benchmark code to compare old method and new method of slot check
    Code (vJASS):

    include "cj_types.j"
    include "cj_typesEx.j"
    include "cj_print.j"
    include "cj_types_priv.j"  
    include "cj_typesEx_priv.j"
    include "cj_order.j"  
    include "cj_antibj_base.j"

    scope Demo initializer Initialization {
        trigger t = CreateTrigger()
        event e = TriggerRegisterTimerEvent(t, 0, false)
        int sw, i = 5000; float mark
       
        bool Test() {
            sw = StopWatchCreate()
            do {
                if GetPlayerTeam(Player(0)) != -1 {} //.007
                //if GetPlayerSlotState(Player(0)) == PLAYER_SLOT_STATE_PLAYING {} //.011
            } whilenot --i == 0
            mark = StopWatchMark(sw)
            StopWatchDestroy(sw)
            printf(R2S(mark))
            return false
        }
       
        void Initialization() {
            TriggerAddCondition(t, Condition(function Test))
        }
    }
     


    This wasn't working right because the trigger wasn't firing ^_^. It should be ok now ; p.

    If player 4 leaves
    Player count is 5

    it'll go from this-

    1 2 3 4 5 6

    to this

    1 2 3 6 5

    4 is removed and the last player is put in it's place. This is why you can always loop through all the current players ^_^.
     
  17. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,143
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    PlayerTracker 6.0 vJASS is up! : D

    Edit
    PlayerTracker 1.0 cJASS is up! : D
     
    Last edited: Nov 25, 2009
  18. MapperMalte

    MapperMalte

    Joined:
    Nov 4, 2007
    Messages:
    326
    Resources:
    5
    Maps:
    2
    Spells:
    2
    JASS:
    1
    Resources:
    5
    Wrong.
    Proof:
    [​IMG]
     
  19. YourNameHere

    YourNameHere

    Joined:
    Apr 29, 2007
    Messages:
    745
    Resources:
    4
    Maps:
    1
    Spells:
    2
    JASS:
    1
    Resources:
    4
    Maybe show us your whole testing code before claiming any proof?
    Real benchmarks should use StopWatch and not some systems coded within the World Editor.
     
  20. MapperMalte

    MapperMalte

    Joined:
    Nov 4, 2007
    Messages:
    326
    Resources:
    5
    Maps:
    2
    Spells:
    2
    JASS:
    1
    Resources:
    5
    This uses StopWatch.

    Here:
    Code (vJASS):

    scope Tests initializer SetUp

        globals
            private HandleTable Data
        endglobals
       
    private function test takes nothing returns nothing
        local timer t
        local integer i
        call TestHelper.NextInstance()

            if TestHelper.IsFinished() then
                call PauseTimer(GetExpiredTimer())
                call DestroyTimer(GetExpiredTimer())
                call Test.Compare()
                //call Test.createTable()
                return
            endif
       
            call Test.Start("PT","GetPlayer")
                call GetPlayer(0)
            call Test.End()
           
            call Test.Start("Native","Player")
                call Player(0)
            call Test.End()

    endfunction

        function TestSC takes nothing returns nothing
            call TestHelper.SetTest(170,170)
            call TimerStart(CreateTimer(),0.,true,function test)
        endfunction
       
        private function SetUp takes nothing returns nothing
            set Data = HandleTable.create()
            call Test.Declare("PT")
            call Test.Declare("Native")
        endfunction

    endscope