Author Topic: Forcing a secondary weapon, no primary  (Read 1685 times)

0 Members and 1 Guest are viewing this topic.

Offline Mexer

  • Soldier
  • **
  • Posts: 121
  • real eyes. realize. real lies.
Forcing a secondary weapon, no primary
« on: February 07, 2012, 04:55:32 am »
How do I force a player have secondary only when he does !command ,while his primary disappears and when he respawns he won't be able to pick any primary (only secondaries) ?
Soldat devs and community: We want this game to be successful and have new players and make it popular!

Soldat devs and community: But we want the oldskool graphics and bugs and errors to be left alone! Soldat shall never change!!!

Offline Tehbugerz0r

  • Soldier
  • **
  • Posts: 158
Re: Forcing a secondary weapon, no primary
« Reply #1 on: February 07, 2012, 09:00:19 am »
This question confuses me, from what I can tell you want people who type "!command" to be doomed to be without primaries? If the question is just how to give player no primary then the answer is simple:

Code: [Select]
procedure RemovePrimary( ID, Primary, Secondary :byte );

begin

   if ( ( Secondary <= 10 ) and ( Secondary > 0 ) ) then
   ForceWeapon( ID, Primary, 255, GetPlayerStat( ID, 'Ammo' ) );

   if ( ( Primary <= 10 ) and ( Primary > 0) ) then
   ForceWeapon( ID, 255, Secondary, 0 );

end;

Untested, probably not the best way, correct any mistakes if you need. This will also regenerate the secondary weapon's ammo, unless it's in primary slot.
Again, I'm having trouble understanding the question so this may not be the answer you're looking for.
« Last Edit: February 07, 2012, 09:04:03 am by Tehbugerz0r »

Offline Mexer

  • Soldier
  • **
  • Posts: 121
  • real eyes. realize. real lies.
Re: Forcing a secondary weapon, no primary
« Reply #2 on: February 07, 2012, 11:16:56 am »
Well, I want to make a script so whenever someone does !medic, his primary disappears (or drops off) and he'll be left only with the secondary. In addition to that , I wanna make him not able to pick up any other primaries from the ground, not able to pick a primary when he respawns, and when he switches team or does !medic again so he won't be medic anymore, to allow him to use primaries as before.
Soldat devs and community: We want this game to be successful and have new players and make it popular!

Soldat devs and community: But we want the oldskool graphics and bugs and errors to be left alone! Soldat shall never change!!!

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Forcing a secondary weapon, no primary
« Reply #3 on: February 07, 2012, 11:44:36 am »
What part are you having trouble with? Seems fairly straight forward... Keep track of it with a boolean array, switch it on/off in OnCommand (and OnJoinTeam)... You could use SetWeaponActive to get rid of it in when picking weapons, combined with ForceWeapon in OnWeaponChange and OnPlayerRespawn.

Offline Bonecrusher

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1397
  • High above
    • Zabijaka.pl
Re: Forcing a secondary weapon, no primary
« Reply #4 on: February 07, 2012, 01:27:49 pm »
seems like a good script i guess i'll use it

Im chill like that

Offline Tehbugerz0r

  • Soldier
  • **
  • Posts: 158
Re: Forcing a secondary weapon, no primary
« Reply #5 on: February 07, 2012, 02:57:02 pm »
Well, I want to make a script so whenever someone does !medic, his primary disappears (or drops off) and he'll be left only with the secondary. In addition to that , I wanna make him not able to pick up any other primaries from the ground, not able to pick a primary when he respawns, and when he switches team or does !medic again so he won't be medic anymore, to allow him to use primaries as before.
Ah, context helps.
I strongly recommend you don't use setweaponactive on all primaries, from my experience that causes the player to get stuck at the weapon menu.

It might just be easier for me to give you a code for it.
Code: [Select]
var
Medic:array[1..MaxPlayers] of boolean;

procedure RemovePrimary( ID, Primary, Secondary :byte );

begin

 if ( ( Secondary <= 10 ) and ( Secondary > 0 ) ) then
 ForceWeapon( ID, Primary, 255, GetPlayerStat( ID, 'Ammo' ) );

 if ( ( Primary <= 10 ) and ( Primary > 0) ) then
 ForceWeapon( ID, 255, Secondary, 0 );

end;

