Data Realms Fan Forums
http://45.55.195.193/

script fix (fixed by none)
http://45.55.195.193/viewtopic.php?f=73&t=18352
Page 1 of 1

Author:  salt_1219 [ Sun Apr 04, 2010 3:36 am ]
Post subject:  script fix (fixed by none)

Still learning, but I think I understand some of the code. Right now the code I have that works (an edit of Grif's clone tube) doesn't charge me for units, and spawns a new one when one dies. I would like it to charge me and only make a unit when I tell it to.

Code:
-- the point of this code is to vend a scud unit when gold dig AI is selected, thank the user for choosing scudco,...
-- and have the vended scud flash white when spawned, further more only vend a scud if there is not a scud already in play.

function Create(self) -- when object is created
   self.cost = 90; -- how much to charge for vending a scud unit
   self.vendoption = Vector(0,0); -- location of gold digger AI option?
   self.spawntimer = Timer(); -- timer for vend delay

end -- end of first block

-- While the object is existing.
function Update(self)
   self.vendoption.Pos = self.parentactor.AboveHUDPos -- not sure how to use this i think it should be a if statement
   if MovableMan:IsActor(self.clone) == false then -- check if a scud exists already or not
      if self.spawntimer:IsPastSimMS(5000) == true then -- spawn delay
         self.clone = CreateAHuman("Scud");
         self.clone.Pos = Vector(self.Pos.X, self.Pos.Y); -- where to spawn unit
         self.clone.Team = self.Team; -- set unit to players team
         MovableMan:AddActor(self.clone);
         self.cost = Actor.GoldValue; -- charge player for scud unit
                     print("Thank you for choosing Scudco!")(5000); -- is this the right way to make the statement display for a while?
         self.clone:FlashWhite(500);

      end -- end secound if
   else -- end first if
      self.spawntimer:Reset();
      if (math.abs(self.clone.Pos.X - self.Pos.X) < 40) and (math.abs(self.clone.Pos.Y - self.Pos.Y) < 80) then
         if self.clone:IsPlayerControlled() == false then
            self.clone.Pos = Vector(self.Pos.X, self.Pos.Y);
         end -- end plyercontrolled if
      end -- end math if
   end -- end else
end -- end of all


Any tips to help me learn are appreciated.

Author:  salt_1219 [ Sat Apr 24, 2010 11:27 pm ]
Post subject:  Re: script fix needed

Sorry for the double post, I edited the code I had before with a new, slightly less retarded version. Given time and practice I might even make a competent version. :P

Author:  CrazyMLC [ Sun Apr 25, 2010 12:18 am ]
Post subject:  Re: script fix needed

Code:
-- the point of this code is to vend a scud unit when gold dig AI is selected, thank the user for choosing scudco,...
-- and have the vended scud flash white when spawned, further more only vend a scud if there is not a scud already in play.

function Create(self) -- when object is created
   self.spawntimer = Timer(); -- timer for vend delay
   self.clone = CreateAHuman("Scud");
   self.clone.Team = self.Team; -- set unit to players team
end -- end of first block

-- While the object is existing.
function Update(self)
   if self.AIMode == Actor.AIMODE_GOLDDIG then -- check if activated
      if MovableMan:IsActor(self.clone) == false then -- check if a scud exists already or not
         if self.spawntimer:IsPastSimMS(5000) == true then -- spawn delay
            self.clone.Pos = self.Pos; -- where to spawn unit, make it simple
            self.CurrentF = ActivityMan:GetActivity():GetTeamFunds(self.Team); -- get the current funds
            if self.CurrentF > 89 then -- check if player can afford scud
               ActivityMan:GetActivity():SetTeamFunds(CurrentF-90, self.Team) -- charge player for scud
               MovableMan:AddActor(self.clone); -- create scud
               print("Thank you for choosing Scudco!"); -- thank you
               self.clone:FlashWhite(500); -- flash
            end -- end cost if
            self.spawntimer:Reset();
         end -- end second if
      else -- end first if
         if (math.abs(self.clone.Pos.X - self.Pos.X) < 40) and (math.abs(self.clone.Pos.Y - self.Pos.Y) < 80) then
            if self.clone:IsPlayerControlled() == false then
               self.clone.Pos = self.Pos; -- make it simpler
            end -- end playercontrolled if
         end -- end math if
      end -- end else
   end -- mode check
end -- end of all

This might work better, not sure.

Author:  salt_1219 [ Sun Apr 25, 2010 1:14 am ]
Post subject:  Re: script fix needed

thank you vary much CrazyMLC I will give that a try right now.

***OK I tried it out. I tacked this onto a dummy to test it, and nothing happened so I did some trouble shooting to see if its just an error on my end.

I made sure to tab correctly, checked my file path and made sure there were no missing end statements.

So I think the problem must be with trying to use the gold AI, I think dragonxp made a guy that explodes when you hit fire, maybe that would be a better trigger for vending my actor. (bombcrab or nuke one I don't remember)

Anyway thank you VARY much I will continue to work on this. -- Kaizen: Japanese for "improvement" or "change for the better"

replaced
Code:
if self.AIMode == Actor.AIMODE_GOLDDIG then

with
Code:
if self:GetController():IsState(Controller.RELEASE_PRIMARY) then

maybe its IsMouseControlled and something about left click hmmm?

Author:  CaveCricket48 [ Sun Apr 25, 2010 12:51 pm ]
Post subject:  Re: script fix needed

Do you have any Lua errors in the console? You also should change the cloner's AI mode to sentry after the clone has been made, or it'll keep spawning things untill your gold runs out.

Author:  salt_1219 [ Sun Apr 25, 2010 8:44 pm ]
Post subject:  Re: script fix needed

That would help if it spawned at all, right now it doesn't and I'm trying to figure out why. I will read over the code a few more times and see if there's a logic error or something... I don't get any errors when it runs?

Wait if playercontrolled == false keeps it from spawning an actor if one already exists.

If it helps I could post the mod this is for.

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