Author Topic: 2nd Firing mode in a custom tank using Spacebar [SOLVED]  (Read 831 times)

I can't make my tank fire using the space bar. Problem solved, but another problem popped up.

See the code, again:


Code: [Select]
package ShootOnClick_Pack2
{
function armor::onTrigger(%db,%obj,%slot,%val)
{
if(%obj.getClassName()$="AIPlayer")
{
if(%slot==2)
{
if(%val)
{
if($Sim::Time<%obj.SOC_LastFireTime2)
{
return;
}
}
%obj.SOC_Shoot2(%slot,%val);
}
}
return Parent::onTrigger(%db,%obj,%slot,%val);
}
};

EDIT: Problem solved, I can now shoot with space bar. When I press space, I am recognized as an AI Player, and the SOC_Shoot2 function is in the Player so I renamed it to be used on AIPlayer. Ive made some changes, then it worked.

But...

There's one problem: It can't kill vehicles nor damage them. It can kill bricks, but not vehicles.

Here's the AIPlayer code I'm talking about:


Code: [Select]
function AIPlayer::SOC_Shoot2(%obj,%slot,%val)
{
if(!%val) {cancel(%obj.SOC_reshoot2);return;}

%data= %obj.getDatablock();

%mountObj= %obj.getMountNodeObject(%data.shootOnClick_RequiredSlot2);
//if(%mountObj!$=%Obj) {return;}

if(%data.shootOnClick2)
{
//Checks OK, shoot it all.
%cnt=%data.shootOnClick_ProjectileCount2;
for(%i=0;%i<%cnt;%i++)
{
%pos= %obj.getPosition();
%PVec= %data.ShootOnClick_Position2[%i];
%VVec= %data.ShootOnClick_Velocity2[%i];
%iPos= repeatedVectorAddwithScale(
%obj.getEyeVector() SPC getWord(%PVec,0) TAB
%obj.getLeftVector() SPC getWord(%PVec,1) TAB
%obj.getUpVector() SPC getWord(%PVec,2)
);
%iVel= repeatedVectorAddwithScale(
%obj.getEyeVector() SPC getWord(%VVec,0) TAB
%obj.getLeftVector() SPC getWord(%VVec,1) TAB
%obj.getUpVector() SPC getWord(%VVec,2)
);
%scale=%data.ShootOnClick_Scale2[%i];
if(%scale$="") {%scale="1 1 1";}
%p= new Projectile()
{
dataBlock= %data.ShootOnClick_Projectile2[%i];
initialPosition= vectorAdd(%pos,%iPos);
initialVelocity= %iVel;
sourceObject= %obj;
client= %obj;
sourceSlot= %slot;
scale= %scale;
};missionCleanup.add(%p);
}
serverPlay3d(%data.ShootOnClick_Sound2,%pos);

//If hold, schedule.
if(%data.ShootOnClick_Hold2)
{
//Delay according to datablocks.
%obj.SOC_reshoot2= %obj.schedule(%data.ShootOnClick_ReshootDelay2,SOC_Shoot2,%slot,%val);
}
%obj.SOC_LastFireTime2=$Sim::Time+%data.ShootOnClick_ShootDelay2/1000;
}
}

Take note: %obj is the AIPlayer

Problem Solved.
« Last Edit: June 21, 2009, 06:36:49 AM by Jaydee »


1 is Alternate Fire, which isn't normally bound to a key. You can use it with altTrigger(); (use like crouch() jet() etc.) but the majority of people won't have it.

2 is Crouch, I think. 3 is Jump. 4 is Jet.


There is, but Blockland does not use it by default.

Start a server. Spawn and pick up the "Guns Akimbo". Use them. Go into the console and type altTrigger();altTrigger();. The left gun fires - this is slot 1.

There is, but Blockland does not use it by default.

Start a server. Spawn and pick up the "Guns Akimbo". Use them. Go into the console and type altTrigger();altTrigger();. The left gun fires - this is slot 1.

Oh, so by default, most people won't able to bind it in their BL's? Lolwutfail

I tried using echoes (With space bar successfully triggered). It seems to execute the code smoothly, but it doesnt shoot.


Oh, so by default, most people won't able to bind it in their BL's? Lolwutfail

I tried using echoes (With space bar successfully triggered). It seems to execute the code smoothly, but it doesnt shoot.
This may be a little obvious, but does %obj have the function SOC_Shoot2(%slot,%val);?

Oh, so by default, most people won't able to bind it in their BL's? Lolwutfail

I tried using echoes (With space bar successfully triggered). It seems to execute the code smoothly, but it doesnt shoot.
Badspot never added Alternate Fire in Controls like he did for normal Fire, Crouch, Jump and Jet. It's possible to add via mods but I would advise against using it unless it is added in an official update so that everyone can use it.

Can I do a delayed fire?

For example: I hold the left click for 2 seconds, then it shoots rapidly. It can shoot if I hold less than 2 seconds.

I think its possible


Ok, the 2nd firing mode thing using the space bar is now solved.

But there's another problem (see main post)

Code: [Select]
client= %obj;This should be the firer's client, not the bot AIPlayer.

Code: [Select]
client= %obj;This should be the firer's client, not the bot AIPlayer.

That's it. Even if I put %obj.client, it still doesnt work, because %obj is the AIPlayer. Can I get a workaround around this just for the code to recognize the player? If so, please give me a basic code. Thanks.

What if I used a code to detect what's mounted on the AIPlayer? Then recognize it as a client?
« Last Edit: June 21, 2009, 05:23:12 AM by Jaydee »

%obj.client is nothing, because the AIPlayer does not have a client. You need to find the player mounted to the object.

Look at the Tank code.

%obj.client is nothing, because the AIPlayer does not have a client. You need to find the player mounted to the object.

Look at the Tank code.

WOW! I did it! I used this:

Code: [Select]
%player = %obj.getMountedObject(0);
I found getMountedObject from the references topic. 0 means mount0, it gets the ID of the mounted object at mount0.

Then the projectile:

Code: [Select]
%p= new Projectile()
{
dataBlock= %data.ShootOnClick_Projectile2[%i];
initialPosition= vectorAdd(%pos,%iPos);
initialVelocity= %iVel;
sourceObject= %player;
client= %player.client;
sourceSlot= %slot;
scale= %scale;
};missionCleanup.add(%p);


It worked!! Hahaha! Thanks Space Guy! I owe you alot.