Official Soldat Forums

Server Talk => Scripting Discussions and Help => Topic started by: koolazngy94 on June 19, 2009, 08:44:43 pm

Title: Disable Weapon Help?
Post by: koolazngy94 on June 19, 2009, 08:44:43 pm
I'm new to making script and I finish reading the tutorial. I made a test script but it didn't work.

Code: [Select]
procedure SetWeaponActive(ID, WeaponNum: byte; State: boolean);
begin
SetWeaponActive(0,1,false);
SetWeaponActive(0,2,false);
SetWeaponActive(0,3,false);
end;

SetWeaponActive won't work or WeaponChange. What do I need to add?
Title: Re: Disable Weapon Help?
Post by: DorkeyDear on June 19, 2009, 09:28:36 pm
I'm not 100% certain, but player id. 0 may not work for all players in this function. Try SetWeaponActive(1, ...) and see if that works. If so, you'll have to create a var i: byte; and a for i := 1 to 32 do if (GetPlayerStat(i, 'Active') = true) then begin SetWeaponActive(i, 1, false); SetWeaponActive(i, 2, false); SetWeaponActive(i, 3, false); end;

Lol I just realized.. your procedure name is SetWeaponActive as well, and I don't think you cave have multiple of the same procedure with the same name.
Title: Re: Disable Weapon Help?
Post by: danmer on June 20, 2009, 02:28:28 am
ie just try this:
Code: [Select]
procedure RestrictWeapons();
begin
SetWeaponActive(0,1,false);
SetWeaponActive(0,2,false);
SetWeaponActive(0,3,false);
end;

and call this RestrictWeapons() procedure in onweaponchange or wherever you want it to be called
Title: Re: Disable Weapon Help?
Post by: koolazngy94 on June 23, 2009, 01:22:06 pm
ie just try this:
Code: [Select]
procedure RestrictWeapons();
begin
SetWeaponActive(0,1,false);
SetWeaponActive(0,2,false);
SetWeaponActive(0,3,false);
end;

and call this RestrictWeapons() procedure in onweaponchange or wherever you want it to be called

So how I call RestrictWeapons() in OnWeaponChange() ?
Title: Re: Disable Weapon Help?
Post by: tk on June 23, 2009, 01:26:56 pm
procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: byte); begin RestrictWeapons; end;
Title: Re: Disable Weapon Help?
Post by: ~Niko~ on June 23, 2009, 03:10:12 pm
The whole code should look like this:

Code: [Select]
procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: byte);
begin
   RestrictWeapons;
end;

procedure RestrictWeapons();
begin
   SetWeaponActive(0,1,false);
   SetWeaponActive(0,2,false);
   SetWeaponActive(0,3,false);
end;

or

Code: [Select]
var
i: Integer;

procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: byte);
begin
   RestrictWeapons;
end;

procedure RestrictWeapons();
begin
   for i := 1 to 3 do
   SetWeaponActive(0,i,false);
end;
Title: Re: Disable Weapon Help?
Post by: koolazngy94 on June 23, 2009, 03:55:42 pm
It said RestrictWeapons() is not defined.
Title: Re: Disable Weapon Help?
Post by: danmer on June 23, 2009, 04:01:52 pm
place that procedure above OnWeaponChange
Title: Re: Disable Weapon Help?
Post by: koolazngy94 on June 23, 2009, 04:08:20 pm
place that procedure above OnWeaponChange

Thank you it works now!

--Edit--
But how can we disable when player join?
Title: Re: Disable Weapon Help?
Post by: danmer on June 23, 2009, 04:15:58 pm
place that procedure above OnWeaponChange

Thank you it works now!

--Edit--
But how can we disable when player join?
put it in onjointeam. But since you disable the weapons for everyone (ID 0), i'd just put it in activateserver ::)
Title: Re: Disable Weapon Help?
Post by: JFK on June 23, 2009, 06:06:24 pm
But since you disable the weapons for everyone (ID 0), i'd just put it in activateserver ::)

