• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[vJASS] Entered Game Event

This nifty system detects when a player actually enters the game through the first firing of EVENT_PLAYER_MOUSE_MOVE event. It is guaranteed to fire once the player physically enters the game by setting War3 as the main focus.

I've tested this in lan and it doesn't desync (in a map that has a lot going on).
JASS:
library GameEnterEvent initializer init
    globals
        private constant integer MAX_PLAYER_ID = 23
        private constant string SYNC_PREFIX = "GameEnterEvent_Sync"
    endglobals

    public function onEnter takes nothing returns boolean
        //triggerPlayer just entered the game, do actions here
        return false
    endfunction

    private function OnGameEnter takes nothing returns nothing
        call DisableTrigger(GetTriggeringTrigger())
        call BlzSendSyncData(SYNC_PREFIX,"")
    endfunction

    private function init takes nothing returns nothing
        local integer i = 0
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerEvent(t, GetLocalPlayer(), EVENT_PLAYER_MOUSE_MOVE)
        call TriggerAddCondition(t, function OnGameEnter )
        set t = CreateTrigger()
        loop
            exitwhen i > MAX_PLAYER_ID
            call BlzTriggerRegisterPlayerSyncEvent(t, Player(i), SYNC_PREFIX, false)
            set i = i + 1
        endloop
        call TriggerAddCondition(t, function onEnter)
        set t = null
    endfunction
endlibrary
 
Last edited:
Level 15
Joined
Mar 25, 2016
Messages
1,327
What's the use case for this? Detect AFK players and give them time to enter the game?

vJASS:
private function GameEnterFunc takes player triggerPlayer returns nothing
    //triggerPlayer just entered the game, do actions here
    ...
endfunction
Users should not have to edit the library code. You can add a non-private function so users can define the actions from outside.

vJASS:
private constant integer MAX_PLAYER_ID = 23
Please use a function/constant from common.j for this, so it doesn't break if number of players changes (even if unlikely).

because we cannot safely check GetPlayerController or GetPlayerSlotState during initialization without desync
Do you have a source for this? I've never heard of this problem and these functions are frequently used at initialization. For example PlayerUtils by TriggerHappy.
 
What's the use case for this? Detect AFK players and give them time to enter the game?

vJASS:
private function GameEnterFunc takes player triggerPlayer returns nothing
    //triggerPlayer just entered the game, do actions here
    ...
endfunction
Users should not have to edit the library code. You can add a non-private function so users can define the actions from outside.

vJASS:
private constant integer MAX_PLAYER_ID = 23
Please use a function/constant from common.j for this, so it doesn't break if number of players changes (even if unlikely).


Do you have a source for this? I've never heard of this problem and these functions are frequently used at initialization. For example PlayerUtils by TriggerHappy.
Use case for me specifically is to not start a cinematic sequence/spawn a player until they are ready to join the game

this private constant integer MAX_PLAYER_ID = 23 is meant to be changeable by the user to fit their map specifically (to reduce events/triggers created)

I removed the old code anyways, as it is far less efficient than the new version (which is safe from my testing)
 
Last edited:

Apparently TriggerRegisterPlayerEvent is a big no no during initialization. I humbly request this be graveyarded due to the risk it poses.
 
Top