procedure OnWeaponChange( ID, PrimaryNum, SecondaryNum: Byte );

begin

 if Medic[ID]=true then
 RemoveSecondary( ID, PrimaryNum, SecondaryNum );

end;

procedure OnPlayerRespawn( ID: Byte );
begin

 if Medic[ID]=true then
 RemoveSecondary( ID, GetPlayerStat( ID, 'Primary' ), GetPlayerStat( ID, 'Secondary' );

end;

procedure OnPlayerSpeak( ID: byte; Text: string );

begin

if Lowercase(Text)='!medic' then
 begin
 
  Medic[ID] := ( Medic[ID] = false );
  if ( Medic[ID] = true ) then RemoveSecondary( ID, GetPlayerStat( ID, 'Primary' ), GetPlayerStat( ID, 'Secondary' );
 
 end;

end;

procedure OnJoinTeam( ID, Team: byte );

begin

 if ( Medic[ID] = true ) then Medic[ID] := false;

end;

Again, untested and made in a few minutes. Might not compile.

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Forcing a secondary weapon, no primary
« Reply #6 on: February 07, 2012, 06:11:54 pm »
Found in above after a quick look:
- array 1..MaxPlayers won't compile as MaxPlayers is variable. Also it is not a good idea to do player array from 1 to whatever is set in INI as there may be bots on the server.
- Secondary > 0 and Primary > 0 has no sense as both are unsigned bytes
- in OnPlayerRespawn player has most likely still weapon menu opened
- doesn't Medic[ID] := not Medic[ID] look sexier? also just if Medic[ID] instead of if ( Medic[ID] = true )
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline Tehbugerz0r

  • Soldier
  • **
  • Posts: 158
Re: Forcing a secondary weapon, no primary
« Reply #7 on: February 08, 2012, 12:39:56 am »
Found in above after a quick look:
- array 1..MaxPlayers won't compile as MaxPlayers is variable. Also it is not a good idea to do player array from 1 to whatever is set in INI as there may be bots on the server.
- Secondary > 0 and Primary > 0 has no sense as both are unsigned bytes
- in OnPlayerRespawn player has most likely still weapon menu opened
- doesn't Medic[ID] := not Medic[ID] look sexier? also just if Medic[ID] instead of if ( Medic[ID] = true )

- Derp, somehow that slipped my mind. I was hoping he'd replace it with whatever the max players would be. Just couldn't bring myself to put 1..32.

- How does it make no sense? An unsigned byte ranges from 0 to 255. I think 0 also represents the Socom which is secondary. Did you mistake it for ">="? Sure, you could do it another way than "> 0" but I figured that was easiest to read. Guess I was wrong.

- I added that last second in case they disabled weapon menu.

- I guess if you want it smaller, but it looks better and easier to understand the way I did it in my own opinion. I have always preferred putting " = true" after a boolean variable even though it's like saying "true = true", just an odd personal preference.
« Last Edit: February 08, 2012, 12:49:25 am by Tehbugerz0r »

Offline Mexer

  • Soldier
  • **
  • Posts: 121
  • real eyes. realize. real lies.
Re: Forcing a secondary weapon, no primary
« Reply #8 on: February 08, 2012, 10:12:36 am »
Code: [Select]
procedure RemovePrimary( ID, Primary, Secondary :byte );
  • tkpunish -> [Error] (120:12): Unknown identifier 'Secondary'
  • Compilation Failed.


what's his problem? ._.  Can't verify it cause enesce.com/help is offline..
Soldat devs and community: We want this game to be successful and have new players and make it popular!

Soldat devs and community: But we want the oldskool graphics and bugs and errors to be left alone! Soldat shall never change!!!

Offline Tehbugerz0r

  • Soldier
  • **
  • Posts: 158
Re: Forcing a secondary weapon, no primary
« Reply #9 on: February 08, 2012, 10:23:32 am »
Code: [Select]
procedure RemovePrimary( ID, Primary, Secondary :byte );
  • tkpunish -> [Error] (120:12): Unknown identifier 'Secondary'
  • Compilation Failed.


what's his problem? ._.  Can't verify it cause enesce.com/help is offline..

Dunno what that's about, but the last code I gave had problems. Also enesce.com/help wouldn't help with that.

Code: [Select]
Const

MAXPLAYERSANDBOTS=14;

var
Medic:array[1..MAXPLAYERSANDBOTS] of boolean;

procedure RemovePrimary( ID, PrimaryNum, SecondaryNum :byte );

begin

 if ( ( SecondaryNum <= 10 ) and ( SecondaryNum > 0 ) ) then
 ForceWeapon( ID, PrimaryNum, 255, GetPlayerStat( ID, 'Ammo' ) );

 if ( ( PrimaryNum <= 10 ) and ( PrimaryNum > 0) ) then
 ForceWeapon( ID, 255, SecondaryNum, 0 );

end;

procedure OnWeaponChange( ID, PrimaryNum, SecondaryNum: Byte );

begin

 if Medic[ID]=true then
 RemovePrimary( ID, PrimaryNum, SecondaryNum );

end;

procedure OnPlayerRespawn( ID: Byte );
begin

 if Medic[ID]=true then
 RemovePrimary( ID, GetPlayerStat( ID, 'Primary' ), GetPlayerStat( ID, 'Secondary' ) );

end;

procedure OnPlayerSpeak( ID: byte; Text: string );

begin

if Lowercase(Text)='!medic' then
 begin
 
  Medic[ID] := ( Medic[ID] = false );
  if ( Medic[ID] = true ) then RemovePrimary( ID, GetPlayerStat( ID, 'Primary' ), GetPlayerStat( ID, 'Secondary' ) );
 
 end;

end;

procedure OnJoinTeam( ID, Team: byte );

begin

 if ( Medic[ID] = true ) then Medic[ID] := false;

end;

Compiled and tested.

For some reason I was putting RemoveSecondary, must've been because I made it at 4 AM.
« Last Edit: February 08, 2012, 10:29:34 am by Tehbugerz0r »

Offline Mexer

  • Soldier
  • **
  • Posts: 121
  • real eyes. realize. real lies.
Re: Forcing a secondary weapon, no primary
« Reply #10 on: February 08, 2012, 12:55:18 pm »
The thing is, with your script, after you respawn both of your primary and secondary is removed.

Also picking up weapons still works, need to change OnWeaponChange...
Soldat devs and community: We want this game to be successful and have new players and make it popular!

Soldat devs and community: But we want the oldskool graphics and bugs and errors to be left alone! Soldat shall never change!!!

Offline Tehbugerz0r

  • Soldier
  • **
  • Posts: 158
Re: Forcing a secondary weapon, no primary
« Reply #11 on: February 08, 2012, 10:32:12 pm »
The thing is, with your script, after you respawn both of your primary and secondary is removed.

Also picking up weapons still works, need to change OnWeaponChange...
That's very odd, false readings would have to be involved here, I looked it over a few times and couldn't see why it would do that for any other reason. I also found that it somehow unselected your selected weapons so you'd have to pick them again O.o. However AOI works, after spending a minute of testing:
Prevent Weapon grab: tested
Respawn: tested
Remove After !medic: tested.

Code: [Select]
Const

MAXPLAYERSANDBOTS=20;

var
Medic:array[1..MAXPLAYERSANDBOTS] of boolean;

procedure RemovePrimary( ID, PrimaryNum, SecondaryNum :byte );

begin

 if ( ( SecondaryNum <= 10 ) and ( SecondaryNum > 0 ) ) then
  ForceWeapon( ID, PrimaryNum, 255, GetPlayerStat( ID, 'Ammo' ) );

 if ( ( PrimaryNum <= 10 ) and ( PrimaryNum > 0) ) then
  ForceWeapon( ID, 255, SecondaryNum, 0 );

end;

procedure AppOnIdle( Ticks: Integer );
var i:byte;
begin

 for i := 1 to MAXPLAYERSANDBOTS do
  if ( ( Medic[i]=true ) and ( GetPlayerStat( i, 'Alive' ) ) ) then
   RemovePrimary( i, GetPlayerStat( i, 'Primary' ), GetPlayerStat( i, 'Secondary' ) );

end;

procedure OnPlayerSpeak( ID: byte; Text: string );

begin

 if Lowercase(Text)='!medic' then
  Medic[ID] := ( Medic[ID] = false );

end;

procedure OnJoinTeam( ID, Team: byte );

begin

 if ( Medic[ID] = true ) then Medic[ID] := false;

end;