Well it turned out to be pretty simple.
Note: I tested this out in Cod/UO and it works fine.
This is in response to another thread on how to detect and award points to players as in a shooting range for eg;
In this example there are only two targets, to add others just replicate them and give them unique targetnames for each one and add another section in the script for them.
Firstly in the editor (mapping stage)
On the target make a small box about 8x8 and texture with origin.
Then make a larger box the same size as you target area and just proud of the front of the target and texture this with trigger.
Select BOTH these new brushes and right click 2D window and select trigger_damage, give it a targetname of dist_trig (this is your distant one right?) :) and tick off explosion,splash,melee,flame as they are not usefull for a rifle range.
Now on the baseline where your player should be standing make another trigger the same way you made the trigger_damage on the target but this time make it a trigger_multiple.
No need to give it a targname just yet.
Once you have those two triggers correct, deselect everything and then shift+left click on the target trigger (just select the larger box) then do the same for the player trigger (select outer box) and hit Ctrl+K to make the target trigger point to the player trigger.
You should see a red line running from the small inner box on the target trigger to the small inner box on the player trigger.
You will notice that the player trigger just made it's own targetname, if it didn't check your editor setup.
For any other targets you do exactly the same as the first.
In this example script the second target is called close_trig.
For each target you MUST have a corresponding trigger where the player should be standing (this is important to detect who hit the target and who should get the points) and that trigger MUST be targeted from the trigger on the target in your rifle range.
Ok here is the script for two targets.
There are comments in the script to show the important things you need to know.
Enjoy!
Grassy
Code:
main()
{
thread init_targets();
}
init_targets()
{
closetrig = getent ("close_trig", "targetname");
if(!isDefined(closetrig))
return;
disttrig = getent ("dist_trig", "targetname");
if(!isDefined(disttrig))
return;
disttrig thread watchdist();
closetrig thread watchclose();
}
watchdist()
{
if (isdefined (self.target))
ent = getent (self.target,"targetname");
else
return;
//Set amount of points awarded on hitting this target
points = 2;
while(1)
{
self waittill("trigger",other);
//This is a visual to see the trigger hits
//Comment it out when not needed anymore
iprintln("Trigger was hit by ",other.name);
//The person who shot the target must be in this trigger
if(other istouching(ent) && isAlive(other) && other.sessionstate != "spectator")
other.score += points;
}
}
watchclose()
{
if (isdefined (self.target))
ent = getent (self.target,"targetname");
else
return;
//Set amount of points awarded on hitting this target
points = 1;
while(1)
{
self waittill("trigger",other);
//This is a visual to see the trigger hits
//Comment it out when not needed anymore
iprintln("Trigger was hit by ",other.name);
//The person who shot the target must be in this trigger
if(other istouching(ent) && isAlive(other) && other.sessionstate != "spectator")
other.score += points;
}
}
Woops almost forgot, you can add a "wait" key on each trigger_damage to speed it up, I used 0.1 for a quick response for rapid fire, otherwise every second shot is not detected.
Grassy
edited on Jan. 10, 2007 03:07 am by WHC_Grassy
LOL I just thought I had better add some extra error checking, in case the targeted triggers are not found.
edited on Jan. 10, 2007 03:10 am by WHC_Grassy