Author Topic: Mich1103's scripting thread  (Read 10211 times)

0 Members and 1 Guest are viewing this topic.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Mich1103's scripting thread
« Reply #100 on: July 26, 2010, 01:56:58 pm »
Here it is !  ;D
Code: [Select]
//here is wath i added in the script

type tsoldier = record
godcooldown:integer;


//i added this onplayerdamage
if soldier[Victim].godcooldown = 0 then begin
if (Soldier[Victim].GodTime <> -1) then begin 
   Result := -99999; 
   Exit;


//i added this onjoingame
soldier[ID].godcooldown := 0;

//i added this in AppOnIddle
    if (Soldier[i].godcooldown := 100) then begin
      Soldier[i].godcooldown := Soldier[i].godcooldown - 1;
      if (Soldier[i].godcooldown = 0) then begin
        Soldier[i].godcooldown := -1;
        WriteConsole(i,'Shield can now be casted !',$CC0000);

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Mich1103's scripting thread
« Reply #101 on: July 26, 2010, 02:35:04 pm »
your apponidle seems wrong - here's kinda what it should look like:

here's conceptually what needs to happen:
When god-shield is casted, set cooldown to 100 (or however many seconds you want).  Then in apponidle, do this for every player:
Code: [Select]
if soldier[i].godcooldown > 0 then begin
soldier[i].godcooldown := soldier[i].godcooldown - 1;
if soldier[i].godcooldown = 0 then draw(shield ready);
end;
this will keep counting down until 0 is reached (your code seems to only count down ONCE, when godcooldown = 100.  This means it'll stay at 99).
this will also display the message when shield is ready.

then when the player wants to use god-shield, you have to do a check to make sure cooldown = 0

Anyway, i haven't actually given you the actual script, only the concept. Try at it one more time and let us know if you got it or still need help ;)
Can't think of anything original to put here...

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Mich1103's scripting thread
« Reply #102 on: July 26, 2010, 03:55:26 pm »
Something like that ?



Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Mich1103's scripting thread
« Reply #103 on: July 26, 2010, 04:18:58 pm »
you're making huge errors in your onplayerdamage

when using if then begin, you must use END to mark the end of the code to be executed given the condition.
in your code, you leave out the END line until the end of your procedure, which is wrong.
i'm not gonna bother correcting it, i'll just give you the code:

Code: [Select]

function OnPlayerDamage(Victim,Shooter:Byte; Damage:Integer):Integer;
begin

Result := Damage

if (Victim = Shooter) then Exit;

if (Soldier[Victim].GodTime > 0) then begin  // 0 means god-mode
Result := 0;
end else begin
if (soldier[shooter].level >= 55) and (Random(1,101) <= FatalHitChance) then begin
FatalHit(Victim,Shooter);
WriteConsole(Shooter,'Fatal Hit !',colorr);
end;
// i put loot ammo here, so that you can't loot from someone in god-mode
if (soldier[shooter].level >= 50) and (Random(1,101) <= LootAmmoChance) then LootAmmo(Shooter);
end;

end;


// this is in your apponidle:
for i:= 1 to 32 do if GetPlayerStat(i,'Active') then begin
if (Soldier[i].GodTime > 0) then begin
Soldier[i].GodTime := Soldier[i].GodTime - 1;
if (Soldier[i].GodTime = 0) then WriteConsole(i,'You are mortal again..',$CC0000);
end else begin
if (Soldier[i].godcooldown > 0) then begin  // cooldown doesn't start until god-mode is over
Soldier[i].godcooldown := Soldier[i].godcooldown - 1;
if (Soldier[i].godcooldown = 0) then WriteConsole(i,'God shield is ready to cast !',$CC0000);
end;
end;
end;

// this goes in your OnPlayerCommand
if regExpMatch('^/(god|shield)$', Text) then begin
if (soldier[ID].level >= 60) then begin
if (soldier[ID].godcooldown = 0) then begin
soldier[ID].GodTime := 20;
soldier[ID].godcooldown := 120;
WriteConsole(ID,'You are invincible for 20 seconds!',$FFFFFF);
end else WriteConsole(ID, 'God shield not ready.  ' + inttostr(soldier[ID].godcooldown) + ' seconds remaining', Color);
end else WriteConsole(ID, 'You are not lvl 60 + Or you have too wait until the spell is ready', Color);
end;
« Last Edit: July 26, 2010, 04:56:37 pm by zyxstand »
Can't think of anything original to put here...

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Mich1103's scripting thread
« Reply #104 on: July 26, 2010, 05:45:42 pm »
So i've tried /god after i use it ! and it was always staying at 118 second ...
and i got this erro in the console : (AppOnIdle): Out of range

DarkCrusade

  • Guest
Re: Mich1103's scripting thread
« Reply #105 on: July 26, 2010, 06:12:49 pm »
Should work better ;)

