Author Topic: Writing my own "class" script!  (Read 3742 times)

0 Members and 1 Guest are viewing this topic.

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Writing my own "class" script!
« on: May 09, 2009, 05:52:03 pm »
Ok I study'ed the starter tips and came out with a start for my script...

Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin
if Text = '/class runner' then begin
WriteLn('Good luck as a Runner!');
end;
end;

First question: Is this (wee small) part of script WORKING. if I would export it?
(would it say "Good luck as a Runner!")

Second question: How can I get a player ID, and give them the following:
MP5, Knife and Vest.   

Code: [Select]
begin
    SpawnObject(GetPlayerStat(1,'x'),GetPlayerStat(1,'y'),19);
end;

This would spawn a Vest, But for player 1. HOW can I make it so that the player that says the /class runner. gets the item?
« Last Edit: May 09, 2009, 05:55:41 pm by D4NG3R NL »
                  Forum Rules   -   Search

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Writing my own "class" script!
« Reply #1 on: May 09, 2009, 06:01:03 pm »
WriteLn writes it to the server console. Use WriteConsole to write it to a player.

To give them an mp5 and a knife use ForceWeapon. To give them a vest use GiveBonus.

To give it to the player that says it just stick it in the if thingey.

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Re: Writing my own "class" script!
« Reply #2 on: May 09, 2009, 06:11:03 pm »
WriteLn writes it to the server console. Use WriteConsole to write it to a player.

To give them an mp5 and a knife use ForceWeapon. To give them a vest use GiveBonus.

To give it to the player that says it just stick it in the if thingey.

Aint "forceweapon" crashing in 1.5?

Weapons:
2 = MP5
12 = Knife
0 = Amount of ammo (0 is standard)

Bonus
3 = Vest


Weapon:
procedure ForceWeapon(ID, 2, 12, 0: Byte);
Bonus:
procedure GiveBonus(ID, 3: byte);

but HOW to put them into the script  ???

Im not that good with the pascal scripting yet :(, but Im learning quickly (as I didnt knew ANYTHING about it 60 mins ago!)
« Last Edit: May 09, 2009, 06:18:40 pm by D4NG3R NL »
                  Forum Rules   -   Search

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Writing my own "class" script!
« Reply #3 on: May 09, 2009, 06:23:11 pm »
Aint "forceweapon" crashing in 1.5?
Yep, but hopefully it'll get fixed sometime soon so we can continue to party with it.

Might as well show you how it's done:
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin
   if Text = '/class runner' then begin
      WriteConsole(ID, 'Good luck as a Runner!', $FFFFFF);
      ForceWeapon(ID, 2, 12, 0);
      GiveBonus(ID, 3);
   end;
end;
NOT tested

If you want some more examples of stuff then check out my guide.

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Re: Writing my own "class" script!
« Reply #4 on: May 09, 2009, 06:27:10 pm »
Aint "forceweapon" crashing in 1.5?
Yep, but hopefully it'll get fixed sometime soon so we can continue to party with it.

Might as well show you how it's done:
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin
   if Text = '/class runner' then begin
      WriteConsole(ID, 'Good luck as a Runner!', $FFFFFF);
      ForceWeapon(ID, 2, 12, 0);
      GiveBonus(ID, 3);
   end;
end;
NOT tested

If you want some more examples of stuff then check out my guide.

Thx :D

I could just change this to make other classes to :)?

function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin
   if Text = '/class heavy' then begin
      WriteConsole(ID, 'Good luck as a Heavy!', $FFFFFF);
      ForceWeapon(ID, 5, 13, 0);
      GiveBonus(ID, 2);
   end;
end;

This would give an AK-74 & Chainsaw instead of MP5 & Knife on the command /class heavy

Btw what is this
$FFFFFF,
Colour code?
                  Forum Rules   -   Search

Offline Snack

  • Soldier
  • **
  • Posts: 115
  • Ehm ;_;
