Author Topic: Need help with player throwing Script  (Read 2904 times)

Code: [Select]
package Throw
{
    function armor::onTrigger(%this, %obj, %triggerNum, %val)
    {
        Parent::onTrigger(%this,%obj,%triggerNum,%val);
        %target = containerRayCast(%client.player.getEyePoint(), vectorAdd(vectorScale(vectorNormalize(%client.player.getEyeVector()), 2), %client.player.getEyePoint()), $typeMasks::playerObjectType, %obj); //< what did you do here?
        %client = %obj.client;
        if(%obj.dudemounted==1)
        {
            dudecheck(%dude, %obj);
            return;
        }
        if(isObject(%target))
        {
            %dude = %target;
            %target.playThread(%slot, "death1");
            %this.player.mountobject(1, %dude);
            %this.dudemounted=1;
        }
    }
};
activatepackage(Throw);

function dudecheck(%dude, %obj)
{
    %dude.dismount();
    %dude.setVelocity(vectorAdd(%obj.getVelocity(),vectorScale(%obj.client.player.getEyeVector(),8)));
    %dude.client.centerprint('',"\c3" @ %this.name @ "\c2 threw you!",3);
}
When I execute this code, I spawn a bot and try to 'pick him up', yet when I click him, nothing happens and anytime I just click the console says this:
Code: [Select]
Add-Ons/Script_Throw/server.cs (6): Unable to find object: '' attempting to call function 'getEyePoint'
BackTrace: ->[throw]armor::onTrigger


Add-Ons/Script_Throw/server.cs (6): Unable to find object: '' attempting to call function 'getEyeVector'
BackTrace: ->[throw]armor::onTrigger


Add-Ons/Script_Throw/server.cs (6): Unable to find object: '' attempting to call function 'getEyePoint'
BackTrace: ->[throw]armor::onTrigger


Add-Ons/Script_Throw/server.cs (6): Unable to find object: '' attempting to call function 'getEyePoint'
BackTrace: ->[throw]armor::onTrigger


Add-Ons/Script_Throw/server.cs (6): Unable to find object: '' attempting to call function 'getEyeVector'
BackTrace: ->[throw]armor::onTrigger


Add-Ons/Script_Throw/server.cs (6): Unable to find object: '' attempting to call function 'getEyePoint'
BackTrace: ->[throw]armor::onTrigger
Yes, all 6 of those... Error thingies. There are no problems with that script (nothing comes up when I scroll up in the console to the add-on). Somebody help please.

Also Amade helped me when I had console errors with it. I took from the clickpush script and edited it a lot so it mounts players in a person's hands and when they click next they'd throw them.
« Last Edit: June 12, 2010, 06:35:38 PM by Crysist »

You were calling those functions before %client was even defined.

You were calling those functions before %client was even defined.
So I should put the  %client = %obj.client;  before the  %target = containerRayCast(%client.player.getEyePoint(), vectorAdd(vectorScale(vectorNormalize(%client.player.getEyeVector()), 2), %client.player.getEyePoint()), $typeMasks::playerObjectType, %obj)?

Ok I did it, now new problem:

When I click it makes the bot play the animation, yet he doesn't mount and this happens even if I click him while holding a wrench or something. It just gives this console error:
Code: [Select]
Add-Ons/Script_Throw/server.cs (17): Unable to find object: '' attempting to call function 'mountObject'
BackTrace: ->[throw]armor::onTrigger


Add-Ons/Script_Throw/server.cs (17): Unable to find object: '' attempting to call function 'mountObject'
BackTrace: ->[throw]armor::onTrigger
Code:
Code: [Select]
package Throw
{
    function armor::onTrigger(%this, %obj, %triggerNum, %val)
    {
        Parent::onTrigger(%this,%obj,%triggerNum,%val);
        %client = %obj.client;
        %target = containerRayCast(%client.player.getEyePoint(), vectorAdd(vectorScale(vectorNormalize(%client.player.getEyeVector()), 2), %client.player.getEyePoint()), $typeMasks::playerObjectType, %obj); //< what did you do here?
        if(%obj.dudemounted==1)
        {
            dudecheck(%dude, %obj);
            return;
        }
        if(isObject(%target))
        {
            %dude = %target;
            %target.playThread(%slot, "death1");
            %this.player.mountobject(1, %dude);
            %this.dudemounted=1;
        }
    }
};
activatepackage(Throw);

function dudecheck(%dude, %obj)
{
    %dude.dismount();
    %dude.setVelocity(vectorAdd(%obj.getVelocity(),vectorScale(%obj.client.player.getEyeVector(),8)));
    %dude.client.centerprint('',"\c3" @ %this.name @ "\c2 threw you!",3);
}

