HALO Style Weapon System

Topics regarding Scripting with Reality Factory
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: HALO Style Weapon System

Post by Juutis » Thu Feb 19, 2009 10:08 pm

metal_head wrote:Nope, with

Code: Select all

Give();
the script didin't execute the "Give" order, I put "Give" in literals:

Code: Select all

self.think = "Give"; 
then the console showed that the "Give" order is being executed, but nothing changed, and there was no weapon swap.
If you call an order like that it is treated just like a normal command and the console won't show it.

I'm sorry I haven't told this before, but I just realized there's a couple of things you need to do:

Set some kind of limit to the Q key. The player is likely to press it a lot longer than just for one frame. Right now it swaps the weapons each frame when Q is pressed, leading to the weapons being swapped many times really fast. You should make it so that it can only swap the weapons if the Q has been released since the last push. Like push -> swap once -> release -> push -> swap once. To do this you gotta add a new variable that tells if the key is pressed. I'll call it button_pressed. Then do these changes to the slot system script:

Code: Select all

      if(IsKeyDown(14) and (button_pressed = false))
      {
           button_pressed = true;
           Give();
      }
      if(IsKeyDown(14) = false)
      {
           button_pressed = false;
      }
(I used IsKeyDown() to see if the key is pressed. That's more reliable than self.key_pressed)

And the second thing:
It might be that you've already done this but I thought I'd mention it anyway. Does the slot system script change the player's weapon when the weapon is swapped? In other words, do you call the SetPlayerWeapon() command every frame or only when the player selects another weapon slot? If you don't get what I mean just post the script. :)

metal_head wrote:Oh, and another question:
Once we're done with this, I'll have to visualize the guns swaping. I'm going to use the

Code: Select all

AttachAccessory();
command, but how will the script know which of the weapon pawns (defined for atatchemnd in Pawn.ini) to use when for example the MY_WEAPON variable is 4.
It's not possible to make it like the weapon arming:

Code: Select all

SetPlayerWeapon(GetAttribute("weapon2","Player"));
I'll have to make all the different accesory pawns responding to the different MY_WEAPON variable values, right? All I can think about for this is using "if" statements to check the different values of the MY_WEAPON variblae and then Remove the current accessory and add the new one, responding to the current MY_WEAPON value.
I'd approach this by creating an array with the weapon indices and the correct accessory names. And as I believe you haven't used arrays yet, here's a short introduction:

An array is defined like this:

Code: Select all

array_name
{
   [item_0]
   [item_1]
   [item_2]
   ...
   [item_n]
}
And you can read the value of an array item with

Code: Select all

array_name[item_number]
Where item_number is the index of the array item you want. The indexing starts from 0. So in the above array, array_name[0] would return the string "item_0". array_name[1] would return "item_1" etc.

See where I'm getting at? You can link numbers with strings. And that's exactly what you need to do. You need to attach an accessory name (string) to each weapon index (number). So add something like this in the start of your script where the variables are defined:

Code: Select all

    weaponarray
    {
        [accessory_pistol]           //weapon index = 0
        [accessory_shotgun]       //weapon index = 1
        [accessory_smg]            //etc...
        [accessory_assaultrifle]
        [accessory_sniper]
    }
Add as many weapons as you have.

Then you should be able to change the accessory with a single command:

Code: Select all

AttachAccessory(weaponarray[WEAPON]);
Pain is only psychological.

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

Re: HALO Style Weapon System

Post by metal_head » Fri Feb 20, 2009 7:19 pm

OK, so here's how the weapon Pickup script looks now:

Code: Select all

