View unanswered posts | View active topics It is currently Fri Dec 27, 2024 7:59 am



Reply to topic  [ 25 posts ]  Go to page 1, 2  Next
 Lua and attachables work around. 
Author Message
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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


Sun Jun 14, 2009 5:16 am
Profile
User avatar

Joined: Wed Jan 14, 2009 7:12 pm
Posts: 1525
Location: In between your sister's legs, showing her how to use a... PS3 controller!
Reply with quote
Post Re: Lua and attachables work around.
If I had any idea what these meant I'd bow down and worship you as a god.


Mon Jun 15, 2009 6:02 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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.


Mon Jun 15, 2009 6:10 pm
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Lua and attachables work around.
I don't suppose we can selectively pick out certain attachments, right?


Tue Jun 16, 2009 5:24 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Lua and attachables work around.
Standard class name, preset name or group checks should work.


Tue Jun 16, 2009 5:29 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Lua and attachables work around.
<3
your lua messings around are really paying off for the rest of us. this is awesomefantastic.


Tue Jun 16, 2009 6:37 am
Profile WWW
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post 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?


Fri Jun 19, 2009 7:34 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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.


Fri Jun 19, 2009 8:02 pm
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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.


Sat Jun 20, 2009 7:21 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Lua and attachables work around.
Looks valid, but it's a cleaner way, not a simpler way.


Sat Jun 20, 2009 7:29 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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.


Sat Jun 20, 2009 7:55 pm
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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.


Sun Jun 21, 2009 1:08 am
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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.


Sun Jun 21, 2009 1:26 am
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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


Sun Jun 21, 2009 2:57 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Lua and attachables work around.
That's not looping.


Sun Jun 21, 2009 3:07 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 25 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.060s | 13 Queries | GZIP : Off ]