Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New API Code with December Update
Author Message
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #11
RE: New API Code with December Update
Thanks for the info =)
11-12-2012 07:39 PM
 Search   Quote 
BergErr Offline
Member
***

Posts: 220
Joined: Apr 2012
Post: #12
RE: New API Code with December Update
Nice Smile
12-12-2012 10:00 AM
 Search   Quote 
StryfeASphears Offline
Junior Member
**

Posts: 33
Joined: Nov 2012
Post: #13
RE: New API Code with December Update
(11-12-2012 09:41 AM)Tecin Wrote:  
(06-12-2012 03:28 PM)EA_rhiordd Wrote:  Upgrade all buildings of the current own city:
Code:
var newLevel = 25
ClientLib.API.City.GetInstance().UpgradeAllBuildingsToLevel(newLevel);

First quick question: are there similar function for defense and units?

Also i have a problem with this function, because it does not seem to work for me like i expect.

I tested it with this base:
- Hand of Nod and War Factory at level 27
- all other buildings are level 28
- about enough ressources to upgrade Hand of Nod and War Factory

Now my script trys to upgrade all buildings to the level of the construction yard - which got evaluated correctly with 28, but the function:

ClientLib.API.City.GetInstance().UpgradeAllBuildingsToLevel(28);

ended with my base like this:
- Construction Yard at level 29
- War Factory still at level 27
- all other buildings including Hand of Nod are level 28

After transfering resources and testing it again the construction yard got upgraded to level 30, instead of the others buildings being upgraded to level 29.

Is it intended that the construction yard gets upgraded every time or am i doing something wrong?

Thanks,
Tecin

Can you share your script so i could use it with greesmonkey?
13-12-2012 01:56 AM
 Search   Quote 
Tecin Offline
Junior Member
**

Posts: 9
Joined: May 2012
Post: #14
RE: New API Code with December Update
(13-12-2012 01:56 AM)StryfeASphears Wrote:  Can you share your script so i could use it with greesmonkey?

Yes, the code below is only the relevant part, which is quite simple. I removed the event handler because that is right now not very user-friendly.

Code:
var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
if (city == null) {
    console.log("No current base.");
    return;
}
console.log("Base name: " + city.get_Name());

var buildingData = city.get_CityBuildingsData();
if (buildingData == null) {
    console.log("No buildings");
    return;
}

var defenseHQ = buildingData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Defense_HQ);
if (defenseHQ != null) {
    var newLevelDefense = defenseHQ.get_CurrentLevel();
    console.log("New level defense: " + newLevelDefense);

    //TODO: function for defense unknown
    //ClientLib.API.City.GetInstance().UpgradeAllDefenseToLevel(newLevelDefense);
} else {
    console.log("No defense HQ found");
}

var commandcenter = buildingData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Command_Center​);
if (commandcenter != null) {
    var newLevelUnits = commandcenter.get_CurrentLevel();
    console.log("New level units: " + newLevelUnits);

    //TODO: function for offense unknown
    //ClientLib.API.City.GetInstance().UpgradeAllOffenseToLevel(newLevelUnits);
} else {
    console.log("No command center found");
}

var conyard = buildingData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Construction_Y​ard);
if (conyard != null) {
    var newLevelBuildings = conyard.get_CurrentLevel();
    console.log("New level buildings: " + newLevelBuildings);

    //TODO: remove "-1" when function has been fixed
    ClientLib.API.City.GetInstance().UpgradeAllBuildingsToLevel(newLevelBuildin​gs - 1);
} else {
    console.log("No construction yard found");
}

Also i dont know if this is only a problem with the preview for me but there are seems to be useless spaces inserted at "newLevelBuildin​ gs - 1" or "ClientLib.Base.ETechName.Construction_Y ​ard".

Edit: Okay this seems to be only a local problem with my browser.
(This post was last modified: 13-12-2012 08:56 AM by Tecin.)
13-12-2012 08:48 AM
 Search   Quote 
StryfeASphears Offline
Junior Member
**

Posts: 33
Joined: Nov 2012
Post: #15
RE: New API Code with December Update
(13-12-2012 08:48 AM)Tecin Wrote:  
(13-12-2012 01:56 AM)StryfeASphears Wrote:  Can you share your script so i could use it with greesmonkey?

Yes, the code below is only the relevant part, which is quite simple. I removed the event handler because that is right now not very user-friendly.

