Thread Rating:
  • 6 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
API Knowledgebase Questionthread
Author Message
AcersEleven Offline
Community Manager
*****

Posts: 1,646
Joined: Mar 2012
Post: #1
API Knowledgebase Questionthread
Dear Community,

we know that you need some help in understanding how the API works exactly and we’ve seen and collected a lot of your questions. That’s why we would like to introduce to you the

API Knowledgebase

In this Thread you will find all the information that we can give you as well as a kind of FAQ. We will try to keep it as up to date as possible, but we can’t update it daily, so bear with us.

In this thread here, you can ask questions about the API and ONLY the API.
Please stick to the topic, everything else will be removed.


Best,
AcersEleven

01-10-2012 03:03 PM
 Search   Quote 
cravis411 Offline
Junior Member
**

Posts: 20
Joined: Mar 2012
Post: #2
RE: API Knowledgebase Questionthread
Running the following in Firefox with Firebug on World 5 (372567)

webfrontend.Util.attachNetEvent(
ClientLib.Vis.VisMain.GetInstance().get_Battleground(),
"OnSimulateBattleFinished",
ClientLib.Vis.Battleground.OnSimulateBattleFinished,
this,
this.OnSimulateBattleFinished
);

Gives

TypeError: cs is undefined
(30548 out of range 454)

Any advice?
02-10-2012 04:24 PM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #3
RE: API Knowledgebase Questionthread
it is not implemented right now, this will come with the next patch
03-10-2012 02:05 PM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #4
RE: API Knowledgebase Questionthread
webfrontend.Util.attachNetEvent(/*instance of object which calls the event*/, /*name of the event*/, /*type of the event*/, /*context object*/, /*callback function*/);



Which is the right instance for ArmyChanged event?
04-10-2012 08:18 PM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #5
RE: API Knowledgebase Questionthread
normally it is the class where the add and remove functions are, according to the event. In your case it is "ClientLib.Data.CityPreArmyUnits" but you need to find the right object.

var ownCity = ClientLib.Data.MainData.GetInstance().get_Cities().get_CurrentOwnCity();
var/*ClientLib.Data.CityPreArmyUnits*/ units = ownCity.get_CityArmyFormationsManager().GetFormationByTargetBaseId(/*base id*/)

webfrontend.Util.attachNetEvent(units, "ArmyChanged", ClientLib.Data.CityPreArmyUnitsChanged, this, this.__callback);

i didn't test this but it should work like this.
04-10-2012 09:20 PM
 Search   Quote 
DeathDealer2BK Offline
Junior Member
**

Posts: 1
Joined: Oct 2012
Post: #6
RE: API Knowledgebase Questionthread
Can someone show me a hello world example or somthing? lol I want to learn some of the API but I'm lost
05-10-2012 03:22 AM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #7
RE: API Knowledgebase Questionthread
Ok Topper, I did what you suggestion and now there's a new issue (I solved it but perhaps you can tell me a better idea).

To add unit moved change function I have to do it when I am inside a base.
When you leave a base u need to do it again.

Basically what I did is, I added the UnitMove event every time I enter a city, also I added to my view change event an event remover to the UnitChange to make sure I give it multiple times.

Any thoughts?
05-10-2012 05:49 AM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #8
RE: API Knowledgebase Questionthread
@DeathDealer

Start by making a script header:

Code:
// ==UserScript==
// @name       My Fancy New Userscript
// @namespace  http://use.i.E.your.homepage/
// @version    0.1
// @description  enter something useful
// @match      http://*/*
// @copyright  2012+, You
// ==/UserScript==

the most important part is adding the following line to your script header:
Code:
// @include     https://prodgame*.alliances.commandandconquer.com/*/index.aspx

For example, my script looks like this:
Code:
// ==UserScript==
// @name        C&C - Tiberium Alliances Combat Simulator
// @namespace   Deyhak
// @description C&C Tiberium Alliances Basic Combat Simulator
// @include     https://prodgame*.alliances.commandandconquer.com/*/index.aspx
// @version     0.1.7.9
// @author      Deyhak,rusty149
// @require     http://sizzlemctwizzle.com/updater.php?id=147335
// @grant       MetaData
// ==/UserScript==

