Game Development Community

SHOOTING

by James Reue · in Torque Game Engine · 08/20/2001 (10:02 am) · 15 replies

Hi, I was wondering since the projectile system isn't up yet has anyone figured out how to do the LOS check to
add Counter Strike-like shooting? i've got a gun loaded in, now i just need to figure out where to go from here..

thanks
j

#1
08/20/2001 (12:56 pm)
Still in my paste buffer... :)

This is quoting Harold Brown, and it was posted in the Vehicles thread:

"Something like this

function ShapeBaseImageData::onFire(%data, %obj, %slot)
{

//Find what weapon you are using
%weapon = %obj.getMountedImage(%slot);
// muzVec is the vector coming from the weapons's "muzzle"
%muzVec = %obj.getMuzzleVector(%slot);
// muzNVec = normalized muzVec
%muzNVec = VectorNormalize(%muzVec);
// Range of the projectile
%range = $weapon::range[%data.getDatablock().getName()];
// scale muzNVec to the range the repair beam can reach
%muzScaled = VectorScale(%muzNVec, %range);
// muzPoint = the actual point of the gun's "muzzle"
%muzPoint = %obj.getMuzzlePoint(%slot);
// rangeEnd = muzzle point + length of beam
%rangeEnd = VectorAdd(%muzPoint, %muzScaled);
// search for just about anything that can be damaged as well as interiors
%searchMasks = $TypeMasks::PlayerObjectType; mask, 0);
// search for objects within the beam's range that fit the masks above
%scanTarg = ContainerRayCast(%muzPoint, %rangeEnd, %searchMasks, %obj);


if(%scanTarg && !(%scanTarg.getType())
{
// a target in range was found
%target = firstWord(%scanTarg);


// Do damage functions here

}
}"

I hope Mr. Brown doesnt midn my copy and paste of his work. :)
#2
08/20/2001 (1:35 pm)
Not at all... the example is a modification of some of the code used in T2 for the repair gun to verify that there is an item in range that needs repaired.
#3
08/20/2001 (2:55 pm)
question about the weapon, i've got it to where it will load in an all, but when it is loaded it is above my head and when i
move it just falls down, how do you mount items to your player?

or if i had any random item how would i go about picking it up?

thanks for all the help

j
#4
08/20/2001 (3:48 pm)
also, where does that function go?

i keep getting syntax errors first one being at

%searchMasks = $TypeMasks::PlayerObjectType; mask, 0);

]
#5
08/20/2001 (5:01 pm)
remove the mask, 0); from that line... it was an error in editing on my end.
#6
08/21/2001 (6:05 pm)
nm i got it... but now it's telling me ...unknown command getDataBlock and couldn't find object null for getName at

%range = $weapon::range[%data.getDatablock().getName()];

can you just define %range as a number?
#7
08/21/2001 (9:05 pm)
Yes.. I was getting detailed and setting up an array for different ranges for different weapons.
#8
08/22/2001 (12:31 pm)
I dont understand how to get the function to work. Sorry if it seems blatantly obvious (it probably is... :)

How do you get the game to call OnFire?

On a very related note, how do you normally program stuff like this? I dont know how to call these functions and where to cal them from, becuase I dont know how to give them the correct parameters. For example, this function needs:

(%data, %obj, %slot)

How do I know what they are? Where do they come from? I know that %data is a pointer to a datablock (or something like that) and I thnk %obj is the player, and %slot has something to do with which weapon it is. But I dont know what to put there when I call it and where to call it from. I just need a very general description sof how things work in this engine/scripts.
#9
08/23/2001 (12:14 am)
i found you can put the function pretty much any where ...weapons.cs , sniperrifle.cs, vehicles.cs, vehicle_shrike.cs ..etc...

i chose to use this function in sniperrifle.cs because i am just going to define the range as a number for each gun..this is probably slow but until the projectile system comes up it will due..here is my modified function in sniperrifle.cs