Re: Writing my own "class" script!
« Reply #5 on: May 09, 2009, 06:28:27 pm »
Yes it's a colour code

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Writing my own "class" script!
« Reply #6 on: May 09, 2009, 06:34:33 pm »
They're both the same function:

Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin
   if Text = '/class runner' then begin
      WriteConsole(ID, 'Good luck as a Runner!', $FFFFFF);
      ForceWeapon(ID, 2, 12, 0);
      GiveBonus(ID, 3);
   end;
   if Text = '/class heavy' then begin
      WriteConsole(ID, 'Good luck as a Heavy!', $FFFFFF);
      ForceWeapon(ID, 5, 13, 0);
      GiveBonus(ID, 2);
   end;
end;

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Re: Writing my own "class" script!
« Reply #7 on: May 09, 2009, 06:53:00 pm »
Ok, I compiled the script & tested it out (I removed the forceweapon lines just to test). It will give packs of bonuses smoothly.
Now the problem is, I want to make the script in such manner that you can only take a class ONCE. (and cannot switch to a different one)
How to make the script check if someone already has a class?
+ If I wanted to make weapons undropable, How would I do this.
                  Forum Rules   -   Search

Offline Snack

  • Soldier
  • **
  • Posts: 115
  • Ehm ;_;
Re: Writing my own "class" script!
« Reply #8 on: May 09, 2009, 06:55:25 pm »
Probably by using a variable, I'm not sure

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Re: Writing my own "class" script!
« Reply #9 on: May 09, 2009, 07:19:43 pm »
Stuff to do:

Wait until ForceWeapon doesnt make soldat crash anymore (waiting for 1.5.1 xD)

Need to figure out how to limit the times you can pick a class to 1.

Need to figure out how to make weapons un-dropable.

Need to figure out how to place people in spectator mode WHERE THEY CANNOT LEAVE UNTIL THE NEXT ROUND STARTS!

Need to figure out how to make a timer, so the enemy's (zombies) will start spawning after 30 seconds :) to give you enough time to pick a class :D

Current pieces of script:

Info script:
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin;
if Text = '/runner info' then begin
      WriteConsole(ID, 'With the Runner class you get: MP5, Knife & 1 Vest kit!', $FFFFFF);
  WriteConsole(ID, 'Type /class runner to take the Runner class!', $808080);
end;
if Text = '/assault info' then begin
      WriteConsole(ID, 'With the Assault class you get: AK-74, Knife & 1 Cluster kit!', $FFFFFF);
      WriteConsole(ID, 'Type /class assault to take the Assault class!', $808080);
end;
    if Text = '/hunter info' then begin
      WriteConsole(ID, 'With the Hunter class you get: M82a1, USSOCOM & 1 Predator kit!', $FFFFFF);
      WriteConsole(ID, 'Type /class hunter to take the Hunter class!', $808080);
end;
    if Text = '/heavy info' then begin
      WriteConsole(ID, 'With the Heavy class you get: Spas-12, Chainsaw & 1 Berseker kit!', $FFFFFF);
      WriteConsole(ID, 'Type /class heavy to take the Heavy class!', $808080);
end;   
end;
Pickup script(I removed the forceweapon for a while)
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin;
   if Text = '/class runner' then begin
      WriteConsole(ID, 'Good luck as a Runner!', $FFFFFF);
      GiveBonus(ID, 3);
   end;
   if Text = '/class assault' then begin
      WriteConsole(ID, 'Good luck as a Assaulter!', $FFFFFF);
      GiveBonus(ID, 5);
   end;
    if Text = '/class hunter' then begin
      WriteConsole(ID, 'Good luck as a Hunter!', $FFFFFF);
      GiveBonus(ID, 1);
   end;
    if Text = '/class heavy' then begin
      WriteConsole(ID, 'Good luck as a Heavy!', $FFFFFF);
      GiveBonus(ID, 2);
   end;
end;

Pickup script with forceweapon
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin;
   if Text = '/class runner' then begin
      WriteConsole(ID, 'Good luck as a Runner!', $FFFFFF);
      ForceWeapon(ID, 2, 12, 0);
      GiveBonus(ID, 3);
   end;
   if Text = '/class assault' then begin
      WriteConsole(ID, 'Good luck as a Assaulter!', $FFFFFF);
      ForceWeapon(ID, 3, 12, 0);
      GiveBonus(ID, 5);
   end;
    if Text = '/class hunter!' then begin
      WriteConsole(ID, 'Good luck as a Hunter!', $FFFFFF);
      ForceWeapon(ID, 8, 11, 0);
      GiveBonus(ID, 1);
   end;
    if Text = '/class heavy' then begin
      WriteConsole(ID, 'Good luck as a Heavy!', $FFFFFF);
      ForceWeapon(ID, 5, 13, 0);
      GiveBonus(ID, 2);
   end;
