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



Reply to topic  [ 31 posts ]  Go to page 1, 2, 3  Next
 Specifically random 
Author Message
User avatar

Joined: Sat Nov 10, 2012 3:31 pm
Posts: 114
Location: Australia
Reply with quote
Post Specifically random


I'm currently trying to work lua scripts that give custom units randomized parts ala ronin. One attachable (armour) is supposed to be a specific sprite depending on the randomised head (head frame 1 = armour frame 1, head frame 2 = armour frame 2).
Would anyone be willing to provide an example script or to tell me how to get this done?


Last edited by omegadrace on Sun Dec 09, 2012 7:04 am, edited 2 times in total.



Thu Nov 15, 2012 9:03 am
Profile WWW

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Flying units
Look here: viewtopic.php?f=75&t=31687&hilit=brainfighter

You'll need to know a bit of lua to edit it to your liking, or get help (normally this is where I'd offer to help but I'm backed up in scripts I'm doing for people already and busy in real life). The variables are pretty self explanatory though so I'm sure you'll be able to figure it out even if you don't know lua.


Thu Nov 15, 2012 12:57 pm
Profile
User avatar

Joined: Sat Nov 10, 2012 3:31 pm
Posts: 114
Location: Australia
Reply with quote
Post Re: Flying units
I just can't wrap my head around lua very well, even after looking at tutorials. Anyway, after trying that code, I'm sorry to say that it is not what I am looking for. What I want is something similar to the aco mod's gunship style of movement. I can't use that code, however, due to it belonging to someone else and the ai not moving when I set them to patrol/go-to/hunt.
Nonetheless thank you for providing something. :)


Thu Nov 15, 2012 1:49 pm
Profile WWW

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Flying units
Well you should ask him for it. I haven't looked at the script but I imagine it's fairly similar to mine, just more polished and with fancy visuals (and probably forces for more realistic movement stuff).
AI is a whole other can of worms. Sorry to be the bearer of bad news but even though flying ai would probably not be too bad compared to the current ai (not to mention a lot could be scavenged) it'd be pretty time consuming and I doubt it'll be made til someone wants to make it for themselves.

And lua's not hard, it just takes time or prior programming knowledge. Keep trying, look at scripts you know the results of and try to figure out how it was done, you'll get it in no time.


Fri Nov 16, 2012 1:44 am
Profile
User avatar

Joined: Sat Nov 10, 2012 3:31 pm
Posts: 114
Location: Australia
Reply with quote
Post Re: Flying units
Ah. I could ask, but if the main mod itself doesn't have aerial ai then what hope do I have? It looks like I might have to rely on invisible legs for now.

Anyway. While yes I do have some programming experience, I don't have any with lua. And I won't anytime soon.
Thank you for your time.


Fri Nov 16, 2012 5:18 am
Profile WWW

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Flying units
It's possible the game's basic ai is still there and will kick in without a lua ai stuck in, in which case you might be able to get away with that. I haven't looked into that at all so I may be dead wrong.
Either way, fair enough, you're welcome and good luck with whatever you're working on.


Fri Nov 16, 2012 7:58 am
Profile
User avatar

Joined: Mon Apr 13, 2009 12:27 pm
Posts: 813
Location: Yogyakarta, Indonesia. A slice o' paradise.
Reply with quote
Post Re: Flying units
I believe Darlos9 had made a stationary flyer in his DarkStorm mod. I've used it in my Shamsy Electric Technology mod, and it works (back in B26/B27 anyways).
I think the script could be modified a bit so it'll be closer to ACO though.


Fri Nov 16, 2012 6:01 pm
Profile YIM WWW
User avatar

Joined: Sat Nov 10, 2012 3:31 pm
Posts: 114
Location: Australia
Reply with quote
Post Re: Flying units
The longer invisible legs gave me the desired effect. Currently I can't figure out why one particular 'flying' actor isn't moving when set to patrol. If any of you guys have any idea of what might be wrong, please tell me.


