Autoswitch Weapons.

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Autoswitch Weapons.

Post by metal_head » Sun Aug 10, 2008 7:28 pm

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?

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Autoswitch Weapons.

Post by Juutis » Sun Aug 10, 2008 8:32 pm

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;
      }
   }

} ]
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Autoswitch Weapons.

Post by metal_head » Sun Aug 10, 2008 8:57 pm

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. :)

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Autoswitch Weapons.

Post by Juutis » Sun Aug 10, 2008 9:12 pm

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. :)
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Autoswitch Weapons.

Post by metal_head » Sun Aug 10, 2008 9:14 pm

Thanks,one more thing I learned from you :D!

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Autoswitch Weapons.

Post by metal_head » Sun Oct 05, 2008 6:40 pm

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:

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Autoswitch Weapons.

Post by Juutis » Wed Oct 22, 2008 2:34 pm

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.
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Autoswitch Weapons.

Post by metal_head » Wed Oct 22, 2008 4:10 pm

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).

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Autoswitch Weapons.

Post by Juutis » Wed Oct 22, 2008 4:28 pm

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 [ ()
{

} ]

}
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Autoswitch Weapons.

Post by metal_head » Wed Oct 22, 2008 5:22 pm

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.

Post Reply