Blockland Forums > Modification Help
Need help with player throwing Script
<< < (3/4) > >>
Destiny/Zack0Wack0:
use Player::activateStuff(%player) instead of Armor::onTrigger(~)
It's only called when you click (not stop clicking) and when you have empty hands.
Crysist:

--- Quote from: lilboarder32 on June 12, 2010, 11:25:21 PM ---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.

--- End quote ---

--- Quote from: Destiny/Zack0Wack0 on June 13, 2010, 12:15:48 AM ---use Player::activateStuff(%player) instead of Armor::onTrigger(~)
It's only called when you click (not stop clicking) and when you have empty hands.

--- End quote ---
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);
}

--- End quote ---
Crysist:
Tested, now no console errors when I click or in the script yet he wont mount.

--- Code: ---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);
}
--- End code ---
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: ---%guyimholding=%player.mountedobj;
--- End code ---
Defiantly not that, but you get my point.
Truce:

--- Quote from: Crysist on June 13, 2010, 09:52:18 AM ---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: ---%guyimholding=%player.mountedobj;
--- End code ---
Defiantly not that, but you get my point.

--- End quote ---

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: ---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;
}
--- End code ---


--- Code: ---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;
}
--- End code ---
Crysist:

--- 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;
}
--- End quote ---
Also, whats with all the return 0;s and return 1;s?
Navigation
Message Index
Next page
Previous page

Go to full version