View unanswered posts | View active topics It is currently Wed Dec 25, 2024 5:30 pm



Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
 Attachment's through lua? 
Author Message
User avatar

Joined: Thu Jan 21, 2010 10:59 pm
Posts: 151
Reply with quote
Post Attachment's through lua?
I was wondering, is it possible to add an attachable through lua?

because what I had in mind was, having an item with a pie menu button which when pressed, adds an helmet attachable on an actor's head...


Last edited by ShadowStorm on Tue Jul 17, 2012 8:34 pm, edited 1 time in total.



Tue Jul 17, 2012 8:22 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: Attachment's through lua?
As an attachable, I'm not sure.

But, you can create the helmet and make it's position the head position, simulating to be a helmet.


Tue Jul 17, 2012 8:29 pm
Profile
User avatar

Joined: Thu Jan 21, 2010 10:59 pm
Posts: 151
Reply with quote
Post Re: Attachment's through lua?
hmm.. would it still function as a helmet though?
Edit: Or are you suggesting something that would replace the head?


Tue Jul 17, 2012 8:35 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: Attachment's through lua?
Nonono, of course not!

You create the helmet, and do something like Helmet.Pos = self.Head.Pos.

It would work like a helmet, except that it wouldn't transfer the kinetic energy of the bullets if it is hit to the head.


Tue Jul 17, 2012 8:43 pm
Profile
User avatar

Joined: Thu Jan 21, 2010 10:59 pm
Posts: 151
Reply with quote
Post Re: Attachment's through lua?
Oh, Alright, well I'll try it out anyways and see how badly "... It wouldn't transfer the kinetic energy of the bullets if it is hit to the head" would affect the actor. Thanks btw.


Tue Jul 17, 2012 8:49 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: Attachment's through lua?
Post the results later, to see if you need more help.


Tue Jul 17, 2012 8:53 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Attachment's through lua?
There is an attach function, but it is extremely buggy and not officially documented.


Tue Jul 17, 2012 11:06 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: Attachment's through lua?
Really?

Where did you see that?


Tue Jul 17, 2012 11:51 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Attachment's through lua?
You could also make the helmet have two frames, with the first one transparent. Change to the second frame with the pie button on the item. Though that may make the helmet completely unhittable even when it's showing, I'm not really sure.


Wed Jul 18, 2012 5:30 am
Profile
User avatar

Joined: Thu Jan 21, 2010 10:59 pm
Posts: 151
Reply with quote
Post Re: Attachment's through lua?
I have a few questions.. (Still new to lua, but previous programming helps!.. a bit)

@Asklar -

"Helmet.Pos = self.Head.Pos"

Helmet is a variable I have to set/define right?

@Bad Boy - I'm gonna try both methods and see which works better but I currently don't know how to switch frames...

@Anyone -

If what I think the "CreateAttachable" function does what I think it does then this:

The following script is attached to a TDExplosive I've created

Code:
function Create(self)
   local Parent = ToAHuman(Actor)
   if Parent.EquippedItem then
      CreateAttachable("Civilian Helmet 1", "Shadow.rte") -- Create the Helmet? also, not sure if I did the "preset,rte name" thing right
      local Helmet = ("Civilian Helmet 1") -- Set recently created helmet as "Helmet" variable, or at least it is suppose to..
      Helmet.Pos = Parent.Head.Pos -- Position Helmet to head position, Parent.Head.Pos is used because a bomb doesn't have limbs
      ToTDExplosive(Parent.EquippedItem):GibThis() -- Gib Helmet item
   end
end


EDIT: Fix't

Should work, but it doesn't (and it usually doesn't on the first try). I get a error on the first line for some reason.
EDIT: Alright so I am getting this error in the lua console:
ERROR: [string "CreateHelmet"(ToActor(LuaMan.TempEntity));"]:1: attempt to call global 'CreateHelmet' (a nil value)
Nevermind, I know why.

This is the pie code on the actual Helmet item
Code:
   AddPieSlice = Slice
      Description = Equip Helmet
      Direction = 1
      Icon = Icon
         PresetName = Helmet
         FrameCount = 1
         BitmapFile = ContentFile
            FilePath = Shadow.rte/Sprites/IconHelmet.bmp
      ScriptPath = Shadow.rte/Create Helmet.lua
      FunctionName = CreateHelmet


Last edited by ShadowStorm on Wed Jul 18, 2012 8:23 pm, edited 5 times in total.



Wed Jul 18, 2012 7:06 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Attachment's through lua?
To get tabs, put it in [code] bbcodes. It'll change tabs into 3 spaces unfortunately but it's better than nothing.

Anyway, I don't remember if there is actually a CreateAttachable but if it doesn't bug out there then I guess there is. Either way, you should combine the helmet making lines to be:
local Helmet = CreateAttachable("Civilian Helmet 1", "Shadow.rte");

Then you'll want to actually add the helmet; as before I'm not sure if AddAttachable works either (but I doubt it) so you might have to change it a bit.
MovableMan:AddAttachable(Helmet);

Also, you don't seem to have defined actor and it's not part of the function. Unless there's more I'm not seeing or something you'll want to put
local Actor = MovableMan:GetMOFromID(self.RootID);
at the top of the create function. You could also combine it into one line with setting the parent if you wanted.

Oh, and I'm not sure what you're going for but it might be better for the helmet maker to be deleted instead of gibbed, i.e. replace the gibbing line with
Parent.EquippedItem.ToDelete = true;

Finally, if this is supposed to be a pie script you'll either want to move everything into a pie button script instead or move all of this into the update function for the item and have it trigger when the item's sharpness changes (the pie button would be used to change the sharpness instead).


Wed Jul 18, 2012 7:19 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Attachment's through lua?
Asklar wrote:
Where did you see that?

Kyred found one here, and Darlos9D found another here.


Wed Jul 18, 2012 8:27 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Attachment's through lua?
CreateAttachable isn't a new function, we've had all the Create<<MO> functions for some time. Kyrid discovered the Attach function.


Wed Jul 18, 2012 9:42 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Attachment's through lua?
Okay yeah, I just couldn't remember if there was a CreateAttachable or if you had to create something else like an MOSRotating or whatever. I haven't really had to use CreateAttachable since most of what I do is activity scripting.


Wed Jul 18, 2012 10:02 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Attachment's through lua?
Well it has no purpose really other than to prepare an attachable for being attached, you'd do better to create the MOSR and pseudooffset it.


Wed Jul 18, 2012 10:40 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 28 posts ]  Go to page 1, 2  Next

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.055s | 13 Queries | GZIP : Off ]