Data Realms Fan Forums http://45.55.195.193/ |
|
Lua and attachables work around. http://45.55.195.193/viewtopic.php?f=73&t=15359 |
Page 1 of 2 |
Author: | mail2345 [ Sun Jun 14, 2009 5:16 am ] |
Post subject: | Lua and attachables work around. |
Just posting this very minor snippet of code that does nothing of significant importance. Code: i = 1; while i < MovableMan:GetMOIDCount() do if MovableMan:GetMOFromID(i).RootID == ActivityMan:GetActivity():GetControlledActor(0).ID then MovableMan:GetMOFromID(i).Scale = 0 end i = i + 1 end Ohh, look another pointless snippet! Code: i = 1; while i < MovableMan:GetMOIDCount() do if MovableMan:GetMOFromID(i).RootID == ActivityMan:GetActivity():GetControlledActor(0).ID and MovableMan:GetMOFromID(i).ID ~= MovableMan:GetMOFromID(i).RootID then ToAttachable(MovableMan:GetMOFromID(i)):Detach() end i = i + 1 end |
Author: | Flammablezombie [ Mon Jun 15, 2009 6:02 pm ] |
Post subject: | Re: Lua and attachables work around. |
If I had any idea what these meant I'd bow down and worship you as a god. |
Author: | mail2345 [ Mon Jun 15, 2009 6:10 pm ] |
Post subject: | Re: Lua and attachables work around. |
They work in the console, btw. Number one makes the unit mostly invisible, number two detaches every attachable of the unit. |
Author: | zalo [ Tue Jun 16, 2009 5:24 am ] |
Post subject: | Re: Lua and attachables work around. |
I don't suppose we can selectively pick out certain attachments, right? |
Author: | mail2345 [ Tue Jun 16, 2009 5:29 am ] |
Post subject: | Re: Lua and attachables work around. |
Standard class name, preset name or group checks should work. |
Author: | Geti [ Tue Jun 16, 2009 6:37 am ] |
Post subject: | Re: Lua and attachables work around. |
<3 your lua messings around are really paying off for the rest of us. this is awesomefantastic. |
Author: | Daman [ Fri Jun 19, 2009 7:34 pm ] |
Post subject: | Re: Lua and attachables work around. |
I don't see how this is a work around or anything important? Why'd it need a new topic? |
Author: | mail2345 [ Fri Jun 19, 2009 8:02 pm ] |
Post subject: | Re: Lua and attachables work around. |
I was pointing out that attachables were not something living ouside of lua. The first thing might have applications in stealth tech. The second thing shows that via conversion to attachable object, attachable functions can be accessed. |
Author: | CrazyMLC [ Sat Jun 20, 2009 7:21 am ] |
Post subject: | Re: Lua and attachables work around. |
I have a programming friend that is trying to help me learn lua, he said this might be a simpler way to do number two. Code: local controlled = ActivityMan:GetActivity():GetControlledActor(0) for i = 1, MovableMan:GetMOIDCount() do local mo = MovableMan:GetMOFromID(i) if mo.RootID == controlled.ID and mo.ID ~= mo.RootID then ToAttachable(mo):Detach() end end I don't know if this is valid, but he knows a lot of languages, but not lua. Just asking because we were using your code as a lesson. |
Author: | mail2345 [ Sat Jun 20, 2009 7:29 am ] |
Post subject: | Re: Lua and attachables work around. |
Looks valid, but it's a cleaner way, not a simpler way. |
Author: | TheLastBanana [ Sat Jun 20, 2009 7:55 pm ] |
Post subject: | Re: Lua and attachables work around. |
Nice find, mail. This will be very useful for scripts of all kinds. CrazyMLC, one problem I see with that code is that mo is declared as a local variable every time the for loop loops. That can cause a lot of problems. It would be best to declare mo as nil outside of the for loop. |
Author: | CrazyMLC [ Sun Jun 21, 2009 1:08 am ] |
Post subject: | Re: Lua and attachables work around. |
Some wiki somewhere said that if the number is not listed, it is automatically set to 1. I don't know if that is what you mean, though. |
Author: | TheLastBanana [ Sun Jun 21, 2009 1:26 am ] |
Post subject: | Re: Lua and attachables work around. |
If a variable isn't declared, it's automatically nil, actually. And no, that's not what I mean. If you declare a local variable more than once you encounter problems. Let me give you an example: Code: local x = 5; local x = 7; x would still be 5, as declaring the variable as local twice doesn't work. So, in that code, think of it this way: Code: for i = 1, MovableMan:GetMOIDCount() do local mo = MovableMan:GetMOFromID(i) if mo.RootID == controlled.ID and mo.ID ~= mo.RootID then ToAttachable(mo):Detach() end end Let's say there are 2 MOs. This will be what actually happens: Code: local mo = MovableMan:GetMOFromID(1) if mo.RootID == controlled.ID and mo.ID ~= mo.RootID then ToAttachable(mo):Detach() end local mo = MovableMan:GetMOFromID(2) if mo.RootID == controlled.ID and mo.ID ~= mo.RootID then ToAttachable(mo):Detach() end Notice that "local mo" is declared twice. That's where the problem is. On the other hand, if we declare mo as local outside of the for loop... Code: local mo = nil; mo = MovableMan:GetMOFromID(1) if mo.RootID == controlled.ID and mo.ID ~= mo.RootID then ToAttachable(mo):Detach() end mo = MovableMan:GetMOFromID(2) if mo.RootID == controlled.ID and mo.ID ~= mo.RootID then ToAttachable(mo):Detach() end mo just gets set twice, which is fine. |
Author: | CrazyMLC [ Sun Jun 21, 2009 2:57 am ] |
Post subject: | Re: Lua and attachables work around. |
-_-; Well, I don't know. ...When I told him what you said he showed me this page. then pointed at Code: local a, b = 1, 10 if a<b then print(a) --> 1 local a -- `= nil' is implicit print(a) --> nil end -- ends the block started at `then' print(a,b) --> 1 10 |
Author: | mail2345 [ Sun Jun 21, 2009 3:07 am ] |
Post subject: | Re: Lua and attachables work around. |
That's not looping. |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |