Author Topic: No Capping - My First Script  (Read 3479 times)

0 Members and 1 Guest are viewing this topic.

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
No Capping - My First Script
« on: August 06, 2007, 12:51:37 am »
This is kindof a release and a help asking thing, if it should be moved then move it.

Script Name: No Capping
Script Description:When a player joins the game, it puts a big message on their screen "Capping is Not Allowed!" When they grab a flag it tells them not to cap. You can remove the "// " on the Command('/kill ' + inttostr(ID)); line and it will kill them if they grab a flag. If they cap it will kick them and say "CAPPING NOT ALLOWED, GOOD RIDDANCE". That is, if capping is turned off.
Admins can use /capon and /capoff to turn on capping or turn it off.
Original Author(s): Me, iDante
Core Version: the latest one (2.6.1?)

Code: [Select]
var cap: boolean;
function OnCommand(ID: Byte; Text: string): boolean;
begin
if Text='/capon' then begin
DrawText(0,'Capping is Allowed!',300,RGB(255,255,255),0.15,40,240);
Command('/say Capping is Allowed!');
cap :=true;
end else if Text='/capoff' then begin
DrawText(0,'Capping is NOT Allowed!',300,RGB(255,255,255),0.15,40,240);
Command('/say Capping is NOT Allowed!');
cap :=false;
end;
end;
procedure OnJoinGame(ID, Team: byte);
begin
if cap=false then begin
DrawText(ID,'Capping is Not Allowed!',300,RGB(255,255,255),0.15,40,240);
end else if cap=true then begin
DrawText(ID,'Capping is Allowed!',300,RGB(255,255,255),0.15,40,240);
end;
end;
procedure OnFlagGrab(ID, TeamFlag: byte;GrabbedInBase: boolean);
begin
if cap=false then begin
// Uncomment the next line if you want players to die when they grab flag.
// Command('/kill ' + inttostr(ID));
Command('/say Capping is BAD!');
Command('/say THAT MEANS YOU, ' + IDToName(ID) + '!');
End;
End;
procedure OnFlagScore(ID, TeamFlag: byte);
begin
if cap=false then begin
Command('/kick ' + inttostr(ID));
Command('/say CAPPING NOT ALLOWED, GOOD RIDDANCE');
end;
end;

I know its kindof simple and probably done many times before, but it's my first and I'm wondering if its done right. Also:
Code: [Select]
procedure OnJoinGame(ID, Team: byte);
begin
if cap=false then begin
DrawText(ID,'Capping is Not Allowed!',300,RGB(255,255,255),0.15,40,240);
end else if cap=true then begin
DrawText(ID,'Capping is Allowed!',300,RGB(255,255,255),0.15,40,240);
end;
end;
I'm pretty sure that this is condensable into half as many lines by like, being:
if cap=false then DrawText...
else DrawText...

but I tried several things and it didnt like me. I havent looked at any tutorials on pascal so I don't know it very well (c++ is my main language).

Offline mikembm

  • Soldier
  • **
  • Posts: 210
Re: No Capping - My First Script
« Reply #1 on: August 06, 2007, 01:40:35 am »
To answer your question
Code: [Select]
procedure OnJoinGame(ID, Team: byte);
begin
if cap=false then begin
DrawText(ID,'Capping is Not Allowed!',300,RGB(255,255,255),0.15,40,240);
end else if cap=true then begin
DrawText(ID,'Capping is Allowed!',300,RGB(255,255,255),0.15,40,240);
end;
end;

Can be reduced to:
Code: [Select]
procedure OnJoinGame(ID, Team: byte);
begin
if cap=false then DrawText(ID,'Capping is Not Allowed!',300,RGB(255,255,255),0.15,40,240)
else DrawText(ID,'Capping is Allowed!',300,RGB(255,255,255),0.15,40,240);
end;

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: No Capping - My First Script
« Reply #2 on: August 07, 2007, 02:22:02 pm »
There is a procedure in the next version of soldat dedicated server that can change the score of a team, so for non-survival games, you could just subtract 1 from the team's score whenever a player caps the flag. i dont know if the event of when a  player caps the flag occurs b4 or after the variable is updated, but there will be a little error either way, unless you feel like going around that. if it tries subtracting 1 b4 the value is added, then if the current value of the score is 0, 0 -1 = -1, but i don't know how it will act with negatives. And if the score is added and then a score is subtracted, if the limit = 1, then the map will end b4 it has a chance to subtract 1 from it. easy fix for the 2nd 1 will be having a higher limit than 1. Only problem is if ur using the scores for something else and somebody caps, then you would need to change the limit to at least 1 more than what you want it to be, and manually check if it hits the number you want it to only when you are raising the score of a team, and not when a player caps.

now if the server has survival enabled, then you may have some issues that may be pretty hard to smoothly fix. i would make my own custom-survival mode if this was the case, where the actual survival mode would be disabled. only problem would be spamming with _ has joined _ team sense players will be going spec, and you would need to make your own lock to make sure the player doesn't rejoin the team.
« Last Edit: August 07, 2007, 02:24:23 pm by DorkeyDear »

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: No Capping - My First Script
« Reply #3 on: August 09, 2007, 10:30:06 pm »
Kicking the player on capping?  That's a bid harsh...
Hey DD, I got a good sciripting idea that I'm too lazy to do:  No Cap Points - basically, when someone caps he doesn't get 20 points for it...
Can't think of anything original to put here...

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: No Capping - My First Script
« Reply #4 on: August 10, 2007, 12:25:01 pm »
Kicking the player on capping?  That's a bid harsh...
Hey DD, I got a good sciripting idea that I'm too lazy to do:  No Cap Points - basically, when someone caps he doesn't get 20 points for it...
very very simple. I already have this in {SS} private servers
ill just put it here sense it doesn't deserve a whole new topic ^^ or does it? lol
Code: [Select]
const
  CapPoints = 0;

procedure OnFlagScore(ID, TeamFlag: byte);
begin
  SetScore(ID,GetPlayerStat(ID,'Kills') + CapPoints - 20);
end;
i added a const to set how many points a cap is worth.

Offline ghg

  • Camper
  • ***
  • Posts: 411
  • Village Idiot
Re: No Capping - My First Script
« Reply #5 on: August 10, 2007, 12:50:26 pm »
Out of curiosity, is their any difference between a constant and a variable, aside from constants having a fixed, unchangeable value?
-=Gradius wuz you=-

Offline zyxstand

  • Veteran
  • *****
  • Posts: 1106
  • Mother of all Bombs
Re: No Capping - My First Script
« Reply #6 on: August 10, 2007, 10:14:37 pm »
Out of curiosity, is their any difference between a constant and a variable, aside from constants having a fixed, unchangeable value?

if you don't need to change it it's better to define it as a constant as it's easier for the computer...
Can't think of anything original to put here...

Offline Karvinen

  • Major(1)
  • Posts: 5
Re: No Capping - My First Script
« Reply #7 on: August 26, 2007, 02:27:54 pm »
CTF means Capture The Flag, not deathmatch or teammatch.

Offline ghg

  • Camper
  • ***
  • Posts: 411
  • Village Idiot
Re: No Capping - My First Script
« Reply #8 on: August 26, 2007, 02:39:05 pm »
Sometimes you want red Vs blue. I suppose it's still the mappers fault.
-=Gradius wuz you=-