Author Topic: how to kill anyone within a 2 block radius of the player?  (Read 2960 times)

basically, /title.

I'm making some crash bandicoot stuff and the spin attack needs this function, but I am clueless on how to do it.

Can someone help?

Loop through all players/bots in the server, check if the distance to the player is less than 2 studs, if so kill them.

You could also use initContainerRadiusSearch and have it check for $TypeMasks::PlayerObjectType, and if the Radius Search returns a player for the radius size you specified (2 bricks), kill them.

You could also use initContainerRadiusSearch and have it check for $TypeMasks::PlayerObjectType, and if the Radius Search returns a player for the radius size you specified (2 bricks), kill them.

This is the correct way to do it. For your use (and posterity), initContainerRadiusSearch is used as follows:

initContainerRadiusSearch( source position , radius, mask )

In your case, this will look something like:

initContainerRadiusSearch( %brick.getPosition() , 4 , $TypeMasks::PlayerObjectType );

Once you call this, you need to loop through the results using the function containerSearchNext.

This is done as follows: while(%searchObject = containerSearchNext()) { %searchObject.doWhatever(); }



Also, as a note to Ninjaman, you don't need to type out [font=Courier][/font] around your "code" areas. The typewriter icon () is known as teletype and creates [tt][/tt] tags around the content you select.

Thanks for the help! Unfortunately, now the attack goes off at random times without the player triggering it.

Code: [Select]
package spin
{
 function Player::ActivateStuff(%player)
 {
  Parent::ActivateStuff(%player);
  initContainerRadiusSearch( %player.getPosition() , 5 , $TypeMasks::PlayerObjectType );
  while(%searchObject = containerSearchNext())
  {
   serverCmdSelf Delete(%searchObject);
  }
 }
};
Code: [Select]
Add-Ons/Script_Crash/script.cs (4): unknown command ActivateStuff.

I've cut out parts that aren't related to the problem, such as the spin or playing the spin sound.
« Last Edit: July 09, 2014, 12:38:19 PM by TeeOS »

Activatestuff isn't a player function, so you can't parent it. What you're thinking of is commandToServer('activateStuff');

Activatestuff isn't a player function, so you can't parent it. What you're thinking of is commandToServer('activateStuff');

How do you think it was triggered then?




I've cut out parts that aren't related to the problem, such as the spin or playing the spin sound.
Don't do this, most of the time the error hides in some other code that you think is working fine. Post the whole code.

Code: [Select]
new AudioDescription(AudioNonLooping)
{
 volume = 1.0;
 isLooping= false;
 is3D = false;
 type = $GuiAudioType;
};

new AudioProfile(SpinAudio)
{
 filename = "./spin.wav";
 description = AudioNonLooping;
 preload = true;
};

package spin
{
 function Spin()
 {
  serverPlay3D(SpinSound, %this.getPosition());
  $mvYaw = $pi;
 }
 
 function Player::ActivateStuff(%player)
 {
  Spin();
  Parent::ActivateStuff(%player);
  initContainerRadiusSearch(%player.getPosition(), 5 , $TypeMasks::PlayerObjectType );
  while(%searchObject = containerSearchNext())
  {
   serverCmdSelf Delete(%searchObject);
  }
 }
};

Neither this nor the code I put above are even working anymore, regardless of the audio/spin. ActivateStuff works like the default function and none of the edits are occuring, though it doesnt list any errors when it is executed.



Console.log below.
« Last Edit: July 09, 2014, 12:47:15 PM by TeeOS »

That shouldn't work at all. serverCmdSelf Delete takes in a client, not a player. You shouldn't use the Self Delete command as a method of killing a target anyway. It does not appear your package is ever activated. Since there's no exclusionary check, if it did work, it would also kill the user. "Script_Crash" probably isn't the best name for an add-on.

Well. You're mixing up client and server sided code.

$mvYaw = $pi; is client sided and is going to make your player do an instant spin - as in a teleport to the orientation it is already facing. It does basically nothing. Your code is supposed to be server-sided however, so this can't be used to turn the player. You're using %this inside spin(), but it's not set to anything. Your datablock is called SpinAudio, but you're trying to use SpinSound. You're also using new AudioProfile instead of datablock AudioProfile, but I'm not sure if that causes problems. You're trying to call servercmdSelf Delete with a player object, but it needs a client object, and you also forgot to activate the package.

I'd do it like this:


if(!isObject(SpinSound))
{
   datablock AudioProfile(SpinSound)
   {
      filename = "./spin.wav";
      description = AudioDefault3d;
      preload = true;
   };
}

function Player::Spin(%this)
{
   serverPlay3D(SpinSound, %this.getPosition());

   //Find a way to make the player spin.
}

package SpinAttack
{   
   function Player::ActivateStuff(%this)
   {
      Parent::ActivateStuff(%this);

      %this.Spin();

      initContainerRadiusSearch(%this.getPosition(), 2.5, $TypeMasks::PlayerObjectType);   

      while(%obj = containerSearchNext())
         if(%obj != %this)
            %obj.kill();
   }
};

activatePackage(SpinAttack);


It's going to kill everyone close to the player (but not the attacker) and play the sound, but I don't know how to get a smooth spin right now.
« Last Edit: July 09, 2014, 01:01:29 PM by Zeblote »

You shouldn't use the Self Delete command as a method of killing a target anyway.

the source of that command is as follows:

Code: [Select]
function serverCmdSelf Delete(%client)
{
   %player = %client.Player;
   if(isObject(%player))
      %player.Damage(%player, %player.getPosition(), "10000", $DamageType::Self Delete);
}

theres nothing wrong with it, but I understand your point. Doesn't matter still.

"Script_Crash" probably isn't the best name for an add-on.

I'm 9000% sure he just named it that because he didn't think of a good name at the time, and that he's smart enough to conclude this. Throwmod is named Script_Blah afterall, so maybe its kinda like a scripting-playground sort of thing

the source of that command is as follows:

Code: [Select]
function serverCmdSelf Delete(%client)
{
   %player = %client.Player;
   if(isObject(%player))
      %player.Damage(%player, %player.getPosition(), "10000", $DamageType::Self Delete);
}

theres nothing wrong with it, but I understand your point. Doesn't matter still.
There is. Can't kill bots with serverCmdSelf Delete.

There is. Can't kill bots with serverCmdSelf Delete.

Then why am I able to kill bots?

I'm 9000% sure he just named it that because he didn't think of a good name at the time, and that he's smart enough to conclude this. Throwmod is named Script_Blah afterall, so maybe its kinda like a scripting-playground sort of thing

Kinda, im using it as a placeholder name until its ready.

That shouldn't work at all. serverCmdSelf Delete takes in a client, not a player. Since there's no exclusionary check, if it did work, it would also kill the user.

It does work somehow though. Although if a bot starts activating things it can also use the spin attack, so theres that.

the source of that command is as follows:

Code: [Select]
function serverCmdSelf Delete(%client)
{
   %player = %client.Player;
   if(isObject(%player))
      %player.Damage(%player, %player.getPosition(), "10000", $DamageType::Self Delete);
}
There is. Can't kill bots with serverCmdSelf Delete.
Additionally, the damage isn't properly sourced, so you can't attribute the death to the attacker. Also, while not directly a problem of using Self Delete, there's no minigameCanDamage check or anything of the sort so it'd have problems in a multiplayer environment.

Then why am I able to kill bots?
[...]
It does work somehow though. Although if a bot starts activating things it can also use the spin attack, so theres that.
Perhaps you have some mod setting %player.player then? Either way, calling serverCmdSelf Delete is inappropriate for pretty much everything besides the player hitting ctrl-k.