[vJass] Any suggestions for this system?

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
I'm still polishing some things of the system however perhaps someone has an idea on how to improve it even more.
The userdata system was created to enable you to use user specific values without having to worry about their index number.
Executing player specific natives is pretty much unnecessary with this system because everything is embedded into the struct user.
Everything works asfar as I'm aware off, I'm just not sure about the way I handle the onUpdate event.
Does anyone has perhaps an idea for it, for an event handler and an idea for the plugin system?

Anyways, please post suggestions that may improve the system.

UserData System
JASS:
library UserData
    scope ReadMe
        //**************************
        //* UserData
        //* ¯¯¯¯¯¯¯¯
        //* Author  : Themis@Azeroth, StealthOfKing@Azeroth.
        //* URL     : <a href="http://www.clanbom.com" target="_blank" class="link link--external" rel="nofollow ugc noopener">www.clanbom.com</a>
        //* Credits : Required.
        //* Date    : Sunday, 21 December, 2008
        //* 
        //* The struct UserData holds values of players that can be used globaly in any map.
        //* Instead of calling the good old natives like &quot;Player&quot; always return the same value.
        //* If you look at the system you will see a lot of globals and methods, these are all
        //*  inlined in your code if you&#039;re using vexorians optimizer so the speed of this script
        //*  will increase, while your way of programming is changed completely.
        //* No more messing with indexes of player values, most values you need are in global 
        //*  variables so no more inefficient scripts!
        //* 
        //* This system is designed to keep track of the players original color.
        //* For example, if I&#039;m first in the game lobby my Player() index would be 0 (red).
        //* However if I can choose my player color ( for example orange ) my index would still
        //*  be 0 but my username in color should change from red to orange.
        //* This system is desinged to fix that issue for you, so even with my index as 0 my
        //*  color would be orange, not only for the hex string but for the rgb color aswell.
        //* RGB can be used for unit vertex color, minimap ping colors, lightning colors, with
        //*  this system keeping track of the player data, making scripts was never so easy!
        //*                                                ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
        //****************************************************************************************************************
    endscope
    
    scope Configuration
        globals
            constant integer USERDATA_HOST_DEFAULT_ID      = 0
            constant boolean USERDATA_HOST_USE_FINDHOST    = true
            constant string  USERDATA_HEX_STRING           = &quot;FF02020041FF1BE6D8530080FFFC00FE890D1FBF00E55AAF9495967DBEF10F61454D2903272727272727272727272727&quot;
            constant string  USERDATA_RGB_R_STRING         = &quot;255000027083255254031229148125015077039039039039&quot;
            constant string  USERDATA_RGB_G_STRING         = &quot;002065230000252137191090149190097041039039039039&quot;
            constant string  USERDATA_RGB_B_STRING         = &quot;002255184128000013000175150241069003039039039039&quot;
            constant string  USERDATA_NAMES_STRING         = &quot;redbluetealpurpleyelloworangegreenpinkgraylight bluedark greenbrown&quot;
            constant string  USERDATA_NAMES_FILTER         = &quot;030711172329343842526267&quot;
        endglobals
    endscope
    
    struct user extends array
        
        static trigger         eventUpdate   = CreateTrigger()
        static gamecache       findHostCache = null
        
        static player          localPlayer
        static user            localUser
        public boolean         isLocal
        static user            host
        
        public player          p
        public integer         cid
        public string          name
        public race            specie
        public playercolor     color
        public string          colorName
        public string          hex
        public string          hexName
        public string          hexColorName
        public integer         rgbRed
        public integer         rgbGreen
        public integer         rgbBlue
        
        public mapcontrol      controller
        public playerslotstate slotState
        

     /////////////////////////////
     // Private Methods
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // These methods are used within the system and do not concern you.
     // Don&#039;t though them unless you know what you&#039;re doing.
      //
        private static method h2i takes handle h returns integer
            return h
            return 0
        endmethod
        private method getHex takes nothing returns string
            return &quot;|cff&quot; + SubString( USERDATA_HEX_STRING, this * 6, ( this * 6 ) + 6 )
        endmethod
        private method getColorRgb takes string s returns integer
            return S2I( SubString( s, this * 3, ( this * 3 ) + 3 ) )
        endmethod
        private method getColorName takes nothing returns string
            return SubString( USERDATA_NAMES_STRING, S2I( SubString( USERDATA_NAMES_FILTER, (this * 2) - 2, (this * 2) ) ), S2I( SubString( USERDATA_NAMES_FILTER, (this * 2), (this * 2) + 2 ) ) )
        endmethod
        private static method findHost takes nothing returns user
            local integer array count
            local user          syncedPlayer = 0
            local user          tempPlayer   = 0
            
            if not USERDATA_HOST_USE_FINDHOST then
                return USERDATA_HOST_DEFAULT_ID
            endif
            loop
               exitwhen tempPlayer &gt;= 12
               set tempPlayer:count = 0
               set tempPlayer = tempPlayer + 1
            endloop
            loop
               exitwhen tempPlayer &lt;= 0
               call StoreInteger( .findHostCache, &quot;find&quot;, &quot;host&quot;, .localUser + 1 ) 
               call TriggerSyncStart()
               call SyncStoredInteger( .findHostCache, &quot;find&quot;, &quot;host&quot; )
               call TriggerSyncReady()
               set syncedPlayer = GetStoredInteger( .findHostCache, &quot;find&quot;, &quot;host&quot; ) - 1
               set syncedPlayer:count = syncedPlayer:count + 1
               set tempPlayer = tempPlayer - 1
            endloop
            set syncedPlayer = 0
            loop
               exitwhen tempPlayer &gt;= 12
               if syncedPlayer:count &lt; tempPlayer:count then
                  set syncedPlayer = tempPlayer
               endif
               set tempPlayer = tempPlayer + 1
            endloop
            return syncedPlayer
        endmethod

        
     /////////////////////////////
     // Fetching The User Type
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // A more simplified way to retrieve the user data of a player.
      //
        static method getTriggerUser takes nothing returns user
            return GetPlayerId( GetTriggerPlayer() )
        endmethod
        static method getFilterUser takes nothing returns user
            return GetPlayerId( GetFilterPlayer() )
        endmethod
        static method getItemUser takes item i returns user
            return GetPlayerId( GetItemPlayer( i ) )
        endmethod
        static method getOwningUser takes unit u returns user
            return GetPlayerId( GetOwningPlayer( u ) )
        endmethod
        static method getEventDetectingUser takes nothing returns user
            return GetPlayerId( GetEventDetectingPlayer() )
        endmethod

        
     /////////////////////////////
     // Display Game Messages
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // Display text to a player, or display them to all using the local player 
     //  variable inside this library.
      //
        method displayText takes string s returns nothing
            call DisplayTextToPlayer( .p, 0, 0, s )
        endmethod
        method displayTextEx takes real x, real y, string s returns nothing
            call DisplayTextToPlayer( .p, x, y, s ) 
        endmethod
        method displayTimedText takes string s, real duration returns nothing
            call DisplayTimedTextToPlayer( .p, 0, 0, duration, s )
        endmethod
        method displayTimedTextEx takes real x, real y, string s, real duration returns nothing
            call DisplayTimedTextToPlayer( .p, x, y, duration, s )
        endmethod
        method displayTimedTextFromUser takes real x, real y, real duration, string message returns nothing
            call DisplayTimedTextFromPlayer( .p, x, y, duration, message )
        endmethod


     /////////////////////////////
     // Add/Remeove Player Values
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // Methods that add or remove player values.
     // These are either natives or simplied methods.
      //     
        method addTechResearched takes integer techId, integer levels returns nothing
            call AddPlayerTechResearched( .p, techId, levels )
        endmethod
        method addState takes playerstate state, integer value returns nothing
            call SetPlayerState( .p, state, GetPlayerState( .p, state ) + value )
        endmethod
        method remState takes playerstate state, integer value returns nothing
            call SetPlayerState( .p, state, GetPlayerState( .p, state ) - value )
        endmethod
        
        
     /////////////////////////////
     // Set Player Values
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // Methods that set player values to their new value.
     // Don&#039;t forget to use the user[0].update() method if you change values that
     //  that are stored in the variables.
     // This is updated on certain events only, but if you set a new player 
     //  name update it manually.
      //
        method setAbilityAvailable takes integer id, boolean avail returns nothing
            call SetPlayerAbilityAvailable( .p, id, avail )
        endmethod
        method setAlliance takes user u, alliancetype setting, boolean value returns nothing
            call SetPlayerAlliance( .p, u.p, setting, value )
        endmethod
        method setBlight takes real x, real y, real radius, boolean addBlight returns nothing
            call SetBlight( .p, x, y, radius, addBlight )
        endmethod
        method setBlightRect takes rect r, boolean addBlight returns nothing
            call SetBlightRect( .p, r, addBlight )
        endmethod
        method setBlightPoint takes real x, real y, boolean addBlight returns nothing
            call SetBlightPoint( .p, x, y, addBlight )
        endmethod
        method setColor takes playercolor c returns nothing
            call SetPlayerColor( .p, c )
        endmethod
        method setController takes mapcontrol controller returns nothing
            call SetPlayerController( .p, controller )
        endmethod
        method setHandicap takes real value returns nothing
            call SetPlayerHandicap( .p, value )
        endmethod
        method setHandicapXP takes real value returns nothing
            call SetPlayerHandicapXP( .p, value )
        endmethod
        method setItemPlayer takes item whichItem, boolean changeColor returns nothing
            call SetItemPlayer( whichItem, .p, changeColor )
        endmethod
        method setName takes string name returns nothing
            call SetPlayerName( .p, name )
        endmethod
        method setOnScoreScreen takes boolean flag returns nothing
            call SetPlayerOnScoreScreen( .p, flag )
        endmethod
        method setRacePreference takes racepreference preference returns nothing
            call SetPlayerRacePreference( .p, preference )
        endmethod
        method setRaceSelectable takes boolean flag returns nothing
            call SetPlayerRaceSelectable( .p, flag )
        endmethod
        method setStartLocation takes integer startIndex returns nothing
            call SetPlayerStartLocation( .p, startIndex )
        endmethod
        method setState takes playerstate state, integer value returns nothing
            call SetPlayerState( .p, state, value )
        endmethod
        method setTaxRate takes user u, playerstate state, integer rate returns nothing
            call SetPlayerTaxRate( .p, u.p, state, rate )
        endmethod
        method setTeam takes integer team returns nothing
            call SetPlayerTeam( .p, team )
        endmethod
        method setTechMaxAllowed takes integer id, integer max returns nothing
            call SetPlayerTechMaxAllowed( .p, id, max )
        endmethod
        method setTechResearched takes integer id, integer toLevel returns nothing
            call SetPlayerTechResearched( .p, id, toLevel )
        endmethod
        method setUnitColor takes unit whichUnit, user r returns nothing
            call SetUnitColor( whichUnit, r.color )
        endmethod
        method setUnitRescueable takes unit whichUnit, boolean flag returns nothing
            call SetUnitRescuable( whichUnit, .p, flag )
        endmethod
        method setUnitsOwner takes integer newOwner returns nothing
            call SetPlayerUnitsOwner( .p, newOwner )
        endmethod
        
        
     /////////////////////////////
     // Get Player Values
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // Some methods like getting the players name are not in this list.
     // Use the variable for that, its more efficient.
      //
        method getAlliance takes user u, alliancetype setting returns boolean
            return GetPlayerAlliance( .p, u.p, setting )
        endmethod
        method getColor takes nothing returns playercolor
            return GetPlayerColor( .p )
        endmethod
        method getController takes nothing returns mapcontrol
            return GetPlayerController( .p )
        endmethod
        method getHandicap takes nothing returns real
            return GetPlayerHandicap( .p )
        endmethod        
        method getHandicapXP takes nothing returns real
            return GetPlayerHandicapXP( .p )
        endmethod 
        method getName takes nothing returns string
            return GetPlayerName( .p )
        endmethod
        method getRace takes nothing returns race
            return GetPlayerRace( .p )
        endmethod
        method getScore takes playerscore score returns integer
            return GetPlayerScore( .p, score )
        endmethod
        method getSelectable takes nothing returns boolean
            return GetPlayerSelectable( .p )
        endmethod
        method getSlotState takes nothing returns playerslotstate
            return GetPlayerSlotState( .p )
        endmethod
        method getStartLocationX takes nothing returns real
            return GetStartLocationX( GetPlayerStartLocation( .p ) )
        endmethod
        method getStartLocationY takes nothing returns real
            return GetStartLocationY( GetPlayerStartLocation( .p ) )
        endmethod
        method getState takes playerstate state returns integer
            return GetPlayerState( .p, state )
        endmethod
        method getStructureCount takes boolean includeIncomplete returns integer
            return GetPlayerStructureCount( .p, includeIncomplete )
        endmethod
        method getTaxRate takes user u, playerstate state returns integer
            return GetPlayerTaxRate( .p, u.p, state )
        endmethod
        method getTeam takes nothing returns integer
            return GetPlayerTeam( .p )
        endmethod
        method getTechCount takes integer id, boolean specifionly returns integer
            return GetPlayerTechCount( .p, id, specifionly )
        endmethod
        method getTechMaxAllowed takes integer id returns integer
            return GetPlayerTechMaxAllowed( .p, id )
        endmethod
        method getTechResearched takes integer id, boolean specificonly returns boolean
            return GetPlayerTechResearched( .p, id, specificonly )
        endmethod
        method getTypedUnitCount takes string unitName, boolean includeIncomplete, boolean includeUpgrades returns integer
            return GetPlayerTypedUnitCount( .p, unitName, includeIncomplete, includeUpgrades )
        endmethod
        method getUnitCount takes boolean includeIncomplete returns integer
            return GetPlayerUnitCount( .p, includeIncomplete )
        endmethod

        
     /////////////////////////////
     // Player ID values
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // Need player values by their true slot ID, use these methods.
     // UserData profides you only with variable indexes that match the player
     //  color, so using these methods allow you access their default values.
     // Still, they are depriciated and you shouldn&#039;t use them.
      //
        method getIdHex takes nothing returns string
            return .getHex()
        endmethod
        method getIdHexName takes nothing returns string
            return .getHex() + .getName() + &quot;|r&quot;
        endmethod
        method getIdColorName takes nothing returns string
            return .getColorName()
        endmethod
        method getIdHexColorName takes nothing returns string
            return .getHex() + .getColorName() + &quot;|r&quot;
        endmethod
        method getIdRgbRed takes nothing returns integer
            return .getColorRgb( USERDATA_RGB_R_STRING )
        endmethod
        method getIdRgbGreen takes nothing returns integer
            return .getColorRgb( USERDATA_RGB_G_STRING )
        endmethod
        method getIdRgbBlue takes nothing returns integer
            return .getColorRgb( USERDATA_RGB_B_STRING )
        endmethod
        
        
     /////////////////////////////
     // Is Checks
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // These methods profide an easy boolean check for players.
     // From slotstates to controller to race checks, and other
     //  stuff all made easy.
      //
        method isHost takes nothing returns boolean
            return this == user.host
        endmethod
        method isUser takes nothing returns boolean
            return .controller == MAP_CONTROL_USER
        endmethod
        method isComputer takes nothing returns boolean
            return .controller == MAP_CONTROL_COMPUTER
        endmethod
        method isCreep takes nothing returns boolean
            return .controller == MAP_CONTROL_CREEP
        endmethod
        method isNeutral takes nothing returns boolean
            return .controller == MAP_CONTROL_NEUTRAL
        endmethod
        method isNone takes nothing returns boolean
            return .controller == MAP_CONTROL_NONE
        endmethod
        method isRescuable takes nothing returns boolean
            return .controller == MAP_CONTROL_RESCUABLE
        endmethod
        method isPlaying takes nothing returns boolean
            return .slotState == PLAYER_SLOT_STATE_PLAYING
        endmethod
        method isLeaver takes nothing returns boolean
            return .slotState == PLAYER_SLOT_STATE_LEFT
        endmethod
        method isEmpty takes nothing returns boolean
            return .slotState == PLAYER_SLOT_STATE_EMPTY
        endmethod
        method isPlayingUser takes nothing returns boolean
            return .isUser() and .isPlaying()
        endmethod
        method isUserAlly takes user u returns boolean
            return IsPlayerAlly( .p, u.p )
        endmethod
        method isUserEnemy takes user u returns boolean
            return IsPlayerEnemy( .p, u.p )
        endmethod
        method isInForce takes force whichForce returns boolean
            return IsPlayerInForce( .p, whichForce )
        endmethod
        method isObserver takes nothing returns boolean
            return IsPlayerObserver( .p )
        endmethod
        method isHuman takes nothing returns boolean
            return .specie == RACE_HUMAN
        endmethod
        method isOrc takes nothing returns boolean
            return .specie == RACE_ORC
        endmethod
        method isNightElve takes nothing returns boolean
            return .specie == RACE_NIGHTELF
        endmethod
        method isUndead takes nothing returns boolean
            return .specie == RACE_UNDEAD
        endmethod
        method isDemon takes nothing returns boolean
            return .specie == RACE_DEMON
        endmethod
        method isOther takes nothing returns boolean
            return .specie == RACE_OTHER
        endmethod
        method isRace takes race whichRace returns boolean
            return .specie == whichRace
        endmethod
        method isRacePrefSet takes racepreference pref returns boolean
            return IsPlayerRacePrefSet( .p, pref )
        endmethod
        method isUnitOwner takes unit whichUnit returns boolean
            return IsUnitOwnedByPlayer( whichUnit, .p )
        endmethod
        method isUnitAlly takes unit whichUnit returns boolean
            return IsUnitAlly( whichUnit, .p )
        endmethod
        method isUnitEnemy takes unit whichUnit returns boolean
            return IsUnitEnemy( whichUnit, .p )
        endmethod    
        method isUnitVisible takes unit whichUnit returns boolean
            return IsUnitVisible( whichUnit, .p )
        endmethod  
        method isUnitDetected takes unit whichUnit returns boolean
            return IsUnitDetected( whichUnit, .p )
        endmethod   
        method isUnitInvisible takes unit whichUnit returns boolean
            return IsUnitInvisible( whichUnit, .p )
        endmethod  
        method isUnitFogged takes unit whichUnit returns boolean
            return IsUnitFogged( whichUnit, .p )
        endmethod       
        method isUnitMasked takes unit whichUnit returns boolean
            return IsUnitMasked( whichUnit, .p )
        endmethod     
        method isUnitSelected takes unit whichUnit returns boolean
            return IsUnitSelected( whichUnit, .p )
        endmethod   
        method isVisible takes real x, real y returns boolean
            return IsVisibleToPlayer( x, y, .p )
        endmethod
        method isFogged takes real x, real y returns boolean
            return IsFoggedToPlayer( x, y, .p )
        endmethod
        method isMasked takes real x, real y returns boolean
            return IsMaskedToPlayer( x, y, .p )
        endmethod


     /////////////////////////////
     // Force Related Methods
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // These methods profide an easy call to a force related native.
     // You are not forced to use them, but just like the event registering
     //  it can make it easier to do things.
      //
        method forceAdd takes force whichForce returns nothing
            call ForceAddPlayer( whichForce, .p )
        endmethod
        method forceRemove takes force whichForce returns nothing
            call ForceRemovePlayer( whichForce, .p )
        endmethod
        method forceEnumAllies takes force whichForce, boolexpr filter returns nothing
            call ForceEnumAllies( whichForce, .p, filter )
        endmethod
        method forceEnumEnemies takes force whichForce, boolexpr filter returns nothing
            call ForceEnumEnemies( whichForce, .p, filter )
        endmethod
        
     /////////////////////////////
     // Unit Related Methods
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // These methods profide an easy call to a unit related native.
     // You are not forced to use them, but just like the event registering
     //  it can make it easier to do things.
      //
        method createBlightedGoldmine takes real x, real y, real face returns unit
            return CreateBlightedGoldmine( .p, x, y, face )
        endmethod
        method createUnit takes integer id, real x, real y, real face returns unit
            return CreateUnit( .p, id, x, y, face )
        endmethod
        method createUnitByName takes string unitname, real x, real y, real face returns unit
            return CreateUnitByName( .p, unitname, x, y, face )
        endmethod
        method createUnitAtLoc takes integer id, location l, real face returns unit
            return CreateUnitAtLoc( .p, id, l, face )
        endmethod
        method createUnitAtLocByName takes string unitname, location l, real face returns unit
            return CreateUnitAtLocByName( .p, unitname, l, face )
        endmethod
        method createCorpse takes integer id, real x, real y, real face returns unit
            return CreateCorpse( .p, id, x, y, face )
        endmethod
        method groupEnumUnits takes group whichGroup, boolexpr filter returns nothing
            call GroupEnumUnitsOfPlayer( whichGroup, .p, filter )
        endmethod
        method groupEnumUnitsSelected takes group whichGroup, boolexpr filter returns nothing
            call GroupEnumUnitsSelected( whichGroup, .p, filter )
        endmethod
        method issueNeutralImmediateOrder takes unit neutralStructure, string unitToBuild returns boolean
            return IssueNeutralImmediateOrder( .p, neutralStructure, unitToBuild )
        endmethod
        method issueNeutralImmediateOrderById takes unit neutralStructure, integer unitId returns boolean
            return IssueNeutralImmediateOrderById( .p, neutralStructure, unitId )
        endmethod
        method issueNeutralPointOrder takes unit neutralStructure, string unitToBuild, real x, real y returns boolean
            return IssueNeutralPointOrder( .p, neutralStructure, unitToBuild, x, y )
        endmethod
        method issueNeutralPointOrderById takes unit neutralStructure, integer unitId, real x, real y returns boolean
            return IssueNeutralPointOrderById( .p, neutralStructure, unitId, x, y )
        endmethod
        method issueNeutralTargetOrder takes unit neutralStructure, string unitToBuild, widget target returns boolean
            return IssueNeutralTargetOrder( .p, neutralStructure, unitToBuild, target )
        endmethod
        method issueNeutralTargetOrderById takes unit neutralStructure, integer unitId, widget target returns boolean
            return IssueNeutralTargetOrderById( .p, neutralStructure, unitId, target )
        endmethod
        method placeRandomUnit takes unitpool whichPool, real x, real y, real facing returns unit
            return PlaceRandomUnit( whichPool, .p, x, y, facing )
        endmethod
        method restoreUnit takes gamecache cache, string missionKey, string key, real x, real y, real facing returns unit
            return RestoreUnit( cache, missionKey, key, .p, x, y, facing )
        endmethod
        method unitShareVision takes unit whichUnit, boolean flag returns nothing
            call UnitShareVision( whichUnit, .p, flag )
        endmethod

     /////////////////////////////
     // Leaderboard
     //¯¯¯¯¯¯¯¯¯¯¯¯
      //
        method leaderboardAdd takes leaderboard lb, string label, integer value returns nothing
            call LeaderboardAddItem( lb, label, value, .p )
        endmethod
        method leaderboardRemove takes leaderboard lb returns nothing
            call LeaderboardRemoveItem( lb, this )
        endmethod
        method LeaderboardHasItem takes leaderboard lb returns boolean
            return LeaderboardHasPlayerItem( lb, .p )
        endmethod
        method LeaderboardGetIndex takes leaderboard lb returns integer
            return LeaderboardGetPlayerIndex( lb, .p )
        endmethod
        method setLeaderboardUser takes leaderboard lb returns nothing
            call PlayerSetLeaderboard( .p, lb )
        endmethod
        method getLeaderboardUser takes nothing returns leaderboard
            return PlayerGetLeaderboard( .p )
        endmethod
        
     /////////////////////////////
     // Other Methods
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // These methods are uncatagorized, just look at the method
     //  name and see what it does.
      //
        method cachePlayerHeroData takes nothing returns nothing
            call CachePlayerHeroData( .p )
        endmethod
        method dialogDisplay takes dialog whichDialog, boolean flag returns nothing
            call DialogDisplay( .p, whichDialog, flag )
        endmethod
        method forceStartLocation takes integer startLocIndex returns nothing
            call ForcePlayerStartLocation( .p, startLocIndex )
        endmethod
        method remove takes playergameresult gameResult returns nothing
            call RemovePlayer( .p, gameResult )
        endmethod


     /////////////////////////////
     // Fog Modifiers
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // Artificial Intellegence base of operations.
      //
        method createFogModifierRadius takes fogstate whichState, real x, real y, real radius, boolean sharedVision, boolean afterUnits returns fogmodifier
            return CreateFogModifierRadius( .p, whichState, x, y, radius, sharedVision, afterUnits )
        endmethod
        method createFogModifierRect takes fogstate whichState, rect whichRect, boolean sharedVision, boolean afterUnits returns fogmodifier
            return CreateFogModifierRect( .p, whichState, whichRect, sharedVision, afterUnits )
        endmethod
        method setFogStateRect takes fogstate whichState, rect where, boolean useSharedVision returns nothing
            call SetFogStateRect( .p, whichState, where, useSharedVision )
        endmethod
        method setFogStateRadius takes fogstate whichState, real centerX, real centerY, real radius, boolean useSharedVision returns nothing
            call SetFogStateRadius( .p, whichState, centerX, centerY, radius, useSharedVision )
        endmethod
        
        
     /////////////////////////////
     // AI Methods
     //¯¯¯¯¯¯¯¯¯¯¯
     // Artificial Intellegence base of operations.
      //
        method startMeleeAI takes string script returns nothing
            call StartMeleeAI( .p, script )
        endmethod
        method startCampaignAI takes string script returns nothing
            call StartCampaignAI( .p, script )
        endmethod
        method commandAI takes integer command, integer data returns nothing
            call CommandAI( .p, command, data )
        endmethod
        method pauseCompAI takes boolean pause returns nothing
            call PauseCompAI( .p, pause )
        endmethod
        method getAIDifficulty takes nothing returns aidifficulty
            return GetAIDifficulty( .p )
        endmethod
        method removeAllGuardPositions takes nothing returns nothing
            call RemoveAllGuardPositions( .p )
        endmethod


        
     /////////////////////////////
     // Registering Player Events
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // Registering player events made easy.
      //
        method registerEvent takes trigger t, playerevent e returns event
            return TriggerRegisterPlayerEvent( t, .p, e )
        endmethod
        method registerChatEvent takes trigger t, string message, boolean exactMatch returns event
            return TriggerRegisterPlayerChatEvent( t, .p, message, exactMatch )
        endmethod
        method registerAllianceChange takes trigger t, alliancetype a returns event
            return TriggerRegisterPlayerAllianceChange( t, .p, a )
        endmethod
        method registerStateEvent takes trigger t, playerstate state, limitop opcode, real limitval returns event
            return TriggerRegisterPlayerStateEvent( t, .p, state, opcode, limitval )
        endmethod
        method registerUnitEvent takes trigger t, playerunitevent e, boolexpr filter returns event
            return TriggerRegisterPlayerUnitEvent( t, .p, e, filter )
        endmethod
        
        
     /////////////////////////////
     // Update Player Data
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // Important if you use some set methods, otherwise obeselete.
      //
        method update takes nothing returns nothing
            set .controller     = .getController()
            set .slotState      = .getSlotState()
            
            if .color != .getColor() or .name != .getName() then
                set .name           = .getName()
                set .color          = .getColor()
                set .cid             = h2i( .color )
                
                set .colorName      = user[.cid].getColorName()
                set .hex            = user[.cid].getHex()
                set .hexName        =           .hex + .name + &quot;|r&quot;
                set .hexColorName   =           .hex + .colorName + &quot;|r&quot;
                set .rgbRed         = user[.cid].getColorRgb( USERDATA_RGB_R_STRING )
                set .rgbGreen       = user[.cid].getColorRgb( USERDATA_RGB_G_STRING )
                set .rgbBlue        = user[.cid].getColorRgb( USERDATA_RGB_B_STRING )
            endif
            
            if .isHost() then
                set .host = .findHost()
            endif
        endmethod
        private static method onEventUpdate takes nothing returns nothing
            call .getTriggerUser().update()
        endmethod

        
     /////////////////////////////
     // UserData Plugin System
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // The UserData library supports plugins that could extend the use of it.
     // Instead of making a wide complicated system and give support for
     //  everything, people have the option to use a plugin or not.
     // Run the plugin textmacro for the UserData library here.
      //
        
        
     /////////////////////////////
     // The onInit method
     //¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
     // This is were the magic happens.
      //        
        private static method onInit takes nothing returns nothing
            local user    u = 0
                       
            loop
                exitwhen integer( u ) &gt; 15
                
                set u.p      = Player( u )
                set u.specie = GetPlayerRace( u.p )
                
                call u.update()
                
                if u.isPlayingUser() then
                    call u.registerEvent( .eventUpdate, EVENT_PLAYER_LEAVE )
                endif
                
                set u = u + 1
            endloop
            
            set .findHostCache = InitGameCache( &quot;findHost.w3v&quot; )
            call StoreInteger( .findHostCache, &quot;1&quot;, &quot;1&quot;, 1 )
            
            set .localPlayer       = GetLocalPlayer()
            set .localUser         = GetPlayerId( .localPlayer )
            set .localUser.isLocal = true
            set .host              = .findHost()
            
            call TriggerAddAction( .eventUpdate, function user.onEventUpdate )
        endmethod

    endstruct

