BNWCS Target API
Intro
To make destructible objects compatible with the BNWCS, you will need the "BNWCS Developer's Kit."
The BNWCS Target API allows an in-world, rezzed object to take damage from physical collisions and BNWCS splash damage according to the same formula that avatars do. Targets
- Can have armor
- Can have any amount of HP
- Can be repaired
- Can be set to only take damage from explosives
- Can be set to automatically respawn
To make a BNWCS target, all you need is an object rezzed in-world. Then, follow these steps to turn it into a BNWCS Target.
- Place a "!BNWCS Target Settings" notecard in the root prim of the target.
This target may contain the following options (Shown here with their default values):
- target_health=100
The target's hit points. - armor_factor=1
You may change the "armor factor" to any number. Any damage taken will be divided by this number. - active_only=yes
If this is "yes," the target will only take damage from avatars that are wearing an active BNWCS meter. Otherwise, all avatars will be able to damage it. - explosive_only=no
If this is "yes," the target will only take damage from explosives. Use this for things like concrete walls and heavy blast doors that shouldn't ever yield to small-arms fire. - respawn_time=180
- If this number is positive, the target will return to full health and able to be damaged, this many seconds after being destroyed.
- If this number is zero, the target will not automatically reset itself.
- If this number is negative, the target will use 180. - state_on_rez=off
If this is "on," the target will be in the "combative" mode and able to take damage when it is rezzed. If it is "off," the target will be "non-combative" when it is rezzed, and will need to be turned on by its owner ("/8 ton") before it can take damage.
- target_health=100
- Place the "BNWCS.api.target.lsl2" script in the target's root prim, right next to the notecard.
- If you want the target's health to be visible to everyone drop the "BNWCS.api.floating.lsl2" script into ANY prim in the target. It is a good idea to choose a prim that will keep the floating text as visible as possible.
- Done!
There's one more optional step, though - the included "BNWCS.api.target.plugin.HPColor.lsl2" script will, when added to a BNWCS target, cause it to change in color to a darker and darker red as its HP approaches zero, then turn invisible and phantom (good for walls and doors and such) when destroyed. To test your target, put on your BNWCS, make sure the target is turned "on," and take a shot at it!
Usage
Targets respond to the following commands:
- /8 ton
Turns the target's BNWCS on, making it destructible. - /8 toff
Turns the target's BNWCS off and hides its floating text, making it indestructible. - /8 treset
- If the target is turned "off," this resets its script.
- If the target is turned "on," this does nothing.
- If the target is destroyed, this returns it to full HP in the "combative" mode.
Linked Messages
The BNWCS Target API script sends some link messages that you can use. A summary of these messages, and a description of when they will be sent, follows.
llMessageLinked(LINK_SET,state,"BNWCS Target State","");
This message is sent when the target enters the combative, non-combative, or destroyed state. It is sent every time the state changes. The integer will be:
0: Non-combative
1: Combative
2: Destroyed
llMessageLinked(LINK_SET,targetHealth,"BNWCS Target HP","");
This message is sent every time the target's HP changes. "targetHealth" will be an integer representing the target's current remaining health.
In addition to sending link messages, the BNWCS Target API will listen for some, too, allowing you to control the script to some extent.
llMessageLinked(LINK_SET,newState,"Set BNWCS Target State,"");
Sending this message allows you to change the target's state from combative or non-combative to one of the other states. The possible values of the "newState" integer are the same as the other link messages:
-1: Revive the target (only works if target is destroyed; goes to combative)
0: Non-combative (only works if target is combative)
1: Combative (only works if target is non-combative)
2: Destroyed (works whether target is combative or not)