View unanswered posts | View active topics It is currently Thu Mar 28, 2024 8:14 pm



Reply to topic  [ 11 posts ] 
 [Request] Two Scripts (probably not very complicated) 
Author Message
User avatar

Joined: Wed Feb 10, 2010 12:41 pm
Posts: 182
Location: OMG where am i ?
Reply with quote
Post [Request] Two Scripts (probably not very complicated)
Can someone please write me two scripts

The first one i need is to make a missile fly in random dirrection (in mid air it will curve in different directions)

And the second one i need is a script for a weapon where i can specify which actor can hold it, if he can't then the weapon is instantly dropped from his inventory.


Sun Dec 09, 2012 7:31 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: [Request] Two Scripts (probably not very complicated)
The first one you can do it using .ini. Just give spread to the particles that pushes the emitter (rocket).

The second one isn't hard, but I haven't got any reliable methods for checking the parent, so this might simply result laggy:

Code:
function Create(self)
self.ActorThatCanHoldThisWeapon = "Name of the Actor that can hold the weapon"
self.parent = MovableMan:GetMOFromID(self.RootID)
end

function Update(self)

      if self.parent == nil or self.parent.ClassName ~= "AHuman" then   
      self.parent = MovableMan:GetMOFromID(self.RootID)
   end   
   if self.parent.PresetName ~= MovableMan:GetMOFromID(self.RootID).PresetName or self.parent.ClassName ~= "AHuman" then
      self.parent = MovableMan:GetMOFromID(self.RootID)
   end

if self.parent.PresetName ~= self.ActorThatCanHoldThisWeapon then
    self.parent:SetState(Controller.WEAPON_DROP,true)
end
end


It probably won't work, my CC lua is pretty rusty.


Sun Dec 09, 2012 10:42 pm
Profile
User avatar

Joined: Wed Feb 10, 2010 12:41 pm
Posts: 182
Location: OMG where am i ?
Reply with quote
Post Re: [Request] Two Scripts (probably not very complicated)
1) Not what i was aiming to get, but it will do for now, maybe with some tweaking i can get it just right.

2) Just like you said, the script does not work :-(


Sun Dec 09, 2012 11:40 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: [Request] Two Scripts (probably not very complicated)
Try changing the 3rd last line to
self.parent:GetController():SetState(Controller.WEAPON_DROP,true);

Everything else seems okay on a cursory glance, though it could probably be streamlined a bit to use 2 if statements instead of 3.


Mon Dec 10, 2012 3:43 am
Profile
User avatar

Joined: Wed Feb 10, 2010 12:41 pm
Posts: 182
Location: OMG where am i ?
Reply with quote
Post Re: [Request] Two Scripts (probably not very complicated)
In both cases this line seems causing some errors.


Mon Dec 10, 2012 12:50 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: [Request] Two Scripts (probably not very complicated)
What does it print?


Mon Dec 10, 2012 9:33 pm
Profile
User avatar

Joined: Wed Feb 10, 2010 12:41 pm
Posts: 182
Location: OMG where am i ?
Reply with quote
Post Re: [Request] Two Scripts (probably not very complicated)
Ok guys i was busy a ♥♥♥♥ ton of time and could not respond.
Anyway, here what console prints:


Attachments:
error.PNG
error.PNG [ 1.85 KiB | Viewed 8043 times ]
Sat Feb 23, 2013 4:36 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: [Request] Two Scripts (probably not very complicated)
Change
Code:
self.parent:GetController():SetState(Controller.WEAPON_DROP,true);

to
Code:
ToActor(self.parent):GetController():SetState(Controller.WEAPON_DROP,true);


Sat Feb 23, 2013 4:47 am
Profile
User avatar

Joined: Wed Feb 10, 2010 12:41 pm
Posts: 182
Location: OMG where am i ?
Reply with quote
Post Re: [Request] Two Scripts (probably not very complicated)
It worked, but it floods the console with this mesage now, i'm afraid if i will place multiple weapons on a map it will produce massive lag.

BTW i was wondering how to make this weapon availiable to multiple units do i just write "self.ActorThatCanHoldThisWeapon = "Unit1"; "Unit2"; "Unit3"" ?
And making a message popup when units that cant use it tries to pick it up, something like "Wrong unit class".


Attachments:
error2.PNG
error2.PNG [ 2.48 KiB | Viewed 8040 times ]
Sat Feb 23, 2013 5:05 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: [Request] Two Scripts (probably not very complicated)
Code:
function Create(self)

   self.permittedUsers = {};
   self.permittedUsers[1] = "Dummy";
   self.permittedUsers[2] = "Browncoat Light";
   self.permittedUsers[3] = "Crab";
   -- You get the idea

end

function Update(self)

   if self.RootID ~= self.ID then
      local actor = MovableMan:GetMOFromID(self.RootID);
      if MovableMan:IsActor(actor) then
         local isPermitted = false;
         for i = 1, #self.permittedUsers do
            if actor.PresetName == self.permittedUsers[i] then
               isPermitted = true;
               break;
            end
         end
         if not isPermitted then
            ToActor(actor):GetController():SetState(Controller.WEAPON_DROP,true);
            if ToActor(actor):IsPlayerControlled() then
               local parentPlayer = ToActor(actor):GetController().Player;
               FrameMan:ClearScreenText(parentPlayer);
               FrameMan:SetScreenText("YOU ARE NOT PERMITTED TO USE THIS ITEM!",parentPlayer,0,2,true);
            end
         end
      end
   end

end


Sun Feb 24, 2013 6:10 am
Profile
User avatar

Joined: Wed Feb 10, 2010 12:41 pm
Posts: 182
Location: OMG where am i ?
Reply with quote
Post Re: [Request] Two Scripts (probably not very complicated)
Awesome!
Theres only slight problem, somehow the message desplays only once per match :P


Sun Feb 24, 2013 10:49 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.057s | 19 Queries | GZIP : Off ]