Author Topic: Question Thread  (Read 33198 times)

0 Members and 1 Guest are viewing this topic.

DarkCrusade

  • Guest
Re: Question Thread
« Reply #240 on: June 06, 2010, 05:40:35 am »
Code: (Pascal) [Select]
const
  HK = 36;

Function OnPlayerDamage(Victim,Shooter:Byte; Damage:Integer):Integer;
var
  Tmp:Integer; 
  begin
    case GetPlayerStat(Shooter,'Primary') of
      [...]
      2: begin
    Tmp := Round(Result * (100 - HK) / 100);
    if Tmp + GetPlayerStat(Shooter,'Health') < 150 then begin
  DoDamage(Shooter,-Tmp);
end else DoDamage(Shooter,GetPlayerStat(Shooter,'Health') - 150);
  end;
      [...]
    end;
  end;

Somehow this seems to cause the script I'm working on to crash after some time and I can't see any problems here..

EDIT: After I saw my post I acknowledged a possible cause why the forums' built-in syntax highlighting sometimes connects pieces of code. In this code I didn't use any tabs, could it be that?
« Last Edit: June 06, 2010, 05:42:24 am by DarkCrusade »

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Question Thread
« Reply #241 on: June 06, 2010, 06:38:04 am »
how does it crash? And why are you so sure it's this exact piece of code that's doing it?

DarkCrusade

  • Guest
Re: Question Thread
« Reply #242 on: June 06, 2010, 07:20:09 am »
I took it out for a test and the server didn't crash. What's so weird is that there the server just shuts down. There is nothing special in the log ...

EDIT: Got a log:

Code: [Select]
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13 [*] Too many script errors! Shutting down server -> "RandomWar"
10-06-06 17:52:13  [*] [Error] RandomWar -> (OnPlayerDamage): Exception: Access violation at address 00413D89 in module 'soldatserver.exe'. Read of address 015ABA8C
10-06-06 17:52:13 [*] Too many script errors! Shutting down server -> "RandomWar"

Keeps repeating until it crashed. I just attached the script now.. involved weapons were Ruger and HK.
« Last Edit: June 06, 2010, 10:55:31 am by DarkCrusade »

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Question Thread
« Reply #243 on: June 06, 2010, 01:34:50 pm »
try changing line 88 to
Code: (pascal) [Select]
    if GetPlayerStat(Yah, 'Active') = true then begin
Edit: line 74 to
Code: (pascal) [Select]
  Player: Array [0..32] of Stats;

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Question Thread
« Reply #244 on: June 06, 2010, 02:11:35 pm »
Dude, it's pretty much terrible to keep looking at those GetPieces().

Use "Var First, Second, Third" For "GetPieces(..0), 1 and 2".

@Dnmr, Array[0..32] ? Why would you use ID 0 ? Oo
www.soldatx.com.br - The brazilian Soldat community.

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Question Thread
« Reply #245 on: June 06, 2010, 02:29:17 pm »
@Dnmr, Array[0..32] ? Why would you use ID 0 ? Oo
ask the scriptcore why it like accessing the 0'th elements of arrays, i can only tell you it does that sometimes. And that leads to access violations all right (with different results on different systems)

Edit: ofc im not trying to say this will definitely solve the problem, i'm just saying i've had troubles with a similar case. And i haven't studied the code thoroughly, just went through it quickly, so someone else might find something more broken ::)
« Last Edit: June 06, 2010, 02:31:47 pm by dnmr »

Offline Serial K!ller

  • Camper
  • ***
  • Posts: 408
    • Soldat Mods Archive
Re: Question Thread
« Reply #246 on: June 06, 2010, 02:50:48 pm »
Might be a loop created by the dodamage inside the onplayerdamage().
The dodamage invokes a new onplayerdamage() which then does a new dodamage calling another onplayerdamage() and so on until it crashes

should try making a check so an onplayerdamage() started from the dodamage() can't do a dodamage.

DarkCrusade

  • Guest
Re: Question Thread
« Reply #247 on: June 06, 2010, 03:36:10 pm »
@Squiddy: I changed the part for you
@Dnmr: Changed what you've mentioned
@Serial: Sounds reasonable, I'll give it a serious try :)

EDIT: I attached the updated script. Although I did what SK suggested the server crashes as soon as I hit an enemy with a HK bullet. If only the new Soldat version was out.. I'd be able to use M2 bullets via CreateBullet() to heal a specific amount of health :3

« Last Edit: June 06, 2010, 03:47:05 pm by DarkCrusade »

Offline Serial K!ller

  • Camper
  • ***
  • Posts: 408
    • Soldat Mods Archive
Re: Question Thread
« Reply #248 on: June 06, 2010, 04:28:17 pm »
Tried it and it also crashed with me but when I commented the dodamage calls in onplayerdamage() there where no problems.

My guess is that the scriptcore doesn't like recursion, you could try storing the actions in an array or something and do them in AppOnIdle()

In 2.7.0 you can use the SetPlayerStat(ID,'health',value); function that doesn't call onplayerdamage() and so no recursion issues.
« Last Edit: June 06, 2010, 04:38:31 pm by Serial K!ller »

DarkCrusade

  • Guest
Re: Question Thread
« Reply #249 on: June 07, 2010, 05:05:53 am »
That worked out great, but I wonder how Avarax coded Vampirism (a skill in Hexer that does the same as the HK does in RandomWar) since you directly gain health..

How do I detect a kill by a grenade?

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Question Thread
« Reply #250 on: June 07, 2010, 06:04:33 am »
Pass the damage from onplayerdamage to dovamp():
Code: [Select]
procedure DoVamp(ID: byte; Damage: integer);
var heal: integer;
begin
heal := round((damage*0.4)+0.6);
dodamage(ID,-heal);
end;