function ShapeBaseImageData::onFire(%data,%obj, %slot)
{
echo("bang");
//Find what weapon you are using
%weapon = %obj.getMountedImage(%slot);
// muzVec is the vector coming from the weapons's "muzzle"
%muzVec = %obj.getMuzzleVector(%slot);
// muzNVec = normalized muzVec
%muzNVec = VectorNormalize(%muzVec);
// Range of the projectile

%range = 85;
// scale muzNVec to the range the repair beam can reach
%muzScaled = VectorScale(%muzNVec, %range);
// muzPoint = the actual point of the gun's "muzzle"
%muzPoint = %obj.getMuzzlePoint(%slot);
// rangeEnd = muzzle point + length of beam
%rangeEnd = VectorAdd(%muzPoint, %muzScaled);
// search for just about anything that can be damaged as well as interiors
%searchMasks = $TypeMasks::PlayerObjectType;
// search for objects within the beam's range that fit the masks above
%scanTarg = ContainerRayCast(%muzPoint, %rangeEnd, %searchMasks, %obj);


if(%scanTarg)
{
// a target in range was found
%target = firstWord(%scanTarg);

%amount = ".34";

%target.applyDamage(%amount);
// Do damage functions here
echo("hit ", %target);
}
}

this is the same except that if it hits a player model it applies dammage ...i have my max dammage at 1 so 3 hits should kill the player ..

then

if you go into default.bind.cs there is a mouseFire function there is where the shooting takes place .. this should already be in there

function mouseFire(%val)
{
$mvTriggerCount0++;

}

function altTrigger(%val)
{
$mvTriggerCount1++;
}

moveMap.bind( mouse, button0, mouseFire );
moveMap.bind( mouse, button1, altTrigger );


somehow that calls the onFire event ..

then *some where* there is an onKilled event that you can do something like %targetObject.playPain();

or whatever...

i'm not sure how it's called though...but the way i've done it, it has already been set up to call onFire via the mouseFire or altTrigger in default.bind.cs

hope this helps...

thanks again LabRat
#10
09/04/2001 (6:52 pm)
Well, I managed to get myself pretty much lost here. I obviously don't grasp the scripting basics sufficiently.

The script code shown by Reue above - it goes where ? I know you say pretty well anywhere, but I don't understand that :-) I put it in a file, named it weapons.cs and dropped it in base\scripts ... is that the right place ?

I don't get anything happening. I'm running a seperate standalone dedicated server - it does not have the weapons.cs file - does it need it ?

After finding *a* right place to put the file, then what ? Don't I have to call the weapons.cs file from somewhere ? one of the main.cs's maybe ? floundering floundering floundering - see both of my eyes on top of my head now ! :-)

Any help would be appreciated ...
#11
09/05/2001 (9:35 am)
don't put it in base/scripts put it in server/scripts and make sure you have got the item.cs inventory.cs and weapons.cs from tribes 2..
you could put that stuff at the bottom of the weapons.cs or like i said i put it in sniperrifle.cs which i also got from tribes 2 and it is also in server/scripts
you will also need to modify the main.cs in /server to exec("") each script ..search the forums i believe there is a weapons mod that has been posted
#12
09/05/2001 (9:40 am)
ah, great James, thanks.


but, but, but I don't have Tribes 2. >sob<

Can I find the same files in the Demo version which I just d/l'd ? I looked quickly and all those files appear to be dso files. Is there a script decompiler somewhere that I should know about ?
#13
09/05/2001 (2:15 pm)
dunno about the demo .. but even for the game there are just .dso files you actually have to open up a .vl2 file with a zip extractor and get the scripts out of that ..so look around in the demo stuff for a .vl2 file and open it to get the .cs files any zip extractor will open it ..also you might look around for the weapons mod ..they might have included the t2 scripts.. search the forums for "complete working weapon" it's in the mod's forum i believe
#14
09/05/2001 (4:01 pm)
The complete working weapon example contains all of the basics you need to get a weapon into the game. It has also been sanitized of all T2 inventory specific controls other then a few function names.
#15
09/05/2001 (7:01 pm)
Thanks guys - with your help I finally got it going, and was even able to give a little something back, I hope, in LabRat's Weapons thread in the Mods forum.