end;
« Last Edit: May 09, 2009, 07:22:34 pm by D4NG3R NL »
                  Forum Rules   -   Search

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Writing my own "class" script!
« Reply #10 on: May 10, 2009, 03:27:51 am »
just store everyone's class in an array of 32 ints, set all the values to 0 on activateserver and onmapchange. Then if someone does /class - check if his value is zero, then he can choose a class (set the according array value to the ID of the class when he chooses a class too). I hope this made sense to you.

Also, you might want to use case here (http://www.learn-programming.za.net/programming_pascal_learn05.html)

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Writing my own "class" script!
« Reply #11 on: May 10, 2009, 09:07:35 am »
Btw what is this
$FFFFFF,
Colour code?

FIY, in this context it's used as a color code, but a $ actually means a number defined in hexadecimals. You can set any (integer like) variable with that. Read more here:
http://simple.wikipedia.org/wiki/Hexadecimal

And err.. good luck with the script, it seems quite a big challenge for a beginner like you ;)
Come join: EliteCTF
Listen to: My Music

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Re: Writing my own "class" script!
« Reply #12 on: May 10, 2009, 10:35:51 am »
And err.. good luck with the script, it seems quite a big challenge for a beginner like you ;)


Thats why I like doing it :D. IDC if it takes me a month, OR EVEN LONGER to create. I just want to make it :)
                  Forum Rules   -   Search

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Re: Writing my own "class" script!
« Reply #13 on: May 10, 2009, 12:19:16 pm »
just store everyone's class in an array of 32 ints, set all the values to 0 on activateserver and onmapchange. Then if someone does /class - check if his value is zero, then he can choose a class (set the according array value to the ID of the class when he chooses a class too). I hope this made sense to you.

