Data Realms Fan Forums http://45.55.195.193/ |
|
Changing reloading speed of a weapon http://45.55.195.193/viewtopic.php?f=73&t=45627 |
Page 1 of 1 |
Author: | Asklar [ Tue Apr 15, 2014 8:37 pm ] |
Post subject: | 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? |
Author: | Abdul Alhazred [ Tue Apr 15, 2014 9:34 pm ] |
Post subject: | Re: Changing reloading speed of a weapon |
self.EquippedItem is of the type MovableObject, have you tried ToHDFirearm(self.EquippedItem).ReloadTime ? |
Author: | Arcalane [ Tue Apr 15, 2014 9:39 pm ] |
Post subject: | 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; |
Author: | Asklar [ Tue Apr 15, 2014 9:56 pm ] |
Post subject: | 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. :/ |
Author: | Abdul Alhazred [ Wed Apr 16, 2014 8:12 am ] |
Post subject: | 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 |
Author: | Asklar [ Wed Apr 16, 2014 9:52 pm ] |
Post subject: | 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. |
Author: | Abdul Alhazred [ Wed Apr 16, 2014 10:17 pm ] |
Post subject: | 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. |
Author: | Asklar [ Wed Apr 16, 2014 10:22 pm ] |
Post subject: | Re: Changing reloading speed of a weapon |
Oh gawd, so this was just a silly situation. Thanks a lot for the help ! EDIT: Random question, when B30 is released is it going to be released to the licensing.datarealms page too? |
Author: | Abdul Alhazred [ Thu Apr 17, 2014 8:59 am ] |
Post subject: | 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. |
Author: | Asklar [ Thu Apr 17, 2014 4:38 pm ] |
Post subject: | Re: Changing reloading speed of a weapon |
Okay, thanks again! |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |