View unanswered posts | View active topics It is currently Mon Jan 13, 2025 5:18 pm



Reply to topic  [ 9 posts ] 
 I need help with this script real quick, small script. 
Author Message
User avatar

Joined: Sat Nov 18, 2006 8:11 pm
Posts: 267
Reply with quote
Post I need help with this script real quick, small script.
Hey, so I have this weapon the "C4 Shotgun"

I set it up so that it can be detonated by pressing Z and also by using a detonator, but the detonator only works sometimes and I'm not sure why. 80 percent of the time it doesn't blow up the C4. Here's the code

Code:
function Create(self)
end

function Update(self)
   if (UInputMan:KeyHeld(26)) then
      self:GibThis();
   
    print("C4 Spray planted!");
    --Make sure the C-4 Spray list exists.
    if c4ListS == nil then
   --If not, create it.
   c4ListS = { };
    end
    --Add this C-4 to the list.
    c4ListS[#c4ListS + 1] = self;
end

end



And the code the detonator itself uses, but I don't think this is the problem
Code:
function Create(self)
    print("C4 Spray detonated!");
    --Make sure the C-4 Spray list exists.
    if c4ListS ~= nil then
       --Go through the list of C-4 Spray.
   for i=1,#c4ListS do
       --Make sure the C-4 still exists, it may have been destroyed.
       if MovableMan:IsParticle(c4ListS[i]) then
           --Detonate the C-4!
      c4ListS[i]:GibThis();
       end
   end
    end
    --Empty/create the red C-4 list.
    c4ListS = { };
end


Wed Jun 24, 2009 10:51 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: I need help with this script real quick, small script.
if not C4ListS then
c4ListS = { };
else
c4ListS[#c4ListS + 1] = self;
end


Wed Jun 24, 2009 11:04 pm
Profile
User avatar

Joined: Sat Nov 18, 2006 8:11 pm
Posts: 267
Reply with quote
Post Re: I need help with this script real quick, small script.
Grif wrote:
if not C4ListS then
c4ListS = { };
else
c4ListS[#c4ListS + 1] = self;
end


What do I do with that? D:

I don't know Lua at all, just some common sense.


Wed Jun 24, 2009 11:06 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: I need help with this script real quick, small script.
The way you have it, it's checking whether a list exists, and REGARDLESS of whether it does, adding to that list. That means that most of the time it WON'T add to the list properly, or will do other strange stuff.

The way mine is written, it will only add if there IS already a list.


Wed Jun 24, 2009 11:11 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: I need help with this script real quick, small script.
You appear to have a missplaced end statement, and the list adding code belongs in Create.


Wed Jun 24, 2009 11:14 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: I need help with this script real quick, small script.
No, he's got the correct number of ends, they're just tabbed horribly.

Here, this should work, and also isn't terrible syntax.

Code:
function Create(self)
   if c4ListS == nil then
      --If not, create it.
      c4ListS = { };
    else
      --Add this C-4 to the list.
      c4ListS[#c4ListS + 1] = self;
   end
end

function Update(self)
   if (UInputMan:KeyHeld(26)) then
      self:GibThis();
   end
end


Last edited by Grif on Wed Jun 24, 2009 11:18 pm, edited 1 time in total.



Wed Jun 24, 2009 11:17 pm
Profile
User avatar

Joined: Sat Nov 18, 2006 8:11 pm
Posts: 267
Reply with quote
Post Re: I need help with this script real quick, small script.
Grif wrote:
The way you have it, it's checking whether a list exists, and REGARDLESS of whether it does, adding to that list. That means that most of the time it WON'T add to the list properly, or will do other strange stuff.

The way mine is written, it will only add if there IS already a list.


Not to be difficult, but I still don't know what to do with that.

Where in the code do I put it?


Wed Jun 24, 2009 11:17 pm
Profile WWW
User avatar

Joined: Sat Nov 18, 2006 8:11 pm
Posts: 267
Reply with quote
Post Re: I need help with this script real quick, small script.
mail2345 wrote:
You appear to have a missplaced end statement, and the list adding code belongs in Create.


Like I said, I don't know Lua at all.


Could you fix up my script? :[


Wed Jun 24, 2009 11:18 pm
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: I need help with this script real quick, small script.
Please avoid double posting in the future.
Anyway, even if you don't know Lua, the only way you're going to learn Lua is to figure out how everything fits together. In order to do that, you'll want to learn the syntax first. It's very difficult to help with code that can't be read.


Thu Jun 25, 2009 3:56 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 9 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.028s | 15 Queries | GZIP : Off ]