Also, you might want to use case here (http://www.learn-programming.za.net/programming_pascal_learn05.html)

I don't really get that part, HOW do I make the script check if you already picked (any) class?

Code: [Select]
var
   i: Integer;
 
begin
   Readln(i);
   if i > 0 then
      WriteConsole('You already picked a class');
   else
      (WHAT TO PUT HERE?)
end.
This part should be OK
« Last Edit: May 10, 2009, 12:24:45 pm by D4NG3R NL »
                  Forum Rules   -   Search

Offline D4NG3R NL

  • Soldier
  • **
  • Posts: 130
  • You got Rickroll'd
Re: Writing my own "class" script!
« Reply #14 on: May 10, 2009, 12:43:45 pm »
   1 - Predator
   2 - Berserker
   3 - Bulletproof vest
   4 - Grenades
   5 - Cluster grenades

I need a damn Flamegod pickup command :@
Just a line of text (after "if)
like
GiveBonus(ID, 3);
For vest
                  Forum Rules   -   Search

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Writing my own "class" script!
« Reply #15 on: May 10, 2009, 01:01:14 pm »

Code: [Select]
var
   picked_class: array[1..32] of boolean;

//This bit should run when the player has tried to pick a class.
begin
   if picked_class[ID] then
      WriteConsole('You already picked a class')
   else begin
      { Give them the bonus here }
      picked_class[ID] := true;
   end;
end;

And for flamegod I guess you have to spawn it on them.

Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
Re: Writing my own "class" script!
« Reply #16 on: May 10, 2009, 01:14:25 pm »
i am on my ipod touch ,
i made the you can only pick one class. I will send it when i will be at home

Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
Re: Writing my own "class" script!
« Reply #17 on: May 10, 2009, 02:08:39 pm »
Ok, I compiled the script & tested it out (I removed the forceweapon lines just to test). It will give packs of bonuses smoothly.
Now the problem is, I want to make the script in such manner that you can only take a class ONCE. (and cannot switch to a different one)
How to make the script check if someone already has a class?
+ If I wanted to make weapons undropable, How would I do this.

For this you will need to create a boolean. Which means its a true or a false.
Like in all beginning of scripts you need to define what you are gonna use. Like
Code: [Select]
var
Classtaken: array[1..32] of boolean;
ok, i defined it.
Now with script it should look like that
Code: [Select]
var
Classtaken: array[1..32] of boolean;

function OnPlayerCommand(ID: Byte; Text: string): boolean;
//Here is for runner
Var
  B: Byte;
   begin
     For B:= 1 To 32 Do
      if Text = '/class runner' then begin
       If Classtaken= False Then begin
       Classtaken:=True;
       IF GetPlayerStat(B, 'Human') Then Begin
        Classtaken:=True;
        WriteConsole(ID, 'Good luck as a Runner!', $FFFFFF);
        GiveBonus(ID, 3);
        end;
     end else if GetPlayerStat(B, 'Human') Then Begin
    WriteConsole(ID, 'You already have a class' ,$FFFFFF);
  end;
end;
// Here is for assaulter
     For B:= 1 To 32 Do
   if Text = '/class assault' then begin
    If Classtaken= False Then begin
       Classtaken:=True;
       IF GetPlayerStat(B, 'Human') Then Begin
       Classtaken:=True;
       WriteConsole(ID, 'Good luck as a Assaulter!', $FFFFFF);
       GiveBonus(ID, 5);
      end;
     end else if GetPlayerStat(B, 'Human') Then Begin
    WriteConsole(ID, 'You already have a class' ,$FFFFFF);
  end;
end;
//Here is for hunter
     For B:= 1 To 32 Do
    if Text = '/class hunter' then begin
     If Classtaken= False Then begin
       Classtaken:=True;
       IF GetPlayerStat(B, 'Human') Then Begin
       Classtaken:=True;
       WriteConsole(ID, 'Good luck as a Hunter!', $FFFFFF);
      GiveBonus(ID, 1);
     end;
end else if GetPlayerStat(B, 'Human') Then Begin
      WriteConsole(ID, 'You already have a class' ,$FFFFFF);
    end;
end;
// Here is for Heavy
     For B:= 1 To 32 Do
    if Text = '/class heavy' then begin
    If Classtaken= False Then begin
       Classtaken:=True;
       IF GetPlayerStat(B, 'Human') Then Begin
        Classtaken:=True;
      WriteConsole(ID, 'Good luck as a Heavy!', $FFFFFF);
      GiveBonus(ID, 2);
      end;
      end else if GetPlayerStat(B, 'Human') Then Begin
      WriteConsole(ID, 'You already have a class' ,$FFFFFF);
    end;
   end;
  end;
I removed the ForceWeapon 'cause i was testing it =]
It works perfectly
If you have question just ask :D

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Writing my own "class" script!
« Reply #18 on: May 10, 2009, 02:13:47 pm »
Please don't double post so much, people. You can edit your previous messages and I don't think this topic will die very quickly :p

What i don't get is what you're planning to do after a player dies. Will he have to select a class again or will the same class still apply? In the last case you will need to remember what class each player has chosen and thus you'll need to store that. That means you could use iDante's example the way danmer suggests. Then instead of an array of boolean, create an array of integers and store there for each player a number which represents the class. If the number is zero then the player hasn't chosen yet.

adapted from iDante:
Code: [Select]
var
   picked_class: array[1..32] of integer;

//This bit should run when the player has tried to pick a class.
begin
   if picked_class[ID] > 0 then
      WriteConsole('You already picked a class')
   else begin
      { Give them the bonus here }
      picked_class[ID] := classnumber; //classnumber being the class that the player has chosen
   end;
end;

Btw, I'm always willing to help ppl learn2script (in Dutch). You can find my xfire on elitectf.com
« Last Edit: May 10, 2009, 02:23:26 pm by JFK »
Come join: EliteCTF
Listen to: My Music

Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
Re: Writing my own "class" script!
« Reply #19 on: May 10, 2009, 02:22:02 pm »
Yep, iDante's one is quite more simple than mine :)
I am a beginner too. I'm helping with what i know and i learned alot doing this. If you can explain me what i didn't do correct it could be nice staying in the topic's subject.

And yeah, i don't know what to do when player dies.

D4NG3R : Did you make an includes.txt ?

Edit : JFK, i know what to do, i'll script it =]
« Last Edit: May 10, 2009, 02:25:54 pm by VinceBros »