Ok I saw from the error before that %client wasn't defined or something before the clicking thing. But for this error I though what is '%this' and I noticed that I had to use %client instead. So I used it and when I clicked a bot ingame, the error didn't appear yet same thing; bot plays death animation. Yet also when I hold down click, he 'dies', yet when I let go he 'dies' again.
Code: [Select]
package Throw
{
    function armor::onTrigger(%this, %obj, %triggerNum, %val)
    {
        Parent::onTrigger(%this,%obj,%triggerNum,%val);
        %client = %obj.client;
        %target = containerRayCast(%client.player.getEyePoint(), vectorAdd(vectorScale(vectorNormalize(%client.player.getEyeVector()), 2), %client.player.getEyePoint()), $typeMasks::playerObjectType, %obj); //< what did you do here?
        if(%obj.dudemounted==1)
        {
            dudecheck(%dude, %obj);
            return;
        }
        if(isObject(%target))
        {
            %dude = %target;
            %target.playThread(%slot, "death1");
            %client.player.mountobject(1, %dude);
            %client.dudemounted=1;
        }
    }
};
activatepackage(Throw);

function dudecheck(%dude, %obj)
{
    %dude.dismount();
    %dude.setVelocity(vectorAdd(%obj.getVelocity(),vectorScale(%obj.client.player.getEyeVector(),8)));
    %dude.client.centerprint('',"\c3" @ %this.name @ "\c2 threw you!",3);
}
Also is there a way to check if %client is holding an item in their hands?

Could you explain what you're trying to do?

Could you explain what you're trying to do?
Player A clicks a guy, without holding someone, the guy he clicked, player B, mounts in player A's arms. The next time player a clicks player B will dismount his arms and add velocity by like 15 in the direction player A is looking.

try flipping lines 6 and 7

try flipping lines 6 and 7
lilboarder said I had to put %client = %obj.client; before the raycast part, cause client wasn't yet defined until it.

try flipping lines 6 and 7
Silly, that wouldn't be good, he needs %client defined.
Also is there a way to check if %client is holding an item in their hands?
I think it might be isObject(%client.player.getMountedImage()) or something similar, dump all methods of the player class using %client.player.dump() in console and it will list all possible methods to use players and certain variables assigned to them.

use Player::activateStuff(%player) instead of Armor::onTrigger(~)
It's only called when you click (not stop clicking) and when you have empty hands.

Silly, that wouldn't be good, he needs %client defined.I think it might be isObject(%client.player.getMountedImage()) or something similar, dump all methods of the player class using %client.player.dump() in console and it will list all possible methods to use players and certain variables assigned to them.
use Player::activateStuff(%player) instead of Armor::onTrigger(~)
It's only called when you click (not stop clicking) and when you have empty hands.
And I changed it to activate stuff. I'll go test. Current script (bolded changes):
Quote
package Throw
{
    function Player::activateStuff(%player)
    {
        Parent::activateStuff(%player);
        %client = %player.client;
        %target = containerRayCast(%client.player.getEyePoint(), vectorAdd(vectorScale(vectorNormalize(%client.player.getEyeVector()), 2), %client.player.getEyePoint()), $typeMasks::playerObjectType, %player);
        if(%player.dudemounted==1)
        {
            dudecheck(%dude, %player);
            %client.dudemounted=0;
            return;
        }
        if(isObject(%target))
        {
            %dude = %target;
            %target.playThread(%slot, "death1");
            %client.player.mountobject(1, %dude);
            %client.dudemounted=1;
        }
    }
};
activatepackage(Throw);

function dudecheck(%dude, %player)
{
    %dude.dismount();
    %dude.setVelocity(vectorAdd(%player.getVelocity(),vectorScale(%player.client.player.getEyeVector(),8)));
    %dude.client.centerprint('',"\c3" @ %player.name @ "\c2 threw you!",3);
}
« Last Edit: June 13, 2010, 08:25:07 AM by Crysist »

Tested, now no console errors when I click or in the script yet he wont mount.
Code: [Select]
package Throw
{
    function Player::activateStuff(%player)
    {
        Parent::activateStuff(%player);
        %client = %player.client;
        %target = containerRayCast(%client.player.getEyePoint(), vectorAdd(vectorScale(vectorNormalize(%client.player.getEyeVector()), 2), %client.player.getEyePoint()), $typeMasks::playerObjectType, %player);
        if(%player.dudemounted==1)
        {
            dudecheck(%dude, %player);
            %client.dudemounted=0;
            return;
        }
        if(isObject(%target))
        {
            %dude = %target;
            %target.playThread(%slot, "death1");
            %client.player.mountobject(1, %dude);
            %client.dudemounted=1;
        }
    }
};
activatepackage(Throw);

function dudecheck(%dude, %player)
{
    %dude.dismount();
    %dude.setVelocity(vectorAdd(%player.getVelocity(),vectorScale(%player.client.player.getEyeVector(),8)));
    %dude.client.centerprint('',"\c3" @ %player.name @ "\c2 threw you!",3);
}
EDIT: The problem was I had to put the  ,1 after %dude for the mountobject part, yet now he wont throw.
EDIT2: I know the problem, on dudecheck(); it doesn't get the guy hes holding, it gets the guy hes looking at, is there a way to get the person you're holding? Like:
Code: [Select]
%guyimholding=%player.mountedobj;Defiantly not that, but you get my point.
« Last Edit: June 13, 2010, 09:10:13 AM by Crysist »

