question

Alexey Sudarev avatar image
Alexey Sudarev asked

How get access to a drop table items?

I have some code:

    var catalogs = ['cars', 'players'];
    var catalog = catalogs[Math.round(Math.random() * catalogs.length)];
    var tableResult;
    
    if(catalog == 'cars') {
        tableResult = server.GetRandomResultTables(
        {
            CatalogVersion: catalog,
            TableIDs: ["CarDrops"]
        }).Tables; 
    } else if(catalog == 'players') {
        tableResult = server.GetRandomResultTables(
        {
            CatalogVersion: catalog,
            TableIDs: ["SkinDrops"]
        }).Tables; 
    }
    
    var totalWeight = 0;


    log.debug(tableResult.SkinDrops);

Why I can't get access to "Nodes" field? I always need to type tableResult."name of my table". But I can't know in advance which table I will use. If I type tableResult.Nodes - it is wrong

documentation
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Citrus Yan avatar image
Citrus Yan answered

Referring to the API reference: GetRandomResultTablesResult, property “Nodes” is nested in each table’s entry, therefore, you must first enter one of the tables before accessing its nodes. Besides, looking at your code, seems that there is only one table gets returned eventually, I don’t get why you were saying that you can’t know in advance which table to use. Maybe changing your code to the following can help:

var catalogs = ['cars', 'players'];
    var catalog = catalogs[Math.round(Math.random() * catalogs.length)];
    var tableResult;
    if(catalog == 'cars') {
        tableResult = server.GetRandomResultTables(
        {
            CatalogVersion: catalog,
            TableIDs: ["CarDrops"]
        }).Tables["CarDrops"]; 
    } else if(catalog == 'players') {
        tableResult = server.GetRandomResultTables(
        {
            CatalogVersion: catalog,
            TableIDs: ["SkinDrops"]
        }).Tables["SkinDrops"]; 
    }
    var totalWeight = 0;
log.debug(tableResult.Nodes);

In this way, you can access the “Nodes” field without typing “tableResult.name_your_table”.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.