Author Topic: (OnWeaponChange): Out of Global Vars range  (Read 1720 times)

0 Members and 1 Guest are viewing this topic.

Offline Mercury92

  • Camper
  • ***
  • Posts: 284
(OnWeaponChange): Out of Global Vars range
« on: May 01, 2010, 09:17:54 am »
Forces Bravo players to spawn weapon back they picked up and forces their weapon back to fists. But..
(OnWeaponChange): Out of Global Vars range

Code: (pascal) [Select]
procedure OnWeaponChange(ID, PrimaryNum, SecondaryNum: byte);

begin
if (GetPlayerStat(ID,'Active') = true) then
begin
if (GetPlayerStat(ID,'Team') = 2) then
begin
if (GetPlayerStat(ID,'Alive') = true) then
begin
if (PrimaryNum <> 255) then // if wep was in primary slot
if (PrimaryNum <> 15) then
SpawnObject(GetPlayerStat(ID, 'x'),GetPlayerStat(ID, 'y')-32,PrimaryNum);

if (SecondaryNum <> 255) then // if wep was in secondary slot
if (SecondaryNum <> 15) then
SpawnObject(GetPlayerStat(ID, 'x'),GetPlayerStat(ID, 'y')-32,SecondaryNum);

ForceWeapon(ID, 255, 255, 0);

end;
end;
end;
end;
[saw]  on 1.5.1

DarkCrusade

  • Guest
Re: (OnWeaponChange): Out of Global Vars range
« Reply #1 on: May 01, 2010, 10:01:26 am »
Line 4 is not necessary since the procedure gets called whenever a player on the server changes his weapons. Also he is not able to change his weapons while waiting for the respawn.

What is the point of this script? You want that players in Bravo use fists only no matter what weapons they pick up? Then I'd call AppOnIdle every second to check their gun, like

Code: [Select]
Procedure AppOnIdle(Ticks: Integer);
var ID: Byte; 
  begin
    for ID := 1 to 32 do begin
      if GetPlayerStat(ID,'Primary') <> 255 then
        ForceWeapon(ID,255,255,0);
      if GetPlayerStat(ID,'Secondary') <> 255 then
        ForceWeapon(ID,255,255,0);
    end;
  end;     
 

If you want to go even further and spawn the weapon he just picked up afterwards do something like this

Code: [Select]
Procedure AppOnIdle(Ticks: Integer);
var ID,Weapon1,Weapon2,X,Y: Byte; 
  begin
    for ID := 1 to 32 do begin
      Weapon1 := GetPlayerStat(ID,'Primary');
      Weapon2 := GetPlayerStat(ID,'Secondary');
      GetPlayerXY(ID,X,Y);
      if Weapon1 <> 255 then begin
        ForceWeapon(ID,255,255,0);
        if Weapon1 <> 15 then
          SpawnObject(X,Y-32,Weapon1);
      end;
      if Weapon2 <> 255 then begin
        ForceWeapon(ID,255,255,0);
        if Weapon2 <> 15 then
          SpawnObject(X,Y-32,Weapon2);
      end;
    end;
  end;     


Didn't test it but it should work.

Offline Mercury92

  • Camper
  • ***
  • Posts: 284
Re: (OnWeaponChange): Out of Global Vars range
« Reply #2 on: May 01, 2010, 10:39:36 am »
Still I would like to stay with OnWeaponChange not AppOnIdle.
[saw]  on 1.5.1

DarkCrusade

  • Guest
Re: (OnWeaponChange): Out of Global Vars range
« Reply #3 on: May 01, 2010, 10:50:32 am »
Then just change the necessary parts ...

Offline Mercury92

  • Camper
  • ***
  • Posts: 284
Re: (OnWeaponChange): Out of Global Vars range
« Reply #4 on: May 01, 2010, 11:02:03 am »
I am sure removing "if (GetPlayerStat(ID,'Active') = true)" then and "if (GetPlayerStat(ID,'Alive') = true) then" is not a big deal and won't solve error.

Error comes up at random time.
[saw]  on 1.5.1

DarkCrusade

  • Guest
Re: (OnWeaponChange): Out of Global Vars range
« Reply #5 on: May 01, 2010, 11:52:31 am »
I just said that they are really not necessary and make your script less effective. Did you post the whole procedure or just a part of it? Because there are no global variables in it that could be out of range.

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: (OnWeaponChange): Out of Global Vars range
« Reply #6 on: May 01, 2010, 11:55:06 am »
I just said that they are really not necessary and make your script less effective.
You suggested putting it in apponidle... Glass houses and all that?

Offline Mercury92

  • Camper
  • ***
  • Posts: 284
Re: (OnWeaponChange): Out of Global Vars range
« Reply #7 on: May 01, 2010, 12:17:27 pm »
It is a whole procedure in that code.
[saw]  on 1.5.1

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: (OnWeaponChange): Out of Global Vars range
« Reply #8 on: May 01, 2010, 12:21:13 pm »
What server version? I'm not getting any errors at all with the current one..

Offline Mercury92

  • Camper
  • ***
  • Posts: 284
Re: (OnWeaponChange): Out of Global Vars range
« Reply #9 on: May 01, 2010, 01:03:09 pm »
2.6.5
Playing with bots doesn't seems to give any error. Happens often with players.
[saw]  on 1.5.1

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: (OnWeaponChange): Out of Global Vars range
« Reply #10 on: May 01, 2010, 01:04:15 pm »
Comment out parts of OnWeaponChange and see if the error still appears.

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: (OnWeaponChange): Out of Global Vars range
« Reply #11 on: May 01, 2010, 02:27:07 pm »
how can you not understand that GetPlayerStat's weapon IDs are different from the SpawnObject IDs? You need to replace some numbers before spawning what you need.

Also, anyone tried spawning an object with ID 0 or 255?

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: (OnWeaponChange): Out of Global Vars range
« Reply #12 on: May 01, 2010, 03:06:34 pm »
Also, anyone tried spawning an object with ID 0 or 255?
Why would you O_o?

DarkCrusade

  • Guest
Re: (OnWeaponChange): Out of Global Vars range
« Reply #13 on: May 01, 2010, 05:23:13 pm »
Because Mercury tried to spawn fists