View unanswered posts | View active topics It is currently Sat Jan 11, 2025 7:24 am



Reply to topic  [ 6 posts ] 
 script fix (fixed by none) 
Author Message
User avatar

Joined: Tue Jan 12, 2010 8:25 pm
Posts: 400
Location: mukilteo, wa
Reply with quote
Post 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.


Last edited by salt_1219 on Wed Apr 28, 2010 8:56 am, edited 3 times in total.



Sun Apr 04, 2010 3:36 am
Profile
User avatar

Joined: Tue Jan 12, 2010 8:25 pm
Posts: 400
Location: mukilteo, wa
Reply with quote
Post 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


Sat Apr 24, 2010 11:27 pm
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post 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.


Sun Apr 25, 2010 12:18 am
Profile WWW
User avatar

Joined: Tue Jan 12, 2010 8:25 pm
Posts: 400
Location: mukilteo, wa
Reply with quote
Post 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?


Last edited by salt_1219 on Mon Apr 26, 2010 4:19 am, edited 2 times in total.



Sun Apr 25, 2010 1:14 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Sun Apr 25, 2010 12:51 pm
Profile
User avatar

Joined: Tue Jan 12, 2010 8:25 pm
Posts: 400
Location: mukilteo, wa
Reply with quote
Post 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.


Sun Apr 25, 2010 8:44 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.106s | 13 Queries | GZIP : Off ]