Author Topic: [solved] error OnPlayerDamage  (Read 1075 times)

0 Members and 1 Guest are viewing this topic.

Offline GhostRiderSwiss

  • Camper
  • ***
  • Posts: 294
  • Scripting beginner, mapper&owner of BCB servers.
    • BCB-Forum
[solved] error OnPlayerDamage
« on: April 17, 2013, 09:23:55 am »
Hi all,

I've been working since my last help post alot more on my script and once more i've created a small error which i am not able to solve, so if someone has a bit time, feel free to find the error and help  :)

here the error :
Code: [Select]
(23:37:28)  [*] [Error] King-Mode -> (OnPlayerDamage): Out Of Range
here the function :
Code: [Select]
function OnPlayerDamage(Victim, Shooter: byte; damage: integer): integer;
var
  Injury: double;
begin
  Injury := Damage;
  Result := Damage;
  if (Victim <> Shooter) and (GetPlayerStat(Victim, 'team') = GetPlayerStat(Shooter, 'team')) then
  begin
    Injury := 0;
  end
  else begin
      Players[Victim].hp := Players[Victim].hp - Damage;
      if Players[Victim].hp <= 0 then begin
Players[Victim].hp := 0;
Injury := Damage;
      end else begin
Injury := Damage * 150/Classes[Players[Victim].ClassID].Hp;
      end;
  end;
  Result := round(Injury);
end;



Also, i have another question which came just to my mind,

I have made a "skill" for a class called the Dragon which will allow him to spit fire when he's dead curently OnPlayerCommand /db

So my question is as i keep failing to create a "cooldown" for that skill, if someone can add it quick to the code so that i can make it myself in future  :P

here the code :
Code: [Select]
  if (Text = '/db') then
  begin
    if Players[ID].ClassID = 13 then begin
      if (Players[ID].Dead = True) then begin
        CreateBullet(GetPlayerStat(ID,'X')-5, GetPlayerStat(ID,'Y')-5, -15,  -1, 250, 5, ID);
        CreateBullet(GetPlayerStat(ID,'X')-5, GetPlayerStat(ID,'Y')-5,  15,  -1, 250, 5, ID);
        CreateBullet(GetPlayerStat(ID,'X')-5, GetPlayerStat(ID,'Y')-7, -18,  -1, 250, 5, ID);
        CreateBullet(GetPlayerStat(ID,'X')-5, GetPlayerStat(ID,'Y')-7,  18,  -1, 250, 5, ID);
DrawText(ID, ' Let em burn!', 240, $FF0000, 0.1875, 50, 175);
      end;
    end;
  end;


Thanks for any help  :)
« Last Edit: April 18, 2013, 09:32:44 am by GhostRiderSwiss »
BCB-Clan Page
You also can find clan BCB on our servers.

BCB-Soldier till i die!

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: [help] error OnPlayerDamage
« Reply #1 on: April 17, 2013, 08:07:20 pm »
Out of Range errors involve arrays. It would be *very* useful if you could present the line that gives the error, but anyway.

My best guess is with this line -> Injury := Damage * 150/Classes[Players[Victim].ClassID].Hp;

Haven't tested or anything, just a hunch.
www.soldatx.com.br - The brazilian Soldat community.

Offline TheOne

  • Soldier
  • **
  • Posts: 208
Re: [help] error OnPlayerDamage
« Reply #2 on: April 18, 2013, 04:16:53 am »
- how big is your Players array?
- how big is your Classes array?
- which values does Player.ClassID hold? can it be zero at times, maybe you missed initialising a class?

About the cooldown: If you have one for every class, you might want to include it into your Classes- or player-structure.
Generally it works like this:

Code: [Select]
const
BREATH_COOLDOWN = 30;

var
cooldownVar: byte;

procedure AppOnIdle(Ticks: integer);
begin
if cooldownVar > 0 then
begin
cooldownVar := cooldownVar - 1;
if cooldownVar = 0 then
WriteConsole(DragonPlayer, 'Breath cooled down!', $FF0000);
end;
end;