Then I'd change soldat.ini
Title: Re: Disable Weapon Help?
Post by: ~Niko~ on June 23, 2009, 06:14:25 pm
Then I'd change soldat.ini
way better.
Title: Re: Disable Weapon Help?
Post by: koolazngy94 on June 23, 2009, 08:15:22 pm
Well I just want to enabled it back when it gets * kills.
Title: Re: Disable Weapon Help?
Post by: ~Niko~ on June 24, 2009, 06:29:21 am
then tell us exactly what you want and we'll tell you how, or we'll make it.
Title: Re: Disable Weapon Help?
Post by: shantec on June 24, 2009, 06:30:38 am
Quote
procedure Activateserver;
var
   i: Integer;
begin
   for i := 1 to 3 do //Might wanna change to 10?
   SetWeaponActive(0,i,false);
end;


procedure OnPlayerKill(Killer, Victim: byte;Weapon: string);
begin
   If GetPlayerStat(Killer,'Kills') > 1 then SetWeaponActive(0,1,true);
   If GetPlayerStat(Killer,'Kills') > 2 then SetWeaponActive(0,2,true);
   //etc. etc, i suggest using ">", if its used on CTF mode
end;

Title: Re: Disable Weapon Help?
Post by: koolazngy94 on June 24, 2009, 12:28:12 pm
then tell us exactly what you want and we'll tell you how, or we'll make it.

What I want is all weapons to be disabled beside the first gun. When they get 10 kills, first gun is disabled and the second gun is enabled then next gun then .etc.
Title: Re: Disable Weapon Help?
Post by: ~Niko~ on June 24, 2009, 03:43:47 pm
then tell us exactly what you want and we'll tell you how, or we'll make it.

What I want is all weapons to be disabled beside the first gun. When they get 10 kills, first gun is disabled and the second gun is enabled then next gun then .etc.
k, ill do it.

EDIT: this huge code should do the trick, but it seems that in doesn't works for soldat...

Code: (Pascal) [Select]
var
i, b: Integer;

procedure OnPlayerKill(Killer, Victim: byte;Weapon: string);
begin
if GetPlayerStat(Killer,'Kills') in [11..20] then begin //If kill amount is needed
for i := 1 to 10 do //To call all weapons inactive
SetWeaponActive(Killer,i,false); //Set all weapons inactive
SetWeaponActive(Killer,2,true); //Set next weapon active
end; //End block if guy has 11 to 20 kills
if GetPlayerStat(Killer,'Kills') in [21..30] then begin
for i := 1 to 10 do
SetWeaponActive(Killer,i,false);
SetWeaponActive(Killer,3,true);
end;
if GetPlayerStat(Killer,'Kills') in [31..40] then begin
for i := 1 to 10 do
SetWeaponActive(Killer,i,false);
SetWeaponActive(Killer,4,true);
end;
if GetPlayerStat(Killer,'Kills') in [41..50] then begin
for i := 1 to 10 do
SetWeaponActive(Killer,i,false);
SetWeaponActive(Killer,5,true);
end;
if GetPlayerStat(Killer,'Kills') in [51..60] then begin
for i := 1 to 10 do
SetWeaponActive(Killer,i,false);
SetWeaponActive(Killer,6,true);
end;
if GetPlayerStat(Killer,'Kills') in [61..70] then begin
for i := 1 to 10 do
SetWeaponActive(Killer,i,false);
SetWeaponActive(Killer,7,true);
end;
end;
//Damn this turned out in a huge code... fix anyone?

procedure OnJoinTeam(ID, Team: byte);
begin
for b := 2 to 10 do
SetWeaponActive(ID,b,false);
end;
Title: Re: Disable Weapon Help?
Post by: koolazngy94 on June 24, 2009, 10:39:56 pm
then tell us exactly what you want and we'll tell you how, or we'll make it.

What I want is all weapons to be disabled beside the first gun. When they get 10 kills, first gun is disabled and the second gun is enabled then next gun then .etc.
k, ill do it.

EDIT: this huge code should do the trick, but it seems that in doesn't works for soldat...

Code: (Pascal) [Select]
var
i, b: Integer;