endlibrary


Example Script - Might give you some insight on howto use the system.
JASS:
scope UserDataExample initializer init
    
    function actions takes nothing returns nothing
        local unit uDying  = GetDyingUnit()
        local unit uKiller = GetKillingUnit()
        local user dying   = user.getOwningUser( uDying )
        local user killer  = user.getOwningUser( uKiller )
        
        // What if the player is killing his own units...
        if dying == killer then
            return
        endif
        
        // Display Messages to the triggering players.
        call dying.displayText( &quot;Your unit was kiled by one of &quot; + killer.hexName + &quot;&#039;s units.&quot; )
        call killer.displayText( &quot;You killed &quot; + dying.hexName + &quot;&#039;s unit for an aditional 10 gold bonus!&quot; )
        call killer.addState( PLAYER_STATE_RESOURCE_GOLD, 10 )
        
        if dying.isLocal or killer.isLocal then
            // Exit the code for the people who were battling against each other..
            return
        endif
        
        // Ping the minimap in the colors of the triggering players..
        call PingMinimapEx( GetUnitX( uDying ), GetUnitY( uDying ), 10, dying.rgbRed, dying.rgbGreen, dying.rgbBlue, false ) 
        call PingMinimapEx( GetUnitX( uKiller ), GetUnitY( uKiller ), 10, killer.rgbRed, killer.rgbGreen, killer.rgbBlue, true ) 
        
        // Display messages to the players that must know their was an epic battle..
        // Since the triggering users already exited the function, this doesn&#039;t count for them.
        call user.localUser.displayText( killer.hexName + &quot; has killed &quot; + dying.hexName + &quot;&#039;s unit!&quot; )
    endfunction
    
    function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local user    u = 0
        
        loop
            exitwhen integer( u ) &gt; 11
            
            call u.registerUnitEvent( t, EVENT_PLAYER_UNIT_DEATH, null )
            set u = u + 1
        endloop
        
        call TriggerAddAction( t, function actions )
        
        set t = null
    endfunction

endscope
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Looks like a cool idea. I had similar ideas about making struct-wrapper functions for strings, though I put it aside. However, I like the simplicity of the 'get' methods.

One thing that bothered me a little, was the fact that the 'host' was a member of the struct, instead of a global. I think a boolean "isHost" member might be a good idea, as well.

It would be interesting to see a further addition to include forces.

Another idea would be to add a [] operator, and make it simply return user(#).

Kudos to you. This looks to be a useful system! :D
 

Builder Bob

Live free or don't
Reaction score
249
I was a little skeptical at first, but after reading through the system I found many useful methods that I can think of good uses for. If all these methods get inlined by vex optimizer, it'll save me a lot of function calls.

Good job!


To Darthfett: host is a static member, which is the same as a global: user.host
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
Looks like a cool idea. I had similar ideas about making struct-wrapper functions for strings, though I put it aside. However, I like the simplicity of the 'get' methods.

One thing that bothered me a little, was the fact that the 'host' was a member of the struct, instead of a global. I think a boolean "isHost" member might be a good idea, as well.

It would be interesting to see a further addition to include forces.

Another idea would be to add a [] operator, and make it simply return user(#).

Kudos to you. This looks to be a useful system! :D
Thanks, the idea is good but "isHost" will not be a member, I'll make it a method.
Methods get removed from the system by the optimizer if its not used, variable members of the system don't.
Currently you can check it this way:
JASS:
if u == user.host then

But I'm gonna add this method for simplicity ;]
JASS:
if u.isHost() then

Your idea helped me to create a better idea out of it, thanks ;]

The other idea about forces, well. I haven't used forces is a long long time and I think they should be banned from practice.
But I'll think about it.

And a method operator, for what?
JASS:
local user u = 1 // We have all the data of Player(1)!
call DialogDisplay( u.p, DialogCreate(), true )
call DialogDisplay( user[4].p, DialogCreate(), true )
call user[6].displayText( &quot;Hello, this is a message to Player(6). And his name is, dum dum dum: &quot; + user[6].hexName )
call user.host.displayText( &quot;This is a message to the host.&quot; )
call user.localUser.displayText( &quot;This is a message to all the players!&quot; )

These are all valid syntaxes.

Yeah, the simplicity of the get methods is pretty sweet however player related data like names should be fetched out of the variables, not methods.

I was a little skeptical at first, but after reading through the system I found many useful methods that I can think of good uses for. If all these methods get inlined by vex optimizer, it'll save me a lot of function calls.

Good job!


To Darthfett: host is a static member, which is the same as a global: user.host

The system is build upon the idea that it should be optimized otherwise it isn't really efficient, but thanks for the support ;]
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
Updated the UserData, added every native that takes a player so you don't ever have to use "*.p" again in normal calls.

Any comments?
 

emjlr3

Change can be a good thing
Reaction score
395
that is a lot to remember syntax for...
 

Viikuna

No Marlo no game.
Reaction score
265
True. Systems should not have too many custom functions/methods because it takes lot of time to learn and rememebr them all.

Anyways, that example looks prety neat.
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
that is a lot to remember syntax for...

True. Systems should not have too many custom functions/methods because it takes lot of time to learn and rememebr them all.

Anyways, that example looks prety neat.

Well actually the method names differ not so much from the natives themselves.

JASS:
native SetPlayerTeam()
native getPlayerTeam()
call u.setTeam()
call u.getTeam()

native IsPlayerInForce()
call u.isInForce()

native GetTriggerPlayer()
call u.getTriggerUser()


Actually most of them just begin with a small letter instead of a capital one.
It is not so much of remembering them, its getting used to the ones you use.
I highly doubt you will use all the methods in this library, but everything is added in case you do need to call that specific native.

Would you instead have methods that arn't used much removed from the library?
I added them just in case someone does need them.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top