If you're still looking into this kind of thing, definitely look into the CheckAttack function as was mentioned earlier. You can also check out FindTarget() in the ai.qc. In terms of firing of a gun and having them turn on you, I'm not sure what the float show_hostile does, but you may want to look into it. A weird roundabout way that I've been able to this was by modifying the T_RadiusDamage in combat.cq. Originally I used it for pedestrians to "call for help", and if a guard heard them he would come looking for you.
Essentially, whenever they would call for help, they'd send out T_AlarmDamage (my modified function), which works more or less the same way as radius damage, except it's set to only take off 1 damage and only affects other non-alarmed monsters. It works off the general notion that when a monster takes damage, if the player is the attacker then he'll start searching for you.
Code: Select all
void (entity inflictor, entity attacker, float damage, entity ignore) T_AlarmDamage =
{
local float points;
local entity head;
local vector org;
head = findradius(inflictor.origin, damage); //the damage in this case only specifies the range of the sound
while (head) {
if (head != ignore) {
if (head.takedamage) {
org = (head.origin) + (((head.mins) + (head.maxs)) * 0.5);
points = 0.5 * (vlen((inflictor.origin) - org));
if (points < FALSE) {
points = FALSE;
}
points = damage - points;
if (head == attacker) {
points = points * 0.5;
}
if (points > -1) {
if (CanDamage(head, inflictor)) {
if ((head.classname) == "player") { //so it doesn't effect other players
}
else {
if ((head.targetname) == "good") {
}
else {
if ((head.alarmed) > 0){ //so it doens't keep alarming/hurting the same monsters
}
else {
head.alarmed = 1;
T_DamageAlarm(head, inflictor, attacker, 1); //note how the "damage" specified when the function is called is only for range.
}
}
}
}
}
}
}
head = head.chain;
}
};
In your case you could probably put something like this along with W_Attack or something
T_AlarmDamage(self, self, 500, world);
The cool part is that because it has range built into the damage part (ie. 500), you could make differences for silenced and unsilenced weapons. So when you shoot your unsilenced rifled the "damage" is 1000, but when it's silenced it's only 100. You can also put it in the final death frame of any dead body so that guards or people freak out when they find one
Also, I could be wrong but I don't think this goes through walls.
Anyway, that should help.
Alex