Data Realms Fan Forums
http://45.55.195.193/

Critical Hits by %?
http://45.55.195.193/viewtopic.php?f=73&t=18773
Page 1 of 2

Author:  Shyguy1994 [ Mon May 17, 2010 11:15 pm ]
Post subject:  Critical Hits by %?

Finally getting around to ol' Hector again, this time to make his axe score ridiculous critical hits every 1 out of 20 swings or so. I figure a math.ceil sort of thing a la Full-On Assault's spawning system might do the trick, but I'm not sure how to put it together.

tl;dr halp with crits.

Author:  Grif [ Tue May 18, 2010 12:14 am ]
Post subject:  Re: Critical Hits by %?

math.random(1,20)

Author:  Shyguy1994 [ Tue May 18, 2010 12:27 am ]
Post subject:  Re: Critical Hits by %?

EDIT: Took a proverbial stab in the dark and proverbially stabbed myself in the leg. Even after taking a bunch of different bits of code from a bunch of different people and fixing the "script" up a bit, I've no bloody clue how to get this thing to work. Suffice to say I know nothing about Lua, aside from tutorials, the wiki, and the rest of the forum.

Here's the remains of my axe crit lua files, I'll leave em up here until I figure out what I want to do with them.

Code:
function Update(self)

local theta = ToActor(self.owner):GetAimAngle(true);

   if IsSetToBurst = 1 then
      self.Pos = self.gun.Pos + Vector(math.cos(theta)*10,math.sin(theta)*-10);
   end
self.LifeTime = 1

end


Code:
function Update(self)

local crit = 20;

if HeldDevice:IsActivated then
   if math.random(1,20) == crit then
      CreateAEmitter ("Splodey Crit");
         AEmitter("Splodey Crit"):TriggerBurst("Splodey Crit");      
   end
   
end

end

Author:  CrazyMLC [ Tue May 18, 2010 9:19 am ]
Post subject:  Re: Critical Hits by %?

Code:
function Create(self)
   self.CritTimer = Timer()   -- Our timer!!
end

function Update(self)
   for actor in MovableMan.Actors do   --this makes it so that this code runs on every actor in the scene. 'actor' is used as the variable, but it could be whatever you want.
      local dist = SceneMan:ShortestDistance(self.Pos, actor.Pos, true).Magnitude   --this finds the distance between two points. I put a check in to find the distance, so you'd put this code on a bullet or something.
      if dist < 4 and self.CritTimer:IsPastMS(500) and math.random(1,20) == 20 then   -- if you didn't use the CritTimer, it would make a random roll about 30 times a second, almost guaranteeing a crit.
         self.Gore = actor   --copy the actor.
         self.Gore.Vel = actor.Vel   --give it the same velocity.
         self.Gore.Pos = actor.Pos   --make it spawn in the same place.
         self.GoreAmount = math.random(1,3)   --Find the amount of gore randomly! MUAHAHAAH!
         actor:GibThis()   --KILL THE ACTOR! MUAHAHAHAH!
         if actor.ClassName == "AHuman" then   --Find the Classname to use the right function.
            for i = 1,self.GoreAmount do   --make this code run so many times depending on how many 'i's or 1s are in it.
               CreateAHuman(self.Gore)   --create the pseudo-actor.
               self.Gore:GibThis()   --MAKE IT EXPLODE TO CREATE MORE GORE!!!!! MUAHAHAHAHAAH!!
            end
         elseif actor.ClassName == "ACrab" then   --same as before but with crabs. might want to put in things for other types. Use elseif to be a bit more efficient. Tables are even better, but I don't know how to use them.
            for i =1,self.GoreAmount do
               CreateACrab(self.Gore)
               self.Gore:GibThis()   --BOOOM!!
            end
         end
      end
   end
end

Hope it helps.

Author:  lolinternets [ Tue May 18, 2010 4:49 pm ]
Post subject:  Re: Critical Hits by %?

could you post that without the comments? its hard to follow with all of that.

edit: stupid and lazy of me! but i will do it for eeryone else! :)

Code:
function Create(self)
   self.CritTimer = Timer()
end

function Update(self)
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos, actor.Pos, true).Magnitude
      if dist < 4 and self.CritTimer:IsPastMS(500) and math.random(1,20) == 20 then   
         self.Gore = actor
         self.Gore.Vel = actor.Vel
         self.Gore.Pos = actor.Pos
         self.GoreAmount = math.random(1,3)
         actor:GibThis()
         if actor.ClassName == "AHuman" then
            for i = 1,self.GoreAmount do
               CreateAHuman(self.Gore)
               self.Gore:GibThis()
            end
         elseif actor.ClassName == "ACrab" then
            for i =1,self.GoreAmount do
               CreateACrab(self.Gore)
               self.Gore:GibThis()   --BOOOM!!
            end
         end
      end
   end
end

Author:  CrazyMLC [ Wed May 19, 2010 4:35 am ]
Post subject:  Re: Critical Hits by %?

