Author Topic: Question Thread  (Read 26862 times)

0 Members and 1 Guest are viewing this topic.

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: Question Thread
« Reply #20 on: March 31, 2010, 11:48:12 pm »
Code: [Select]
function OnPlayerDamage(Victim,Shooter: Byte;Damage: Integer) : integer;
begin
result := damage;
if (damage>0) AND (damage<3000) AND (shooter<>victim) then begin
result := damage * (150.0/desiredmaxhealth);
end;
end;


DarkCrusade

  • Guest
Re: Question Thread
« Reply #21 on: April 03, 2010, 03:26:00 pm »
Hm, I tried compiling your script a day ago and got an error that I am not able to fix by myself. 



I messed a bit with it for some time but got no positive results.

Code: [Select]
function OnPlayerDamage(Victim,Shooter: Byte;Damage: Integer;) : Integer;
 begin
 result := damage;
if (damage>0) AND (damage<3000) AND (shooter<>victim) then begin
result := damage * (150.0/desiredmaxhealth);
end;
end;

// desiredmaxhealth,300 : Integer;
// desiredmaxhealth: Integer;


I tried declaring desiredmaxhealth as a variable and stuff the way I know it from Java and afterwards tried declaring it like the variables you declared in OnPlayerDamage(...); but that didn´t work either so now I really need help. I didn´t get the other scripts working, too, so ...

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Question Thread
« Reply #22 on: April 03, 2010, 07:36:07 pm »
You only need ; to separate the arguments of a function, the last one is not needed.
In other words remove ; after Damage: Integer
Come join: EliteCTF
Listen to: My Music

DarkCrusade

  • Guest
Re: Question Thread
« Reply #23 on: April 03, 2010, 09:14:37 pm »
Thanks JFK, that was one bug. But another one occured that I was able to find by the super-special bugfinding tactic that I use in Java (take out lines to see whether something changes).

Code: [Select]
function OnPlayerDamage(Victim,Shooter: Byte;Damage: Integer) : Integer;
 begin
 result := damage;
if (damage>0) AND (damage<3000) AND (shooter<>victim) then begin
result := damage * (150.0/desiredmaxhealth);                          // THIS LINE CAUSES THE ERROR
end;
end;

Offline croat1gamer

  • Veteran
  • *****
  • Posts: 1327
  • OMG CHANGING AVATAR!!! ^ω^
Re: Question Thread
« Reply #24 on: April 03, 2010, 09:20:11 pm »
Did you specify the desiredmaxhealth before the first begin as a const?

Something like this:
Code: [Select]
function OnPlayerDamage(Victim,Shooter: Byte;Damage: Integer) : Integer;
const
desiredmaxhealth= *THIS BE EDITED TO VALUE YOU WANT*;
 begin
 result := damage;
if (damage>0) AND (damage<3000) AND (shooter<>victim) then begin
result := round(damage * (150.0/desiredmaxhealth));                         
end;
end;
« Last Edit: April 03, 2010, 09:23:27 pm by croat1gamer »
Last year, I dreamt I was pissing at a restroom, but I missed the urinal and my penis exploded.

DarkCrusade

  • Guest
Re: Question Thread
« Reply #25 on: April 03, 2010, 10:41:38 pm »
Hell my script looked exactly like yours, croat, I just forgot I need to declare variables via "const" ... Thanks for reminding me.

EDIT:

Code: [Select]
procedure OnAdminMessage(IP, Msg: String);
begin
  if (Msg='/say') then begin
  procedure WriteLn(Output: String);
  Output='/say #################';
  end;
end;
 

This is my latest project. To make admin messages more visable I want the script to add a line of charakters that highlight the admin messages so that even totally focussed players will be seeing those messages that may be important for them.
The compilation fails: Admin Text -> [ERROR] (5:3): Identifier expected.
And I really don´t know what could have caused this problem that has occured before. I hope it´s no general problem ... I checked my settings already.

EDIT#2:

I am also working on a script that adds a bot as spectator who comments the happenings at the server. I´m getting the error, that a ´;´ is expected in (3:3).

Code: [Select]
// When the server starts for the first time a bot should be added as a spectator. He will comment the game/////////
procedure ActivateServer()                                                                                     
    begin
        Command ('/addbot5 Spectator');
    end;    
end;
// If a flag is stolen the spectator bot writes the comment below. He has ID #1, because he join OnServerStart /////
procedure OnFlagGrab(ID, TeamFlag: byte;GrabbedInBase: boolean)
begin
    procedure BotChat(ID:Byte;Text:string)
    begin
            BotChat(1,'Players keeps sake! Flag has been taken!')
        end;
    end;
