Author Topic: "ForceWeapon" on "OnPlayerRespawn" problem  (Read 1734 times)

0 Members and 1 Guest are viewing this topic.

Offline DarkSpread

  • Major(1)
  • Posts: 25
"ForceWeapon" on "OnPlayerRespawn" problem
« 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

Offline croat1gamer

  • Veteran
  • *****
  • Posts: 1327
  • OMG CHANGING AVATAR!!! ^ω^
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #1 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.
Last year, I dreamt I was pissing at a restroom, but I missed the urinal and my penis exploded.

Offline DarkSpread

  • Major(1)
  • Posts: 25
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #2 on: February 13, 2011, 04:00:29 pm »
..and there is a way for "bypass" this? ???

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #3 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

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.
The truth is out there? Does anyone know the URL?
The URL is here

Offline DarkSpread

  • Major(1)
  • Posts: 25
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #4 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:

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;
« Last Edit: February 13, 2011, 04:55:17 pm by DarkSpread »

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #5 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;
The truth is out there? Does anyone know the URL?
The URL is here

Offline Hacktank

  • Camper
  • ***
  • Posts: 462
  • Soldat Scripter
    • HTZRPG
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #6 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.


Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #7 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.

Offline DarkSpread

  • Major(1)
  • Posts: 25
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #8 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..


LOL.

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #9 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.
The truth is out there? Does anyone know the URL?
The URL is here

Offline DarkSpread

  • Major(1)
  • Posts: 25
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #10 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.



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" ???
« Last Edit: February 14, 2011, 01:31:26 pm by DarkSpread »

Offline Polifen

  • Soldier
  • **
  • Posts: 127
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #11 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;


Offline DarkSpread

  • Major(1)
  • Posts: 25
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #12 on: February 14, 2011, 01:45:29 pm »
Type Mismatch :(

Offline Polifen

  • Soldier
  • **
  • Posts: 127
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #13 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.

Offline croat1gamer

  • Veteran
  • *****
  • Posts: 1327
  • OMG CHANGING AVATAR!!! ^ω^
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #14 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.
Last year, I dreamt I was pissing at a restroom, but I missed the urinal and my penis exploded.

Offline DarkSpread

  • Major(1)
  • Posts: 25
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #15 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
« Last Edit: February 14, 2011, 02:46:25 pm by DarkSpread »

Offline croat1gamer

  • Veteran
  • *****
  • Posts: 1327
  • OMG CHANGING AVATAR!!! ^ω^
Re: "ForceWeapon" on "OnPlayerRespawn" problem
« Reply #16 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.
Last year, I dreamt I was pissing at a restroom, but I missed the urinal and my penis exploded.