Author Topic: Question Thread  (Read 29214 times)

0 Members and 1 Guest are viewing this topic.

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Question Thread
« Reply #60 on: April 09, 2010, 02:49:26 pm »
You need ( ) because it does it this way atm:
1. Text = '!help' => boolean1
2. boolean1 OR Text => boolean or string operation => failure

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Question Thread
« Reply #61 on: April 09, 2010, 02:49:36 pm »
The brackets weren't wrong.
Code: [Select]
if Text = '!help' then begin
if (Text = '!help') then begin
Both of these ways work.



Example for or, Here you need brackets!
Code: [Select]
if (Text = '!help') or (Text = '!Help') then beginThat's how you go, however heres a better solution:
Code: [Select]
if LowerCase(Text) = '!help' then beginNo matter how a player wrote !help, will it be !HeLp or !helP, it will be always executed.

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Question Thread
« Reply #62 on: April 09, 2010, 02:53:05 pm »
you were missing begin and end; in the last post, that's what PIE fixed

DarkCrusade

  • Guest
Re: Question Thread
« Reply #63 on: April 09, 2010, 03:33:01 pm »
type:
Code: [Select]
// Declare the type
type
   TPlayer = Record
     Task: byte; // I used task instead of Class because Class is a reserved word :/
   end;

// Now create an array, one index slot for each player
var
   Player: Array [1..32] of TPlayer;

// Looks like that when you use it:
procedure SetTask(ID, Task: byte);
begin
  Player[ID].Task := Task;
end;

Now I only need to know what the hell you did there and how I can use it.

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Question Thread
« Reply #64 on: April 09, 2010, 03:38:23 pm »
You don't need types as a beginner...

DarkCrusade

  • Guest
Re: Question Thread
« Reply #65 on: April 10, 2010, 02:39:39 am »
That didn´t help me much, Gizd.

I want to have different classes for different people.

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: Question Thread
« Reply #66 on: April 10, 2010, 03:41:38 am »
Code: (pascal) [Select]
// Declare the type
type // Use the type keyword so the compiler knows we are defining a type
   TPlayer = Record // Tell the compiler the name of the type and what type the type will be (in this case, record)
     Task: byte; // Write a list of variables to go with that type
     Var2: string;
   end; // end type decleration

// Now create an array, one index slot for each player
var
   Player: Array [1..32] of TPlayer;

// Looks like that when you use it:
procedure SetTask(ID, Task: byte);
begin
  Player[ID].Task := Task;
end;

Types are basically a way to re-use groups of variables, a type is itself used like a variable, with several sub-variables assigned to it.
In the example, the type is called TPlayer (T for type, and then the name of the variable it will be used on is a convention) and its sub-variables are Task and Var2.

What this means is that any variable that is of type TPlayer will have the sub-variables Task and Var2 assigned to it.

They can be accessed by dot notation, as shown in the line
Code: (pascal) [Select]
TypedVar.SubVar
When used with arrays, make sure you treat the variable and the []'s as one, i.e TypedArray[index].SubVar, not TypedArray.[index]SubVar, or any other wierd ideas you may get.

So for example Types would be extremely useful if you had to manage several of the same variables for every player in a server
Code: (pascal) [Select]
Type
  TPlayer = record
    Level: Byte;
    LoggedIn: boolean;
    Account: string;
    Skills: string;
    Power: Byte;
    EXP: integer;
  end;

var
  Player: Array [1..32] of TPlayer

Information for each player can be accessed in a standard way
Code: (pascal) [Select]
Player[12].Level
Player[3].LoggedIn
Player[7].Skills
« Last Edit: April 10, 2010, 03:43:20 am by chutem »
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

DarkCrusade

  • Guest
Re: Question Thread
« Reply #67 on: April 10, 2010, 04:26:47 am »
Okay I went on and used the type function (which I didn´t find at this awesome webpage btw). I use some kind of AppOnIdle function combined with a timer that will force a knife to ones hand if they have a certain class. Still, I got some problems that could need explanations ...

The whole script (with line comments so it´s easier to read) is attached. For those who don´t like downloading here is a piece of my script:

Code: [Select]
procedure AppOnIdle(Ticks: Integer);
if (TPlayer.Klasse = Berserker) then begin
var
Timer: Integer;
Timer = 10;
if Timer > 0 then Timer := Timer -1
if Timer = 0 then begin
ForceWeapon(Player, 14, 255, 0);
        Timer := 10;
end;
end;

14= Knife, 255= Fist, 0=default ammo. Before I used ...

Code: [Select]
type
TPlayer = Record
Klasse: byte;
end;

