Problem with script

Started by Afaut, August 23, 2017, 05:31:34 AM

Afaut

Hi, i'm working on a new mod, a device to restore ammunition it work but i have a problem

i've this
var ballisticWeapons = ship.GetWeaponsOfType(args.ship_id, 2);

   
   

//check weapon
if (ballisticWeapons == null)
    {
ship.DeviceDeactivate(args.ship_id, args.slot_id, true);
        game.SendNotificationError(game.GetShipOwner(args.ship_id), "No Ballistic Weapon"); // Repair is not required: Repair is not required.
        return;
    }


not working, the game just ignore the if.
i've tried if (ballisticWeapons == undefined)
if (!ballisticWeapons )
and nothing work.
Is someone have an idea why it's not working?

ai_enabled

Hello!

it always returns an array of IDs (weapon items IDs).
If there are no ballistic weapons, the array will be empty.
So you can simply check the array length: if (ballisticWeapons.length == 0)...

Regards!

Afaut

#2
i'll try and i'll tell you if it work.
Edit: It work! thank you, i don't know why in specialobject.js if (ballisticWeapons == null) work and not in my script but now it work

Teerawut

#3
I'm looking for a solution to the problem with script.sbobet

ai_enabled

@Teerawut, ok, post it here and we will try to help!