Code: [Select]
function OnPlayerDamage(Victim,Shooter:Byte; Damage:Integer):Integer;
begin
  Result := Damage
  if (Victim = Shooter) then Exit;
  if (Soldier[Victim].GodTime > 0) then begin  // 0 means god-mode
    Result := -99999;
  Exit;
  end;
  if (soldier[shooter].level >= 55) and (Random(1,101) <= FatalHitChance) then begin
    FatalHit(Victim,Shooter);
    WriteConsole(Shooter,'Fatal Hit !',colorr);
  end;
  if (soldier[shooter].level >= 50) and (Random(1,101) <= LootAmmoChance) then LootAmmo(Shooter);
end;

// AppOnIdle part
  for i:= 1 to 32 do if GetPlayerStat(i,'Active') then begin
    if (Soldier[i].GodTime > 0) then begin
      Soldier[i].GodTime := Soldier[i].GodTime - 1;
      if (Soldier[i].GodTime = 0) then WriteConsole(i,'You are mortal again..',$CC0000);
    if (Soldier[i].godcooldown > 0) then begin  // cooldown doesn't start until god-mode is over
Soldier[i].godcooldown := Soldier[i].godcooldown - 1;
if (Soldier[i].godcooldown = 0) then WriteConsole(i,'God shield is ready to cast !',$CC0000);
      end;
    end;
  end;

// this goes in your OnPlayerCommand
  if regExpMatch('^/(god|shield)$', Text) then begin
    if (soldier[ID].level >= 60) then begin
      if (soldier[ID].godcooldown = 0) then begin