Tue Nov 20, 2012 10:40 am
Profile WWW
User avatar

Joined: Sat Nov 10, 2012 3:31 pm
Posts: 114
Location: Australia
Reply with quote
Post Re: Specifically random
First post updated with a new question.


Sun Dec 09, 2012 7:03 am
Profile WWW
User avatar

Joined: Sat Nov 10, 2012 3:31 pm
Posts: 114
Location: Australia
Reply with quote
Post Re: Specifically random
Alright then, let me just post what I've got so far.
The head:
Code:
function Create(self)
   i = math.floor(math.random()*6);
   self.Frame = i;
end

And the armour:
Code:
local i = require "Head"
function Update(self)
   self.Frame = i;
end


The armour is still showing up as random. What am I doing wrong?


Wed Dec 12, 2012 5:31 am
Profile WWW

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Specifically random
require doesn't work like that. You could perhaps require the script and have the head function return i, then set the body frame to be that returned value. However, it seems much easier to just work from actor entirely, since ahumans have the property self.Head (and limbs as well). So you could do something like this:
Code:
function Create(self)
   self.FrameNumber = math.floor(math.rand()*6);
end
function Update(self)
   if self.Frame ~= self.FrameNumber then
      self.Frame = self.FrameNumber;
      self.Head.Frame = self.FrameNumber;
   end
end

I'm not 100% sure the head property is entirely accessible though, so this might not work quite right. In that case you can either find the head attachable by yourself or put the script on the head and find the parent (the actor). There's plenty of examples of how to do this in these forums but, needless to say, post if you need more help.

Also, math.rand() goes from 0 to 1 by default. However, you can give it arguments to set its range, in this case it will always return integers (e.g. neither math.rand(1,6) or math.rand(0,1) will return decimal points anywhere). As is, your method will probably result with the frame being 0 sometimes and very, very rarely being 6, since math.floor rounds down. So the former just requires the value to be less than 0.167 while the latter requires it to be exactly 1.


Thu Dec 13, 2012 9:49 pm
Profile
User avatar

Joined: Sat Nov 10, 2012 3:31 pm
Posts: 114
Location: Australia
Reply with quote
Post Re: Specifically random
I'm afraid that even though I've been trying to use return and require in the scripts, it just won't work. And the script you posted, I have no idea how to make it workable.
Sorry, I'm still relatively new to lua. :(


Mon Dec 17, 2012 6:04 am
Profile WWW

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Specifically random
Set it as the scriptpath for the actor. If you want working ai, make sure to add whatever lua bindings are necessary to also include ai.


Mon Dec 17, 2012 7:22 pm
Profile
User avatar

Joined: Sat Nov 10, 2012 3:31 pm
Posts: 114
Location: Australia
Reply with quote
Post Re: Specifically random
I don't understand what you mean by 'scriptpath for the actor'. Do you mean to set the script to be used in the ini? Because I have already tried that, with no success.

And for the ai issue I had, I solved it by putting the limbpaths back to normal. For some reason making them taller stopped the actor from even attempting to move and/or shoot on it's own.


Tue Dec 18, 2012 3:57 am
Profile WWW

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: Specifically random
Assuming it's for AHumans use this, if it's for crabs or turrets use the relevant AI instead of HumanAI.
And yes, I mean the scriptpath in the ini. Take the code, put in in a new lua file (i.e. a renamed text file) and have the scriptpath point to that file. Then, if it doesn't work, post up any console errors.
Code:
require("Actors/AI/NativeHumanAI")
function Create(self)
   self.AI = NativeHumanAI:Create(self)
   self.FrameNumber = math.floor(math.rand()*6);
end
function Update(self)
   if self.Frame ~= self.FrameNumber then
      self.Frame = self.FrameNumber;
      self.Head.Frame = self.FrameNumber;
   end
end
function UpdateAI(self)
   self.AI:Update(self)
end


Tue Dec 18, 2012 10:01 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 31 posts ]  Go to page 1, 2, 3  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.116s | 13 Queries | GZIP : Off ]