Snippet Players

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:
////////////////////////////////////////////
//
//      PLAYERS v1.0
//          by kingking
//
//  This library sorts types of players
//  in map.
//  
//  Functions :
//  Players_IsHuman(whichPlayer) -> boolean
//  Players_IsComputer(whichPlayer) -> boolean
//  Players_IsEmpty(whichPlayer) -> boolean
//  Players_IsPlaying(whichPlayer) -> boolean
//  Players_IsLeft(whichPlayer) -> boolean
//
//  ForHumanPlayers(whichCallback)
//  ForComputerPlayers(whichCallback)
//  ForEmptyPlayers(whichCallback)
//  ForPlayingPlayers(whichCallback)
//  ForLeftPlayers(whichCallback)
//
//  Players[whichPlayerId] -> player
//
//  TriggerRegisterHumanPlayersLeaveEvent(whichTrigger)
//
//  Requires :
//  Jasshelper 0.A.2.7
//  Event
/////////////////////////////////////////
library Players initializer Init requires Event

    globals
        player array Players
        private force HumanPlayers
        private force ComputerPlayers
        private force EmptyPlayers
        private force PlayingPlayers
        private force LeftPlayers
        private Event HumanPlayersLeaveEvent
    endglobals
    
    //! textmacro PLAYERS takes TYPE
    public function Is$TYPE$ takes player whichPlayer returns boolean
        return IsPlayerInForce(whichPlayer,$TYPE$Players)
    endfunction
    function For$TYPE$Players takes code whichCallback returns nothing
        call ForForce($TYPE$Players, whichCallback)
    endfunction
    //! endtextmacro
    
    //! runtextmacro PLAYERS ("Human")
    //! runtextmacro PLAYERS ("Computer")
    //! runtextmacro PLAYERS ("Empty")
    //! runtextmacro PLAYERS ("Playing")
    //! runtextmacro PLAYERS ("Left")
    
    function TriggerRegisterHumanPlayerLeaveEvent takes trigger whichTrigger returns EventReg
        return HumanPlayersLeaveEvent.register(whichTrigger)
    endfunction
     
    private function FireEvent takes nothing returns boolean
        local player p = GetTriggerPlayer()
        call ForceRemovePlayer(HumanPlayers,p)
        call ForceRemovePlayer(PlayingPlayers,p)
        call ForceAddPlayer(EmptyPlayers,p)
        call ForceAddPlayer(LeftPlayers,p)
        call HumanPlayersLeaveEvent.fire()
        set p = null
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        local integer i = 0
        local trigger trig = CreateTrigger()
        set HumanPlayersLeaveEvent = Event.create()
        
        set HumanPlayers = CreateForce()
        set ComputerPlayers = CreateForce()
        set EmptyPlayers = CreateForce()
        set LeftPlayers = CreateForce()
        set PlayingPlayers = CreateForce()        

        loop
        exitwhen i > bj_MAX_PLAYER_SLOTS
            set Players<i> = Player(i)
            if GetPlayerController(Players<i>) == MAP_CONTROL_USER then
                call ForceAddPlayer(HumanPlayers,Players<i>)
            endif
            if GetPlayerController(Players<i>) == MAP_CONTROL_COMPUTER then
                call ForceAddPlayer(ComputerPlayers,Players<i>)
            endif
            if GetPlayerController(Players<i>) == MAP_CONTROL_NONE then
                call ForceAddPlayer(EmptyPlayers,Players<i>)
            endif
            if GetPlayerSlotState(Players<i>) == PLAYER_SLOT_STATE_PLAYING then
                call ForceAddPlayer(PlayingPlayers,Players<i>)
            endif
            if GetPlayerSlotState(Players<i>) == PLAYER_SLOT_STATE_EMPTY then
                call ForceAddPlayer(EmptyPlayers,Players<i>)
            endif
            if IsPlayerInForce(Players<i>,HumanPlayers) and IsPlayerInForce(Players<i>,PlayingPlayers) then
                call TriggerRegisterPlayerEvent(trig,Players<i>,EVENT_PLAYER_LEAVE)
            endif
            set i = i + 1
        endloop
    endfunction
endlibrary
</i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

Nestharus

o-o
Reaction score
84
This has already been done, and it's been done better, and the done version is graveyarded on this site because moderators say that player tracking is too simple to constitute as a resource.

Host tracking was also done, so don't try to do that ^_- It's rotting in tutorials and resources ;p (not approved or graveyarded)

Although Player Tracking that's been done doesn't track players that are not humans or computers (100% nonplaying), lol.

But a feature was planned last night that would allow for tracking of active and non-active players in the game ^_^ (human players that are in the game, but are actually playing or not playing at the moment).

http://www.thehelper.net/forums/showthread.php?t=135783 (player tracking)
http://www.thehelper.net/forums/showthread.php?t=137438 (host tracking)

But anyways, a few pointers-
JASS:
if GetPlayerController(Players<i>) == MAP_CONTROL_USER then
                call ForceAddPlayer(HumanPlayers,Players<i>)
            endif
            if GetPlayerController(Players<i>) == MAP_CONTROL_COMPUTER then
                call ForceAddPlayer(ComputerPlayers,Players<i>)
            endif
            if GetPlayerController(Players<i>) == MAP_CONTROL_NONE then
                call ForceAddPlayer(EmptyPlayers,Players<i>)
            endif
            if GetPlayerSlotState(Players<i>) == PLAYER_SLOT_STATE_PLAYING then
                call ForceAddPlayer(PlayingPlayers,Players<i>)
            endif
            if GetPlayerSlotState(Players<i>) == PLAYER_SLOT_STATE_EMPTY then
                call ForceAddPlayer(EmptyPlayers,Players<i>)
            endif
</i></i></i></i></i></i></i></i></i></i>


Don't use a set of ifs-
if, else if, else

if player is map controller
else if player is computer
else (obviously neither)

if player slot state is playing
else

Next, don't use player slot state playing. Look under player tracking to see a better method that's faster.

Next, don't use forces. Iterating through players plainly in code is faster than going through a force -.-. Use an indexed array (not a stack or a linked list as there is really no need).

The indexed array should return either player or player id. While you're at it, might as well do a player array. Just look at player tracking for inspiration.

Also, active players and non-active players for game play is a good idea as a feature as it allows people to more easily determine when a game ends and more easily iterate through players. If they want to iterate through all players for something, they can. If they only want to do active players (players that aren't defeated or that are in a match or something), they can. If they only want to do non-active (are they observing?) they can.

A use of active/non-active-
loop
exitwhen activePlayer is not ally to activePlayer2
if i == PlayerCount
endGame


The first active player will always be full. All active players can be cycled through with win and all non-active can be cycled through with loss or w/e ^_^.

Oh yes, and including a boolean as a default (players auto active or auto deactive) would be a good idea ;).

I think you should just leave Player Tracking up to the player tracking utility ;p.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Yea, I still don't think this kind of thing is that useful...

>For$TYPE$Players
I'd like your ForXPlayers functions if it wasn't better/easier to use a loop through integers...

I mean, it's obscure, right? You've covered some random things, but what if people want PlayingHumanPlayers, or PlayingComputerPlayers, or DefeatedComputerPlayersWhoWerePlaying, or...
Just use a loop. :)
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
I mean, it's obscure, right? You've covered some random things, but what if people want PlayingHumanPlayers, or PlayingComputerPlayers, or DefeatedComputerPlayersWhoWerePlaying, or...
Use "And".
JASS:
Players_IsHuman(player) and Players_IsPlaying(player)
 

Nestharus

o-o
Reaction score
84
Yea, I still don't think this kind of thing is that useful...

I use things like this in every map I do and I use things like this in every system that requires initialization for human players or computer players or a combination ;).

I use it all the time, lol ;p
 

Romek

Super Moderator
Reaction score
964
Graveyarded for reasons stated above.

I think everyone uses something like this.
Though I prefer ':' syntax for things like this though.
JASS:
local player p = GetTriggerPlayer()
if p:isPlaying and p:isHuman then
    call BJDebugMsg(p:Name + &quot;&#039;s Number is: &quot; + I2S(p:Id))
endif
 

Nestharus

o-o
Reaction score
84
Actually, as I keep saying, state playing is deprecated as there is a better solution.

Look under my players snippet to find out ^_^, it's in the last or second last post where I discuss the solution ;p. It's even less typing ^_^
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top