View unanswered posts | View active topics It is currently Tue Apr 16, 2024 4:13 pm



Reply to topic  [ 3 posts ] 
 Actor gibbing from grenade 
Author Message
User avatar

Joined: Tue Mar 22, 2011 9:26 pm
Posts: 14
Reply with quote
Post Actor gibbing from grenade
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.

Thanks in advance

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
         teamgrenade = actor.Team
      end
   end
end

function Destroy(self)

self.gib = CreateAHuman("<Name of the actor I want to use>")
self.gib.Pos = self.Pos
self.gib.Team = teamgrenade
MovableMan:AddActor(self.gib)

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
      teamgrenade = actor.Team
      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
self.gib.Team = (teamgrenade)
--Create the actor
MovableMan:AddActor(self.gib)
--Profit!

end


Mon Oct 17, 2011 9:32 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: Actor gibbing from grenade
Scroll down a bit.


Thu Oct 20, 2011 12:10 am
Profile
User avatar

Joined: Tue Mar 22, 2011 9:26 pm
Posts: 14
Reply with quote
Post Re: Actor gibbing from grenade
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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

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.047s | 17 Queries | GZIP : Off ]