Author Topic: Question Thread  (Read 32949 times)

0 Members and 1 Guest are viewing this topic.

DarkCrusade

  • Guest
Question Thread
« on: March 30, 2010, 09:36:25 am »
I just decided to learn scripting by myself since I have a lot of ideas for scripts that I´d like to code on my own. So I checked the existing threads and slowly get into it. But I have no idea what I need to do for this one:

(1)

I want to set the health of a player that scored for his team to 300. I began like

Code: [Select]
procedure OnFlagScore (ID, TeamFlag: byte )
begin
         
end;

But I am not sure how to go on. I know that the function that I need to use is "SetPlayerStat" but I guess I will need to save the ID of that player as an int before, but how? 


(2)

I know Java and HTML. Soldat scripting is totally new to me. Is it Pascal? And what is right? One or two:

#1:
Code: [Select]
thenbegin
#2:
Code: [Select]
then begin
« Last Edit: March 30, 2010, 09:40:00 am by DarkCrusade »

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Question Thread
« Reply #1 on: March 30, 2010, 10:52:45 am »
1 - The ID of the player is already given in that event as a byte. You can input a byte where an integer is expected, not the other way around though. Filling in ID for ID will (always) work.
Instead of setPlayerStat you can use getPlayerStat and DoDamage with negative value (if you're using old script core).

2 - Soldat scripting is based on pascal/delphi. Google "delphi something" usually works for me if I need to know something.
The begin-end syntax is used to identify code blocks. If...then reads a single line as statement by default, but instead you can use begin-end to make it execute multiple lines. A lot of commands in pascal expect single lines by default, so begin-end blocks are used for other things as well (for-loops, case statements, functions).

if..then single line:
Code: [Select]
if (i=0) then //set a condition, statement will follow
  WriteLn('i is zero!');
//more code outside of if..then statement, thus will always be executed:
WriteLn('Hello World!');

if.. then multiple lines:
Code: [Select]
if (i=0) then begin //set condition, statement until end
  //so all this code will only be executed if i is zero
  WriteLn('i is zero!');
  WriteLn('Hello World!');
end;
Come join: EliteCTF
Listen to: My Music

DarkCrusade

  • Guest
Re: Question Thread
« Reply #2 on: March 30, 2010, 11:22:31 am »
I am a little bit confused because of iDantes scripting tutorial (---). I copied his code (Part II) and tried running the server but I got this error message and I don´t know how to read and understand it ...



Also could you tell me whether my line comment is right?

Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;  // When a player uses a command the function starts
                                                                                   // and checks whether the condition is true or not
var i: integer;                              // declaration of the variable i of the type integer
begin                                         // start
  if Text = '/asplode' then begin      // condition for the function
  for i := 1 to 32 do begin              // check the player IDs?
  if GetPlayerStat(i, 'active') then Command('/kill '+inttostr(i));
                                               // If he´s active he gets killed (could you explain "inttostr(i)"?)
            end;
      end;
end;
« Last Edit: March 30, 2010, 11:25:09 am by DarkCrusade »

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Re: Question Thread
« Reply #3 on: March 30, 2010, 11:55:47 am »
IntToStr in Integer To String, because you execute a command and thats a string, but your i-variable is an integer.
The truth is out there? Does anyone know the URL?
The URL is here

Offline Silnikos

  • Soldier
  • **
  • Posts: 129
Re: Question Thread
« Reply #4 on: March 30, 2010, 03:10:28 pm »
Most answers for your questions can be found on soldat scripting tutorial: http://enesce.com/help/

Also, try reading some code of already done by someone else scripts to learn things.
« Last Edit: March 30, 2010, 03:16:34 pm by Silnikos »

DarkCrusade

  • Guest
Re: Question Thread
« Reply #5 on: March 30, 2010, 03:53:48 pm »
I already do that, but still some questions come up. Is the line comment right?

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Question Thread
« Reply #6 on: March 30, 2010, 06:24:10 pm »
The numbers in the error match (line+1:char), line+1 meaning that the first line in your script is line 2 in the compiler.
I don't see any problem with the syntax on line 5 or before that (comments seem ok), so I don't really understand why you get this message. You might want to re-check Includes.txt and maybe you could try different encoding for the files (utf-8 should always work i think).
Come join: EliteCTF
Listen to: My Music

DarkCrusade

  • Guest
Re: Question Thread
« Reply #7 on: March 30, 2010, 08:24:18 pm »
-What are the alternatives for "onscriptcrash = shutdown"?

I am still working on the script. I just don´t get what´s the problem and I already checked different encoding types for the files and I didn´t see any difference. However, I think the problem doesn´t lie in Includes.txt since the script shouldn´t be loaded if Includes.txt has some failures, or am I wrong?

For those who are interested: Script attached.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Question Thread
« Reply #8 on: March 30, 2010, 08:34:52 pm »
Permutations:
shutdown
disable
recompile


DarkCrusade

  • Guest
Re: Question Thread
« Reply #9 on: March 30, 2010, 08:44:00 pm »
Okay, I worked on the script that sets a players health to 300 after he scored for his team and the code is so simple that I am a bit embarrassed that I´m getting the error message that a ";" is expected in line 3 ...

Code: [Select]
procedure OnFlagScore (ID, TeamFlag: byte )
begin
    SetPlayerStat(ID, 'health', GetPlayerStat(ID, 'health') = 300);         
end;

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: Question Thread
« Reply #10 on: March 30, 2010, 10:04:54 pm »
Quote
procedure OnFlagScore (ID, TeamFlag: byte );
begin
    SetPlayerStat(ID, 'health', GetPlayerStat(ID, 'health') = 300);         
end;
Something I used to do too.
Haven't toyed around with scripting for ages, may be wrong, might as well try.
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Question Thread
« Reply #11 on: March 30, 2010, 11:20:06 pm »
Max HP is 200.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Question Thread
« Reply #12 on: March 30, 2010, 11:51:40 pm »
You need to scale the damage done using thier desired max health. Ill post an example onplayerdamage tomarrow if you want.


DarkCrusade

  • Guest
Re: Question Thread
« Reply #13 on: March 31, 2010, 02:32:01 am »
Okay, so I can get their health stat, substract it from 300 and add this amount of health?

@Chutem: I knew I´d miss something that trivial.

Offline ShadowDancer

  • Major(1)
  • Posts: 22
Re: Question Thread
« Reply #14 on: March 31, 2010, 02:44:29 am »
If you want set not standart hp, you must create type/global variable, that will hold player health.
In on player damage you substracting damage from value, not player health, and killing player if virtual hp is less than 0.

In other way(as hacktank said) you must scale damage, something like this:
Code: [Select]
Damage := (Damage * ((100 * Hp) div MaxHp)) div 100; //may not works, written on fastFirst way is better(IMO).
« Last Edit: March 31, 2010, 03:01:33 am by ShadowDancer »
Sorry, I'm not native English speaker...

Offline Mercury92

  • Camper
  • ***
  • Posts: 284
Re: Question Thread
« Reply #15 on: March 31, 2010, 03:48:35 am »
Permutations:
shutdown
disable
recompile
recompile doesn't work for me, never seen it recompiling.
[saw]  on 1.5.1

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Question Thread
« Reply #16 on: March 31, 2010, 05:04:34 am »
Max HP is 200.
Yus, very Important, you can not go over these 200HP without fake health.
But you should leave this for now since it's an more advanced part.

You can not use the SetPlayerStat() function, it's not supported by the current script core.

If you wanna set the health to the maximum use that:
Code: [Select]
DoDamage(ID, -200); //Heals them up to 200HP, w/e health they had before, if they're aliveNote: Negative Damage heals players.



Permutations:
shutdown
disable
recompile
recompile doesn't work for me, never seen it recompiling.
Same here, it displays some message ingame that the script crashed and is recompiling, but it isn't.

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Question Thread
« Reply #17 on: March 31, 2010, 06:39:36 am »
if you're not going to use modified health anywhere else, it's useless to make a whole custom health system imo. Just give a vest

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 558
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Question Thread
« Reply #18 on: March 31, 2010, 02:55:58 pm »
I have a question !
i use special bot by Gizd but how i put the weapon of the bot as fist
i've tried to put 255 but nothing ...

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Question Thread
« Reply #19 on: March 31, 2010, 03:05:18 pm »
I have a question !
i use special bot by Gizd but how i put the weapon of the bot as fist
i've tried to put 255 but nothing ...
Yes, the title looks like you can ask your questions here about scripting but it's not like that actually.
edit: Or is it?
« Last Edit: March 31, 2010, 04:03:51 pm by Gizd »