// Here I create an array for every player.
var
Player: Array [1..32] of TPlayer;

// This saves the players class in the variable Klasse

procedure SetKlasse(ID, Klasse: byte);
begin
Player[ID].Klasse := Klasse;
end;           
« Last Edit: April 10, 2010, 04:28:18 am by DarkCrusade »

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: Question Thread
« Reply #68 on: April 10, 2010, 04:37:31 am »
Type is a core component of the language of pascal.

It is like saying I don't see 'end;' documented at enesce.com/help

Did you mean to make a const called beserker (with a number from 1 to 255)? If you did, you forgot it, if you didn't, you cant assign a string to a byte, and it wasn't a string anyway (no quotes).
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

DarkCrusade

  • Guest
Re: Question Thread
« Reply #69 on: April 10, 2010, 06:34:29 am »
Okay I changed Klasse from byte to string, but now it returns me this:

Code: [Select]
10-04-10 13:32:39  [*] Compiling Knife Server -> KnifeServer.pas...
10-04-10 13:32:39  [*] Knife Server -> [Error] (23:29): Type mismatch
10-04-10 13:32:39  [*] Compilation Failed.
10-04-10 13:32:39 Shutting down server...

Sorry, I really want to finish this project and I can´t wait :P

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: Question Thread
« Reply #70 on: April 10, 2010, 06:44:05 am »
You need to change all other references to Klasse to string aswell.
Such as "procedure SetKlasse(ID, Klasse: byte);" -> "procedure SetKlasse(ID: byte;Klasse: string);"

You also need to change the "TPlayer.Klasse = Berserker;" line (under "!berserker") to "SetKlasse(ID,'Berserker');"

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Question Thread
« Reply #71 on: April 10, 2010, 08:01:05 am »
Upload your script again, then I'm gonna help you abit :]

DarkCrusade

  • Guest
Re: Question Thread
« Reply #72 on: April 10, 2010, 09:23:58 am »
Reupload. Changed the things EnEsCe mentioned but not more yet

The error changed a bit. Now it´s ...

Code: [Select]
10-04-10 16:21:12  [*] Compiling Knife Server -> KnifeServer.pas...
10-04-10 16:21:12  [*] Knife Server -> [Error] (23:11): Type mismatch
10-04-10 16:21:12  [*] Compilation Failed.
10-04-10 16:21:12 Shutting down server...

Offline mich1103

  • Flagrunner
  • ****
  • Posts: 557
  • Did you say chocolate ? O.o
    • ZoMbIe-DeStRoYeR pk server
Re: Question Thread
« Reply #73 on: April 10, 2010, 09:34:37 am »
What mean that ?
if Timer > 0 then Timer := Timer -1

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Question Thread
« Reply #74 on: April 10, 2010, 09:55:06 am »
What mean that ?
if Timer > 0 then Timer := Timer -1
It's a timer, can't you see that  ::)
Btw. you are missing a semicolon here (;)



Code: [Select]
procedure SetKlasse(ID, Klasse: String);
begin
Player[ID].Klasse := Klasse;
end;

Code: [Select]
procedure SetKlasse(ID: byte; Klasse: string);That's correct, ID must be declared as a numeric parameter value.
(It would also work with integer/word, but since eC has byte too in all the other build-in things ppl use byte)
« Last Edit: April 10, 2010, 10:00:29 am by Swompie »

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Question Thread
« Reply #75 on: April 10, 2010, 09:58:54 am »
Hey DC! I'm not sure if you remember me, but anway, I'm gonna help ya :D

Check out the comments in the Script lines.

Hope I've helped :]

Code: [Select]
//Helping DarkCrusade..
//By Squiddy ~


//Note I didn't add any stuff in the OnPlayerSpeak Procedure, because I'm only helping you in the Berserker stuff. You can handle the commands and rules stuff ;]


Const //Setting some Global Constants..
 Color = $FEDEBA; //Color to be used. This is my private color. Change it if you want :P
 
 
 Var //Setting some Global Variants..
  Klasse: Array[1..32] of String; //With this, you don't need the Type Record stuff. Usage: "Klasse[ID]"
 
 

Procedure OnPlayerSpeak(ID: Byte; Text: String);
 Begin //Starts the Procedure..
  Text := LowerCase(Text); //With this, you don't need to add "if Lowercase(Text) = '!berserker'". "Text := LowerCase(Text);" works for every text typed inside the OnPlayerSpeak Procedure.
   if Text = '!berserker' Then Begin //If player types !Berserker..
   WriteConsole(ID,'You are now a freaking berserker!',Color); //Then show this message to him.
  Klasse[ID] := 'Berserker'; //Set his class to berserker..
 end; //Ending the text function..
