Page 1 of 1

Autoswitch Weapons.

Posted: Sun Aug 10, 2008 7:28 pm
by metal_head
Is it possible when the player picks a weapon,the game to switch to the picked up weapon,instead of staying with the same weapon untill the player chooses the picked up weapon?

Re: Autoswitch Weapons.

Posted: Sun Aug 10, 2008 8:32 pm
by Juutis
A little piece of script to get you started:

Code: Select all

gun_variable   [0]
gun_slot       [5]

setup[ ()
{
   gun_variable = GetAttribute("gun","Player");
   think = "run";
} ]

run[ ()
{
   ThinkTime = 0.1;

   if(gun_variable = 0)
   {
      if(GetAttribute("gun","Player") > 0)
      {
          SetPlayerWeapon(gun_slot);
          gun_variable = 1;
      }
   }

} ]

Re: Autoswitch Weapons.

Posted: Sun Aug 10, 2008 8:57 pm
by metal_head
thanks Juutis one more time and actually,that get's me done :D ! I think (have to finnish animating one of the weapons and than I'll test it!

Only if you can explain to me this part,it will be great!

Code: Select all

gun_variable = GetAttribute("gun","Player");
I cant understand whant this line does and how it does it. :)

Re: Autoswitch Weapons.

Posted: Sun Aug 10, 2008 9:12 pm
by Juutis
It just stores the amount of 'guns' the player has in the beginning. So if the player already has the weapon 'gun' (in level start for example) the script won't change the player's weapon. The main idea here is: If player has no 'gun' -> check if he has picked it up -> change weapon. If the player already has 'gun' don't bother checking the attribute anymore. Hope that's clear enough. :)

Re: Autoswitch Weapons.

Posted: Sun Aug 10, 2008 9:14 pm
by metal_head
Thanks,one more thing I learned from you :D!

Re: Autoswitch Weapons.

Posted: Sun Oct 05, 2008 6:40 pm
by metal_head
Amm...I'm terribly sorry for this,I should have posted earlier,but I completely forgot and that's important. I didn't manage to make the desired effect (the weapon autochange).

Code: Select all

{
gun_variable   [0]
gun_slot       [6]

Spawn[ ()
{
Console(true);
PawnRender(false);
LowLevel("setup");
} ]

setup[ ()
{
   gun_variable = GetAttribute("sniper","Player");
   think = "run";
} ]

run[ ()
{
   ThinkTime = 0.1;

   if(gun_variable = 0)
   {
      if(GetAttribute("sniper","Player") > 0)
      {
          SetPlayerWeapon(gun_slot);
          gun_variable = 1;
      }
   }

} ]
Here's the finnished script,I think it should be working,right? When the player picks up the attribute "sniper",the script should change he Player's weapon to the weapon that's in the 6-th position.I'm sorry again,it's totally stupid and incorrect of me to post this after all this time! :oops: :oops:

Re: Autoswitch Weapons.

Posted: Wed Oct 22, 2008 2:34 pm
by Juutis
metal_head wrote:I'm sorry again,it's totally stupid and incorrect of me to post this after all this time!
It's OK. Seriously, which is better: starting a new thread or posting in an old one? :wink:
And besides, I'm a terrible slowpoke too.

Anyway: PawnRender() is a low level command so it should be 'setup' order, not 'Spawn'. You're also missing the ending '}' for the script (probably another copy-paste mistake). But apart from those it worked for me. Also note that the weapon slot 6 is the weapon that has 'slot = 6' in its definition, not the one that's armed with the key 6.

Re: Autoswitch Weapons.

Posted: Wed Oct 22, 2008 4:10 pm
by metal_head
REally,really strange,the missed "}" wasn't a copy/paste mistake,I also removed the PawnRender command and before I put it into the "setup" order,I decided to test how is it working,but it wasn't working again... :(
it's really,really strange,I don't see nothing wrong:

Code: Select all

{
gun_variable   [0]
gun_slot       [6]

Spawn[ ()
{
Console(true);
LowLevel("setup");
} ]

setup[ ()
{
   gun_variable = GetAttribute("sniper","Player");
   think = "run";
} ]

run[ ()
{
   ThinkTime = 0.1;

   if(gun_variable = 0)
   {
      if(GetAttribute("sniper","Player") > 0)
      {
          SetPlayerWeapon(gun_slot);
          gun_variable = 1;
      }
   }
}

} ]
The gun slot is 6 so the sniper rifle arms when I press "7":

Code: Select all

[sniper]
type = weapon
slot = 6
firerate = 2.5
catagory = projectile
projectile = rifle_shell
attribute = enemy_health
ammunition = rifle_shell
the attribute entity gives the Player an ammount of 1 of attribute,which looks like this:

Code: Select all

[sniper]
initial = 0
low = 0
high = 1
When I collect the sniper rifle,it jsut doesn't pick itself automaticly...I have to press "7",so that the weapon in the slot 6 will be activated (and that's the sniper).

Re: Autoswitch Weapons.

Posted: Wed Oct 22, 2008 4:28 pm
by Juutis

Code: Select all

...

run[ ()
{
   ThinkTime = 0.1;

   if(gun_variable = 0)
   {
      if(GetAttribute("sniper","Player") > 0)
      {
          SetPlayerWeapon(gun_slot);
          gun_variable = 1;
      }
   }
}

} ]
->

Code: Select all

...

run[ ()
{
   ThinkTime = 0.1;

   if(gun_variable = 0)
   {
      if(GetAttribute("sniper","Player") > 0)
      {
          SetPlayerWeapon(gun_slot);
          gun_variable = 1;
      }
   }
} ]

} 


The syntax for a script is:

Code: Select all

{

order1 [ ()
{

} ]

order2 [ ()
{

} ]

}

Re: Autoswitch Weapons.

Posted: Wed Oct 22, 2008 5:22 pm
by metal_head
oh,silly me,I shouldn't be making such mistakes... :oops: that was really stupid of me,and I checked the script twice for this type of mistakes.