Author Topic: getActivateDirection + ItemCount  (Read 1566 times)

So I know that you can get the direction of a bot with
Code: [Select]
%obj.hActivateDirection = %dir;

How do I go about getting the direction the player is facing when throwing an item? I am trying to make a serverCommand that throws a number of items in the direction the player is facing, but with a slightly random velocity of the initial direction.

Here is my code

Code: [Select]
function serverCmdTossGITEM(%client, %input)
{
%velocity = %client.player.getVelocity();
%position = %client.player.getTransform();
%item = GTHISItem;

if(isObject(%client.player) && %input >= 1)
{
%item = new Item()
{
datablock = %item;
position = %position;
};

%item.schedulePop();
%itemVel = %item.setVelocity(vectorAdd(%velocity, getRandom(8,-8) SPC getRandom(-8,8) SPC 8));
%item.spawnBrick = %position + %item.Vel;
//%item.BL_ID = %client.BL_ID;
}
}

//Any help is greatly appreciated!

Currently, it only throws one item at a time regardless of %input and in random directions of wherever I am standing.
« Last Edit: March 16, 2015, 12:17:01 AM by Goth77 »

Look at the onFire method for a weapon with bullet spread. You'll want Player.getEyeVector() instead of the muzzle vector, though.

Thanks much, Jetz.

Know anyway I could spawn the %input of said item as well?

If your input is just an item datablock name, you can just run a nameToID on it and use that for your datablock. If not, you're gonna have to search through UI names. Think there's a list of them somewhere in the global variables.

If your input is just an item datablock name, you can just run a nameToID on it and use that for your datablock. If not, you're gonna have to search through UI names. Think there's a list of them somewhere in the global variables.
I already specified %item as GTHISItem; which is elsewhere in the code. It spawns the item, but only one of them, instead of %input. Im stumped

/tossGITEM 1           <    throws only one GTHISItem
/tossGITEM 2           <     also only throws one GTHISItem, instead of 2
« Last Edit: March 16, 2015, 04:14:39 AM by Goth77 »

I already specified %item as GTHISItem; which is elsewhere in the code. It spawns the item, but only one of them, instead of %input. Im stumped

/tossGITEM 1           <    throws only one GTHISItem
/tossGITEM 2           <     also only throws one GTHISItem, instead of 2
Oh. Just use a for loop around the spawning and velocity setting to do it all multiple times.

I am still having problems D; . I cannot get the item to "throw" from the eyeNode and the amount I input doesn't matter as it only drops 1. Could you possibly help by modifying my code to work how I need? It would help me so much man. Thanks again for your help.
« Last Edit: March 16, 2015, 08:02:54 AM by Goth77 »

I am still having problems D; . I cannot get the item to "throw" from the eyeNode and the amount I input doesn't matter as it only drops 1. Could you possibly help by modifying my code to work how I need? It would help me so much man. Thanks again for your help.
Post the new code.

Code: [Select]
if(isObject(%client.player) && %input >= 1)
Currently, it only throws one item at a time

Oh. Just use a for loop around the spawning and velocity setting to do it all multiple times.

Your current if check get run once, so it will only check if %input is greater than one, it will not check any further for any other numbers. You should create a simple for loop, as -Jetz- stated to get it to drop multiple items.
« Last Edit: March 16, 2015, 06:20:39 PM by Thorfin25 »

Code: [Select]
function serverCmdTossGITEM(%client, %input)
{
...
if(isObject(%client.player)) while(%input-- >= 0)
{
...
}
...
}

That's how I'd do it, at least.

edit: fixed formatting
edit2: Originally, I had the check as >= 1. This is incorrect and will cause it to stop 1 iteration early. >= 0 is correct.
« Last Edit: March 17, 2015, 03:14:59 AM by $trinick »

I found a work around by using the projectile of an item in-hand, and spawning the new item() onCollision. This is great, but also lacks the "click-less" feature of being able to instantly toss the said amount in a given velocity of the eye node with a simple /command

That's how I'd do it, at least.
I will have to try that. Ill get back to ya guys later, thanks!
« Last Edit: March 17, 2015, 12:18:32 AM by Goth77 »

edit2: Originally, I had the check as >= 1. This is incorrect and will cause it to stop 1 iteration early. >= 0 is correct.

I am bumping this because I figured out a way to do this after studying for and while loops a bit longer. Thanks again Jetz.

Code: [Select]
%count = 0;
%drop = 7;

while(%count <= %drop)
{
       %count++
       
       if(%requirement >= %int)
       {
              //Do stuff
       }

       echo("The amount of drops is "@%count@" ");
}

Solved and Locked :)