function OnPlayerDamage(Victim, Shooter: byte; Damage: integer): integer;
begin
if (Text = '/db') then
begin
if Players[ID].ClassID = 13 then begin
if (Players[ID].Dead = True) then begin
if cooldownVar = 0 then
begin
CreateBullet(GetPlayerStat(ID,'X')-5, GetPlayerStat(ID,'Y')-5, -15,  -1, 250, 5, ID);
CreateBullet(GetPlayerStat(ID,'X')-5, GetPlayerStat(ID,'Y')-5,  15,  -1, 250, 5, ID);
CreateBullet(GetPlayerStat(ID,'X')-5, GetPlayerStat(ID,'Y')-7, -18,  -1, 250, 5, ID);
CreateBullet(GetPlayerStat(ID,'X')-5, GetPlayerStat(ID,'Y')-7,  18,  -1, 250, 5, ID);
DrawText(ID, ' Let em burn!', 240, $FF0000, 0.1875, 50, 175);
end else
WriteConsole(ID, 'Skill not cooled down yet!', $FF0000);
end;
end else
WriteConsole(ID, 'You are not the dragon!', $FF0000);
end;
end;

"DragonPlayer" - don't know if you have a structure where you can easily access a player with that class.
Otherwise you'll have to loop through all players to find him (and you'll need several of those cooldowns of course)

I didn't test this code though.
btw.. why can you cast the spell only when you are dead?
« Last Edit: April 18, 2013, 04:26:45 am by TheOne »

Offline GhostRiderSwiss

  • Camper
  • ***
  • Posts: 294
  • Scripting beginner, mapper&owner of BCB servers.
    • BCB-Forum
Re: [help] error OnPlayerDamage
« Reply #3 on: April 18, 2013, 09:32:11 am »
@ Squiddy, thanks it helped, though, sometimes it still gives an error but alot lesser, so thx! Also the problem is pretty much that i only see the errors in arsse and not on the server itself as im not hosting myself, the problems only appear online, so it didnt help me to find that on my own server :(

@TheOne,

- how big is your Players array?
Code: [Select]
Players: array[1..NumOfPlayers] of tPlayer; and NumOfPlayers is in the constant part on top, currently = 12.

-how big is your Classes array?
Code: [Select]
Classes: array[1..NumOfClasses] of tClass; and NumOfClasses in constant part on top, currently = 14.

- which values does Player.ClassID hold? can it be zero at times, maybe you missed initialising a class?
Code: [Select]
  //classes initialization
  Classes[1].Name := 'King';
  Classes[1].Dist := 70;
  Classes[1].Hp := 190;
  Classes[1].HealRate := 10;
 
  Classes[2].Name := 'Hunter';
  Classes[2].Dist := 5;
  Classes[2].Hp := 160;
  Classes[2].HealRate := 11;

  Classes[3].Name := 'Knight';
  Classes[3].Dist := 5;
  Classes[3].Hp := 150;
  Classes[3].HealRate := 19;
 
  Classes[4].Name := 'Assasin';
  Classes[4].Dist := 5;
  Classes[4].Hp := 175;
  Classes[4].HealRate := 13;
 
  Classes[5].Name := 'Mage';
  Classes[5].Dist := 5;
  Classes[5].Hp := 150;
  Classes[5].HealRate := 19;

  Classes[6].Name := 'Tank';
  Classes[6].Dist := 5;
  Classes[6].Hp := 300;
  Classes[6].HealRate := 22;

  Classes[7].Name := 'Priest';
  Classes[7].Dist := 100;
  Classes[7].Hp := 150;
  Classes[7].HealRate := 24;

  Classes[8].Name := 'Jumper';
  Classes[8].Dist := 5;
  Classes[8].Hp := 150;
  Classes[8].HealRate := 17;

  Classes[9].Name := 'Kamikaze';
  Classes[9].Dist := 5;
  Classes[9].Hp := 150;
  Classes[9].HealRate := 11;

  Classes[10].Name := 'Ghost';
  Classes[10].Dist := 5;
  Classes[10].Hp := 150;
  Classes[10].HealRate := 20;

  Classes[11].Name := 'Demon';
  Classes[11].Dist := 5;
  Classes[11].Hp := 150;
  Classes[11].HealRate := 11;

  Classes[12].Name := 'Bird';
  Classes[12].Dist := 5;
  Classes[12].Hp := 150;
  Classes[12].HealRate := 17;

  Classes[13].Name := 'Dragon';
  Classes[13].Dist := 5;
  Classes[13].Hp := 150;
  Classes[13].HealRate := 11;

  Classes[14].Name := 'Turncoat';
  Classes[14].Dist := 5;
  Classes[14].Hp := 150;
  Classes[14].HealRate := 11;

  ResetFreePos();
end;

it seems good to me^^

also thanks for the code example i will try it myself now to add myself :)

