GetDataModule, or some other way to find all modules
Author
Message
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
GetDataModule, or some other way to find all modules
I'm trying to make an explosion where the gibs will ignore the users team (or beter yet ignore any actors from a particular tech) I tried a bunch of stuff along the lines of detecting the nearest actor and deleting the gib if it's on the users team, but that didn't seem to make any difference. Does anyone know of an easy way to do this?
Last edited by clunatic on Sun Feb 09, 2014 10:58 pm, edited 5 times in total.
Wed May 29, 2013 2:38 am
Arcalane
Joined: Sun Jan 28, 2007 10:32 pm Posts: 1609 Location: UK
Re: Making a MOpixel ignore your team/tech
If I remember rightly this can be solved by using emissions, rather than gibs; gibs have no team assigned, which is probably why they're not being deleted. The script is checking, but the value it's checking against isn't the same as the one you actually want it to be.
That said, emissions are a little trickier to use. You'll probably need to use a script to spawn the AEmitter that emits the damaging particles, and simply have scripts on those that filter out that Tech in particular by checking which .rte it comes from.
Wed May 29, 2013 12:03 pm
p3lb0x
Forum Moderator
Joined: Fri Feb 02, 2007 3:53 pm Posts: 1896 Location: in my little gay bunker
Re: Making a MOpixel ignore your team/tech
Alternatively, spawn EVERYTHING from the lua file. That way you have control over all parameters. About not hitting a certain tech, you'll probably have to have each particle do its own checks. But that's probably really expensive
Wed May 29, 2013 1:09 pm
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
Re: Making a MOpixel ignore your team/tech
Thanks for the replies guys, I sorta got it working, but I decided to scrap it in the end. It didn't add much to gameplay and turned out to be rather overpowered.
Anyway, I started working on something else. I wanted a beter way of controlling multiple units, so I cobbled together this script using some base scripts and a parent finding method Bad Boy posted elsewhere in this forum and stuck it on a gun firing a fake bullet:
Code:
function Create(self) print("create") self.Parent = nil; self.ParentPickTimer = Timer(); local actor = MovableMan:GetMOFromID(self.RootID);
if MovableMan:IsActor(actor) then self.Parent = ToActor(actor); self.Parentpickingdone = true; end end
function Update(self) --Set the parent to nil if he's dead if not MovableMan:IsActor(self.Parent) then self.Parent = nil; end --This part is a safety check to make sure we do get the parent. You can end up without a parent when you spawn them in base editor or manually drop them out of a dropship if you don't put the parent finding in here too. if self.ParentPickTimer:IsPastSimMS(500) then local actor = MovableMan:GetMOFromID(self.RootID); if MovableMan:IsActor(actor) then self.Parent = ToActor(actor); self.Parentpickingdone = true; end end
if self.Magazine ~= nil and self.Magazine.RoundCount <= 0 and ToActor(self.Parent):IsPlayerControlled() then
self.targetPos = self.MuzzlePos + Vector(SceneMan:ShortestDistance(self.Pos,self.MuzzlePos,SceneMan.SceneWrapsX).Magnitude+300,0):RadRotate(self.Parent:GetAimAngle(true)) if SceneMan.SceneWrapsX == true then if self.targetPos.X > SceneMan.SceneWidth then self.targetPos = Vector(self.targetPos.X - SceneMan.SceneWidth,self.targetPos.Y) elseif self.targetPos.X < 0 then self.targetPos = Vector(SceneMan.SceneWidth + self.targetPos.X,self.targetPos.Y) end end
if self.RootID ~= self.ID then print("yep") for Act in MovableMan.Actors do if Act.Team == self.Team then local Trace = SceneMan:ShortestDistance(self.Parent.Pos, Act.Pos, true) if Trace.Magnitude < 400 then print(self.Parent) print(self.targetPos) print(self.Parent.Pos) print(Act) if SceneMan:CastObstacleRay(self.Parent.EyePos, Trace, Vector(), Vector(), self.ID, self.Team, 0, 3) < 0 then print("yup") -- We have LOS to this actor if self.targetPos ~= self.Parent.Pos then Act:ClearAIWaypoints() Act:AddAISceneWaypoint(self.targetPos); Act.AIMode = 3 end break end end end end end
self:Reload(); end
end
It works pretty well, you fire the gun and a nearby friendly actor will get a waypoint added where you're pointing. The targetpos part is still rather crude, I definitely need a beter way of doing that, but what I'd really like some help with is getting this to work for more than one actor. I'm guessing I'd need to stick all the found actors into a table and then apply the waypoint lines to all of them, I just have no idea what that would look like. Anyone mind writing that part for me or pointing me in the direction of a script that I could use as a reference?
the prints are just for debugging purposes, I had some troubles with finding the actors and getting the rays working, but that's sorted now.
Whoops, I meant to reply to this and help you out a while back, sorry about the delay here. I'd like to preface by saying that I haven't actually looked at your script (a brief glance at most) so I'm kinda guessing what you want to do by your descriptions. If I'm understanding right, and you want 1 actor's actions to be mimicked by a bunch of actors then yes, tables would probably be the best idea for what you want.
Tables are actually really straightforward once you get the hang of them. They're really just an organization tool, they let you collect a group of similar things under 1 name to save space and make it easy to check through all of them. While they may seem hard at first, especially since their syntax is less easy to understand than most in lua (I know I balked at them for quite a while), they become invaluable once you know how to use them. In the limits of CC lua, they're absolutely the best way to store information. Here's the lua-users instructions for them but I found all that kind of a pain to learn from. Instead, look at scripts that use them and see how they're used.
To start you off, you can add things to a table in a couple of ways but the easiest (imo) and most commonly used syntax here on drl is
Code:
self.tablenamehere[#self.tablenamehere+1] = value
This sets the next empty spot for the table to be the value you want, in this case the actor you want to control. To iterate through the table, there are also several ways of doing it, but the one most used on drl is
Code:
for i = 1, #self.tablenamehere do --perform actions here, where self.tablenamehere[i] will reference the value in the table. e.g. self.tablenamehere[i]:GetController():SetState(Controller.WEAPON_FIRE, true); end
To remove things from a table, you use
Code:
table.remove(self.tablenamehere, number you want to remove); --e.g. to remove all but the first element of a table for i = 1, #self.tablenamehere do if i ~= 1 then table.remove(self.tablenamehere, i); end end --or better yet, saving space: for i = 2, #self.tablenamehere do table.remove(self.tablenamehere, i); end
Lemme know if you need any help.
Mon Jun 24, 2013 4:42 am
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
Re: Finding multiple actors.
Thanks so much, this was just what I needed! It took me 15 minutes to make it do what I wanted. Thank you thank you thank you!
Mon Jun 24, 2013 5:46 pm
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
Re: Finding multiple actors.
New question:
why is this script, which is attached to a MOSRotating fired from a gun:
Code:
function Destroy(self) for i = 1, 4 do local cloud = CreateMOPixel("Ritans.rte/Bomber Cloud"); cloud.Pos = self.Pos; cloud.Vel = Vector(math.random()*4,0):RadRotate(math.random()*(math.pi*2)) MovableMan:AddParticle(cloud); end end
giving me the error: "ERROR: Tried to add a Particle that already exists in the simulation!" in the console? It was just one actor shooting and the gun only fires 1 particle at a time, so it's not as if I was spamming particles.
Wed Jul 31, 2013 12:51 am
Abdul Alhazred
DRL Developer
Joined: Tue Aug 11, 2009 5:09 am Posts: 395
Re: Help with adding particles
Some obscure bug in the engine sometimes cause that error if you try to spawn things in the Destroy function. One workaround is to move it to Update(), like this:
Code:
function Update(self) if self.ToDelete then -- Whether this MO is marked for deletion or not for i = 1, 4 do local cloud = CreateMOPixel("Ritans.rte/Bomber Cloud") cloud.Pos = self.Pos cloud.Vel = Vector(math.random()*4,0):RadRotate(math.random()*(math.pi*2)) MovableMan:AddParticle(cloud) end end end
Wed Jul 31, 2013 7:15 am
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
Re: Help with adding particles
Thanks, that did it.
Wed Jul 31, 2013 6:19 pm
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
Re: Help with adding particles
I sure do seem to be the only still using this sub forum, but ok, new question again:
I'm trying to make an activity that randomises the team of all actors on a key press or when a brain enters an area or so, just as a sort of test activity. To quickly see if something like that was possible I wrote this code:
Code:
function Carnage:UpdateActivity() if self.HuntTimer:IsPastSimMS(10000) then for Act in MovableMan.Actors do if Act.Sharpness ~= 2 then if not Act:HasObjectInGroup("Brains") then if not Act:IsPlayerControlled() then Act.Team = math.floor(math.random(0,3)) Act.Sharpness = 2 end end end end self.HuntTimer:Reset() end
end
Along with the usual start, pause and end functions for an activity.
The code works, in that it randomises the team of all the right actors, but after the teams have been changed cortex command crashes as soon as I try to buy something or switch actor. No errors in the console before it crashes, it just stop working and crashes to desktop. Anyone have any idea why this happens and how I can fix it?
Fri Sep 13, 2013 12:58 am
Arcalane
Joined: Sun Jan 28, 2007 10:32 pm Posts: 1609 Location: UK
Re: Randomising actors team
As far as I'm aware, you can't. Actors switching teams has never worked properly to my knowledge.
To be more/less specific, it's complicated and glitchy at best. You'll have to change controllers around to match teams and even then it doesn't really work well. Basically it's usually not a good idea to change teams of added actors, unless it's for a quick gimmick (e.g. change an actor's team when the mission is won, but the actor can't be selected or anything still). In terms of reliability, and someone please correct me if I'm wrong but you'd probably be better off saving each actor (i.e. position, health, inventory, etc.), removing it and readding it with the team changed. It'd be more of a pain to code and it'd be slower but you'd avoid controller/engine issues.
Fri Sep 13, 2013 7:45 am
clunatic
Joined: Fri Nov 23, 2012 5:42 am Posts: 143
Re: Randomising actors team
I was afraid of that. I know Weegee posted a method to save and transfer inventory from one actor to another, somewhere in this forum section, maybe I'll give that a try. It's such a shame that so many things need to be handled so needlessly complicated. Anyway, thanks guys!
Fri Sep 13, 2013 3:26 pm
MacStacker6
Joined: Thu Aug 29, 2013 1:34 am Posts: 8
Re: Randomising actors team
Not sure if this helps, but this is a mod with an item that switches the team of an actor when used:
Thanks, but I already got it working, thanks to some scripts that Weegee made.
While I got the "randomise the team of all actors on a button press" part working, I ran into a different problem elsewhere, forcing me to turn to the lua gods with yet another question:
I made a function that stores all the actor's positions, presetnames and teams in tables and then spawns all the actors using those tables on the press of a button. But the position part doesn't work. On the first button press it sets the position to 0,0 for all the actors. On every press of the button after that, it uses the current position of the actors spawned on the first button press, or 0,0 if the actor is dead .
Code:
function SaveActors()
if Carnage.Save1 == true then --is set to false in the create function. for i = 1, #Carnage.SavedActorsName do
MovableMan:AddActor(NewActor) end else --save actors for Act in MovableMan.Actors do if not Act:HasObjectInGroup("Brains") then --Can I combine the "is not brain" and "is not player controlled" into one line? if not Act:IsPlayerControlled() then if Act.ClassName == "AHuman" then
Everything works, except the position part. Prints show that the position is getting saved in the save actors part, but in the spawn part its suddenly been changed to 0,0. Is there an error in my code somewhere that I keep overlooking or am I yet again trying to do something in the wrong way?
Also, but less important, why am I having to use Carnage. (the name of the activity) instead of self. in this function? I defined all the variables and tables as self.whatever in the create function, but in this function I have to use Carnage.? What's up with that?
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