Now, from here, I suggest as main start with the following code:
Code:
function waitForClientLib(){
    
    qx = unsafeWindow["qx"];
    ClientLib = unsafeWindow["ClientLib"];
    webfrontend = unsafeWindow["webfrontend"];
    
        if ((typeof ClientLib == 'undefined') || (typeof qx == 'undefined') || (qx.core.Init.getApplication().initDone == false))
        {
            setTimeout(waitForClientLib, 1000);
            return;
        }
}

function startup(){
    
    setTimeout(waitForClientLib, 1000);
};

startup();


You can start your code in the startup function or in the waitforclientlib after it acctually loaded the ClientLib.

Try
Code:
alert("Hello World");


so your waitForClientLib should looks somewhat like this:
Code:
function waitForClientLib(){
    
    qx = unsafeWindow["qx"];
    ClientLib = unsafeWindow["ClientLib"];
    webfrontend = unsafeWindow["webfrontend"];
    
        if ((typeof ClientLib == 'undefined') || (typeof qx == 'undefined') || (qx.core.Init.getApplication().initDone == false))
        {
            setTimeout(waitForClientLib, 1000);
            return;
        }
alert("Hello World");
}


Or all in one:
Code:
// ==UserScript==
// @name        C&C - DeathDealer's first script
// @namespace   DeathDealer
// @description DeathDealer's Test Script
// @include     https://prodgame*.alliances.commandandconquer.com/*/index.aspx
// @version     0.1
// @author      DeathDealer
// ==/UserScript==

function waitForClientLib(){
    
    qx = unsafeWindow["qx"];
    ClientLib = unsafeWindow["ClientLib"];
    webfrontend = unsafeWindow["webfrontend"];
    
        if ((typeof ClientLib == 'undefined') || (typeof qx == 'undefined') || (qx.core.Init.getApplication().initDone == false))
        {
            setTimeout(waitForClientLib, 1000);
            return;
        }
    alert("Hello World");
}

function startup(){
    
    setTimeout(waitForClientLib, 1000);
};

startup();
(This post was last modified: 05-10-2012 06:11 AM by Deyhak.)
05-10-2012 06:10 AM
 Search   Quote 
Topper42 Offline
Developer
***

Posts: 248
Joined: Dec 2011
Post: #9
RE: API Knowledgebase Questionthread
(05-10-2012 05:49 AM)Deyhak Wrote:  Ok Topper, I did what you suggestion and now there's a new issue (I solved it but perhaps you can tell me a better idea).

To add unit moved change function I have to do it when I am inside a base.
When you leave a base u need to do it again.

Basically what I did is, I added the UnitMove event every time I enter a city, also I added to my view change event an event remover to the UnitChange to make sure I give it multiple times.

Any thoughts?

for combat preparation it think there is no better solution than adding the event listener while in base/defense and remove it on closing.
(This post was last modified: 05-10-2012 08:30 AM by Topper42.)
05-10-2012 08:17 AM
 Search   Quote 
Deyhak Offline
Member
***

Posts: 53
Joined: Jul 2012
Post: #10
RE: API Knowledgebase Questionthread
(05-10-2012 08:17 AM)Topper42 Wrote:  
(05-10-2012 05:49 AM)Deyhak Wrote:  Ok Topper, I did what you suggestion and now there's a new issue (I solved it but perhaps you can tell me a better idea).

To add unit moved change function I have to do it when I am inside a base.
When you leave a base u need to do it again.

Basically what I did is, I added the UnitMove event every time I enter a city, also I added to my view change event an event remover to the UnitChange to make sure I give it multiple times.

Any thoughts?

for combat preparation it think there is no better solution than adding the event listener while in base/defense and remove it on closing.

Alright then, I am on the right track =) Thanks for the reply.
05-10-2012 12:38 PM
 Search   Quote 


Forum Jump:


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