{
temporary_variable [0]
WEAPON [0]
button_pressed [false]

weaponarray
    {
        [accessory_alien_bolter] 
        [accessory_neon]       
        [accessory_sniper]  
	}
  
	Setup[ ()
	{
		Console(true);
		SetNoCollision(true);
		AttachAccessory(weaponarray[WEAPON]);
		NewOrder("StandBy"); 
 	} ] 

	StandBy[ ()
	{
		PlayerDistOrder(200, "DoIt"); 
	} ]

	DoIt[ ()
	{ 
		LowLevel("Action");
	} ]

	Action[ () 
	{
	if(IsKeyDown(14) and (button_pressed = false))
      {
           button_pressed = true;
           Give();
      }
      if(IsKeyDown(14) = false)
      {
           button_pressed = false;
      }

		if(self.player_range>200) 
        	{
		HighLevel("StandBy"); 
		return 0;
		}
	} ]
	Give[ ()
{
      
	self.ThinkTime = 0.0;
		if(GetAttribute("weaponslot","Player") = 1)
		{
  		 temporary_variable = GetAttribute("weapon1","Player");
   		SetAttribute("weapon1",WEAPON,"Player");
   		WEAPON = temporary_variable;
		HighLevel("Accessory");
		}
		if(GetAttribute("weaponslot","Player") = 2)
		{
   		temporary_variable = GetAttribute("weapon2","Player");
  		 SetAttribute("weapon2",WEAPON,"Player");
  		 WEAPON = temporary_variable;
		HighLevel("Accessory");
		}
		if(GetAttribute("weaponslot","Player") = 3)
		{
  		 temporary_variable = GetAttribute("weapon3","Player");
  		 SetAttribute("weapon3",WEAPON,"Player");
  		 WEAPON = temporary_variable;
		HighLevel("Accessory");
		}
		
} ]

	Accessory[ ()
{
AttachAccessory(weaponarray[WEAPON]);
NewOrder("StandBy");
} ]


}
Now the script switches the weapon which is the WEAPON variable holding (0 - the pistol), but I can't swap the weapon back, the script gives some error with IsKeyDown(); I think. Also: if I look at the pawn, the game will crash with no error log, so I can't see if the accessories are attatched to the pawn.
Any ideas of what could be wrong ?

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

Re: HALO Style Weapon System

Post by Juutis » Mon Feb 23, 2009 11:34 am

metal_head wrote:the script gives some error with IsKeyDown(); I think.
That's because you have no return command when you change to high level. So the script tries to finish the low level order with high level commands and as IsKeyDown is low level only, it gives an error. That's nothing to worry about, though, since the script will still work.
metal_head wrote:Also: if I look at the pawn, the game will crash with no error log, so I can't see if the accessories are attatched to the pawn.
I just couldn't reproduce this crash. Make sure you're not trying to attach an accessory that doesn't exist and maybe try it with a different model.


Anyway, I made some changes to the script and now it should work:
(at least it worked for me)

Code: Select all

{
temporary_variable [0]
WEAPON [0]
button_pressed [false]

weaponarray
    {
        [accessory_alien_bolter]
        [accessory_neon]       
        [accessory_sniper] 
   }
 
   Setup[ ()
   {
      Console(true);
      SetNoCollision(true);
      AttachAccessory(weaponarray[WEAPON]);
      NewOrder("StandBy");
   } ]

   StandBy[ ()
   {
      PlayerDistOrder(200, "DoIt");
   } ]

   DoIt[ ()
   {
      LowLevel("Action");
   } ]

   Action[ ()
   {
   if(IsKeyDown(14) and (button_pressed = false))
      {
           button_pressed = true;
           Give();
           return 0;
      }
      if(IsKeyDown(14) = false)
      {
           button_pressed = false;
      }

      if(self.player_range>200)
      {
           HighLevel("StandBy");
           return 0;
      }
   } ]
   Give[ ()
  {
     
   self.ThinkTime = 0.0;
    
      if(GetAttribute("weaponslot","Player") = 1)
      {
         temporary_variable = GetAttribute("weapon1","Player") + 0;
         SetAttribute("weapon1",WEAPON,"Player");
         HighLevel("Accessory");
         return 0;
      }
      if(GetAttribute("weaponslot","Player") = 2)
      {
         temporary_variable = GetAttribute("weapon2","Player");
         SetAttribute("weapon2",WEAPON,"Player");
         HighLevel("Accessory");
         return 0;
      }
      if(GetAttribute("weaponslot","Player") = 3)
      {
         temporary_variable = GetAttribute("weapon3","Player");
         SetAttribute("weapon3",WEAPON,"Player");
         HighLevel("Accessory");
         return 0;
      }
      
} ]

   Accessory[ ()
{
    DetachAccessory(weaponarray[WEAPON]);
    WEAPON = temporary_variable + 0;
    AttachAccessory(weaponarray[WEAPON]);
    NewOrder("StandBy");
} ]

}
Pain is only psychological.

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: HALO Style Weapon System

