I'm making a gamemode where one player has a bomb, and when the player with the bomb gets close enough to any other player, the bomb is transferred to the new player. Note that the bomb should not be transferred if there are bricks with raycasting between the players.
Let me know if you have a better idea than mine for how to do this. I'm not sure if my way will lag the server.
My idea is to use %raycast = containerRaycast(%start,%end,%type,%ignore) in a loop that runs every 33 ms.
%start will be the bomb-holder's position.
%end will be every player in the minigame's position (looping through all minigame players)
%type will be $TypeMasks::FxBrickObjectType (bricks with raycasting on)
%ignore is an optional input and will not be used
As it loops through all minigame players, I'll check if %raycast == 0 (meaning that there are no bricks between the bomb-holder and the player).
If that's true, I can then check the distance between the bomb-holder and the player with VectorDist(%start , %end).
If that distance is low enough, the bomb will transfer to the new player.
Final code used:
%bomberPosition=$bomberClient.player.getHackPosition();
InitContainerRadiusSearch(%bomberPosition,3,$TypeMasks::PlayerObjectType); //in a radius of 3 from the bomb-carrier, search for any other players
while(%targetObject=containerSearchNext())
{
if(%targetObject != $bomberClient.player)
{
%end = %targetObject.getHackPosition();
%type = $TypeMasks::FxBrickObjectType;
%raycast = containerRaycast(%bomberPosition,%end,%type);
if(firstWord(%raycast) == 0) //if true, there are no raycasting bricks between the 2 players
{
//set the new bomber
$bomberClient = %cl;
//de-activate the bomb for 9 seconds to allow for the previous bomb holder to escape
$bombActive = 0;
schedule(9000,0,activateBomb,0);
}
}
}