Mounting guns on vehicles and having them fire.
by Phil Carlisle · in Torque Game Engine · 12/27/2001 (8:19 am) · 14 replies
Ive got a vehicle (spaceship, but basically, could be anything), and Ive mounted a few guns on it.
Now if I mount the guns onto a player, they fire fine. If I mount the same guns onto a vehicle, they dont fire.
Has anyone got any script clue's as to why guns mounted onto a vehicle wouldnt fire when they do on a player?
Am I supposed to do something in the vehicle script to pass firing info onto the weapons? (Ive noticed that the player code basically runs through its mounted images telling them to updateState).
I am pretty clueless as regards the v12 scripting, but unfortunately understanding the code doesnt really help much here. Afaik this IS supposed to work. In that I used a T2 script as an example.
I just want to fly in a vehicle that can fire its weapons is all.
Phil.
Now if I mount the guns onto a player, they fire fine. If I mount the same guns onto a vehicle, they dont fire.
Has anyone got any script clue's as to why guns mounted onto a vehicle wouldnt fire when they do on a player?
Am I supposed to do something in the vehicle script to pass firing info onto the weapons? (Ive noticed that the player code basically runs through its mounted images telling them to updateState).
I am pretty clueless as regards the v12 scripting, but unfortunately understanding the code doesnt really help much here. Afaik this IS supposed to work. In that I used a T2 script as an example.
I just want to fly in a vehicle that can fire its weapons is all.
Phil.
About the author
Recent Threads
#2
12/27/2001 (5:30 pm)
I've been running into the same problem, Phil. For one reason or another, the triggers aren't working right for mounted images. I've got mine hacked to work by calling the weapon datablock's onFire function manually.
#3
12/28/2001 (9:15 am)
Just took a look at the Vehicle code and it does appear to be triggering the first two mount slots, just as the player does. Trigger 0 goes to slot 0, trigger 1 to slot 1, so you must have your weapon mounted in one of those slots.
#4
In T2's scripts, I see the following:
The Shrike's weapons are mounted on points 2 and 3. I've basically duplicated this functionality for my game (albeit with different slots), but the image triggers aren't being activated.
12/28/2001 (9:26 pm)
Well, yes, the triggers for firing and jumping are being called, but that goes to the vehicle datablock. The problem occurs when it comes time to activate triggers for mounted images in response to the main fire trigger being activated.In T2's scripts, I see the following:
function ScoutFlyer::onTrigger(%data, %obj, %trigger, %state)
{
// data = ScoutFlyer datablock
// obj = ScoutFlyer object number
// trigger = 0 for "fire", 1 for "jump", 3 for "thrust"
// state = 1 for firing, 0 for not firing
if(%trigger == 0)
{
switch (%state) {
case 0:
%obj.fireWeapon = false;
%obj.setImageTrigger(2, false);
%obj.setImageTrigger(3, false);
case 1:
%obj.fireWeapon = true;
if(%obj.nextWeaponFire == 2) {
%obj.setImageTrigger(2, true);
%obj.setImageTrigger(3, false);
}
else {
%obj.setImageTrigger(2, false);
%obj.setImageTrigger(3, true);
}
}
}
}The Shrike's weapons are mounted on points 2 and 3. I've basically duplicated this functionality for my game (albeit with different slots), but the image triggers aren't being activated.
#5
The player.cc file definitely iterates all the mounted images, but I didnt see that in vehicle (certainly not saying anything about firing).
I'll have another look at the vehicle and see if I cant get it to iterate all the mounted objects (rather than just the first two as tim suggested happens now).
But this code is straight from T2 scripts, so wouldnt that mean it wouldnt work in T2 either? (it does).
Thanks for the info guys.
Phil.
12/29/2001 (4:11 am)
Hmm, the thing I dont understand, is that its the weapon's image that handles the firing. Presumably by seeing a trigger state on the shapebase its mounted on?The player.cc file definitely iterates all the mounted images, but I didnt see that in vehicle (certainly not saying anything about firing).
I'll have another look at the vehicle and see if I cant get it to iterate all the mounted objects (rather than just the first two as tim suggested happens now).
But this code is straight from T2 scripts, so wouldnt that mean it wouldnt work in T2 either? (it does).
Thanks for the info guys.
Phil.
#6
ShapeBase automatically invokes the "onTrigger()" script callback for each activated trigger in the current move. This happens for all shape base objects that recieve moves, including the player, vehicles, camera, etc. (all script callbacks are server only)
Unfortunutely, having onTrigger processed on the server does not allow the clients to perform any immediate weapon state predictions. To help mitigate weapon response lag, the player and vehicle objects automatically trigger the mounted images in slot 0 and 1 (with triggers 0 & 1). This happens on both the client and server and is totally seperate from the server side onTrigger() script callback which happens regardless.
The scout flyer code you have there was setup to alternate the firing of the left and right weapons, which why it's a little more complicated. The weapons are mounted on to slot 2 & 3 so that they won't get triggered by the vehicle's internal "automatic" mapping of trigger 0 & 1 to slot 0 & 1, and the onTrigger callback is then used to activate the weapon system.
Now, why don't they fire? If the weapon works on the player but not on the vehicle, the usual cause is ammo. Which could be inventory ammo or energy, depending on how the weapon's image states are setup.
ps. the other possible problem is if you've mounted your scout weapons in slots 0 and 1. The vehicle codew will be clearing those triggers on every move and you won't be able to trigger them from the onTrigger script (which is why they in T2 they were in slots 2 & 3).
12/30/2001 (10:06 am)
You guys are both talking about different things :)ShapeBase automatically invokes the "onTrigger()" script callback for each activated trigger in the current move. This happens for all shape base objects that recieve moves, including the player, vehicles, camera, etc. (all script callbacks are server only)
Unfortunutely, having onTrigger processed on the server does not allow the clients to perform any immediate weapon state predictions. To help mitigate weapon response lag, the player and vehicle objects automatically trigger the mounted images in slot 0 and 1 (with triggers 0 & 1). This happens on both the client and server and is totally seperate from the server side onTrigger() script callback which happens regardless.
The scout flyer code you have there was setup to alternate the firing of the left and right weapons, which why it's a little more complicated. The weapons are mounted on to slot 2 & 3 so that they won't get triggered by the vehicle's internal "automatic" mapping of trigger 0 & 1 to slot 0 & 1, and the onTrigger callback is then used to activate the weapon system.
Now, why don't they fire? If the weapon works on the player but not on the vehicle, the usual cause is ammo. Which could be inventory ammo or energy, depending on how the weapon's image states are setup.
ps. the other possible problem is if you've mounted your scout weapons in slots 0 and 1. The vehicle codew will be clearing those triggers on every move and you won't be able to trigger them from the onTrigger script (which is why they in T2 they were in slots 2 & 3).
#7
Edit: Got it to work, I had to call setImageAmmo explicitly from the vehicle's datablock.
01/01/2002 (1:04 pm)
Regardless of current ammo count, shouldn't the onTrigger function for the weapon datablock images still run when I call setImageTrigger on its slot? I've put some echoes in there and I'm not getting anything...Edit: Got it to work, I had to call setImageAmmo explicitly from the vehicle's datablock.
#8
01/02/2002 (11:26 am)
could you share your script? I am working on the same thing and fear I am going to have the same problems.
#9
It's quite a lot of stuff to post, and not all mine. We started with T2's vehicle setup and are clipping out/redoing it section-by-section. Drop me a line if you run into problems.
01/02/2002 (1:48 pm)
Logically, it works the same as the T2 Shrike. The difference between it and T2, however, is you have to put ammo in it with %obj.setImageAmmo([slot], true). T2 has that part commented out.It's quite a lot of stuff to post, and not all mine. We started with T2's vehicle setup and are clipping out/redoing it section-by-section. Drop me a line if you run into problems.
#10
One thing to note, the shrike code is actually implemented in 3 different files (which I honestly dont understand the reasoning behind), you need vehicle.cs, vehicle_shrike.cs and mountImagetrigger.cs (cant remember that last one exactly, but its got some shrike trigger code in it, so do a find in files for "shrike" :))
Now when I moved the code from that last file into vehicle_shrike it needed a couple of tweaks to get the firing right (I'd messed with the code so much I cant remember what else was needed). But it pretty much should work from the get-go.
Weird weird weird stuff :))
Phil.
01/06/2002 (4:03 am)
Turns out I got my version of this running from the T2 shrike code with almost no changes (save altering the datablocks for some particles and weapons).One thing to note, the shrike code is actually implemented in 3 different files (which I honestly dont understand the reasoning behind), you need vehicle.cs, vehicle_shrike.cs and mountImagetrigger.cs (cant remember that last one exactly, but its got some shrike trigger code in it, so do a find in files for "shrike" :))
Now when I moved the code from that last file into vehicle_shrike it needed a couple of tweaks to get the firing right (I'd messed with the code so much I cant remember what else was needed). But it pretty much should work from the get-go.
Weird weird weird stuff :))
Phil.
#11
01/06/2002 (9:49 am)
It is wierd stuff... nothing to do with me though :)
#12
01/06/2002 (10:22 am)
Phil I keep doing a seach for that file callled "mountImagetrigger.cs" or just looking for skrike or mountImagetrigger in another file but it is not working could you specify the t2 script name Thanks Anthony
#13
01/06/2002 (3:37 pm)
Try weapTurretCode.cs. =)
#14
Seems that when you look for examples in T2 script, be aware that your example might be spread across a few files :))
Phil.
01/07/2002 (1:29 am)
Thats the one.. almost right :)))Seems that when you look for examples in T2 script, be aware that your example might be spread across a few files :))
Phil.
Torque Owner Chris "Dark" Evans
...I think...
Dark