EDIT2: I know the problem, on dudecheck(); it doesn't get the guy hes holding, it gets the guy hes looking at, is there a way to get the person you're holding? Like:
Code: [Select]
%guyimholding=%player.mountedobj;Defiantly not that, but you get my point.

The problem is that you haven't defined %dude prior to calling dudecheck in the activateStuff function. As for your question, you can use Player.getMountedObject(%slot) to retrieve the object that is mounted to the object.



Here's the two primary functions from the throw mod I had made back in October. If you want to look over them, please use these for reference and don't just mindlessly copypasta from it. If you can't tell how something works or what something does from the context, make sure to ask so you can learn about it.

Code: [Select]
function Player::attemptGrab(%this)
{
%scale = getWord(%this.getScale(),2);
%start = %this.getEyePoint();
%vec   = %this.getEyeVector();
%end   = vectorAdd(%start,vectorScale(%vec,2 * %scale));

%ray = containerRaycast(%start,%end,$TypeMasks::PlayerObjectType,%this);
%col = firstWord(%ray);

if(!isObject(%col) || %col.isHeld || %col.isHolding)
return 0;

%client = %this.client;
%scale2 = getWord(%col.getScale(),2);
%model  = fileName(%col.getDatablock().shapeFile);
%proper = (minigameCanDamage(%this,%col) == 1 || %col.spawnBrick.client == %client);

if(%scale2 > %scale || %model !$= "m.dts" || !%proper)
return 0;

%this.isHolding  = 1;
%col.isHeld      = 1;
%col.canDismount = 0;

%col.setLookLimits(0.5,0.5);
%col.unMountImage(0);

if(isObject(%them = %col.client))
{
%them.camera.setMode("Grabbed");
%them.setControlObject(%them.camera);
%them.camera.setorbitmode(%this,0,5,10,5,0);
}

%this.mountObject(%col,1);
%col.playThread(2,death1);

if(%scale2 >= %scale / 2)
%this.playThread(2,armreadyboth);
else
%this.playThread(2,armreadyleft);

%pos = %col.getPosition();
%col.setTransform(%pos SPC "0 0 -0.85 90");

return 1;
}

Code: [Select]
function Player::attemptThrow(%this)
{
if(!%this.isHolding)
return 0;

%held = %this.getMountedObject(0);
%vec  = %this.getEyeVector();

%this.unMountObject(%held);
%this.playThread(2,root);
%held.playThread(2,root);
%held.setLookLimits(1,0);

%held.addVelocity(vectorScale(%vec,10));

if(isObject(%them = %held.client))
%them.setControlObject(%held);

%this.isHolding   = 0;
%held.isHeld      = 0;
%held.canDismount = 1;

return 1;
}

Quote
function Player::attemptGrab(%this)
{
   %scale = getWord(%this.getScale(),2);
   %start = %this.getEyePoint();
   %vec   = %this.getEyeVector();
   %end   = vectorAdd(%start,vectorScale(%vec,2 * %scale));
   
   %ray = containerRaycast(%start,%end,$TypeMasks::PlayerObjectType,%this);
   %col = firstWord(%ray);
   
   if(!isObject(%col) || %col.isHeld || %col.isHolding)
      return 0;
   
   %client = %this.client;
   %scale2 = getWord(%col.getScale(),2);
   %model  = fileName(%col.getDatablock().shapeFile);
   %proper = (minigameCanDamage(%this,%col) == 1 || %col.spawnBrick.client == %client);
   
   if(%scale2 > %scale || %model !$= "m.dts" || !%proper)
 //Why would you have to check it its size hasn't been changed.
      return 0;
   
   %this.isHolding  = 1;
   %col.isHeld      = 1;
   %col.canDismount = 0;
   
   %col.setLookLimits(0.5,0.5); //What does this part do, and why
   %col.unMountImage(0);
   
   if(isObject(%them = %col.client))
   {
      %them.camera.setMode("Grabbed");              //
      %them.setControlObject(%them.camera);      //        What do these 3 lines do?
      %them.camera.setorbitmode(%this,0,5,10,5,0); //
   }
   
   %this.mountObject(%col,1);
   %col.playThread(2,death1);
   
   if(%scale2 >= %scale / 2)
      %this.playThread(2,armreadyboth);
   else
      %this.playThread(2,armreadyleft); //oh so if the thrower is holding a small player they'll throw with 1 arm?
   
   %pos = %col.getPosition();
   %col.setTransform(%pos SPC "0 0 -0.85 90");         //Why do you need to get their position?
   
   return 1;
}

function Player::attemptThrow(%this)
{
   if(!%this.isHolding)
      return 0;
   
   %held = %this.getMountedObject(0);
   %vec  = %this.getEyeVector();
   
   %this.unMountObject(%held);
   %this.playThread(2,root);
   %held.playThread(2,root);
   %held.setLookLimits(1,0);
   
   %held.addVelocity(vectorScale(%vec,10));
   
   if(isObject(%them = %held.client))
      %them.setControlObject(%held);
   
   %this.isHolding   = 0;
   %held.isHeld      = 0;
   %held.canDismount = 1;
   
   return 1;
}
Also, whats with all the return 0;s and return 1;s?