View unanswered posts | View active topics It is currently Mon Jul 08, 2024 4:16 pm



Reply to topic  [ 9 posts ] 
 Script: Delay on weapon switch? [Solved] 
Author Message
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Script: Delay on weapon switch? [Solved]
Hello people,

Could anyone somehow change this script in a way that it takes 2 seconds for it to change to the other weapon?

Code:
function SteyrAUGSwitchMain(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      gun.Sharpness = 1;
   end
end

function SteyrAUGSwitchAlt(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      gun.Sharpness = 2;
   end
end

function Create(self)

   self.weaponNameTable = {"Steyr AUG", "Steyr AUG Alt Fire"};
   self.weaponClassTable = {"HDFirearm", "HDFirearm"};
   self.switchPhase = 0;

end

function Update(self)

   if self.Sharpness ~= 0 then
      if self.switchPhase == 0 then
         local actor = MovableMan:GetMOFromID(self.RootID);
         if MovableMan:IsActor(actor) then
            self.parent = ToAHuman(actor);
            if self.weaponClassTable[self.Sharpness] == "HDFirearm" then
               local switchGun = ToActor(self.parent):AddInventoryItem(CreateHDFirearm(self.weaponNameTable[self.Sharpness]));
            elseif self.weaponClassTable[self.Sharpness] == "TDExplosive" then
               local switchGun = ToActor(self.parent):AddInventoryItem(CreateTDExplosive(self.weaponNameTable[self.Sharpness]));
            elseif self.weaponClassTable[self.Sharpness] == "HeldDevice" then
               local switchGun = ToActor(self.parent):AddInventoryItem(CreateHeldDevice(self.weaponNameTable[self.Sharpness]));
            end
            ToActor(self.parent):GetController():SetState(Controller.WEAPON_DROP,true);
            self.switchPhase = 1;
         else
            self.Sharpness = 0;
         end

      else
         if MovableMan:IsActor(self.parent) then
            if ToActor(self.parent):IsInventoryEmpty() == false then
               ToActor(self.parent):GetController():SetState(Controller.WEAPON_CHANGE_PREV,true);
            end
         end
         self.ToDelete = true;
      end
   end

end


Last edited by Gotcha! on Sun Sep 18, 2011 6:51 pm, edited 1 time in total.



Sun Sep 18, 2011 2:10 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: Script: Delay on weapon switch?
Try:
Code:
function SteyrAUGSwitchMain(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      gun.Sharpness = 1;
   end
end

function SteyrAUGSwitchAlt(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      gun.Sharpness = 2;
   end
end

function Create(self)

   self.weaponNameTable = {"Steyr AUG", "Steyr AUG Alt Fire"};
   self.weaponClassTable = {"HDFirearm", "HDFirearm"};
   self.switchPhase = 0;

   self.switchTimer = Timer();
   self.flipTimer = false;
   self.switchDelay = 2000; -- This is the time delay

end

function Update(self)

   if self.Sharpness ~= 0 then

      if self.flipTimer == false then
         self.flipTimer = true;
         self.switchTimer:Reset();
      end

      if self.switchTimer:IsPastSimMS(self.switchDelay) then
         if self.switchPhase == 0 then
            local actor = MovableMan:GetMOFromID(self.RootID);
            if MovableMan:IsActor(actor) then
               self.parent = ToAHuman(actor);
               if self.weaponClassTable[self.Sharpness] == "HDFirearm" then
                  local switchGun = ToActor(self.parent):AddInventoryItem(CreateHDFirearm(self.weaponNameTable[self.Sharpness]));
               elseif self.weaponClassTable[self.Sharpness] == "TDExplosive" then
                  local switchGun = ToActor(self.parent):AddInventoryItem(CreateTDExplosive(self.weaponNameTable[self.Sharpness]));
               elseif self.weaponClassTable[self.Sharpness] == "HeldDevice" then
                  local switchGun = ToActor(self.parent):AddInventoryItem(CreateHeldDevice(self.weaponNameTable[self.Sharpness]));
               end
               ToActor(self.parent):GetController():SetState(Controller.WEAPON_DROP,true);
               self.switchPhase = 1;
            else
               self.Sharpness = 0;
            end

         else
            if MovableMan:IsActor(self.parent) then
               if ToActor(self.parent):IsInventoryEmpty() == false then
                  ToActor(self.parent):GetController():SetState(Controller.WEAPON_CHANGE_PREV,true);
               end
            end
            self.ToDelete = true;
         end
      end

   end

end

Also, lol:
Image


Sun Sep 18, 2011 2:25 pm
Profile
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Re: Script: Delay on weapon switch?
Strange, there's no difference. Also, no error messages.

Also: Wow, for a moment there I felt pretty 1337. *feels warm and fuzzy*


Sun Sep 18, 2011 3:07 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: Script: Delay on weapon switch?
It seems to work for me. Also, do you have your weapons' sharpness set to 0 in INI?


Sun Sep 18, 2011 3:24 pm
Profile
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Re: Script: Delay on weapon switch?
No. :oops: Did so now, but no change though. Well, it works for you so I must be forgetting something somewhere.
Thanks. :)

No. :oops: Did so now, but no change though. Well, it works for you so I must be forgetting something somewhere.
Thanks. :)

Edit: Nope, didn't forget anything, except that I have one less 'end' at the end. But if I add one then the console tells me it did not expect one.

Code:
function SteyrAUGSwitchMain(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      gun.Sharpness = 1;
   end
end

function SteyrAUGSwitchAlt(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      gun.Sharpness = 2;
   end
end

function Create(self)

   self.weaponNameTable = {"Steyr AUG", "Steyr AUG Alt Fire"};
   self.weaponClassTable = {"HDFirearm", "HDFirearm"};
   self.switchPhase = 0;
   self.BurstTimer = Timer()
   self.switchTimer = Timer();
   self.flipTimer = false;
   self.switchDelay = 2000;
end

function Update(self)

   if self.Sharpness ~= 0 then
      if self.flipTimer == false then
         self.flipTimer = true;
         self.switchTimer:Reset();
      end
      if self.switchPhase == 0 then
         local actor = MovableMan:GetMOFromID(self.RootID);
         if MovableMan:IsActor(actor) then
            self.parent = ToAHuman(actor);
            if self.weaponClassTable[self.Sharpness] == "HDFirearm" then
               local switchGun = ToActor(self.parent):AddInventoryItem(CreateHDFirearm(self.weaponNameTable[self.Sharpness]));
            elseif self.weaponClassTable[self.Sharpness] == "TDExplosive" then
               local switchGun = ToActor(self.parent):AddInventoryItem(CreateTDExplosive(self.weaponNameTable[self.Sharpness]));
            elseif self.weaponClassTable[self.Sharpness] == "HeldDevice" then
               local switchGun = ToActor(self.parent):AddInventoryItem(CreateHeldDevice(self.weaponNameTable[self.Sharpness]));
            end
            ToActor(self.parent):GetController():SetState(Controller.WEAPON_DROP,true);
            self.switchPhase = 1;
         else
            self.Sharpness = 0;
         end

      else
         if MovableMan:IsActor(self.parent) then
            if ToActor(self.parent):IsInventoryEmpty() == false then
               ToActor(self.parent):GetController():SetState(Controller.WEAPON_CHANGE_PREV,true);
            end
         end
         self.ToDelete = true;
      end
   end
   if self:IsActivated() and self.Magazine then
      if not self.burst then
         self.burst = self.Magazine.RoundCount
         self.BurstTimer:Reset()
      elseif self.burst - 3 >= self.Magazine.RoundCount then
         self:Deactivate()
         if self.BurstTimer:IsPastSimMS(400) then
            self.burst = nil
         end
      end
   else
      self.burst = nil
   end
end


Last edited by Gotcha! on Sun Sep 18, 2011 4:20 pm, edited 1 time in total.



Sun Sep 18, 2011 3:58 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: Script: Delay on weapon switch?
Here's the RTE I have with the modifications, perhaps I missed something in my post.


Attachments:
Dual Weapon Mode.rte.rar [1.25 KiB]
Downloaded 214 times
Sun Sep 18, 2011 4:16 pm
Profile
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Re: Script: Delay on weapon switch?
Yeah, found the missing line. It works now. :) Thanks.

During the 2 second changing period the actor is still allowed to fire his gun.
Is it also possible to add a line in there that would somehow 'jam' the gun during those two seconds?


Sun Sep 18, 2011 4:52 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: Script: Delay on weapon switch?
Here you go.


Attachments:
Dual Weapon Mode.rte.rar [1.27 KiB]
Downloaded 183 times
Sun Sep 18, 2011 6:06 pm
Profile
User avatar

Joined: Tue Apr 01, 2008 4:49 pm
Posts: 1972
Location: The Netherlands
Reply with quote
Post Re: Script: Delay on weapon switch?
Thaaaanks! Works like a charm. :)


Sun Sep 18, 2011 6:34 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.156s | 14 Queries | GZIP : Off ]