How do I detect a kill by a grenade?
You dont, not until 1.5.1 anyway...


DarkCrusade

  • Guest
Re: Question Thread
« Reply #251 on: June 07, 2010, 06:23:45 am »
I tried that, HackTank, just the way you suggested to do it, but either I messed something up or it's not working properly because the server crashes again.

Script attached :3 (important lines: 277,492)

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Question Thread
« Reply #252 on: June 07, 2010, 07:00:03 am »
Are you using the beta server version? Does it crash on compile or during runtime?

I would think there would be extreme integer rounding because of integer math in your heal calculation, if there is (not sure if pascal does it this way, but in cpp it would be important) you need to replace the heal calculations with this:
Heal := Round(base * (100.0 - HK) / 100.0);

If you are running the beta version then the dodamage needs to be dodamage(target,target,-heal); If its runtime, it is due to an infanite loop, add an "if shooter <> victim" check before your case call.


Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Question Thread
« Reply #253 on: June 07, 2010, 07:13:59 am »
How do I detect a kill by a grenade?
You dont, not until 1.5.1 anyway...
You can:
Code: [Select]
if Weapon = 'Grenage' then
  WriteConsole(0, 'It was a grenade \o/', color);

DarkCrusade

  • Guest
Re: Question Thread
« Reply #254 on: June 07, 2010, 08:41:16 am »
@HackTank: Works after adding Victim <> Shooter, thank you :)
@Swompie: Didn't know that that's possible.. lol

EDIT:

Code: (pascal) [Select]
Procedure OnPlayerKill(Killer,Victim:Byte; Weapon:String);
  begin
    if Killer <> Victim then
      case LowerCase(Weapon) of
    m79: if Random(1,101) <= M79 then Explosion(Victim,Killer);
    minimi: if Random(1,101) <= Minimi then GiveRoundsBack(Killer,50);
    minigun: if Random(1,101) <= Minigun then begin
      GiveRoundsBack(Killer,MinigunR);
      GiveBonus(Killer,5);
    end;
    flamer: if Random(1,101) <= Flamer then SetEnemiesOnFire(Killer);
    knife: if Random(1,101) <= Knife then ForceNewKnife(Killer);
    chainsaw: if Random(1,101) <= Chainsaw then begin
      RestoreHealth(Killer,150);
  GiveVest(Killer);
    end;
    law: if Random(1,101) <= LAW then ShootNextEnemy(Killer);
grenade: if Random(1,101) <= Grenade then
  end; 
  end;

Code: [Select]
10-06-07 17:04:50  [*] RandomWar -> [Error] (488:3): Unknown identifier 'grenade'
« Last Edit: June 07, 2010, 10:06:36 am by DarkCrusade »

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Question Thread
« Reply #255 on: June 07, 2010, 10:39:52 am »
(hint: weapon var is a string)

DarkCrusade

  • Guest
Re: Question Thread
« Reply #256 on: June 07, 2010, 10:45:26 am »
Referring to my own dumbness (thanks, Swomp): Kids out there please listen, don't do alcohol nor terrorcore :3

EDIT: I'm working on some kind of AntiCheat script (currently working against TeleHacks,MassFlag and .. too high ping). I use a .ini to make changes to the settings easier for users, but it fails badly. I put the .ini into the main server directory and always get the exception message that'll load the default settings either..
« Last Edit: June 07, 2010, 01:36:31 pm by DarkCrusade »

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Question Thread
« Reply #257 on: June 07, 2010, 02:46:25 pm »
about HP leech - just make sure it doesnt activate if shooter = victim, otherwise you'll obviously end up in an endless loop (as SK already pointed out). There is no greater trick to it than that.

And thing about config files - they just bring more useless pain imo. Just declare the settings as consts in your script, it's as easy to modify as an .ini file. Unless, of course, you just want to practice handling files in such a widely used scripting language ._.

DarkCrusade

  • Guest
Re: Question Thread
« Reply #258 on: June 07, 2010, 02:56:58 pm »
I'd like to use the .ini actually

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Question Thread
« Reply #259 on: June 07, 2010, 07:13:01 pm »
Sorry for not being able to help you, DC, but I was quite busy. Anyways, seems you've got some amazing help anyway :D

For reading .INI files, use ReadINI(). There is a section for that on the Enesce manual.

It's good that you are able to interact with .INI files, buuut it should be easier, if not too many stuff, to just put that into the Constants, on the Script itself.

Although, if you have many stuff for many different stuff, then an .INI should be the best option, anyway.

Hope I've been helpfull.

Any other questions, feel free to ask us. Cya later :)

Edit.. I took a look at the Script.. Try this:

Code: (pascal) [Select]
Var SettFile: String;
 Begin
  SettFile := 'YourDirectoryHere.ini';
   if FileExists(SettFile) Then Begin
Try
    StuffYouWantToLoad1 := StrToInt(ReadINI(SettFile,'Section','Max_Ping','');
     StuffYouWantToLoad2 := StrToInt(ReadINI(SettFile,'Section','Squiddo','');
Except
   WriteLn('Error ocurred while trying to load settings');
  end;
 end else WriteLn('File doesnt exists!');
end;

//Or something like that.
//I cant help much right now, 'coz I'm on my sister's laptop, and I don't got much time.. :P
//Later I can post an easier way to help you out.
« Last Edit: June 07, 2010, 07:22:27 pm by squiddy »
www.soldatx.com.br - The brazilian Soldat community.