View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:40 am



Reply to topic  [ 5 posts ] 
 Changing An HDFirearm Sprite Using Lua 
Author Message
User avatar

Joined: Sat Jul 23, 2011 6:15 am
Posts: 82
Reply with quote
Post Changing An HDFirearm Sprite Using Lua
Old:


New:
I can't change the gun's sprite using Lua... Help please.


Last edited by kungfuchan13 on Wed Jun 20, 2012 8:53 pm, edited 1 time in total.



Wed Jun 20, 2012 7:27 am
Profile
User avatar

Joined: Sat Jul 23, 2011 6:15 am
Posts: 82
Reply with quote
Post Re: Changing An HDFirearm Sprite Using Lua
For some reason putting FCCALOG = 0 into the create function made it work. Anyways, does anyone know how to change the sprite of an HDFirearm using lua?


Wed Jun 20, 2012 8:52 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Changing An HDFirearm Sprite Using Lua
Your problem was that you referenced a (global) variable that had never been defined. By defining FCCALOG in the create function you allowed it to be referenced.

To change the sprite just make multiple frames and set it to the frame you want. I can't say with 100% surety that this'll fix it but it'll definitely be neater, get rid of the line self.Frame = 0 in the update and add self.Frame = FCCA instead since frame and FCCA seem to always be the same.
Also, I may be mistaken here since I'm not exactly sure what you're trying to achieve but you could probably simplify all the timer stuff to the following, though it may mess up the stuff at the end.
Code:
if self.timer:IsPastSimMS(250) then
self.FCCA = self.FCCA + 1;
self.Timer:Reset();
end

Similarly, it probably makes more sense to check if the gun is firing before doing the timer stuff in the first place instead of resetting the timer whenever it's not but that's not a big deal I think.

In general, when looking for errors I'd suggest throwing in prints to find the problem, printing for each timer change would probably help you out.

Finally, note that since you're using global variables the script will affect every gun that uses it so when one fires they all change frames and the minimum distance of all of them will be affected. To get around that either use things like the gun's sharpness to determine stuff for the bullet or make a global table containing all the guns, sort through everything in that table for the closest gun and use its FCCALOG[i] value. Or maybe I'm looking at this in the wrong way and there's an easier solution, hard to say since I don't really know what the gun does.

Long winded post aside, good luck, keep at it, I'm sure you'll figure it out.


Wed Jun 20, 2012 10:08 pm
Profile
User avatar

Joined: Sat Jul 23, 2011 6:15 am
Posts: 82
Reply with quote
Post Re: Changing An HDFirearm Sprite Using Lua
Thanks for the help. The thing is... HDFirearms don't take kindly to having their frames being changed through Lua. They only change frames when they're shot... (Which is probably through Lua... Or whatever, but that doesn't really matter.) Having something that says self.Frame = x on an HDFirearm doesn't change the frame... So... Kinda at a loss for this... Maybe... Create an MOSRotating right on top of the gun and have that MOSRotating have the same velocity as the gun? Meh.


Fri Jun 22, 2012 4:47 am
Profile
User avatar

Joined: Sun Jan 28, 2007 10:32 pm
Posts: 1609
Location: UK
Reply with quote
Post Re: Changing An HDFirearm Sprite Using Lua
Attachables.

Unfortunately they're a pain to do, but it should be possible. Just tricky.


Fri Jun 22, 2012 4:50 am
Profile YIM
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.076s | 15 Queries | GZIP : Off ]