Author Topic: Scripting help.... shooting.  (Read 592 times)

Ok, here is a script, i want to know what part is controls the shooting times, and if posible explain how it works. I am new at scripting and i would love some pointers lol. and i am trying to get one to do a rapid fire with a machine gun, instead of steady one shot at a time.

if you would, please copy the code that sets the shooting times and tell me what it should be and explain how it works.






 datablock PlayerData(national socialistZombie : PlayerStandardArmor)
{
   //category = "Vehicles";
   minJetEnergy = 0;
   jetEnergyDrain = 0;
   canJet = 0;
   maxItems   = 0;   //total number of bricks you can carry
   maxWeapons = 0;      //this will be controlled by mini-game code
   maxTools = 0;
   runforce = 100 * 90;
   maxForwardSpeed = 8;
   maxBackwardSpeed = 8;
   maxSideSpeed = 8;
   attackpower = 10;
   //jumpsound = "ZombieJumpSound";
   cameradefaultFOV = 90;
   cameraMaxFov = 120;
   cameraMinFov = 10;
   //minlookangle = -1;
   //maxlookangle = -1;
   minlookangle = -1.5708;
   maxlookangle = 1.5708;
   BrickDestroyMaxVolume = 250;
   BrickMaxJumpHeight = 20;
   uiName = "national socialist";
   rideable = true;
   canRide = true;
   BrickKillRadius = 2;
   skinColor = "1 0.79 0.57 1";
   FollowAnim = "ArmReadyright";
   randomwalk = 1;
   aimatplayer = 1;
   SpecialAttack = 1;
   NoBloodyHands = 1;
   DoNotZombify = 1;
   chance = 90;
};
function national socialistZombie::SpecialAttack(%this,%onshot)
{
   %ran = getrandom(-1,1);
   %this.setmovex(%ran);
   schedule(0,0,national socialistShootMode,%this);
   schedule(500,0,national socialistShootMode,%this);
   schedule(1000,0,national socialistShootMode,%this);
   schedule(1500,0,national socialistShootMode,%this);
   %this.schedule(2000,clearmovex);
}
function national socialistShootMode(%this)
{
   if(%this.getstate() !$= "Dead")
   {
      %this.setimagetrigger(0,1);
      %this.setimagetrigger(0,0);
   }
}
function national socialistZombie::ondisabled(%this,%obj)
{
   parent::ondisabled(%this,%obj);
   ZombieDefault::ondisabled(%this,%obj);
}
function national socialistZombie::onCollision(%this, %obj, %col, %fade, %pos, %norm)
{
   parent::oncollision(%this, %obj, %col, %fade, %pos, %norm);
   ZombieDefault::onCollision(%this, %obj, %col, %fade, %pos, %norm);
}
function national socialistZombie::onMount(%a,%player,%vehicle,%d,%e,%f)
{
   ZombieDefault::onMount(%a,%player,%vehicle,%d,%e,%f);
   parent::onMount(%a,%player,%vehicle,%d,%e,%f);
}
function national socialistZombie::onUnMount(%a,%player,%vehicle,%d,%e,%f)
{
   ZombieDefault::onUnMount(%a,%player,%vehicle,%d,%e,%f);
   parent::onUnMount(%a,%player,%vehicle,%d,%e,%f);
}
function national socialistZombie::onAdd(%this,%obj)
{
   parent::onAdd(%this,%obj);
   ZombieDefault::onAdd(%this,%obj);
   //schedule(10,0,national socialistfy,%obj);
   schedule(15,0,national socialistfy,%obj);
   //schedule(20,0,ghostifybot,%obj);
   //%obj.playthread(2,armreadyright);
   //%obj.setarmthread(crouch);
   %obj.mountimage(gunimage,0);
}

function national socialistfy(%obj)
{
   %obj.name = "national socialist";
   %obj.chestcolor = "0.72  0.53 0.29 1";
   %obj.hatcolor = "0.72  0.53 0.29 1";
   %obj.rarmcolor = "0.72  0.53 0.29 1";
   %obj.larmcolor = "1 0 0 1";
   %obj.hipcolor = "0.2 0.2 0.2 1";
   %obj.llegcolor = "0.39 0.19 0 1";
   %obj.rlegcolor = "0.39 0.19 0 1";

   %obj.chest = "0";
   %obj.lhand = "0";
   %obj.rhand = "0";
   %obj.larm = "0";
   %obj.rarm = "0";
   %obj.hat = "6";
   %obj.accent = "0";
   %obj.pack = "0";
   %obj.secondpack = "0";
   %obj.lleg = "0";
   %obj.rleg = "0";
   %obj.hip = "0";

   GameConnection::ApplyBodyParts(%obj);
   GameConnection::ApplyBodyColors(%obj);
   %obj.setfacename(smileyblonde);
   %obj.setdecalname("mod-suit");
   %color = %obj.getdatablock().skincolor;
   %obj.setNodecolor($rhand[0], %color);
   %obj.setNodecolor($lhand[0], %color);
   %obj.setNodecolor("headskin", %color);
   //servercmdupdatebodyparts(%obj,6);
}
function servercmdsigheil(%client)
{
   %client.player.playthread(1,armreadyright);
   %client.player.setarmthread(armattack);
}
function servercmdunsigheil(%client)
{
   %client.player.setarmthread(look);
}
package national socialistAttackPackage
{
function ProjectileData::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
   if(isobject(%obj.sourceobject) && %obj.sourceobject.getdatablock().getname() $= "national socialistZombie")
   {
      //schedule(0,0,PropaneTankDamageF,%this,%obj,%col);
      %source = %obj.sourceobject;

      //echo(%source.getclassname());
      //echo(IsInMiniGame(%source));
      //echo(IsInSameMinigame(%col,%source));
      if(isobject(%obj.sourceobject) && %obj.sourceobject.getclassname() $= "AiPlayer" && IsInMinigame(%obj.sourceobject) && IsInSameMinigame(%col,%source))
      {
         if(%col.client != 0)
         {
            %source.cols = %col.client;
         }
         %col.damage(%obj,0,%obj.getdatablock().directDamage/2,$DamageType::zombiebite);
      }
   }
   parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
}
};
activatepackage(national socialistAttackPackage);

The gun code effects the guns shooting speed, not the player.

Uh oh I didn't look at it before I posted, and now I am stuck knowing nothing.

function national socialistZombie::SpecialAttack(%this,%onshot)
{
   %ran = getrandom(-1,1);
   %this.setmovex(%ran);
   schedule(0,0,national socialistShootMode,%this);
   schedule(500,0,national socialistShootMode,%this);
   schedule(1000,0,national socialistShootMode,%this);
   schedule(1500,0,national socialistShootMode,%this);
   %this.schedule(2000,clearmovex);
}

That makes it do the national socialistShootMode function every .5 seconds, if you lower the increments it might go faster.
« Last Edit: October 24, 2009, 09:45:34 PM by Visage »

The gun code effects the guns shooting speed, not the player.

Uh oh I didn't look at it before I posted, and now I am stuck knowing nothing.

function national socialistZombie::SpecialAttack(%this,%onshot)
{
   %ran = getrandom(-1,1);
   %this.setmovex(%ran);
   schedule(0,0,national socialistShootMode,%this);
   schedule(500,0,national socialistShootMode,%this);
   schedule(1000,0,national socialistShootMode,%this);
   schedule(1500,0,national socialistShootMode,%this);
   %this.schedule(2000,clearmovex);
}

That makes it do the national socialistShootMode function every .5 seconds, if you lower the increments it might go faster.
As i used the Ai_national socialist as a base for my TF2 Ai, i know that he is talking the right way.
The bold numbers is the time when he shoots in that schedule.
Also, i see someone is using an old version of Ai_national socialist.

To fire it constantly though, it needs a bit more then that to change.
If you want him to fire constantly (like with the minigun) you have to replace this:
Code: [Select]
function national socialistZombie::SpecialAttack(%this,%onshot)
{
   %ran = getrandom(-1,1);
   %this.setmovex(%ran);
   schedule(0,0,national socialistShootMode,%this);
   schedule(500,0,national socialistShootMode,%this);
   schedule(1000,0,national socialistShootMode,%this);
   schedule(1500,0,national socialistShootMode,%this);
   %this.schedule(2000,clearmovex);
}
function national socialistShootMode(%this)
{
   if(%this.getstate() !$= "Dead")
   {
      %this.setimagetrigger(0,1);
      %this.setimagetrigger(0,0);
   }
}
with this:
Code: [Select]
function national socialistZombie::SpecialAttack(%this,%onshot)
{
%ran = getrandom(-1,1);
%ran2 = getrandom(-1,1);
%this.setmovex(%ran);
%this.setmovey(%ran);
schedule(0,0,Constantnational socialistShootMode,%this);
schedule(2000,0,Constantnational socialistUnShootMode,%this);
%this.schedule(2000,clearmovex);
}
function national socialistShootMode(%this)
{
if(isobject(%this) && %this.getstate() !$= "Dead")
{
%this.setimagetrigger(0,1);
}
}
function national socialistUnShootMode(%this)
{
if(isobject(%this) && %this.getstate() !$= "Dead")
{
%this.setimagetrigger(0,0);
}
}
I have done exactly the same like you before i created the Ai_TF2, because i needed a minigun Ai. :)

AIPlayer shooting is very strange now. It doesn't appear to actually use the weapon's state system (e.g. holding the trigger makes it fire continuously or 'charge' effects), it just instantly does the onFire bit for the weapon in your hand. No difference for generic weapons like the Rocket Launcher, Gun or Bow, but it might affect the Spear's charging.