Get Local Player?

N(O.O)B

New Member
Reaction score
27
Is there anyway to get the local player with the galaxy language (like the GetLocalPlayer() function in JASS)?
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
I found this but I am not sure if it does the same thing that GetLocalPlayer() does in warcraft 3.

It comes with bonus stuff ^^ (all made by blizzard I guess...)
JASS:
include "TriggerLibs/natives"
include "TriggerLibs/nativelib"

//============================================================
// Globals

const bool key_down = true;
const bool key_up = false;

timer GameGlobalTimer = null;

int Local_Player = 0; //need init


//SwitchToBase
int LastSwitchBaseIndex = 0;
fixed LastSwitchBaseTime = 0;


//============================================================
fixed GameTime () {
  return TimerGetElapsed(GameGlobalTimer);
}

bool FindLocalPlayer (bool testConds, bool runActions) {
    text showText;
    // Actions
    if (!runActions) {
        return true;
    }

    showText = StringToText("Player: "+IntToString(EventPlayer())+" pressed key:  "+IntToString(EventKeyPressed()));
    UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, showText);

    if (Local_Player == 0) {          // if not initialized
        Local_Player = EventPlayer(); // found local player which is != 0
    }

    return true;
}

int GetLocalPlayer () {
    return Local_Player;
}

void ScreenMsg (string showString) {
  UIDisplayMessage(PlayerGroupAll(), c_messageAreaSubtitle, StringToText(showString));
}

//============================================================



//============================================================
bool TriggerTemplate (bool testConds, bool runActions) {
  text showText;
  // Actions
  if (!runActions) {
      return true;
  }

  // Run actions here.

  return true;
}
//============================================================


bool SwitchToBase (bool testConds, bool runActions) {
  unitgroup g_all;
  unitgroup g;
  int i;
  int count;
  unit u;
  string utype;

  // Actions
  if (!runActions) {
      return true;
  }

  g_all = UnitGroup(null, GetLocalPlayer(), RegionEntireMap(), UnitFilter((1 << c_targetFilterStructure), 0, (1 << c_targetFilterMissile), (1 << (c_targetFilterDead - 32)) | (1 << (c_targetFilterHidden - 32))), 0);
  g = UnitGroupEmpty();

  // get all bases of local player
  i = 1;
  count = UnitGroupCount(g_all, c_unitCountAll);
  while (i<=count) {
    u = UnitGroupUnit(g_all, i);
    utype = UnitGetType(u);
    if ( utype=="Nexus" || utype=="CommandCenter" || utype=="CommandCenterFlying" || utype=="OrbitalCommand" || utype=="OrbitalCommandFlying" || utype=="PlanetaryFortress" || utype=="Hatchery" || utype=="Lair" || utype=="Hive" ) {
      UnitGroupAdd(g, u);
    }
    i+=1;
  }
  UnitGroupClear(g_all);

  // choose one base according to the "last pointer",
  // pan camera and select the base with LastSwitchBaseIndex+1 in the unit group.
  count = UnitGroupCount(g, c_unitCountAll);
  if (count <= 0) {
    return true;
  }

  //if the index is over count, or the feature has not been used for 10 seconds, reset the sequence
  LastSwitchBaseIndex+=1;
  if ( (LastSwitchBaseIndex > count) || (GameTime() - LastSwitchBaseTime > 10.0) ) {
    LastSwitchBaseIndex = 1;
  }

  u = UnitGroupUnit(g,LastSwitchBaseIndex); //the chosen base
  UnitGroupClear(g);

  //pan camera
  CameraPan(GetLocalPlayer(), UnitGetPosition(u), 0.0, -1, 10, false);

  //clear selection and select the base
  UnitClearSelection(GetLocalPlayer());
  UnitSelect(u, GetLocalPlayer(), true);

  //remember last pan camera time.
  LastSwitchBaseTime = GameTime();

  //debug
  //ScreenMsg(FixedToString(GameTime(),3)+"  pan!");

  return true;
}



//============================================================
// Init function
//============================================================
void DreamGalaxyInit () {
    trigger t = null;

    //init game timer
    GameGlobalTimer = TimerCreate();
    TimerStart(GameGlobalTimer, c_timerDurationInfinite, false, c_timeGame);

    //init triggers

    //find local player
    t = TriggerCreate("FindLocalPlayer");
    TriggerAddEventKeyPressed(t, c_playerAny, c_keyNone, key_down, c_keyModifierStateExclude, c_keyModifierStateExclude, c_keyModifierStateExclude);

    //[Switch to base]
    //Hotkey: F2
    //toggle screen to each base
    t = TriggerCreate("SwitchToBase");
    TriggerAddEventKeyPressed(t, c_playerAny, c_keyF2, key_down, c_keyModifierStateExclude, c_keyModifierStateExclude, c_keyModifierStateExclude);


}

Wonder why they didn't make it a native instead?
 
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