Official Soldat Forums

Server Talk => Scripting Releases => Topic started by: Mighty on July 13, 2010, 08:57:49 am

Title: Single Flashbang
Post by: Mighty on July 13, 2010, 08:57:49 am
Name: Flash!

Author: Mighty (http://soldatcentral.com/index.php?page=profile&u=406)
Script version: 3.2.0
Server version: 2.6.5
Release Date: 13th of July 2010
Last update: 20th of July 2010
Description:
Script gives player flashbang after using "/flash" command. It saves his weapons of course and after using flash they are given back. Very usefull at RS servers, can be easily modified and included to any shop system. Just modify some stuff in OnPlayerCommand. Would be awesome thing to be seen on Real & Survival servers - perfect anti-camp tool. Just in case someone didn't notice: script DOES include line of sight, it doesnt blind players behind the walls.

Preview: Demo (http://forums.soldat.pl/index.php?action=dlattach;topic=38584.0;attach=26157) (ofc with flashbreak = 0)

Flash320.rar includes 3 files! Includes.txt, Flash320_Normal.pas & Flash320_Survival.pas. In Survival one you can have only 1 flash per round. Default script set (in Includes.txt) is Flash320_Normal.pas

Admin Commands:

Command           X values        Default       Description
/flashhelp--Shows admin commands
/flashmod X1/01Turn the script ON/OFF
/flashwait Xseconds3Time till knife explodes (counted since hitting smth)
/flashlen Xticks?200Blinding time
/flashrange Xdistance700Blinding range
/flashbreak Xminutes4Flash picking interval (not in Survival script: 1 flash/round there)

Player Commands:

Command           X values        Default       Description
/flash--Gives player a flashbang as secondary
!flash--Sends some info about the script




Notes:
  *  Remember that flash spot is place where knife hits, not where it lands!

---
(http://img4.imageshack.us/img4/4158/downloadiz.gif) (http://forums.soldat.pl/index.php?action=dlattach;topic=38584.0;attach=25624)
---

Code: {snippets}
Code: [Select]
(...)
if FlashesOnCount > 0 then
begin
for i:=1 to 128 do
begin
if (Flash[i].Counter > 1)  then
begin
if (GetObjectStat(Flash[i].LinkedTo,'active') = true) then // If still on the ground
begin
// countinue countdown
Flash[i].Counter := Flash[i].Counter - 1;
end
else if (GetObjectStat(Flash[i].LinkedTo,'active') = false) then // If picked up during countdown
begin
WriteConsole(0,'Impressive! FlashBang picked up!',Yellow);
Flash[i].Counter := 0; // reset counter
FlashesOnCount := FlashesOnCount - 1; // substract picked knife
Flash[i].CounterStarted := FALSE; // reset vars so the flash can be used again
Flash[i].Used := FALSE;
ObjectLinked[Flash[i].LinkedTo] := FALSE; // unlink the object completely
end;
end;
if (Flash[i].Counter = 1) then // 1 because then there is no 2nd statement needed
begin
Flash[i].BlindMade := TRUE;
Flash[i].Counter := 0;
WriteConsole(0,'  *  Flash!  *  ',White);
for j:=1 to MaxPlayers do
if CheckFlash(i,j) = TRUE then Blind(j);
FlashesOnCount := FlashesOnCount - 1;
Flash[i].CounterStarted := FALSE;
Flash[i].Used := FALSE;
ObjectLinked[Flash[i].LinkedTo] := FALSE;
KillObject(Flash[i].LinkedTo); // totaly kill the knife (no longer on map)
end;
end;
end;
(...)

Questions? Bugs? Report please --> macekmil@gmail.com

Title: Re: Single Flashbang
Post by: zyxstand on July 13, 2010, 01:06:32 pm
sounds really neat!
questions - does it include:
1. line-of-sight?
2. less time/less blinding if relatively far?
  ie:  flashrange: 100  flashlen: 100
if within range of 0-25, full time and full blinding
if within range of 25-100, decrease time and blinding linearly (to minimum of 25/25)

dunno if i explained well... but does it include something like that?
Title: Re: Single Flashbang
Post by: chutem on July 13, 2010, 05:30:59 pm
Had a quick look and doesn't seem so.

Seeing as line of sight is a pretty major feature of Realistic, I think you should add it, at least as an option. Just add a quick raycast option before the blind procedure is called.
Title: Re: Single Flashbang
Post by: xmRipper on July 13, 2010, 07:29:18 pm
Does it work with different fonts ?
Title: Re: Single Flashbang
Post by: chutem on July 13, 2010, 10:59:22 pm
Unlikely. He uses the string 'WWWWWW' to white out the screen, probably the worst character choice, no need for six of them either.
Title: Re: Single Flashbang
Post by: zyxstand on July 13, 2010, 11:27:50 pm
someone explain how WWWWWW will blank the screen!
i think he should incorporate the points i've made!
it would make it much better!
exclamation mark!
Title: Re: Single Flashbang
Post by: chutem on July 14, 2010, 04:28:13 am
The way typically used to fill a players screen with a colour is to use a large drawtext.
Any character will work, as long as it is large enough and not off the screen, there is no reason to use WWWWWW specifically, just a personal choice by the scripter.

All your points were good and I second them, they are rather standard and easy enough to implement, so why not?
Title: Re: Single Flashbang
Post by: Mighty on July 14, 2010, 04:58:36 am
questions - does it include:
1. line-of-sight?
2. less time/less blinding if relatively far?

1. I'm not sure if I understand it well, would you explain please? I'm not R&S player by the way. If you meant that it shouldn't blind players behind a wall for example - it doesn't. Believe me, many RayCasts used there, just to be sure. One was not enough
2. Nope, but I will add it ;) good idea.

What points you made do you mean?

Sometimes flashes just don't blow up. I actually don't have any idea why but I'm gonna check it more minutely. For now: just change your weapons few times both before and after using "/flash" cmd. Let's say you arm your nade that way :P

@xmRipper: nope, it doesn't
Title: Re: Single Flashbang
Post by: Polifen on July 15, 2010, 02:29:30 am
Sometimes flashes just don't blow up. I actually don't have any idea why but I'm gonna check it more minutely. For now: just change your weapons few times both before and after using "/flash" cmd. Let's say you arm your nade that way :P

Did you try "blowing" a bit higher than the knife really is? Maybe RayCast see floor as a furthest point ( like knife is on -1, floor is on 0 and player is on 1. RayCast form -1 says 0 is a wall ).
Title: Re: Single Flashbang [Updated to 3.0.0]
Post by: Mighty on July 15, 2010, 03:11:42 am

Update to 3.0.0!

Changelog and new ver added to 1st post!

Download: Flash 3.0.0 (http://forums.soldat.pl/index.php?action=dlattach;topic=38584.0;attach=25509)


@up: I don't mean not blinding (it actually blows up 5px higher also), I'm getting some problems with detecting which knife is a flashbang. I've got an idea how to fix it tho, I'm working on it, we'll see if it works after next update
Title: Re: Single Flashbang [Updated to 3.0.0]
Post by: mich1103 on July 15, 2010, 09:23:23 am
You should make a molotov script too !  :D
it would be nice  ;)
Title: Re: Single Flashbang [Updated to 3.0.0]
Post by: Mighty on July 15, 2010, 11:42:41 am
not a big deal, i can make such modification later
Title: Re: Single Flashbang [Updated to 3.0.0]
Post by: DarkCrusade on July 15, 2010, 12:40:53 pm
Instead of...
Code: [Select]
if (...) then begin
  if (...) then begin
    if (...) then begin
      (.....)
    end;
  end;
end;

...you can just use:
Code: [Select]
if (...) AND (...) AND (...) then begin
  (.....)
end;

One thing about booleans:

Bad:
Code: [Select]
if (ABC = true) then begin
  if (DEF = false) then begin
    (.....)
  end;
end;

Good:
Code: [Select]
if (ABC) AND (not DEF) then begin
  (.....)
end;
Title: Re: Single Flashbang [Updated to 3.1.0]
Post by: Mighty on July 16, 2010, 08:18:26 am
About comparing booleans, yeah, i know, tho the script is 10 times clearer for me with the useless stuff

And about ANDs & ORs, I found only 1 place in whole script where using AND instead of 2nd IF would make sense.

There is no offence in that post btw ;)



Update to 3.1.0!

Changelog in 1st post

>>DOWNLOAD 3.1.0<< (http://forums.soldat.pl/index.php?action=dlattach;topic=38584.0;attach=25523)
Title: Re: Single Flashbang [Updated to 3.1.0]
Post by: tk on July 16, 2010, 08:28:57 am
Instead of...
Code: [Select]
if (...) then begin
  if (...) then begin
    if (...) then begin
      (.....)
    end;
  end;
end;

...you can just use:
Code: [Select]
if (...) AND (...) AND (...) then begin
  (.....)
end;
Actually the first option is faster especially with heavy functions in conditions. If the first one is false then the rest is not checked unlike in the second example.

Also AND does not have to be written in upper case
Title: Re: Single Flashbang [Updated to 3.1.0]
Post by: DarkCrusade on July 16, 2010, 08:40:17 am
Writing and in upper case is just my personal coding style.

Actually it depends on what you want to do..
Title: Re: Single Flashbang [Updated to 3.1.0]
Post by: zyxstand on July 16, 2010, 09:16:14 am
Instead of...
Code: [Select]
if (...) then begin
  if (...) then begin
    if (...) then begin
      (.....)
    end;
  end;
end;

...you can just use:
Code: [Select]
if (...) AND (...) AND (...) then begin
  (.....)
end;
Actually the first option is faster especially with heavy functions in conditions. If the first one is false then the rest is not checked unlike in the second example.

Also AND does not have to be written in upper case


If it's like C, then I believe you are mistaken. as soon as the first false result occurs, it skips the rest.  or is that just compiler-optimization?  or are all conditions rendered first in soldat core?
I also don't like the division by zero I can get in this case:
myvar = iif (b=0, -1, a/b).


at any rate i case i have a question (if someone can answer :D)
Code: [Select]
if (condition1) then
if (condition2) then
...
else
...;

under which if-statement is does the else-statement operate.  Is it the same in C as it is in soldat?
Title: Re: Single Flashbang [Updated to 3.1.0]
Post by: Mighty on July 16, 2010, 09:40:32 am
I'm 100% sure it's under second one.
Title: Re: Single Flashbang [Updated to 3.1.0]
Post by: dominikkk26 on July 16, 2010, 09:42:20 am
Add so that after throwing the knife was possible only after 5 minutes. And to be able to set this up with the command. While most existing possi settings.
Title: Re: Single Flashbang [Updated to 3.1.0]
Post by: tk on July 16, 2010, 09:42:40 am
Quote
If it's like C, then I believe you are mistaken. as soon as the first false result occurs, it skips the rest.  or is that just compiler-optimization?  or are all conditions rendered first in soldat core?
It doesn't skip the rest, it checks all

Quote
at any rate i case i have a question (if someone can answer )
Code: [Select]
if (condition1) then
if (condition2) then
...
else
...;

under which if-statement is does the else-statement operate.  Is it the same in C as it is in soldat?
Under the second
Title: Re: Single Flashbang [Updated to 3.1.0]
Post by: DarkCrusade on July 16, 2010, 09:44:44 am
@zxy:
So you think that the other conditions are also checked if you go by
Code: [Select]
if (...) then begin
  if (...) then begin

  end;
end;

;D

If you need to handle such a code: (taken from a project by me)
Code: [Select]
if (Copy(Text,1,5) = '/grav') AND (Gravity_Enabled = true) then
  if (GetPiece(Text,' ',1) <> '') then begin
  try
  Tmp2 := StrToFloat(GetPiece(Text,' ',1));
    if (not ModifyGravity(Tmp2)) then
  WriteConsole(ID,'ERROR: Input too high/low. Max: ' + FloatToStr(Gravity_Max) + ', Min: ' + FloatToStr(Gravity_Min), Bad)
else begin
          WriteConsole(ID,'New gravity value: ' + FloatToStr(Tmp2), NotifierColour);
          WriteConsole(0,'Gravity changed.', Yellow);
          WriteLn('Gravity value was changed to ' + FloatToStr(Tmp2));
        end;
except
        WriteConsole(ID,'ERROR: Invalid input', Bad);
      end;
end else WriteConsole(ID,'ERROR: Command: /grav X.XX', Bad);

You must use those if-elses, but more simple code like
Code: [Select]
repeat
  (...)
until (...) or (...);
It's better to use AND/OR statements.
Title: Re: Single Flashbang [Updated to 3.1.0]
Post by: dnmr on July 16, 2010, 03:05:43 pm
It's better to use AND/OR statements.
it's better to back your points up. Care to elaborate?
Title: Re: Single Flashbang [Updated to 3.1.0]
Post by: DarkCrusade on July 16, 2010, 03:23:57 pm
Visual clearance for example?
Title: Re: Single Flashbang [Updated to 3.2.0]
Post by: Mighty on July 20, 2010, 01:04:39 pm
Update to 3.2.0!

Changelog and new download link (http://forums.soldat.pl/index.php?action=dlattach;topic=38584.0;attach=25624) added to 1st post (http://forums.soldat.pl/index.php?topic=38584.msg471928#msg471928)!
Title: Re: Single Flashbang [Updated to 3.2.0]
Post by: xmRipper on July 20, 2010, 01:54:16 pm
If you are going to make it working on 2.7.0, that would be better to use InterfaceText function instead of DrawText. So that, it will work with different fonts which are default in different languages. Because InterfaceText's font is same for everyone.

btw, firstly you will have to wait to InterfaceText's scaling bug (http://bugs.soldat.pl/view.php?id=635) be fixed.
Title: Re: Single Flashbang [Updated to 3.2.0]
Post by: Mighty on July 21, 2010, 06:11:54 am
yeah, I'll have to find another way to check throws :/ This system doesn't work in 2.7.0+