Author Topic: Difference?  (Read 3116 times)

0 Members and 1 Guest are viewing this topic.

Offline Diretlani

  • Major(1)
  • Posts: 16
Difference?
« on: April 09, 2010, 10:47:24 pm »
A partner and i have been working on a server ultimately.. "! [ Saw & Law ] !".

We needed an anti-bloodsaw script and didn't found one, so we used our common sense and intelligence to make one, and yay it works xD!

I wanna know your opinions of these "scripts".. both work perfectly.

Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
var i: integer;
begin
     if Text = '/mercy' then begin
          for i := 1 to 1 do begin
               if GetPlayerStat(i, 'active') then Command('/kill '+GetPlayerStat(ID, 'Name'));
          end;
     end;
end;

And the one that is running on the server, lol:

Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin
     if Text = '/mercy' then begin
                Command('/kill '+GetPlayerStat(ID, 'Name'));
          end;
     end;

What's the difference between using and not using the variable..?

Offline SpiltCoffee

  • Veteran
  • *****
  • Posts: 1579
  • Spilt, not Split!
    • SpiltCoffee's Site
Re: Difference?
« Reply #1 on: April 10, 2010, 12:06:41 am »
What the fudgebar?! You're not even using the for loop! Tell me who wrote the top script so I can go over to them and slap them in the face for 1 to 1 times.

EDIT: In fact, the top one has a logic error induced by the use of the for loop. Use the bottom one.
When life hands you High Fructose Corn Syrup, Citric Acid, Ascorbic Acid, Maltodextrin, Sodium Acid Pyrophosphate,
Magnesium Oxide, Calcium Fumarate, Yellow 5, Tocopherol and Less Than 2% Natural Flavour... make Lemonade!

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: Difference?
« Reply #2 on: April 10, 2010, 04:45:13 am »
In the first one you are always checking if the ID 1 is active, which is useless. Not to mention you are using a loop that loops from 1, ..... to 1. One loop, you know, you could just put the line of code in and it would do the same damn thing...
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Difference?
« Reply #3 on: April 10, 2010, 10:49:01 am »
This one's better:
Code: [Select]
if GetPlayerStat(ID,'Alive) = true then if GetPlayerStat(ID,'Primary') = 15 then DoDamage(ID,6666);(put that in the place of Command(...))

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Difference?
« Reply #4 on: April 10, 2010, 10:54:07 am »
This one's better:
[...]

You forgot the closing ' after "Alive"..

Complementing Gizd's Script..

Code: [Select]
Function OnPlayerCommand(ID: Byte; Text: String);
 Begin
  Text := LowerCase(Text);
   if Text = '/mercy' Then Begin
  if GetPlayerStat(ID,'Alive') = True Then if GetPlayerStat(ID,'Primary') = 15 Then DoDamage(ID,6666);
 end;
end;
www.soldatx.com.br - The brazilian Soldat community.

Offline Diretlani

  • Major(1)
  • Posts: 16
Re: Difference?
« Reply #5 on: April 10, 2010, 06:16:01 pm »
This one's better:
[...]

You forgot the closing ' after "Alive"..

Complementing Gizd's Script..

Code: [Select]
Function OnPlayerCommand(ID: Byte; Text: String);
 Begin
  Text := LowerCase(Text);
   if Text = '/mercy' Then Begin
  if GetPlayerStat(ID,'Alive') = True Then if GetPlayerStat(ID,'Primary') = 15 Then DoDamage(ID,6666);
 end;
end;

Lol.. why use DoDamage if you can just use /kill id ?

Just to make clear..

var i: integer;     CREATES THE VARIABLE i
for i := 1 to 1 do begin      THIS LINE CHECKS PLAYERS IDS right? if my server has 12 slots, it should be for i := 1 to 12?

I am saying if i use a loop and my server has 12 slots should i do 1 to 12?, becuz in all the scripts is 1 to 32, and 32 is the player limit for anyserver, right?

Offline SpiltCoffee

  • Veteran
  • *****
  • Posts: 1579
  • Spilt, not Split!
    • SpiltCoffee's Site
Re: Difference?
« Reply #6 on: April 10, 2010, 08:15:35 pm »
No no no no no NO.

Listen, and listen careful, for I will only explain this once (although several other people will probably do it too).

OnPlayerCommand(ID: Byte; Text: String);

ID is the ID of the player who typed a command.
Text is the command that they sent.

Therefore, imagine if player 3 typed /mercy, the ScriptCore would call OnPlayerCommand with ID being 3 and Text being '/mercy'. You do NOT have to use a for loop to determine which player to kill, because you get given the player's ID when the function itself is called.

That is why the for loop is not only useless, it also creates a logical error in your script, because, in the first example, you're checking to see if the first player is alive, and THEN killing the player who sent it, so if player 1 is dead, player 3 wouldn't be killed when he types '/mercy'.

In the second example you provided for your want of a for loop, you're now checking against all players to see if any one of them are alive. That means you'll be killing him each time you find a player alive. If you have a 12 slot server, and everyone is alive, and someone does /mercy, he's gonna get killed 11 times in that situation. Or, if I've misunderstood how many times you want to use that i variable, doing your second example could result in a script that kills ALL players when one types /mercy.

Moral of the story (also TL;DR): Don't use a for loop for this script.
« Last Edit: April 10, 2010, 08:18:00 pm by SpiltCoffee »
When life hands you High Fructose Corn Syrup, Citric Acid, Ascorbic Acid, Maltodextrin, Sodium Acid Pyrophosphate,
Magnesium Oxide, Calcium Fumarate, Yellow 5, Tocopherol and Less Than 2% Natural Flavour... make Lemonade!

Offline Diretlani

  • Major(1)
  • Posts: 16
Re: Difference?
« Reply #7 on: April 11, 2010, 03:55:24 am »
No no no no no NO.

Listen, and listen careful, for I will only explain this once (although several other people will probably do it too).

OnPlayerCommand(ID: Byte; Text: String);

ID is the ID of the player who typed a command.
Text is the command that they sent.

Therefore, imagine if player 3 typed /mercy, the ScriptCore would call OnPlayerCommand with ID being 3 and Text being '/mercy'. You do NOT have to use a for loop to determine which player to kill, because you get given the player's ID when the function itself is called.

That is why the for loop is not only useless, it also creates a logical error in your script, because, in the first example, you're checking to see if the first player is alive, and THEN killing the player who sent it, so if player 1 is dead, player 3 wouldn't be killed when he types '/mercy'.

In the second example you provided for your want of a for loop, you're now checking against all players to see if any one of them are alive. That means you'll be killing him each time you find a player alive. If you have a 12 slot server, and everyone is alive, and someone does /mercy, he's gonna get killed 11 times in that situation. Or, if I've misunderstood how many times you want to use that i variable, doing your second example could result in a script that kills ALL players when one types /mercy.

Moral of the story (also TL;DR): Don't use a for loop for this script.

Thank you very much :3

I have to say, we noticed the globalkill effect by using 1 to 12, and using /mercy lol.

It was funny to see how, all people dies because of us doing /mercy.

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Difference?
« Reply #8 on: April 11, 2010, 04:18:20 am »
Lol.. why use DoDamage if you can just use /kill id ?
Because it's better?

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Difference?
« Reply #9 on: April 11, 2010, 09:31:02 am »
'/kill <id>' writes to the player console (and console too im pretty sure). therefore DoDamage has more control on exactly what you want.

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Difference?
« Reply #10 on: April 11, 2010, 11:08:26 am »
Just lik DorkeyDear said, /kill command writes a message to all players.

DoDamage() doesnt.

Just go DoDamage(ID,4000); that it kills player right on time :]
www.soldatx.com.br - The brazilian Soldat community.

