Author Topic: all i can code is like 3 lines... help  (Read 1449 times)

0 Members and 1 Guest are viewing this topic.

Offline kuposrock

  • Major(1)
  • Posts: 33
  • iz are the muffin man
all i can code is like 3 lines... help
« on: December 07, 2008, 10:13:55 pm »
ya I dont get how to code more then three lines.... like all i can do is spawn things.. i cant do anything else because i dont know how.. i read idante's thing about 3 times and stuff but i dont get it. For instance i wanna make a kamakaze script that if you say bomb you explode after 5 secs and i want the console to say something 5,4,3,2,1 to the person after each second.

I cant connect code...
HELP PLOX <('-'<)
DONT DO IT FOR ME. Just lead me in the right direction :0.
[signature removed; please read forum rules]

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: all i can code is like 3 lines... help
« Reply #1 on: December 07, 2008, 10:42:40 pm »
Post what you have so far, as well as what part of the process you don't understand.

idante
You seem to be in err, I cannot find anything on these forums by user: idante. Perhaps you meant iDante? And on top of that never say plox. It makes people not want to help you.

Offline kuposrock

  • Major(1)
  • Posts: 33
  • iz are the muffin man
Re: all i can code is like 3 lines... help
« Reply #2 on: December 07, 2008, 11:10:09 pm »
well all i have is create bullet.. The main part i dont get it the timer and how they work. and how to connect scripts, like a timer and a create bullet thing.
[signature removed; please read forum rules]

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: all i can code is like 3 lines... help
« Reply #3 on: December 07, 2008, 11:36:57 pm »
For instance i wanna make a kamakaze script that if you say bomb you explode after 5 secs and i want the console to say something 5,4,3,2,1 to the person after each second.

I cant connect code...
HELP PLOX <('-'<)
DONT DO IT FOR ME. Just lead me in the right direction :0.
Sorry, it's been done already. And a long time ago, at that.
There are other worlds than these

Offline kuposrock

  • Major(1)
  • Posts: 33
  • iz are the muffin man
Re: all i can code is like 3 lines... help
« Reply #4 on: December 08, 2008, 12:02:03 am »
For instance i wanna make a kamakaze script that if you say bomb you explode after 5 secs and i want the console to say something 5,4,3,2,1 to the person after each second.

I cant connect code...
HELP PLOX <('-'<)
DONT DO IT FOR ME. Just lead me in the right direction :0.
Sorry, it's been done already. And a long time ago, at that.


I know its been done but i wanna do it as well. So can some one lead me the right way
[signature removed; please read forum rules]

Offline GSx_Major

  • Major
  • *
  • Posts: 97
Re: all i can code is like 3 lines... help
« Reply #5 on: December 08, 2008, 02:40:42 am »
Code: [Select]
var Counter: Array [1..32] of Byte;

// Runs every second...
procedure AppOnIdle(Ticks: Integer);
var i: Byte;
begin

  // Go through the array and check what to do...
  for i := 1 to 32 do begin
 
    // Time to blow up?
    if Counter[i] = 1 then begin
      // Blow up here...
      Counter[i] := 0;
    end;

    // Just count down?
    if Counter[i] > 1 then begin
      Counter[i] := Counter[i] - 1;
      SayToPlayer(i, IntToStr(Counter[i]) + '...');
    end
  end;
end;

// So it doesnt cause problems if someone leaves before they blow
procedure OnLeaveGame(ID, Team: Byte; Kicked: Boolean);
begin
  Counter[ID] := 0;
end;

// If a player does /kaboom and isn't already blowing up...
function OnPlayerCommand(ID: Byte; Text: String): Boolean;
begin
  if Text = '/kaboom' then
    if Counter[ID] = 0 then
      Counter[ID] := 5;
end;
...and headbutt the sucker through your banana suit!

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: all i can code is like 3 lines... help
« Reply #6 on: December 08, 2008, 05:08:43 am »
I know its been done but i wanna do it as well. So can some one lead me the right way
If you still haven't figgured this from the code posted...

