View unanswered posts | View active topics It is currently Sat Feb 22, 2020 4:22 pm

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
Author Message

Joined: Tue Mar 22, 2011 9:26 pm
Posts: 14
I have spent about 4 or 5 hours trying to figure this out now so some help would be appreciated. (My lua is terrible).
I'm trying to make a grenade that gibs into an actor, and I want the team of the actor to be the same as the team of the person who threw the grenade. Is this actually possible, and if so then could someone please give me a script for it? I have managed to get this to work for actors and craft, by making the team of the gib the same as the team of the thing that gibbed, but grenades don't normally have teams so that doesn't work.

EDIT: The closest I have got is this:
Code:
function Create(self)
for actor in MovableMan.Actors do
local avgx = actor.Pos.X - self.Pos.X;
local avgy = actor.Pos.Y - self.Pos.Y;
local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if dist < 20 then
end
end
end

function Destroy(self)

self.gib = CreateAHuman("<Name of the actor I want to use>")
self.gib.Pos = self.Pos

end

This is supposed to find the team of the actor initially carrying the grenade (or more accurately their dropship) and use that number for the team of the actor who appears when the grenade gibs, but it doesn't work, but I can't work out why. I know the detecting the actor bit in the first part is working, since I can get it to do other things, but it doesn't want to set a value to "teamgrenade". I think I haev made some kind of very simple mistake so could someone have a look at it please?

EDIT2: Derp!

It's missing brackes around the second instance of "teamgrenade"! That's why it wasn't working...

EDIT3: I seem to have solved this myself despite putting it up here. I'll post the complete code, since I learned a lot of what I did about modding by looking at threads like this. Hopefully someone will be able to learn something by looking at this. It is the first time I have actually written my own Lua script.
Code:
function Create(self)
--Scan all actors
for actor in MovableMan.Actors do
--Do some trigonometry to find the closest actor within 20 pixels
local avgx = actor.Pos.X - self.Pos.X;
local avgy = actor.Pos.Y - self.Pos.Y;
local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if dist < 20 then
--Store the team of the selected actor for later use
end
end
end

function Destroy(self)

--Tell the grenade to spawn an actor when it gibs.
self.gib = CreateAHuman("<Insert name of actor here>")
self.gib.Pos = self.Pos
--Tell the actor to be on the team that we stored earler
--Create the actor
--Profit!

end

Mon Oct 17, 2011 9:32 pm

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 12278
Location: Here
Scroll down a bit.

Thu Oct 20, 2011 12:10 am

Joined: Tue Mar 22, 2011 9:26 pm
Posts: 14
CaveCricket48 wrote:

Thanks for that. I tried searching the forums extensively before I originally posted anything, but I didn't find that post, or anything else relevant. I can probably do it in a less hacky way with your help.
On the other hand before I tried this I knew no Lua at all, and was forced to learn enough to make my hacky code. Even if there is a better way of doing it, which I'm sure there is, I have now learned something valuable, and can continue to make my own new scripts now. I've updated this script, and another I've been working on to use your method of determining the team of the person who throws the grenade, since mine was a really terrible way of doing it, and wouldn't work under a wide variety of circumstances.

Thu Oct 20, 2011 4:13 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 posts ]

#### Who is online

Users browsing this forum: No registered users

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ Cortex Command    Dev Log    Wiki    Game Discussion    Game and Licensing Support    Mod Making       Lua Scripting       Requests    Mod Releases       Older Mods    Scene Releases       Scene Making Planetoid Pioneers    Game Discussion    Pioneer Program Lounge Data Realms Off-Topic    Off Topic Chat       Gaming       Forum Games    Site Support & Feedback