Code:
function Create(self)
   self.CritTimer = Timer()
end

function Update(self)
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos, actor.Pos, true).Magnitude
      if dist < 4 and self.CritTimer:IsPastMS(500) and math.random(1,20) == 20 then   
         self.Gore = CreateAHuman(actor)
         self.Gore.Vel = actor.Vel
         self.Gore.Pos = actor.Pos
         self.Gore.Sharpness = -231
         self.GoreAmount = math.random(1,3)
         actor:GibThis()
         for i = 1,self.GoreAmount do
            MovableMan:AddActor(self.Gore);
            if actor.Sharpness = -231 then
               actor:GibThis()
            end
         end
      end
   end
end

I made a little mistake in the code.

Author:  Shyguy1994 [ Wed May 19, 2010 8:50 pm ]
Post subject:  Re: Critical Hits by %?

Not sure where to stick the code - right now I've got it on the MOPixel bullet, but it isn't working. Any ideas?

Attachments:
Devices.ini [7.36 KiB]
Downloaded 192 times

Author:  CrazyMLC [ Wed May 19, 2010 9:01 pm ]
Post subject:  Re: Critical Hits by %?

Last time I tried, self.Pos doesn't seem to work for MOPixels. That would mean it wouldn't be able to check distances, so the code wouldn't do anything. I'm not entirely sure how else you could do it.
When you start up CC, press ~ to open up the console, and see what errors it has.

Author:  Grif [ Thu May 20, 2010 2:32 am ]
Post subject:  Re: Critical Hits by %?

Huh what? Self.Pos doesn't work for MOPixels? Says who?

Author:  CrazyMLC [ Thu May 20, 2010 3:16 am ]
Post subject:  Re: Critical Hits by %?

I 'unno, I got some sort of error when I was trying a script one time, and it was saying 'self.Pos? BAD!'.

Author:  TheLastBanana [ Thu May 20, 2010 3:30 am ]
Post subject:  Re: Critical Hits by %?

MLC, your code doesn't work for three reasons:
1. You're checking if the MOPixel's distance is less than 4 pixels. Considering that the MOPixel is fired at a velocity of 55, the chances of something coming within this range are slim to none. I would suggest doing a raycast or increasing the range.

2.
Code:
self.Gore = CreateAHuman(actor)
In your code, "actor" is a reference to an Actor, not a string. CreateAHuman only takes an actor's name as an argument. You probably mean:
Code:
self.Gore = CreateAHuman(actor.PresetName)
However, this also doesn't work, as you aren't guaranteed that the actor is an AHuman. It could be an ACrab, ACDropShip, ACRocket or just plain Actor.

3.
Code:
         for i = 1,self.GoreAmount do
            MovableMan:AddActor(self.Gore);
            if actor.Sharpness = -231 then
               actor:GibThis()
            end
         end

You have only created self.Gore once, thus you can only add it once. I'm also not really sure what the sharpness check is for, either.

Author:  CrazyMLC [ Thu May 20, 2010 4:08 am ]
Post subject:  Re: Critical Hits by %?

Well, I wasn't sure if you could still address the created actor by self.Gore, so I gave it a certain sharpness as a code and made it so any object with that sharpness just blew up. :3

(Also, not only do I not know a thing about tables, I'm also clueless about ray casting.)

Author:  TheLastBanana [ Thu May 20, 2010 4:12 am ]
Post subject:  Re: Critical Hits by %?

It won't work the way you think. That's only going to work on the current actor being checked, and only if it's within 4 pixels.

Author:  CrazyMLC [ Thu May 20, 2010 4:14 am ]
Post subject:  Re: Critical Hits by %?

Oh, right. That might cause it to not work, possibly. Maybe.
>_>
<_<
>_>

Code:
function Create(self)
   self.CritTimer = Timer()
end

function Update(self)
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos, actor.Pos, true).Magnitude
      if dist < 25 and self.CritTimer:IsPastMS(250) and math.random(1,20) == 20 then
         self.CritTimer:Reset()
         if actor.ClassName = "AHuman" then
           self.GoreAmount = math.random(1,3)
           for i = 1,self.GoreAmount do
             self.Gore = CreateAHuman(actor.PresetName)
             self.Gore.Vel = actor.Vel
             self.Gore.Pos = actor.Pos
             self.Gore.Sharpness = -231
             MovableMan:AddActor(self.Gore);
           end
         actor:GibThis()
         end
      end
      if actor.Sharpness = -231 then
        actor:GibThis()
     end
   end
end

(If it isn't an AHuman it just wont blow up into a big bloody pile.)

Author:  TheLastBanana [ Thu May 20, 2010 4:30 am ]
Post subject:  Re: Critical Hits by %?

Close, but no cigar.
Code:
self.Gore = CreateAHuman(actor)

Check the last post on what I said about this.

Page 1 of 2 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/