soldier[ID].GodTime := 20;
soldier[ID].godcooldown := 120;
WriteConsole(ID,'You are invincible for 20 seconds!',$FFFFFF);
      end else WriteConsole(ID, 'God shield not ready.  ' + inttostr(soldier[ID].godcooldown) + ' seconds remaining', Color);
    end else WriteConsole(ID, 'You are not lvl 60 + Or you have too wait until the spell is ready', Color);
  end;

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Mich1103's scripting thread
« Reply #106 on: July 26, 2010, 06:22:51 pm »
Same thing ...  >:(

Maybe its a error due to AppOnIdle ...
Code: [Select]
Procedure AppOnIdle(Ticks: Integer);
 Var N,i, K: Byte;
  X, Y, Dista: Single;
   Begin
CheckMines();
  for i:= 1 to 32 do if GetPlayerStat(i,'Active') then begin
    if (Soldier[i].GodTime > 0) then begin
      Soldier[i].GodTime := Soldier[i].GodTime - 1;
      if (Soldier[i].GodTime = 0) then WriteConsole(i,'You are mortal again..',$CC0000);
    if (Soldier[i].godcooldown > 0) then begin  // cooldown doesn't start until god-mode is over
Soldier[i].godcooldown := Soldier[i].godcooldown - 1;
if (Soldier[i].godcooldown = 0) then WriteConsole(i,'God shield is ready to cast !',$CC0000);
      AllDraw(i);
   Heal(i);
end;
    end;
  end;

For N := 1 To maxpsg Do Begin
if sgd[n] = True Then Begin
      CreateBullet(sgx[n],sgy[n],0,0,0,5,sgo[n]);
       For K := 1 To 32 Do Begin
        GetPlayerXy(K,X,Y);
         if GetPlayerStat(K,'Team') <> sgt[n] Then if GetPlayerStat(K,'Alive') = True Then if RayCast(sgx[n],sgy[n],x,y,dista,psgrang) = True Then if dista <= psgrang Then Begin
          x := ((x-sgx[n]) / dista)*psgspee;
         y := ((y-sgy[n]) / dista)*psgspee;
          CreateBullet(sgx[n],sgy[n],x,y,psgpowa,psgtype,sgo[n]); sga[n]:=sga[n]-1;
         if sga[n] = 0 Then Begin
      sgd[n] := false;
      Writeconsole(sgo[n],'One of your sentry guns ran out of ammo.',$0000FF00);     
end;
Break;
    end;
   end;
  end;
 end;
end;
« Last Edit: July 26, 2010, 06:25:21 pm by mich1103 »

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Mich1103's scripting thread
« Reply #107 on: July 26, 2010, 06:53:01 pm »
why are your indentions so weird? note how mine and darkcrusader's work:  when there's a BEGIN, the next lines will be indented.  the END gets UNindented and stays like that until there's another begin.  if there is a BEGIN inside a BEGIN, then you have to indent your code more.

what i want you to do is use that indentation format and look at your code - this should help you figure it out better.  If you don't figure it out, show us your code with proper indentations so we can help you better!
Can't think of anything original to put here...

DarkCrusade

  • Guest
Re: Mich1103's scripting thread
« Reply #108 on: July 26, 2010, 06:59:20 pm »
Mich, you will need to understand how imporant indentations are. Without them your code appears to be scary and (reasonably) unreadable. Hence you will have problems finding simple errors like the error with the redundant 'END'.

Annotation: I don't get why people always call me Dark Crusader when it's meant to be Dark Crusade as I already use it.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Mich1103's scripting thread
« Reply #109 on: July 26, 2010, 07:21:43 pm »
Guys can you explain with simple word i under syand only 50% of what u said ...

DarkCrusade

  • Guest
Re: Mich1103's scripting thread
« Reply #110 on: July 26, 2010, 07:49:55 pm »
Without indentations:

Code: [Select]
Procedure ClusterSpawnTrigger();
var
Team,Heal:Boolean;
i,ii:Byte;
begin
if (not ClusterInitialized) then Exit;
if (ClusterSpecTeam = 0) then Team := false;
if (ClusterRegen > 0) then Heal := false;
for i := 1 to ClusterRegions do if (ClusterSpawnX[i] <> 0) AND (ClusterSpawnY[i] <> 0) then
for ii := 1 to HighestPlayerID() do if (GetPlayerStat(ii,'Active') = true) then
if (GetPlayerStat(ii,'Alive') = true) AND (GetPlayerStat(ii,'Team') <> 5) then
if (Team) then begin
if (GetPlayerStat(ii,'Team') = ClusterSpecTeam) AND     (Distance(GetPlayerStat(ii,'X'),GetPlayerStat(ii,'Y'),ClusterSpawnX[i],ClusterSpawnY[i]) <= ClusterRange) then begin
if (Heal) then begin
if (GetPlayerStat(ii,'Health') < 150) then
if (GetPlayerStat(ii,'Health') + ClusterRegen <= 150) then
DoDamage(ii,ClusterRegen)
else
DoDamage(ii,GetPlayerStat(ii,'Health') -150);
end else DoDamage(ii,ClusterRegen);
CreateBullet(GetPlayerStat(ii,'X'),GetPlayerStat(ii,'Y'),0,0,0,5,ii);
end;
end else if (Distance(GetPlayerStat(ii,'X'),GetPlayerStat(ii,'Y'),ClusterSpawnX[i],ClusterSpawnY[i]) <= ClusterRange) then begin
if (Heal) then begin
if (GetPlayerStat(ii,'Health') < 150) then
if (GetPlayerStat(ii,'Health') + ClusterRegen <= 150) then
DoDamage(ii,ClusterRegen)
else
DoDamage(ii,GetPlayerStat(ii,'Health') -150);
end else DoDamage(ii,ClusterRegen);
CreateBullet(GetPlayerStat(ii,'X'),GetPlayerStat(ii,'Y'),0,0,0,5,ii);
end;
end;

With correct indentations:

Code: [Select]
Procedure ClusterSpawnTrigger();
var
  Team,Heal:Boolean;
  i,ii:Byte;
begin
  if (not ClusterInitialized) then Exit;
  if (ClusterSpecTeam = 0) then Team := false;
  if (ClusterRegen > 0) then Heal := false;
  for i := 1 to ClusterRegions do if (ClusterSpawnX[i] <> 0) AND (ClusterSpawnY[i] <> 0) then
    for ii := 1 to HighestPlayerID() do if (GetPlayerStat(ii,'Active') = true) then
      if (GetPlayerStat(ii,'Alive') = true) AND (GetPlayerStat(ii,'Team') <> 5) then
        if (Team) then begin
  if (GetPlayerStat(ii,'Team') = ClusterSpecTeam) AND (Distance(GetPlayerStat(ii,'X'),GetPlayerStat(ii,'Y'),ClusterSpawnX[i],ClusterSpawnY[i]) <= ClusterRange) then begin
    if (Heal) then begin
              if (GetPlayerStat(ii,'Health') < 150) then
        if (GetPlayerStat(ii,'Health') + ClusterRegen <= 150) then
  DoDamage(ii,ClusterRegen)
                else
                  DoDamage(ii,GetPlayerStat(ii,'Health') -150);
            end else DoDamage(ii,ClusterRegen);
    CreateBullet(GetPlayerStat(ii,'X'),GetPlayerStat(ii,'Y'),0,0,0,5,ii);
  end;
end else if (Distance(GetPlayerStat(ii,'X'),GetPlayerStat(ii,'Y'),ClusterSpawnX[i],ClusterSpawnY[i]) <= ClusterRange) then begin
          if (Heal) then begin
    if (GetPlayerStat(ii,'Health') < 150) then
      if (GetPlayerStat(ii,'Health') + ClusterRegen <= 150) then
        DoDamage(ii,ClusterRegen)
      else
                DoDamage(ii,GetPlayerStat(ii,'Health') -150);
          end else DoDamage(ii,ClusterRegen);
  CreateBullet(GetPlayerStat(ii,'X'),GetPlayerStat(ii,'Y'),0,0,0,5,ii);
        end;
end;

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Mich1103's scripting thread
« Reply #111 on: July 26, 2010, 07:52:46 pm »
Here is what you have (BAD):
Code: [Select]
for i := 0 to 20 do begin
    if y = 3 then begin
        if x = 5 then begin
            x := x + 1;
    if x > 35 then begin
        x := x - 1
       end;
   end;
end;


Here is what you should have (GOOD):

Code: [Select]
for i := 0 to 20 do begin
    if y = 3 then begin
        if x = 5 then begin
            x := x + 1;
        end;
        if x > 35 then begin
            x := x - 1
        end;
   end;
end;

notice after the word "BEGIN" every line is moved to the right and when there is "END" every line goes back left.

I think you don't understand what begin and end do.  look at this code:
Code: [Select]
if x > 0 then begin
x := x - 1;
WriteConsole(ID, x);
end;

the phrase "x > 0" at the beginning is called the conditional.  the 2 lines "x := x - 1;" and "WriteConsole(ID, x)" will ONLY be executed if the conditional is met.  The computer needs to know what code to execute.  the words BEGIN and END show beginning and ending of that code.  In the example, if the CONDITIONAL is not true, then the computer will not execute the code that's between the BEGIN and END words!

I hope this makes sense to you.
Can't think of anything original to put here...

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Mich1103's scripting thread
« Reply #112 on: July 26, 2010, 08:16:12 pm »
@ DC : You've just added some space O.o ...
@ zyxstand : i understand but wath is that code ? (it is in the script ?)

Code: [Select]
for i := 0 to 20 do begin
    if y = 3 then begin
        if x = 5 then begin
            x := x + 1;
        end;
        if x > 35 then begin
            x := x - 1
        end;
   end;
end;

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Mich1103's scripting thread
« Reply #113 on: July 26, 2010, 08:20:22 pm »
DarkCrusade and I showed you the code to put it. I'm sure they'll both work.  If it doesn't work, attach your file in your next post and tell us what's wrong.  The code that you just showed us earlier didn't have that format and it's hard to help you.
Can't think of anything original to put here...

DarkCrusade

  • Guest
Re: Mich1103's scripting thread
« Reply #114 on: July 26, 2010, 08:26:18 pm »
Mich, this is not only space. This is what makes your code understandable. It is important to use proper "free space", because you can fix your code easier and understand the code after some time has passed.

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Mich1103's scripting thread
« Reply #115 on: July 26, 2010, 08:37:41 pm »
i will put indentitions tomorow !
when i type /god it always stay to 100

DarkCrusade

  • Guest
Re: Mich1103's scripting thread
« Reply #116 on: July 26, 2010, 08:40:05 pm »
Maybe you can put the whole code here again so we can check it?

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Mich1103's scripting thread
« Reply #117 on: July 26, 2010, 08:41:22 pm »
Yeah but there is no identation ...  :-\

(And i wanna say thanks to you guys who helped me alot :P)

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: Mich1103's scripting thread
« Reply #118 on: July 26, 2010, 08:54:30 pm »
aahhhh...
we are asking you to make your put text after a BEGIN line more to the right and then after END put it back left.  use the TAB key on your keyboard to move the text to the right.  moving text to the right is called indentation.  Do this and then show us your code.
Can't think of anything original to put here...

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Mich1103's scripting thread
« Reply #119 on: July 27, 2010, 09:15:07 am »
Here it is !
i did the indentations !