View unanswered posts | View active topics It is currently Thu Nov 28, 2024 1:26 pm



Reply to topic  [ 10 posts ] 
 Changing reloading speed of a weapon 
Author Message
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Changing reloading speed of a weapon
Is there any lua function to change reload speed of a weapon? I tried self.EquippedItem.ReloadTime and other things of the like, but it seems that that property is read only.

Do I have to make a huge work around for this?


Tue Apr 15, 2014 8:37 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Changing reloading speed of a weapon
self.EquippedItem is of the type MovableObject, have you tried ToHDFirearm(self.EquippedItem).ReloadTime ?


Tue Apr 15, 2014 9:34 pm
Profile
User avatar

Joined: Sun Jan 28, 2007 10:32 pm
Posts: 1609
Location: UK
Reply with quote
Post Re: Changing reloading speed of a weapon
Just tested on my end by tweaking a script. Looks like it works.

Spoiler'd script as example;



Tue Apr 15, 2014 9:39 pm
Profile YIM
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Changing reloading speed of a weapon
This is my current script. Basically it's like a stimpack that fires a single MOPixel that sticks to the actor, and then the MOPixel modifies the reload of the weapon.

Code:
function Create(self)

   for actor in MovableMan.Actors do
      self.dist = SceneMan:ShortestDistance(actor.Pos, self.Pos, true);
      if math.abs(self.dist.X) < 50 and math.abs(self.dist.Y) < 50 then
         self.parent = ToAHuman(actor);
      end
   end

   self.reloadTime = 100;

end

function Update(self)
   if self.parent.ID ~= 255 then
      self.Pos = self.parent.Pos;
      if self.parent.EquippedItem ~= nil then
         self.weapon = ToHDFirearm(self.parent.EquippedItem);
         self.weapon.ReloadTime = self.reloadTime;
      end
   end
end


It doesn't seem to work. I added print(self.weapon.ReloadTime) and it does show the 100, but the weapon doesn't reload that fast.

EDIT:
In fact, tried printing the reload time before modifying it and it prints nil. It's weird though, I can actually get other variables of the weapon (like the PresetName and RateOfFire) and modify them, but not ReloadTime. :/


Tue Apr 15, 2014 9:56 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Changing reloading speed of a weapon
It is not obvious, but you have to call the function using the correct pointer type because not all classes have all functions and properties available (you can find the v1.05 class hierarchy on the wiki). E.g. EquippedItem is a property of AHuman and ACrab, but not Actor. So if you access EquippedItem on an Actor-pointer it will return nil. MovableMan.Actors is a list of Actor pointers so it can be useful to test for class-membership using the "Is[ClassType]()" functions.

Try spawning a few armed AHumans and then paste this script in to the console:

Code:
for Act in MovableMan.Actors do if IsAHuman(Act) and ToAHuman(Act).EquippedItem then print(Act.PresetName.." "..ToAHuman(Act).EquippedItem.PresetName.." rt: "..ToHDFirearm(ToAHuman(Act).EquippedItem).ReloadTime) else print(Act.PresetName) end end


Wed Apr 16, 2014 8:12 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Changing reloading speed of a weapon
Did that, this is what happened on the console:

Code:
for Act in MovableMan.Actors do if IsAHuman(Act) and ToAHuman(Act).EquippedItem then print(Act.PresetName.." "..ToAHuman(Act).EquippedItem.PresetName.." rt: "..ToHeldDevice(ToAHuman(Act).EquippedItem).ReloadTime) else print(Act.PresetName) end end
PRINT: Door Rotate Long
PRINT: Door Rotate Long
ERROR: [string "for Act in MovableMan.Actors do if IsAHuman..."]:1: attempt to concatenate field 'ReloadTime' (a nil value)

for Act in MovableMan.Actors do if IsAHuman(Act) and ToAHuman(Act).EquippedItem then print(Act.PresetName.." "..ToAHuman(Act).EquippedItem.PresetName.." rt: ") else print(Act.PresetName) end end
PRINT: Door Rotate Long
PRINT: Door Rotate Long
PRINT: Scouting Robot Auto Shotgun rt:
PRINT: Scouting Robot Remote-GL rt:
PRINT: Scouting Robot Gatling Gun rt:
PRINT: Scouting Robot Sniper Rifle rt:
PRINT: Scouting Robot Auto Cannon rt:
PRINT: Scouting Robot Shotgun rt:
PRINT: Scouting Robot Assault Rifle rt:
PRINT: Scouting Robot Compact Assault Rifle rt:
PRINT: Brain Case


Just like in my code, I can get the PresetName but not the ReloadTime. Scripting lately I realised the importance of using the correct pointer type, so I made sure I was using it correctly over here, so that is why I came here with the doubt, it's just so weird.

I'm not using B30 beta by the way if it has anything to do with this.


Wed Apr 16, 2014 9:52 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Changing reloading speed of a weapon
Ha! I just assumed you did use the beta version. Lua access to ReloadTime is not possible in the earlier builds.


Wed Apr 16, 2014 10:17 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Changing reloading speed of a weapon
Oh gawd, so this was just a silly situation.

Thanks a lot for the help :D!

EDIT:

Random question, when B30 is released is it going to be released to the licensing.datarealms page too?


Wed Apr 16, 2014 10:22 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Changing reloading speed of a weapon
I don't know how the release will happen but I assume it will be released there and everywhere else at the same time.


Thu Apr 17, 2014 8:59 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Changing reloading speed of a weapon
Okay, thanks again!


Thu Apr 17, 2014 4:38 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 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.085s | 14 Queries | GZIP : Off ]