Post by Allanon » Tue Feb 24, 2009 11:08 pm

I haven't written any RF scripts but I do program. To make this script more efficient and not call IsKeyDown() twice shouldn't you do this:

Code: Select all

if(IsKeyDown(14))
{
    if (button_pressed = false))
    {
        button_pressed = true;
        Give();
        return 0;
    }
}
else
{
    button_press = false;
}

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

Re: HALO Style Weapon System

Post by metal_head » Thu Feb 26, 2009 4:20 pm

not call IsKeyDown() twice
What do you mean by calling IsKeyDown() twice? I didn't get it.


Amm, having some troubble with the AttatchAccessory command...
It doesn't attatch the pawn to the pawn :X... For exampe here:

Code: Select all

Setup[ ()
   {
      Console(true);
      SetNoCollision(true);
      AttachAccessory("accessory_alien_bolter");
      NewOrder("StandBy");
   } ]
Shouldn't the script attatch "accessory_alien_bolter" to the pawn here? all the pawns including the pawn, holding the scipt have the same skeleton (one joint, named "bone") I though that there's something wrong with the Pawn.ini, so I tried to change the pawn that holds the script with one of the weapon pawns, used for accessories and there was no problem, but no attatching is done... So could he problem be in the models (something with the joint maybe..)?

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

Re: HALO Style Weapon System

Post by Juutis » Thu Feb 26, 2009 5:22 pm

metal_head wrote:What do you mean by calling IsKeyDown() twice? I didn't get it.
He means it is called twice in the original script: First in

Code: Select all

if(IsKeyDown(14) and (button_pressed = false))
And then:

Code: Select all

if(IsKeyDown(14) = false)
And he's right. His way is more efficient.


metal_head wrote:Shouldn't the script attatch "accessory_alien_bolter" to the pawn here? all the pawns including the pawn, holding the scipt have the same skeleton (one joint, named "bone") I though that there's something wrong with the Pawn.ini, so I tried to change the pawn that holds the script with one of the weapon pawns, used for accessories and there was no problem, but no attatching is done... So could he problem be in the models (something with the joint maybe..)?
Could you post your Pawn.ini?
Pain is only psychological.

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

Re: HALO Style Weapon System

Post by metal_head » Thu Feb 26, 2009 5:42 pm

Yep:

Code: Select all

[accessory]
actorname = accessory\accessory.act
actorrotation = 0 180 0
actorscale = 1
fillcolor = 255 255 255
ambientcolor = 255 255 255
subjecttogravity = false
boundingboxanimation = nocollide
shadowsize = 0

[accessory_alien_bolter]
actorname = accessory\accessory_alien_bolter.act
actorrotation = 0 180 0
actorscale = 2
fillcolor = 255 255 255
ambientcolor = 255 255 255
subjecttogravity = false
boundingboxanimation = nocollide
shadowsize = 0

[accessory_neon]
actorname = accessory\accessory_neon.act
actorrotation = 0 180 0
actorscale = 2
fillcolor = 255 255 255
ambientcolor = 255 255 255
subjecttogravity = false
boundingboxanimation = nocollide
shadowsize = 0

[accessory_sniper]
actorname = accessory\accessory_sniper.act
actorrotation = 0 180 0
actorscale = 2
fillcolor = 255 255 255
ambientcolor = 255 255 255
subjecttogravity = false
boundingboxanimation = nocollide
shadowsize = 0
accessory is the pawn, that is made to hold the script, it is just a small box with a joint. The other three are the accessory pawns, that are supposed to be attatched. I can use the other three pawns to hold the script, and they show in the editor, they show in the level, but used as accessories, they don't appear...

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

Re: HALO Style Weapon System

Post by Juutis » Thu Feb 26, 2009 5:46 pm

