ok.my head hurts:(
how can i tell if a origin is hitting/touching/inside a player?
like i could check if the origin is a certain distance from the player (the player width/height)
What i want to do is for my server side weapon is make it shoot but the player can get kills etc when making it shoot if it hits a player.
I dont want to fire a trigger multiple everywhere and then remove it and fire another one or maybe that would be better?
So i get a final origin lets say ( 9 9 9 ) and the players origin at ( 10 10 10 ). Thats 1, i could check that 1 is less then the player width but then i have the players high also so i cant add a huge radius arround the player of the players high as hes not as wide as he s tall.
Scripting: Tell if a player is occupying a origin?
Moderator: Moderators
An origin is just a set of coords you have to have something to tell if a player is touching it . I thought about a mod like this once . Someone posted about it and I happened to save it but I didn't continue with it to check it out but as I remember the guy was a fairly good scripter so it may work .
Code: Select all
wait 5
local.player = $player[1]
local.player iprint "YOU HAVE THE TRIGGER"
local.player thread bullet_detect_init
end
//
// bullet_detect_init -
//
// Call this thread once for each player. self points to the Player object
// we wish to monitor.
//
bullet_detect_init:
local.trigger = spawn trigger_multiple origin local.player.origin setthread bullet_detect_trigger spawnflags 128 // DAMAGE
local.trigger setsize ( -32 -32 0) ( 32 32 96) // I think the bounding box for the player is actually ( -16 -16 0) ( 16 16 96), but with that size, not all bullets were detected, probably because the 'glue'ing of the trigger to the player isn't perfect and the trigger is probably not always completely aligned with the player, hence a margin around the player is needed
local.trigger glue self // attach trigger to player
local.trigger.player = self // so setthread thread can work out which player the trigger is attached to
end
//
// bullet_detect_trigger -
//
// Called when the trigger_multiple glued to a player is damaged.
//
bullet_detect_trigger:
local.player = self.player // the player who this trigger is attached to
local.shooter = parm.other // the player who fired the bullet
iprintln_noloc "Shooter classname: " parm.other.classname
if (isalive local.player) {
if (local.player == local.shooter) {
iprintln_noloc "Player " local.player.entnum " fired/bashed with his weapon" // or injured himself with his own grenade
} else {
iprintln_noloc "Player " local.shooter.entnum " shot at player " local.player.entnum
}
} else {
if (local.player == local.shooter) {
iprintln_noloc "Player " local.player.entnum " killed himself" // or possibly was firing at the same moment he got killed by another player
} else {
iprintln_noloc "Player " local.shooter.entnum " killed player " local.player.entnum
}
}
endYou can do all without triggers as you like, just use some of the knowledge of vectors you now have 
First calculate the vector from the player origin to the bullet point, i.e.
local.hitvec = local.bullet_point - local.player.origin
Now all you have to do is check whether this vector is entirely within the bounding box of the player, i.e. calc the components of the vector in all directions using a dot product:
local.hitvec_fwd = local.hitvec * local.player.forwardvector
local.hitvec_lf = local.hitvec * local.player.leftvector
local.hitvec_up = local.hitvec * local.player.upvector
Now finally the bounding box check is easy:

First calculate the vector from the player origin to the bullet point, i.e.
local.hitvec = local.bullet_point - local.player.origin
Now all you have to do is check whether this vector is entirely within the bounding box of the player, i.e. calc the components of the vector in all directions using a dot product:
local.hitvec_fwd = local.hitvec * local.player.forwardvector
local.hitvec_lf = local.hitvec * local.player.leftvector
local.hitvec_up = local.hitvec * local.player.upvector
Now finally the bounding box check is easy:
Code: Select all
local.is_hit_fwd = (abs local.hitvec_fwd) <= 32.0
local.is_hit_lf = (abs local.hitvec_lf) <= 32.0
local.is_hit_up = local.hitvec_up >= 0.0 && local.hitvec_up <= 92.0
if(local.is_hit_fwd && local.is_hit_lf && local.is_hit_up)
{
// a hit
}
else
{
// not a hit
}

