Author Topic: Click Kill  (Read 2251 times)

Hello, I would like to know how to make it so that if you click on somebody, they die as
if they were killed. I have never done any scripts that had to do with aiming or clicking on
something. So I do not know where to start with. Could somebody please make the script
and explain why it is the way it is? Thanks

Hello, I would like to know how to make it so that if you click on somebody, they die as
if they were killed. I have never done any scripts that had to do with aiming or clicking on
something. So I do not know where to start with. Could somebody please make the script
and explain why it is the way it is? Thanks
look at the "stab" power in Special_Player

look at the "stab" power in Special_Player
I could not find Special_Player...

You'll need to find out how raycasts work and find out how to use the raycast in the armor::onTrigger function.
« Last Edit: February 24, 2013, 03:31:36 PM by elm »

You'll need to find out how raycasts work and find out how to use the raycast in the armor::onTrigger function.
Okay, but how do you suggest learning about it?

Okay, but how do you suggest learning about it?

By doing a series of rituals to contact the Search Gods.


function Player::GetLookTarget(%this,%dist)
{
    %start = %this.getEyePoint();
    %vec   = %this.getEyeVector();
    %end   = vectorAdd(%start,vectorScale(%vec,%dist));
    %ray = containerRaycast(%start,%end,$TypeMasks::PlayerObjectType,%this);
    %col = firstWord(%ray);
    if(!isObject(%col))
      return -1;
    return %col;
}
function Player::Special_Stab(%this)
{
   %obj = %this.GetLookTarget(5);
   if(%obj != -1)
   {
         %obj.kill();
   }
}

now, to explain so eepos doesnt beat me up:
Code: [Select]
function Player::Special_Stab(%this)naming the function and setting parameters
Code: [Select]
  %obj = %this.GetLookTarget(5);setting the target object to be the first thing that container raycast function picks up at distance 5
Code: [Select]
  if(%obj != -1) checks if the player does exist because that container raycast function returns -1 if there is no object
Code: [Select]
       %obj.kill(); kills the target because they exist

for more info on container raycasts, i think there is a vector topic about it or something
« Last Edit: February 24, 2013, 08:26:00 PM by MARBLE MAN »


function Player::GetLookTarget(%this,%dist)
{
    %start = %this.getEyePoint();
    %vec   = %this.getEyeVector();
    %end   = vectorAdd(%start,vectorScale(%vec,%dist));
    %ray = containerRaycast(%start,%end,$TypeMasks::PlayerObjectType,%this);
    %col = firstWord(%ray);
    if(!isObject(%col))
      return -1;
    return %col;
}
function Player::Special_Stab(%this)
{
   %obj = %this.GetLookTarget(5);
   if(%obj != -1)
   {
         %obj.kill();
   }
}

now, to explain so eepos doesnt beat me up:
Code: [Select]
function Player::Special_Stab(%this)naming the function and setting parameters
Code: [Select]
  %obj = %this.GetLookTarget(5);setting the target object to be the first thing that container raycast function picks up at distance 5
Code: [Select]
  if(%obj != -1) checks if the player does exist because that container raycast function returns -1 if there is no object
Code: [Select]
       %obj.kill(); kills the target because they exist

for more info on container raycasts, i think there is a vector topic about it or something
No Syntax errors, but you did something wrong.
Not working.

No Syntax errors, but you did something wrong.
Not working.
He didn't make code for you to copy and paste. He made code for you to learn from.

He didn't make code for you to copy and paste. He made code for you to learn from.
Oh, I thought it was for both.

You can't learn too much when just copying

You can't learn too much when just copying
No, MARBLE MAN explain why it did what it did.
But apparently the code given to me wasn't correct.

No, MARBLE MAN explain why it did what it did.
But apparently the code given to me wasn't correct.
It was.



function servercmdkilllook(%cl)
{
   if(!isObject(%cl.player) || !%cl.isHost)
      return;
   %cl.player.Special_Stab();
}

1. Creates function for the /killlook
2. Checks if player exists and the player is the host
3. if they aren't, end
4. if they are, kill the first player they see

that will tell you if it works or not

to make it click to kill, you need:
Package
Armor::onTrigger(args)
Parent::onTrigger(args)
Player.Special_Stab IF %slot == 0 and %enabled == 1