Ah, just as I expected. :)

Accessories are not pawns. Check the Pawn.ini section in the manual to see how accessories are defined.
Pain is only psychological.

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

Re: HALO Style Weapon System

Post by metal_head » Thu Feb 26, 2009 8:11 pm

Amm :oops: , I searched the whole manual, and couldn't find anuthing, even tried to search for "Accessory"/"Accessories" in the search tab, but nothing was found...strange

Allanon
Posts: 493
Joined: Mon Aug 29, 2005 8:23 am

Re: HALO Style Weapon System

Post by Allanon » Thu Feb 26, 2009 8:25 pm

metal_head wrote:Amm :oops: , I searched the whole manual, and couldn't find anuthing, even tried to search for "Accessory"/"Accessories" in the search tab, but nothing was found...strange
Run the RealityFactory.chm help file which is located in the doc folder of the RF install. Then search for pawn and at the bottom of that page you will see:
Accessories
You can define accessories in the Pawn.ini file that can be attached to the other actor similar to the 3rd person weapons for the player. These accessory actors must have the same skeleton as the actor they get attached to and require no animations, as they are animated by the actor's current animation. The definition is the same as for Pawn weapons except for the type value which has to be accessory

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

Re: HALO Style Weapon System

Post by metal_head » Thu Feb 26, 2009 9:40 pm

Yay, so now everything works great!
But I still got some questions, as need to make some effects.

What I need is to make the script show a HUD image, when the player is in the range. OK, done, but I have some problems:
1. When I get in the radius, the script shows the HUD image for 2 seconds and the image dissaperas, ok, but after getting out of the radius and getting in again, the HUD image won't show up again... why is that, the order where the command is is executed every time, the player is in the range of the pawn, why this command won't execute again?
2.
Here's the part from my hud.ini where I've defined the HUD image:

Code: Select all

[picture14]
bitmap = use\hudtest.bmp
bitmapalpha = use\a_hudtest.bmp
active = false
and here's the line, where the script should show the image:

Code: Select all

ShowHudPicture("picture14", true, "", 650, 450, 2);
when I get in that radius, the script shows a HUD image, but it's not the one I've asked for (picture14), but some other image, take a look at the screen bellow:
Attachments
hudtest.jpg
hudtest.jpg (16.08 KiB) Viewed 897 times

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

Re: HALO Style Weapon System

Post by Juutis » Thu Feb 26, 2009 10:11 pm

metal_head wrote:when I get in that radius, the script shows a HUD image, but it's not the one I've asked for (picture14), but some other image, take a look at the screen bellow:
The command needs an integer as first parameter. You're giving it a string. Try:

Code: Select all

ShowHudPicture(14, true, "", 650, 450, 2);
Pain is only psychological.

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

Re: HALO Style Weapon System

Post by metal_head » Thu Feb 26, 2009 10:28 pm

Man...sometimes I'm amazed of my stupidness :X... thanks...
IT SAYS "int HUDpicture#", not "char HUDPicture#" AND I STILL DON'T SEE IT :X:X
:lol: ...no words... :oops:


EDIt:
At least I managed to make the HUDPicture appear when the player gets in the range of the pawn, and dissappear when he get's out, the only problem is that the HUD pictre won't change when the weapon is swaped, so I'll make another array for the HUD pictures, hope it works! :)

EDIT2:
Yep..done!
Thanks a lot guys!!! Oh, that's so COOL!

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

Re: HALO Style Weapon System

Post by metal_head » Fri Jun 05, 2009 6:33 pm

Am, 3 more questions:
1 Whatever I do, I can't rotate the pawn in the editor, whatever angle I set, the weapon still stands straight, it looks pretty funny and unreallistic

2 I tried to make the pawn to play a swap animation when the player swaps the weapons, but it doesn't work, what am I doing wrong?

3 How is it possible to attatch this pawn to another pawn, I want when the pawn dies, to drops it's weapon, but how will I spawn the weapon pawn right next to the position the pawn has died?

Code: Select all