procedure OnPlayerKill(Killer, Victim: byte;Weapon: string);
begin
if GetPlayerStat(Killer,'Kills') in [11..20] then begin //If kill amount is needed
for i := 1 to 10 do //To call all weapons inactive
SetWeaponActive(Killer,i,false); //Set all weapons inactive
SetWeaponActive(Killer,2,true); //Set next weapon active
end; //End block if guy has 11 to 20 kills
if GetPlayerStat(Killer,'Kills') in [21..30] then begin
for i := 1 to 10 do
SetWeaponActive(Killer,i,false);
SetWeaponActive(Killer,3,true);
end;
if GetPlayerStat(Killer,'Kills') in [31..40] then begin
for i := 1 to 10 do
SetWeaponActive(Killer,i,false);
SetWeaponActive(Killer,4,true);
end;
if GetPlayerStat(Killer,'Kills') in [41..50] then begin
for i := 1 to 10 do
SetWeaponActive(Killer,i,false);
SetWeaponActive(Killer,5,true);
end;
if GetPlayerStat(Killer,'Kills') in [51..60] then begin
for i := 1 to 10 do
SetWeaponActive(Killer,i,false);
SetWeaponActive(Killer,6,true);
end;
if GetPlayerStat(Killer,'Kills') in [61..70] then begin
for i := 1 to 10 do
SetWeaponActive(Killer,i,false);
SetWeaponActive(Killer,7,true);
end;
end;
//Damn this turned out in a huge code... fix anyone?

procedure OnJoinTeam(ID, Team: byte);
begin
for b := 2 to 10 do
SetWeaponActive(ID,b,false);
end;

That is alot. One question tho, what you mean [51..60]?
Title: Re: Disable Weapon Help?
Post by: DorkeyDear on June 25, 2009, 12:21:11 am
That is alot. One question tho, what you mean [51..60]?
I believe the left part must be between (inclusivly) 51 and 60. But I can't say this for certain.

Replacement for the in operator as a function i guess
Code: [Select]
function WithinInt(const Value, Low, High: integer): boolean;
begin
  Result := (Value >= Low) and (Value <= High);
end;
For other types, simply change the time (and preferably the function name; wouldn't be appropiate to leave Int at the end if its for doubles)
Title: Re: Disable Weapon Help?
Post by: Gizd on June 25, 2009, 03:35:02 am
Code: [Select]
const Kills4Weap=2;

procedure SetWeapons(ID: byte);
var i: byte;
begin
  for i:= 1 to 10 do SetWeaponActive(ID,i,false);
  SetWeaponActive(ID, (((GetPlayerStat(ID,'Kills') div Kills4Weap) mod 10) + 1), true);
end;
Call it in OnPlayerKill and OnJoinTeam.
Title: Re: Disable Weapon Help?
Post by: y0uRd34th on June 25, 2009, 06:50:02 am
Code: [Select]
if GetPlayerStat(Killer,'Kills') in [11..20] then begin
Just a question, what is 'in', does it check if one of the arrays is the number of kills, because iv'e  never heard about that.
Title: Re: Disable Weapon Help?
Post by: ~Niko~ on June 25, 2009, 06:59:31 am
if the number of kills is into these numbers, it will do something.
Title: Re: Disable Weapon Help?
Post by: y0uRd34th on June 25, 2009, 09:38:26 am
Thanks for answer. Sounds quite helpfull.
Title: Re: Disable Weapon Help?
Post by: utkesmer on July 14, 2009, 06:09:01 am
Can we create a procedure or function?

Like this...

Code: [Select]
function OnCommand(ID: Byte; Text: string): boolean;
begin
   Result := false;

   MyProcedure;

end;

procedure MyProcedure(Text: string; ID: byte);
begin

   if MaskCheck(Text, '/alpha') then Command('/setteam1 '+INTTOSTR(ID) );
   // Just an example...

end;
Title: Re: Disable Weapon Help?
Post by: Polifen on July 14, 2009, 09:05:10 am
You must call it like you declare.

For:
Code: [Select]
procedure MyProcedure(Text: string; ID: byte);
Example:
Code: [Select]
MyProcedure(Text, ID);
Title: Re: Disable Weapon Help?
Post by: DorkeyDear on July 14, 2009, 10:23:24 am
Also note that functions/procedures you make bust be declared/defined above where you want to call them. So in the example, above OnCommand u can say what MyProcedure is.