Nexus Modding > Scripting

Scripting Issues

<< < (8/25) > >>

Mularac:
A question, is it possible to detect when a fighter wing is completely destroyed? I tried witht the co_devicedestroyed, but it didn't work. Any ideas?

Arparso:
You can recognize bombers of the same wing by checking for the same launcherWeapon. All it then comes down to is counting the surviving wingmates in the event a bomber has been shot down. If there are none left, the squad obviously has been destroyed.

Try this:


--- Code: ---// runs for all exploding bombers and checks, if the whole squad has been destroyed
    RULE event Exploding
        condition E.ship:bomber
        :action
            E.BombersInSameSquad := GetFreeSel();            
            Select(E.BombersInSameSquad, S.bomber & S.launcherWeapon = E.ship:launcherWeapon & S.this != E.ship);
            If(AllNumOf(E.BombersInSameSquad) = 0,
                Debug("Squadron destroyed")
            );
        :end
    END
--- End code ---

/edit:
Just noticed a problem with the above code: if a bomber wing is currently docking and, lets say, the last one is being shot down while his mates already have docked... then the script above will think the whole squadron has been destroyed, because it doesn't count docked wingmates.

/edit2:
Doh! Even simpler solution: Just check the "count" variable of the launcherWeapon of the exploding bomber - this will give you the remaining amount of bombers in that wing (including the currently exploding one). No need to use stupid selections this time ;)


--- Code: ---// runs for all exploding bombers and checks, if the whole squad has been destroyed
    RULE event Exploding
        condition E.ship:bomber
        :action
            // count all remaining bombers in bomber wing
            // (this includes the currently exploding bomber!)
            If(E.ship:launcherWeapon:count = 1,
                Debug("Squadron destroyed")
            );
        :end
    END
--- End code ---

The Old Dragon:
Just a quick question, sure I've seen the answer somewhere. Just can't seem to find it now.

How do you select the slowest ship in a group?

Mularac:
you're right, that sounds oddly familiar to me...

yeah, I know now it's from the skirmisher's AI:

if(AllNumOf(AIFleetL1)>0, m.AITeam_leader:=PickMax(AIFleetL1, 1 / s.this:tGetMaxVelocity()), ChangeState(noTeam1,0)); //slowest ship is AI leader

So, it seems you can do that with the tGetMaxVelocity() command, the exact way this command works seems to elude me... perhaps you can knock more sense out of it :)

Arparso:
Not that hard to explain, I guess. Let's assume, we've got a bunch of ships selected in MyFleet:

Selecting the fastest ship would be easy:
PickMax(MyFleet, s.this:tGetMaxVelocity());

It's like sorting the list by maximum speed and then picking the fastest one using PickMax. Sadly, there's no PickMin function, so you have to invert the sorting. You could do that by simply negating the maximum speed:
PickMax(MyFleet, -s.this:tGetMaxVelocity());

DeSade (who wrote the Skirmisher's AI) chose to divide 1 by the maximum speed, which also works well:
PickMax(MyFleet, 1/s.this:tGetMaxVelocity())

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version