Author Topic: Weapon Limitation - v0.1  (Read 3871 times)

0 Members and 1 Guest are viewing this topic.

Offline Avarax

  • Veteran
  • *****
  • Posts: 1529
    • Official Hexer & MMod site
Weapon Limitation - v0.1
« on: September 09, 2007, 05:02:13 pm »
Script Name: Weapon Limitation v0.1
Original Author(s): Avarax
Core Version: 2.6.2

This script allows you to limit every primary weapon to a certain amount for each team. Customizability via an WeaponLimitation.ini
Might cause quite a bit of CPU usage as it calls (Highest ID * 10) "If thens" on each kill.

Code

Download as scriptingcore v2 structured ZIP

To install, just extract the ZIP to your soldat server folder and then open WeaponLimitation.ini in the server folder to customize it.

This script is still in beta stages, check this thread for updates and please report bugs that you might find.

« Last Edit: September 09, 2007, 05:43:49 pm by Avarax »
I like to have one Martini
Two at the very most
Three I'm under the table
Four I'm under the host

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Weapon Limitation - v0.1
« Reply #1 on: September 09, 2007, 05:24:20 pm »
Nice, quickly tested it with setting each weapon to 1 and adding bots.
But for the MaxID function, wouldn't it return the same number as NumPlayers?

Offline Avarax

  • Veteran
  • *****
  • Posts: 1529
    • Official Hexer & MMod site
Re: Weapon Limitation - v0.1
« Reply #2 on: September 09, 2007, 05:25:39 pm »
No, because if there are 3 players and player ID 2 leaves, MaxID will return 3 and NumPlayers will return 2.
I like to have one Martini
Two at the very most
Three I'm under the table
Four I'm under the host

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Weapon Limitation - v0.1
« Reply #3 on: September 09, 2007, 05:31:25 pm »
would it be this then?:
Code: [Select]
i := 32
while GetPlayerStat(i,'Active') = false do i := i - 1;
Result := i;

Code: [Select]
function MaxID: byte;
var i: byte;
begin
  result:=0;
  for i:=1 to 32 do
    If GetPlayerStat(i,'Active') = true then
      result:=result+1;
end;
there are 2 players, id 1 and 3...
i = 1, # 1 is active (result = 1)
i = 2, # 2 is not active (result = 1)
i = 3, # 3 is active (result = 2)
i = 4..32, all inactive (result = 2)

or replacing "      result:=result+1;" with "      result:=i;" sense it won't be set for anything higher then the last player's id

Offline Avarax

  • Veteran
  • *****
  • Posts: 1529
    • Official Hexer & MMod site
Re: Weapon Limitation - v0.1
« Reply #4 on: September 09, 2007, 05:40:33 pm »
oh shi-

:D

EDIT: fixed, thanks for the report
« Last Edit: September 09, 2007, 05:42:44 pm by Avarax »
I like to have one Martini
Two at the very most
Three I'm under the table
Four I'm under the host

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Weapon Limitation - v0.1
« Reply #5 on: September 09, 2007, 05:44:36 pm »
I actually used to have a function called HighID (or something like that) and i did the exact same thing, lol.

I also forgot something, for my while loop, if u use that, make sure you add a thing so it doesn't go anywhere past 1 :P
« Last Edit: September 09, 2007, 05:46:18 pm by DorkeyDear »

Offline chillis34

  • Major
  • *
  • Posts: 68
    • [FT] Clan Web Site
Re: Weapon Limitation - v0.1
« Reply #6 on: September 09, 2007, 11:38:54 pm »
Thank you Avarax your the best im gonna use this on my server did i mention your like the best? :P
Ill also tell you about any bugs i find
I am the smartest :D

Offline Leo

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1011
Re: Weapon Limitation - v0.1
« Reply #7 on: September 10, 2007, 05:59:27 am »
Nice work, this could be useful.

Offline chrisgbk

  • Moderator
  • Veteran
  • *****
  • Posts: 1739
Re: Weapon Limitation - v0.1
« Reply #8 on: September 10, 2007, 02:25:17 pm »
You should really avoid using that function to find the high ID, as not only is it unnecessary, but it adds additional load. So you can see, this is what happens when you combine the MaxID function directly into the CountWeapon function; look at how much extra processing you are doing that isn't needed:

Code: [Select]
function CountWeapon(WeaponID,Team: byte): byte;
var i: byte;
var MaxID: byte;
begin
  result:=0;
  for i:=1 to 32 do
    If GetPlayerStat(i,'Active') = true then
      MaxID:=i;
  for i:=1 to MaxID do
    If (GetPlayerStat(i,'Active') = true) then
      If (GetPlayerStat(i,'Team') < 5) and (GetPlayerStat(i,'Alive') = true) and ((GetPlayerStat(i,'Team') = Team) or (Team = 0)) and ((GetPlayerStat(i,'Primary') = WeaponID) or (GetPlayerStat(i,'Secondary') = WeaponID)) then
        result:=result+1;
end;

when you could just do this, and it would run much faster:

Code: [Select]
function CountWeapon(WeaponID,Team: byte): byte;
var i: byte;
begin
  result:=0;
  for i:=1 to 32 do
    If (GetPlayerStat(i,'Active') = true) then
      If (GetPlayerStat(i,'Team') < 5) and (GetPlayerStat(i,'Alive') = true) and ((GetPlayerStat(i,'Team') = Team) or (Team = 0)) and ((GetPlayerStat(i,'Primary') = WeaponID) or (GetPlayerStat(i,'Secondary') = WeaponID)) then
        result:=result+1;
end;

This also goes for OnWeaponChange, where it's worse because it's used twice; this is what it actually ends up doing:

Code: [Select]
procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: byte);
var i: byte;
MaxID: Byte;
begin
  If JustRespawned[ID] = true then begin
    JustRespawned[ID]:=false;
    If (PrimaryNum > 0) and (PrimaryNum < 11) then
      If CountWeapon(PrimaryNum,GetPlayerStat(ID,'Team')) >= Allowed[PrimaryNum] then begin
        for i:=1 to 32 do
          If GetPlayerStat(i,'Active') = true then
            MaxID:=i;
        for i:=1 to MaxID do
          If (GetPlayerStat(i,'Active') = true) and (GetPlayerStat(i,'Team') = GetPlayerStat(ID,'Team')) then
            If Allowed[PrimaryNum] > 0 then
              SetWeaponActive(i,PrimaryNum,true)
            else
              SetWeaponActive(i,PrimaryNum,false);
      end;
    If (SecondaryNum > 0) and (SecondaryNum < 11) then
      If CountWeapon(SecondaryNum,GetPlayerStat(ID,'Team')) >= Allowed[SecondaryNum] then begin
        for i:=1 to 32 do
          If GetPlayerStat(i,'Active') = true then
            MaxID:=i;
        for i:=1 to MaxID do
          If (GetPlayerStat(i,'Active') = true) and (GetPlayerStat(i,'Team') = GetPlayerStat(ID,'Team')) then
            If Allowed[SecondaryNum] > 0 then
              SetWeaponActive(i,SecondaryNum,true)
            else
              SetWeaponActive(i,SecondaryNum,false);
      end;
  end;
end;


Fixing that helps optimize the CPU usage.