{
temporary_variable [0]
WEAPON [0]
button_pressed [false]

weaponarray
    {
        [accessory_judge]
        [accessory_neon]       
        [accessory_sniper] 
	[accessory_alien_bolter]
        [accessory_neon]       
        [accessory_sniper] 
	[accessory_alien_bolter]
        [accessory_neon]       
        [accessory_sniper] 
	[accessory_alien_bolter]
        [accessory_neon]       
        [accessory_sniper] 
   }

hudarray
    {
        [0]
        [1]       
        [2] 
	[3]
        [4]       
        [5]  
	[6]
        [7]       
        [8] 
	[9]
        [15]       
        [16] 
   }

   Spawn[ ()
   {
      Console(true);
      SetNoCollision(true);
      AttachAccessory(weaponarray[WEAPON]);
      NewOrder("StandBy");
   } ]

   StandBy[ ()
   {
      LoopAnimation("idle", 0, "");
      PlayerDistOrder(40, "DoIt");

   } ]

   DoIt[ ()
   {
      LowLevel("Action");
   } ]

   Action[ ()
   {
   ShowHudPicture(hudarray[WEAPON], true, "", 630, 0,"");
   if(IsKeyDown(13) and (button_pressed = false))
      {
           button_pressed = true;
           Give();
           return 0;
      }
      if(IsKeyDown(13) = false)
      {
           button_pressed = false;
      }

      if(self.player_range>39)
      {
           ShowHudPicture(hudarray[WEAPON], false, "", 630, 0,"");
           HighLevel("StandBy");
           return 0;
      }
   } ]
   Give[ ()
  {
     
   self.ThinkTime = 0.0;
    
      if(GetAttribute("weaponslot","Player") = 1)
      {
         temporary_variable = GetAttribute("weapon1","Player") + 0;
         SetAttribute("weapon1",WEAPON,"Player");
	 AnimateHold("swap");
	 ShowHudPicture(hudarray[WEAPON], false, "", 630, 0,"");
         HighLevel("Accessory");
         return 0;
      }
      if(GetAttribute("weaponslot","Player") = 2)
      {
         temporary_variable = GetAttribute("weapon2","Player") + 0;
         SetAttribute("weapon2",WEAPON,"Player");
	 AnimateHold("swap");
         ShowHudPicture(hudarray[WEAPON], false, "", 630, 0,"");
         HighLevel("Accessory");
         return 0;
      }
      if(GetAttribute("weaponslot","Player") = 3)
      {
         temporary_variable = GetAttribute("weapon3","Player")+ 0;
         SetAttribute("weapon3",WEAPON,"Player");
	 AnimateHold("swap");
	 ShowHudPicture(hudarray[WEAPON], false, "", 630, 0,"");
         HighLevel("Accessory");
         return 0;
      }
      
} ]

   Accessory[ ()
{
    DetachAccessory(weaponarray[WEAPON]);
    WEAPON = temporary_variable + 0;
    AttachAccessory(weaponarray[WEAPON]);
    NewOrder("StandBy");
} ]
}

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

Re: HALO Style Weapon System

Post by Juutis » Wed Jun 10, 2009 9:25 pm

2.) Your problem is that you start playing the swap animation with AnimateHold and then immediately jump to the high level order 'Accessory'. The easiest fix would probably playing the animation in the high level order. Just add a PlayAnimation command in there before the accessory changes.

3.) One of RF's downsides is that you can't spawn pawns out of nowhere. Each has to be added into the level separately. So you'll have to add one weapon pickup pawn for each enemy pawn, virtually doubling the amount of pawns in your levels. So, what I would do is integrate the pickup script to the enemy script: when the enemy dies, it starts running the pickup script.

Of course, if you want to keep the enemies and the weapon pawns separated, that's not too hard either. Make the enemy pawns activate a unique trigger (the EntityName is your best option) and then give each weapon pawn the corresponding SpawnTrigger. Then you'll need to figure out a way to move the weapon pawn to the enemy pawn. One way would be to name the pawns similarly. Like 'enemy01' and 'enemy01_weapon'. Then the weapon pawn could just take the 7 first letters from its name ('enemy01') and use that to teleport to the correct place.
Pain is only psychological.

Post Reply