you need to create an integer variable and set it to 5 on command (in OnPlayerCommand i suppose), decrease it by 1 every second if it's more than 0 (in AppOnIdle) and output it, and when it equals to 0 - blow up. Thats the actual timer part. Decreasing an integer by 1 every second.

Now when you do this and see that it works, you'll figgure that one variable wont be enough if you want more than one player to use the bomb thing (because, naturally, someone can reset the timer which is counting down for another player already). That's why you want to create an array of integers - that will reserve one integer (timer) for every possible player ID that can exist on the server at any given moment. Of course you then will need to count down each element of that array in AppOnIdle.

If you know how to handle arrays you should now be able to do it yourself...

Offline shantec

  • Soldier
  • **
  • Posts: 140
  • Get ANGREH!!
Re: all i can code is like 3 lines... help
« Reply #7 on: December 08, 2008, 01:31:38 pm »
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: String): Boolean;
begin
  if Text = '/kaboom' then begin
    Writeconsole(ID,'5 seconds 'till explosion',$00FFFF);
    sleep(1000);
    Writeconsole(ID,'4',$00FFFF);
    sleep(1000);
    Writeconsole(ID,'3',$00FFFF);
    sleep(1000);
    Writeconsole(ID,'2',$00FFFF);
    sleep(1000);
    Writeconsole(ID,'1',$00FFFF);
    sleep(1000);
    Writeconsole(ID,'KABOOM',$00FFFF);
   
    //here goes some Createbullet
   
  end;
end;



Kinda easier version to understand... even though i dont suggest using Sleep()
Also Known As REIMA


Lol Happles (happy apples)

Offline Vyka

  • Major
  • *
  • Posts: 59
Re: all i can code is like 3 lines... help
« Reply #8 on: December 08, 2008, 03:56:58 pm »
sleep function sux, use apponidle, first:

create variable, name it timer (or in u'r own way)
in activateserver procedure set it to -1
in oncommand if text /some_text then set variable 5
in apponidle if variable>0 then writeconsole with variable and variable:=variable-1;
if variable=0 then createbullet stuff (check my "Bombing Time" script), writeconsole with info and variable:=-1

thats all

if u need it i can write

Offline kuposrock

  • Major(1)
  • Posts: 33
  • iz are the muffin man
Re: all i can code is like 3 lines... help
« Reply #9 on: December 08, 2008, 08:38:16 pm »
sleep function sux, use apponidle, first:

create variable, name it timer (or in u'r own way)
in activateserver procedure set it to -1
in oncommand if text /some_text then set variable 5
in apponidle if variable>0 then writeconsole with variable and variable:=variable-1;
if variable=0 then createbullet stuff (check my "Bombing Time" script), writeconsole with info and variable:=-1

thats all

if u need it i can write


ummm....... ya i dont get that... Im like super noob just pretend i know nothing.

shantec's is really easy to understand :0
[signature removed; please read forum rules]

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: all i can code is like 3 lines... help
« Reply #10 on: December 08, 2008, 10:15:59 pm »
shantec's is really easy to understand :0
shantec's will also freak out your server at random.

http://www.learn-programming.za.net/learn_pascal_programming.html
Good reference on syntax and such.

To be honest, you need to be able to figure this kind of thing out for yourself if you ever want to be successful as a script writer. Just think through what has to happen and do it (without using sleep()). Post YOUR code here if you are stuck. Don't post here if it doesn't compile, you should be able to figure out what's wrong with it from the compiler output.

Offline kuposrock

  • Major(1)
  • Posts: 33
  • iz are the muffin man
Re: all i can code is like 3 lines... help
« Reply #11 on: December 08, 2008, 11:00:07 pm »
I acually just started to use this today. :) thx though
[signature removed; please read forum rules]