end; //Ending the procedure.

Procedure AppOnIdle(Ticks: Integer);
 Var DC: Byte; //DC is a player's ID. Since AppOnIdle doesn't hold any ID, we have to create one. I used DC because of "DarkCrusade". It's a teaching proccess, it's very helpfull to use the student's initials. It helps student to assimilate stuff.
  Begin
   For DC := 1 To 32 Do if GetPlayerStat(DC,'Alive') = True Then Begin //"1 To 32" is to determine that DC is a player's ID. GetPlayerStat() stuff is to see if player is alive.
    if Klasse[DC] = 'Berserker' Then Begin //Checks if his class is berserker..
    if Ticks Mod 60 * 10 = 0 Then //Every 10 seconds...
   ForceWeapon(DC,14,255,0); //The player receives a knife.
  end; //Ending the Klasse Function..
 end; //Ending the DC function..
end; //Ending the Procedure.
www.soldatx.com.br - The brazilian Soldat community.

DarkCrusade

  • Guest
Re: Question Thread
« Reply #76 on: April 10, 2010, 10:41:02 am »
Sure I remember you, Squiddy, great time back then :) Thanks a lot for your help, now my script works perfectly and I even understood all the new stuff!

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Question Thread
« Reply #77 on: April 10, 2010, 10:43:03 am »
Sure I remember you, Squiddy, great time back then :) Thanks a lot for your help, now my script works perfectly and I even understood all the new stuff!

Glad I could help :]

Any other doubts, feel free to ask.
www.soldatx.com.br - The brazilian Soldat community.

DarkCrusade

  • Guest
Re: Question Thread
« Reply #78 on: April 10, 2010, 10:54:45 am »
Well ... first of all: I get one knife every second and not every 10 seconds. I tried modifying the `Ticks Mod´ but it doesn´t change anything. Second: I tried killing a bot by throwing the knife but I wasn´t even able to kill myself. Stabbing works ... guess it´s caused by lags or stuff.

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Question Thread
« Reply #79 on: April 10, 2010, 11:10:05 am »
About the Damage stuff.. Add this to the Script:

Code: [Select]
Function OnPlayerDamage(Victim, Shooter: Byte; Damage: Integer): Integer;
 Var DC: Integer; //DC is the ammount of damage that will be increased..
  Begin //Starts..
   if Klasse[Shooter] = 'Berserker' Then Begin //Checks is player's class is Berserker..
   DC := Random(10,150); //Sets an value to DC to be added to the damage. It can be from 10 to 149.
  Result := Damage + DC; //Adds DC to Damage..
 end else Result := Damage; //Ending the Klasse Function. If Shooter's class isn't Berserker, the damage dealt will be the same.
end; //Ending the Function.

About the 10 Second stuff, try to replace this to the AppOnIdle Procedure:

Code: [Select]
Procedure AppOnIdle(Ticks: Integer);
 Var DC: Byte; //DC is a player's ID. Since AppOnIdle doesn't hold any ID, we have to create one. I used DC because of "DarkCrusade". It's a teaching proccess, it's very helpfull to use the student's initials. It helps student to assimilate stuff.
  Begin
   For DC := 1 To 32 Do if GetPlayerStat(DC,'Alive') = True Then Begin //"1 To 32" is to determine that DC is a player's ID. GetPlayerStat() stuff is to see if player is alive.
    if Klasse[DC] = 'Berserker' Then Begin //Checks if his class is berserker..
    if Ticks Mod (60 * 10) = 0 Then //Every 10 seconds...
   ForceWeapon(DC,14,255,0); //The player receives a knife.
  end; //Ending the Klasse Function..
 end; //Ending the DC function..
end; //Ending the Procedure.

Hope that helps/works. :]

If you have any doubts on how "else" works, it simply works like this:

Code: [Select]
Function OnPlayerDamage();
 Begin //Starts..
  if Klasse[Shooter] = 'Berserker' Then Begin //Checks is Shooter's class is Berserker
   WriteConsole(Shooter,'You are a Berserker',$FFFFFF); //Send this message if Klasse[Shooter] is Berserker.
  end else WriteConsole(Shooter,'You are so not a Berserker',$FFFFFF); //If Klasse[Shooter] isnt Berserker, send this.
end; //Ending the Function..
« Last Edit: April 10, 2010, 11:15:02 am by squiddy »
www.soldatx.com.br - The brazilian Soldat community.