and it seems im lucky, my mate just came back he's programmer so i will take his time instead of yours ^^ thanks alot.

end yes the spell is supposed to work only when dead, just cauze im pretty much playing arround with everything cauze i actualy learn scripting by doing with examples, it seems the best learn proccess for myself yet, as this is way more interesting then reading a shitload of theory xD

BCB-Clan Page
You also can find clan BCB on our servers.

BCB-Soldier till i die!

Offline JotEmI

  • Soldier
  • **
  • Posts: 188
Re: [solved] error OnPlayerDamage
« Reply #4 on: April 18, 2013, 06:12:37 pm »
Add checking if(Victim<>0) in OnPlayerDamage and see if that helps. If I remember correctly OnPlayerDamage returns Victim=0 when player's dead body is hit. Will have to test that to confirm but I've had a similar issue and adding that check helped.

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: [solved] error OnPlayerDamage
« Reply #5 on: April 18, 2013, 08:33:10 pm »
One would be wise if he were to download the soldatserver and test the scripts in it instead of testing them in the paid hosted server..

Nvm that.
« Last Edit: April 19, 2013, 05:45:28 am by squiddy »
www.soldatx.com.br - The brazilian Soldat community.

Offline GhostRiderSwiss

  • Camper
  • ***
  • Posts: 294
  • Scripting beginner, mapper&owner of BCB servers.
    • BCB-Forum
Re: [solved] error OnPlayerDamage
« Reply #6 on: April 19, 2013, 12:57:36 pm »
my mate solved the OnPlayerDamage bug and told me how to do the cooldowns and such, so i made it like this now :

to constant "Delay4 = 25; (where 25 are the seconds) and each other class uses another Delay1, Delay2 etc...

then Added to AppOnIdle
Code: [Select]
      begin
players[i].Timer := players[i].Timer - 1;
      end;

and to the OnPlayerCommand this
Code: [Select]
  //King skill "Armor"
  if (Text = '/skill1') then
  begin
    if Players[ID].ClassID = 1 then begin
      if (Players[ID].Timer = 0) then begin
        SpawnObject(GetPlayerStat(ID,'x'),GetPlayerStat(ID,'y'),19);
DrawText(ID, ' Armor spawned!', 300,color3,0.10,0,20);
Players[ID].Timer := Delay4;
      end else begin
        DrawText(ID,'Armor NOT ready!',300,color,0.10,0,20);
      end;
    end;
  end;

But now i actualy wanna make when the timer is 0 that it draws a WriteConsole msg to the class, skill ready! or something...

Also i know TheOne showed already how i could do it but somehow im too stupid to add it, so if someone can add it quick properly, many thanks  :-*
BCB-Clan Page
You also can find clan BCB on our servers.

BCB-Soldier till i die!

Offline Silnikos

  • Soldier
  • **
  • Posts: 129
Re: [solved] error OnPlayerDamage
« Reply #7 on: April 22, 2013, 06:27:02 am »
Then change the apponiddle loop to:
Code: [Select]
begin
players[i].Timer := players[i].Timer - 1;
if (players[i].Timer = 0) then WriteConsole(i, 'THE TEXT', $FF0000);
end;
« Last Edit: April 22, 2013, 06:29:08 am by Silnikos »

Offline GhostRiderSwiss

  • Camper
  • ***
  • Posts: 294
  • Scripting beginner, mapper&owner of BCB servers.
    • BCB-Forum
Re: [solved] error OnPlayerDamage
« Reply #8 on: April 22, 2013, 07:54:01 am »
thanks alot, Silnikos  :)

I hope im out of questions now for a while^^
BCB-Clan Page
You also can find clan BCB on our servers.

BCB-Soldier till i die!