Code:
var city = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
if (city == null) {
    console.log("No current base.");
    return;
}
console.log("Base name: " + city.get_Name());

var buildingData = city.get_CityBuildingsData();
if (buildingData == null) {
    console.log("No buildings");
    return;
}

var defenseHQ = buildingData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Defense_HQ);
if (defenseHQ != null) {
    var newLevelDefense = defenseHQ.get_CurrentLevel();
    console.log("New level defense: " + newLevelDefense);

    //TODO: function for defense unknown
    //ClientLib.API.City.GetInstance().UpgradeAllDefenseToLevel(newLevelDefense);
} else {
    console.log("No defense HQ found");
}

var commandcenter = buildingData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Command_Center​);
if (commandcenter != null) {
    var newLevelUnits = commandcenter.get_CurrentLevel();
    console.log("New level units: " + newLevelUnits);

    //TODO: function for offense unknown
    //ClientLib.API.City.GetInstance().UpgradeAllOffenseToLevel(newLevelUnits);
} else {
    console.log("No command center found");
}

var conyard = buildingData.GetUniqueBuildingByTechName(ClientLib.Base.ETechName.Construction_Y​ard);
if (conyard != null) {
    var newLevelBuildings = conyard.get_CurrentLevel();
    console.log("New level buildings: " + newLevelBuildings);

    //TODO: remove "-1" when function has been fixed
    ClientLib.API.City.GetInstance().UpgradeAllBuildingsToLevel(newLevelBuildin​gs - 1);
} else {
    console.log("No construction yard found");
}

Also i dont know if this is only a problem with the preview for me but there are seems to be useless spaces inserted at "newLevelBuildin​ gs - 1" or "ClientLib.Base.ETechName.Construction_Y ​ard".

Edit: Okay this seems to be only a local problem with my browser.
Thanks so i copied this into a tampermonkey sorry not greasemonkey
And run it it lights up green but then does nothing.I am super new at the API aspect of the game and would like to know ifi am missing something.And do i know to change the -1 at the new building level spot?
I also put this in the includes like i said i am still learning!
(This post was last modified: 13-12-2012 10:15 AM by StryfeASphears.)
13-12-2012 10:11 AM
 Search   Quote 
Tecin Offline
Junior Member
**

Posts: 9
Joined: May 2012
Post: #16
RE: New API Code with December Update
(13-12-2012 10:11 AM)StryfeASphears Wrote:  Thanks so i copied this into a tampermonkey sorry not greasemonkey
And run it it lights up green but then does nothing.I am super new at the API aspect of the game and would like to know ifi am missing something.And do i know to change the -1 at the new building level spot?
I also put this in the includes like i said i am still learning!

Well it works for me. This might be stupid of me to ask but you have this embedded in an event handler yourself or do you want/need the complete script?

And you can remove the "-1" but then the buildings might get upgraded one level to high.
13-12-2012 10:41 AM
 Search   Quote 
StryfeASphears Offline
Junior Member
**

Posts: 33
Joined: Nov 2012
Post: #17
RE: New API Code with December Update
(13-12-2012 10:41 AM)Tecin Wrote:  
(13-12-2012 10:11 AM)StryfeASphears Wrote:  Thanks so i copied this into a tampermonkey sorry not greasemonkey
And run it it lights up green but then does nothing.I am super new at the API aspect of the game and would like to know ifi am missing something.And do i know to change the -1 at the new building level spot?
I also put this in the includes like i said i am still learning!

Well it works for me. This might be stupid of me to ask but you have this embedded in an event handler yourself or do you want/need the complete script?

And you can remove the "-1" but then the buildings might get upgraded one level to high.

Yes the full script would be awesome! and any help with where i can read about even handlers!
13-12-2012 08:39 PM
 Search   Quote 
sturdycon Offline
Junior Member
**

Posts: 18
Joined: Mar 2012
Post: #18
RE: New API Code with December Update
How to use these scripts ???
02-02-2013 09:33 PM
 Search   Quote 
Dbendure Offline
Junior Member
**

Posts: 43
Joined: Jan 2013
Post: #19
RE: New API Code with December Update
Ok I'm trying to pull a base name from this code.

Code:
ClientLib.Data.MainData.GetInstance().get_World().GetObjectFromPosition(xcoords,​ycoords).NGRLRM

what would be the term for NGRLRM?
03-06-2015 03:42 AM
 Search   Quote 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)