end;


I will hopefully be able to add more functions to this script as it is the most important one for me right now. It´s not so hard to add more but I want to keep it as simple as possible right now so I don´t need to look through a giant script that I need to understand again first.







« Last Edit: April 04, 2010, 12:57:14 am by DarkCrusade »

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Question Thread
« Reply #26 on: April 04, 2010, 02:13:32 am »
Code: [Select]
procedure OnAdminMessage(IP, Msg: String);
begin
  if Copy(Msg, 1, 4)='/say' then
    WriteConsole(0, '#################', $FFFF00);
end;

Code: [Select]
var BotID: byte;

procedure ActivateServer();
var a: byte;                                                                               
begin
  a := NameToID('Spectator');
  if a > 0 then KickPlayer(a);
  botID := Command('/addbot5 Spectator'); 
end;

procedure OnFlagGrab(ID, TeamFlag: byte;GrabbedInBase: boolean);
begin
      BotChat(BotID,'Players keeps sake! Flag has been taken!');
end;

Untested
« Last Edit: April 04, 2010, 02:20:07 am by tk »

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: Question Thread
« Reply #27 on: April 04, 2010, 02:24:27 am »
First one: You uses Output=, pascal uses := to set values to variables.
Second one: You are forgetting your ;'s after procedure declerations, also BotChat is a built in function, yes? - you don't need to declare it. On a similar note, not sure if you can declare a procedure within a procedure in pascal, but calling the procedure BotChat (which you don't need to declare) will create an infinite loop until the script crashes.
Therefore just remove the red lines: (remember to fix what's left, though)
Quote
procedure OnFlagGrab(ID, TeamFlag: byte;GrabbedInBase: boolean)
begin
    procedure BotChat(ID:Byte;Text:string)
       begin

            BotChat(1,'Players keeps sake! Flag has been taken!')
        end;
    end;

end;

Also need to watch your begin-end pairs, there is an extra end; in there, see if you can find it.

Oh and damn you tk you replied while i was previewing my BB code, but I think this will help so I'm leaving it, plus it took me more than a minute to write.

And one final note: DarkCrusade, your apostrophe's are annoying me, you may not have noticed, but spot the difference:

apostrophe'd word
apostrophe´d word 2

Yeah it's a minor niggle, but I have been noticing it for ages  :|
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

DarkCrusade

  • Guest
Re: Question Thread
« Reply #28 on: April 04, 2010, 02:43:03 am »
Thanks for your advice!

!= means "is not". right? But how can I compare one variable to another and return a boolean? And which apostrophe´s shall I use? Do I get errors for using the wrong one?

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Question Thread
« Reply #29 on: April 04, 2010, 02:49:21 am »
no, in pascal it's <>

BooleanResult := Value1 = Value2;
if they are equal, the result will be true.

DarkCrusade

  • Guest
Re: Question Thread
« Reply #30 on: April 04, 2010, 03:52:33 am »
Code: [Select]
procedure ActivateServer();
  begin
       Command ('/addbot5 Spectator');
  end;    
procedure OnFlagReturn(ID, TeamFlag: byte);
  begin
       BotChat(1,'Flag returned!');
  end;
procedure OnFlagDrop(ID, TeamFlag: byte);
  begin
       BotChat(1,'Flag got lost!');
  end;    
       

//procedure OnFlagGrab(ID, TeamFlag: byte;GrabbedInBase: boolean);
//  if(GrabbedInBase := 1) begin
//       BotChat(1,'Players keeps sake! Flag has been taken!');
//  end;
 
 
//function OnPlayerCommand(ID: Byte; Text: string): boolean;
//  if (Text:='/kill') OR (Text:= '/brutalkill') then begin
//       BotChat(1,'Don´t you dare to suicide again!')
//    Command('/kill ' + ID); 


//procedure OnFlagScore(ID, TeamFlag: byte);
//  begin
//       BotChat(1,'One score, one point!'); 
//  end;

As you can see I worked more on my script and the lines that aren´t cut out don´t return any errors except that they don´t work at my home hosted server. For OnFlagScore and OnFlagGrab it returns the error that it expects a "begin" somewhere ...

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Question Thread
« Reply #31 on: April 04, 2010, 04:39:04 am »
OnFlagReturn and OnFlagDrop aren't supported by the current server version, use v265.

Code: (pascal) [Select]
procedure OnFlagGrab(ID, TeamFlag: byte; GrabbedInBase: boolean);
begin
  if GrabbedInBase then
    BotChat(1, 'Players keeps sake! Flag has been taken!');
end;
Note: You always need an begin after you declare an procedure/function, and don't forget to add an end;

Some examples on boolean: (May helps)
Code: (pascal) [Select]
procedure BooleanTest;
var Bool: boolean;
begin
  Bool := true; // Set to false an it'll output 2 times "Bool is false"

  if Bool then WriteLn('Bool is true!');
  if not Bool then WriteLn('Bool is false!');
  if Bool = false then WriteLn('Bool is false!');
  if Bool = true then WriteLn('Bool is true!');

end;
But you should go with the first two methods, most don't like the last two since it's really useless text.
I'm not sure about if = 1 or = 0 works too, but I think it does. And like the two examples above it's unnecessary text.

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Question Thread
« Reply #32 on: April 04, 2010, 01:41:34 pm »
Code: [Select]
WriteLn('Bool is ' + iif(Bool,'true','false') + '!');\o/

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Question Thread
« Reply #33 on: April 04, 2010, 02:00:34 pm »
Gizd Gizd Gizd!! I tried to explain him the ways he can check if a bool is true/false.
Anyway thats too one xD

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: Question Thread
« Reply #34 on: April 04, 2010, 03:56:39 pm »
You are messing up your operators.

In this line
Code: [Select]
if(GrabbedInBase := 1) begin
You are using the assignment operator (:=) instead of the equality operator (=)

Basically how I think of it, your line reads as 'if set GrabbedInBase to 1 is true then begin', which doesn' make much sense in english, so it _doesn't make much sense in code_ (not sure if it is like this in pascal, but assigning to a variable can return true/false whether it was successful/not).

The correct line would be
Code: [Select]
if(GrabbedInBase = 1) begin
Which would read as 'if GrabbednBase is equal to 1 then begin', which makes much more sense.
So if, as tk said, you used <>, it would read 'if GrabbedInBase is not equal to 1 then begin'

Btw, your apostrophes are not related to pascal, they just make your sentences with them look wierd.
« Last Edit: April 04, 2010, 04:02:00 pm by chutem »
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

DarkCrusade

  • Guest
Re: Question Thread
« Reply #35 on: April 05, 2010, 01:13:30 am »
Maybe I am rushing, maybe I´m not, but I try to create a bigger script for the knife server I have in mind. First of all I want to create a script that will tell players that join what kind of server they did join. For this I used ...

Code: [Select]
procedure OnJoinGame(ID,Team:Byte);
then begin
  WriteConsole(ID,'Text');
  WriteConsole(ID,'Text');
  WriteConsole(ID,'Text');
end;

But it returns the error, that in (4:3) it expects 'begin'. I tried seperating the lines with 'begin' and 'end;' but then I got the same error that I got with just 'begin' at the start, 'invalid number of parameters'.


Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: Question Thread
« Reply #36 on: April 05, 2010, 01:29:10 am »
Remove the 'then', it is confusing the compiler.
Are you trying to use the procedure as some kind of if statement?
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

DarkCrusade

  • Guest
Re: Question Thread
« Reply #37 on: April 05, 2010, 02:03:14 am »
No, I just want that every joining player gets this message. If I remove ´then´ I get the error that there is an invalid number of parameters like I stated already :S

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Question Thread
« Reply #38 on: April 05, 2010, 02:34:27 am »
http://enesce.com/help/index.html?Functions/WriteConsole.html
procedure WriteConsole(ID: Byte; Text: string; Colour: Longint)

DarkCrusade

  • Guest
Re: Question Thread
« Reply #39 on: April 05, 2010, 03:12:43 am »
So I tried

Code: [Select]
procedure OnJoinGame(ID,Team:byte);
then begin
      WriteConsole(ID,'Hello, this server is scripted.'; $FFFFFFFF);
      WriteConsole(ID,'You can choose out of 4 classes.'; $FFFFFFFF);
      WriteConsole(ID,'For further information type !help.'; $FFFFFFFF);
end; 

Code: [Select]
procedure OnJoinGame(ID,Team:byte);
begin
  procedure WriteConsole(ID:Byte;Text:String;Colour:Longint);
    then begin
      WriteConsole(ID,'Hello, this server is scripted.'; $FFFFFFFF);
      WriteConsole(ID,'You can choose out of 4 classes.'; $FFFFFFFF);
      WriteConsole(ID,'For further information type !help.'; $FFFFFFFF);
end; 
end;


And right now I can´t check the logs. It saves them without any text ...