Offline Diretlani

  • Major(1)
  • Posts: 16
Re: Difference?
« Reply #11 on: April 11, 2010, 04:16:04 pm »
Just lik DorkeyDear said, /kill command writes a message to all players.

DoDamage() doesnt.

Just go DoDamage(ID,4000); that it kills player right on time :]

But, i want to show the killed by admin msg to other players.

When someones do /mercy it kills the player and 2 msg appears:

%player% killed by admin
BloodSaw is not allowed.

That's a warn for the other noobs thinking about doing /mercy..

Offline Neosano

  • Camper
  • ***
  • Posts: 253
  • IIAWAK!
Re: Difference?
« Reply #12 on: April 11, 2010, 04:18:14 pm »
Well, a bad idea. They'll flood chat with these stupid shiny messages...
If someone wants to try it - why not?
KAWAAAAAAAIIIIIIIIII

Offline squiddy

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 333
  • Flagger assassin
    • SoldatX
Re: Difference?
« Reply #13 on: April 11, 2010, 04:23:14 pm »
Well, a bad idea. They'll flood chat with these stupid shiny messages...
If someone wants to try it - why not?

I am with you.

When players look at the death console, they will be all like, omg, did he died trying to do /mercy ?

Then they go and do /mercy.

And they die.

And then more noobs try to do /mercy, and there it goes.
www.soldatx.com.br - The brazilian Soldat community.

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: Difference?
« Reply #14 on: April 12, 2010, 08:46:52 am »
Well, a bad idea. They'll flood chat with these stupid shiny messages...
If someone wants to try it - why not?

I am with you.

When players look at the death console, they will be all like, omg, did he died trying to do /mercy ?

Then they go and do /mercy.

And they die.

And then more noobs try to do /mercy, and there it goes.
Your server is made for retards? D:

Offline croat1gamer

  • Veteran
  • *****
  • Posts: 1327
  • OMG CHANGING AVATAR!!! ^ω^
Re: Difference?
« Reply #15 on: April 12, 2010, 09:12:46 am »
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin
if Text = '/mercy' then begin
DoDamage(ID,ID,8001);
WriteConsole(ID,'Dont do that.',$EE81FAA1);
WriteConsole(0,'Dont /mercy kids. '+ IDToName(ID) +' learned why.' ,$EE81FAA1);
SetScore(ID,0);
end;
end;

As simple as possible.
Added the mass message.
« Last Edit: April 12, 2010, 09:29:13 am by croat1gamer »
Last year, I dreamt I was pissing at a restroom, but I missed the urinal and my penis exploded.

Offline Diretlani

  • Major(1)
  • Posts: 16
Re: Difference?
« Reply #16 on: April 13, 2010, 02:19:13 pm »
Thanks for all the comments, and codes <3

But i'm using /kill if you don't mind ._.

Offline croat1gamer

  • Veteran
  • *****
  • Posts: 1327
  • OMG CHANGING AVATAR!!! ^ω^
Re: Difference?
« Reply #17 on: April 13, 2010, 03:02:36 pm »
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
begin
if Text = '/mercy' then begin
Command('/kill ' + ID);
WriteConsole(ID,'Dont do that.',$EE81FAA1);
WriteConsole(0,'Dont /mercy kids. '+ IDToName(ID) +' learned why.' ,$EE81FAA1);
SetScore(ID,0);
end;
end;
Last year, I dreamt I was pissing at a restroom, but I missed the urinal and my penis exploded.