Loading items data from Database?

I want to make a database where each item/weapon in the game has set values such as the amount of damage it does when it strikes an entity. How can I create a code to do this? I have seen how this is done in C#, but not in javascript. please help.

1 Like

I think an actual database to store the kind of information your describe is overkill. Instead, I would use script attributes. So, for example, weapon properties might be:

  • Damage
  • Accuracy
  • Range
  • Reload speed

…and so on. These could simply be script attributes on a weapon script:

pc.script.attribute(‘damage’, ‘number’, 75);
pc.script.attribute(‘accuracy’, ‘number’, 20);
pc.script.attribute(‘range’, ‘number’, 50);
pc.script.attribute(‘reloadTime’, ‘number’, 0.5);

An alternative is that you could specify weapon stats in a JSON asset:

{
    "weapons": [
        {
            "type": "Sniper Rifle",
            "damage": 70,
            "reloadTime": 5,
            "accuracy": 90,
            "range": 500
        },
        {
            "type": "Shotgun",
            "damage": 90,
            "reloadTime": 4,
            "accuracy": 40,
            "range": 20
        }
    ]
}

You can then load and parse the JSON. This demo project shows how to do this.

how can I get this to where each item has a model?

“model”: ‘axe’,

and when u equip the model you enable it… but it’s better if someone give u more details coz i still have to reach that part of development :smile:

does 'axe refer to the name of the model in the assets or does it refer to something else

yes it refer to the name of the model

The code is so big, and I don’t understand it. What parts of the code do I really need from the demo project?

can anyone help me understand how the code works?
there is also the fact that once the Item database is functional how would the items registered in it affect other things?
for instance if a enemy were struck by an item, how would it know what weapon it was struck by and how much damage it is supposed to take. The enemies health is represented with:
this.entity.health = 100;
This is the code for the player’s inventory and stats…

how would I make the item database affect the inventory