Official Soldat Forums

Server Talk => Scripting Discussions and Help => Topic started by: DarkSpread on February 13, 2011, 02:18:27 pm

Title: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: DarkSpread on February 13, 2011, 02:18:27 pm
The script is this:
Quote
procedure OnPlayerRespawn(ID: Byte);
begin
   DoDamage(ID,1);
   ForceWeapon(ID,2,7,0);
   GiveBonus(ID, 3);
end;
It does DoDamage and GiveBonus but doesn't ForceWeapon

If i do this other, it works:
Quote
if GetPlayerStat(ID, 'Alive') then begin
   if Text = 'SomeText' then
   ForceWeapon(ID,2,7,0);
end;

Someone knows why the script doesn't works?? o.O
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: croat1gamer on February 13, 2011, 03:02:03 pm
Forceweapon activates on rewspawn, the problem is that the player gets his weapon that moment, but the weapon he chooses in the weapon tab 'overwrites' that.
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: DarkSpread on February 13, 2011, 04:00:29 pm
..and there is a way for "bypass" this? ???
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: Stuffy on February 13, 2011, 04:26:45 pm
Code: [Select]
procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: Byte);

http://enesce.com/help/index.html?Events/OnWeaponChange.html (http://enesce.com/help/index.html?Events/OnWeaponChange.html)

Quote
Description:
This procedure will be called every time a player switches weapons, drops a weapon, picks up a weapon, and when they pick a gun from the respawn menu.

Maybe that will work.
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: DarkSpread on February 13, 2011, 04:51:10 pm
Not only doesn't work but it doesn't let me to chat and the server doesn't shutdown D:
(http://i53.tinypic.com/ru61ow.png)
Thanks for the help. Anyone else who has any other ideas?

PS: I WAS USING THIS CODE:
Code: [Select]
procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: Byte);
begin
OnWeaponChange(ID, 2, 7);
end;
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: Stuffy on February 13, 2011, 05:31:43 pm
Try this:

Code: [Select]
procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: Byte);
begin
  ForceWeapon(ID,2,7,0);
end;
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: Hacktank on February 13, 2011, 11:18:08 pm
Im pretty sure using forceweapon() calls the OnWeaponChange event again, so that would cause an infinite loop, check to see if the weapon he has switched to is correct or not before you do a forceweapon.
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: dnmr on February 14, 2011, 05:16:51 am
uhh.. Try checking for the first onweaponchange after respawn. Namely set a flag var to true after a player respawns. Then check if it's true in onweaponchange - you'll know that the player has just picked his weapon. Do whatever magic you need and set the flag var back to false so that you don't end up in an endless loop like you just did... I hope you got what i was trying to say, that should be as close as it gets to what you need.
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: DarkSpread on February 14, 2011, 09:30:43 am
Mmh.. I have an idea: is possible to enable the ForceWeapon on OnWeaponChange only "once time"?

To Stuffy: i tried that script but when i change my weapon the primary always be MP5 and when i drop the weapon see what happens..

(http://i51.tinypic.com/309q2hw.png)
LOL.
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: Stuffy on February 14, 2011, 10:48:03 am
do what hacktank and dnmr wrote. Create a var or do
Code: [Select]
if (PrimaryNum <> 2) and (SecondaryNum <> 7) or (PrimaryNum <> 7) and (SecondaryNum <> 2) then ForceWeapon(ID,2,7,0);
Did the "or" because im not sure if the secondary weapon gets the first on change.
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: DarkSpread on February 14, 2011, 01:20:24 pm
I solved with this:
Code: [Select]
procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: Byte);
begin
if (PrimaryNum <> 2) and (SecondaryNum <> 7) then ForceWeapon(ID,7,2,0);
end;

But there are other 2 problems..

1. When i change to M79 (secondary), his ammo resets.
2. When i'm using M79 if i drop it.. The same problem.

(http://i56.tinypic.com/t62jba.png)

If there is no possibility to solve these bugs i will leave these how are.
Or at least make something like "If SecondaryWeapon ammo 0 (default ammo) then ForceWeapon Else Nothing" ???
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: Polifen on February 14, 2011, 01:37:58 pm
Should be easier to do AfterRespawn[ID] := true;in OnPlayerRespawn, and then in OnWeaponChange check if AfterRespawn = true, if yes just change weapons and set AfterRespawn[ID] to false.

Code without checking:
Code: [Select]
var
AfterRespawn : array[1..32] of boolean;

procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: Byte);
begin
   if AfterRespawn[ID] then begin
ForceWeapon(ID,7,2,0);
AfterRespawn := false;
end;
end;

procedure OnPlayerRespawn(ID: Byte);
begin
AfterRespawn[ID] := true;
end;

Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: DarkSpread on February 14, 2011, 01:45:29 pm
Type Mismatch :(
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: Polifen on February 14, 2011, 01:54:54 pm
Code: [Select]
var
AfterRespawn : array[1..32] of boolean;

procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: Byte);
begin
   if AfterRespawn[ID] then begin
ForceWeapon(ID,7,2,0);
AfterRespawn[ID] := false;
end;
end;

procedure OnPlayerRespawn(ID: Byte);
begin
AfterRespawn[ID] := true;
end;

Check this one.
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: croat1gamer on February 14, 2011, 02:10:24 pm
How do you want the weapons to be forced?
I could make a short script if id knew how do you want it to.
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: DarkSpread on February 14, 2011, 02:36:19 pm
How do you want the weapons to be forced?
I could make a short script if id knew how do you want it to.

Thanks! :P
For primary weapon MP5 and for secondary M79. :)

EDIT:

To croat1gamer: I solved with Polifen's script: thanks anyway! :) ..And thanks also to Polifen!! ;D
Title: Re: "ForceWeapon" on "OnPlayerRespawn" problem
Post by: croat1gamer on February 14, 2011, 02:58:45 pm
Yeah, his will work, personally, id like to add a precaution here and there, but this is also okay.