HALO Style Weapon System

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

Re: OK, Changing Plans.

Post by metal_head » Tue Feb 03, 2009 2:52 pm

Your script makes more sence :D
To get it really working you'll have to add a little something to change the weapon when the player swaps to a weapon on the ground. Like a variable that stores the index of the currently armed weapon. Then compare that variable to what should be armed (the attributes 'weapon1', 'weapon2', 'weapon3') and if it's not the same then change the weapon.
Hmm, I didn't understand what do you mean by comparing the variable to what should be armed. I'll have to add a variable with the number of the weapon slots, right? And use it somehow only when the weapon changes?

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

Re: OK, Changing Plans.

Post by Juutis » Tue Feb 03, 2009 3:35 pm

Ah, never mind. You don't actually need a variable for that. The attributes tell which weapon should be armed and the script then changes it, right? So what we wanna do is compare the currently armed weapon and the weapon that should be armed, and if they're different then change the weapon to what it should be.

Something like this:
if(self.player_weapon != GetAttribute("weapon1","Player))
{
SetPlayerWeapon(GetAttribute("weapon1","Player));
}
Pain is only psychological.

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

Re: OK, Changing Plans.

Post by metal_head » Tue Feb 03, 2009 7:33 pm

So this is done, I decided to leave it like this, brcause it's more reallistic (if you so wanna change your weapon with the same one :lol: ).

OK, here's what I did for the other pawn that should be the weapon pickup, this is my first selfmade piece of script, that works actually :D :

Code: Select all

{

	WEAPON[4]
	SOUND1[weapon/available.wav]
	SOUND2[weapon/arm.wav]

	Setup[ ()
	{
		Console(true);
		SetNoCollision(true);
		NewOrder("StandBy"); 
 	} ] 

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

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

	Action[ () 
	{
	self.ThinkTime = 0.1;
		if(self.key_pressed=14) 
		{
		SetAttribute("armour", 100, "Player"); 
		}

		if(self.player_range>200) 
        	{
		HighLevel("StandBy"); 
		return 0;
		}
	} ]
}
It detects if you are in 200 texels radius of the pawn and if you are and you've pressed key 14 ("Q") then the pawn gives you the attribute. I made this with the armour attribute just for instance to see if it works. Now, I got another problem:
How is it possible this script to detect which is the current weapon, that the player holds, so that when the player takes the weapon from the ground to leave the weapon that he has just been holding. I have no idea for this, maybe I'm gonna have to use attributes again?

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

Re: OK, Changing Plans.

Post by Juutis » Tue Feb 03, 2009 8:22 pm

metal_head wrote:Now, I got another problem:
How is it possible this script to detect which is the current weapon, that the player holds, so that when the player takes the weapon from the ground to leave the weapon that he has just been holding. I have no idea for this, maybe I'm gonna have to use attributes again?
You can get the player's current weapon with self.player_weapon.

For the visual effect I'd recommend using the pawn weapons or accessories. Make the pawn itself have no model but add a weapon or accessory to it so you can see the correct model on the ground. Then when the player swaps his weapon with the pawn, just swap the weapon or accessory to show the correct model.
Pain is only psychological.

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

Re: OK, Changing Plans.

Post by metal_head » Tue Feb 03, 2009 9:23 pm

Ammm, what command can I use for attatching and replacing the weapon? I couldn't find the answer in the manual. Oh, and what was the commad for showing a HUD element in LowLevel, I looked for it, but no luck I think it was ShowHudElement(); but it didn't worked.

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

Re: OK, Changing Plans.

Post by Juutis » Tue Feb 03, 2009 9:46 pm

High level commands:
SetWeapon(string Section);

Activate the weapon defined in Pawn.ini as Section. The weapon actor will attach to the Pawn actor.
AttachAccessory(string SlaveName);
AttachAccessory(string SlaveName, string MasterName);

Attach the accessory defined in Pawn.ini as SlaveName to this Pawn's actor. The attached actor will use the same animation as its master.
Attach the accessory defined in Pawn.ini as SlaveName to the actor of the entity MasterName. The attached actor will use the same animation as its master.
Low level commands:
ShowHudPicture(int HUDpicture#, bool IsVisible);

ShowHudPicture(int HUDpicture#, bool IsVisible, string EntityName, int ScreenX, int ScreenY, float DisplayTime);
ShowHudPicture(int HUDpicture#, bool IsVisible, string EntityName, int ScreenX, int ScreenY, float DisplayTime, int WinX, int WinY);

Draws a BMP, JPG, TGA, PNG or an animated GIF file on the screen at location ScreenX, ScreenY.
ActivateHudElement(string AttributeName, bool Flag);

Activate/Deactivate the HUD for the attribute AttributeName.

Just search the scripting commands for 'hud', 'weapon' or 'accessory' and you'll find these all in less than a minute. :roll:
Pain is only psychological.

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

Re: OK, Changing Plans.

Post by metal_head » Tue Feb 10, 2009 5:20 pm

OK, sorry, I didn't have much time to do scripts, but now I'm back:
my biggest problem is how will the pickup pawn detect which slot is activated? In order to gives the value to the right attribute weapon1,2 or 3, the pawn should know which slot is activated, but how will I do this?

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

Re: OK, Changing Plans.

Post by Juutis » Tue Feb 17, 2009 8:53 pm

Sorry for taking so long. I seem to have overlooked this thread.

If you take a look at the first posts of this thread you can see I mention an attribute called 'weaponslot'. Basically, that's the attribute that tells which weapon slot is active.
Pain is only psychological.

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

Re: OK, Changing Plans.

Post by metal_head » Tue Feb 17, 2009 9:54 pm

Hmm, well I think I'm missing something in the weapon system then. The weapon system should change the "weaponslot" attribute every time I choose a weapon slot. For example if I press "1" for the first weapon slot, except for arming the weapon, the system will have to make the attribute "weaponslot" equal to 1, and if I choose the third weapon slot, the system should change the weaponslot attribute to 3. This can happen with the SetAttribute(); command, right?

OK, so when I do this, the weapon pickup script should check the value of the "weaponslot" attribute and then set the correct weapon attribute.

I can think only of this:

Code: Select all

if(GetAttribute("weaponslot","Player") = 1)
{
SetAttribute("weapon1", 1);
}

EDIT:
I edited the weapon system script, so now it should change the "weaponslot" attribute, according to what slot is active, but it doesn't change athe attribute:

Code: Select all

Slot1[ ()
{
	[b]SetAttribute("weaponslot", 1);[/b]
     self.ThinkTime = 0.0;
	SetPlayerWeapon(GetAttribute("weapon1","Player"));

     if(IsKeyDown(19))
     {
          SetPlayerWeapon(GetAttribute("weapon2","Player"));
          self.think = "Slot2";
          return 0;
     }
     if(IsKeyDown(20))
     {
          SetPlayerWeapon(GetAttribute("weapon3","Player"));
          self.think = "Slot3";
          return 0;
     }
} ] 
What is wrong here? The SetAttribute(); command is just ignored.

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

Re: OK, Changing Plans.

Post by Juutis » Wed Feb 18, 2009 6:52 pm

You have to put the "Player" parameter there. Right now it tries to change the pawn's own attribute called 'weaponslot'. The command should be:

Code: Select all

SetAttribute("weaponslot", 1,"Player");
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 » Wed Feb 18, 2009 7:58 pm

Ha thanks, now the weapon system is absolutely complete! And now I have some questions for the weapon pickup script.
Here's what I've done so far:

Code: Select all

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

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

	Action[ () 
	{
	self.ThinkTime = 0.1;
		if(self.key_pressed=14) 
		{
		Self.Think = Do;
		}

		if(self.player_range>200) 
        	{
		HighLevel("StandBy"); 
		return 0;
		}
	} ]
	Do[ ()
{
		if(GetAttribute("weaponslot","Player") = 1)
		{
		SetAttribute("weapon1", 4,"Player");
		}

		if(GetAttribute("weaponslot","Player") = 2)
		{
		SetAttribute("weapon2", 4,"Player");
		}

		if(GetAttribute("weaponslot","Player") = 3)
		{
		SetAttribute("weapon3", 4,"Player");
} ]
}
This will be the script for the weapon in the 4-th slot for instance. Now, everything works, but the script won't execute the "Do" order. I have no idea why is that, I'm in the 200 texel range of the pawn and I'm pressing the "Q" button, but the console still shows the "Action" order without chaging my weapon. Also, when I get out of the 200 texel range, the console still shows the "Action" order, and I think it should be showing "Standby". Any ideas?

Oh, and this is the hardest thing:
when I swap the weapon, the old weapon I've just put in the place of the new one should become pickable... I have no idea how to make this for all of the weapons in the game (which are about 20). Will I need a super long script for each of the weapon pickups, describing the other weapons that the pickup weapon can be swaped for?

Call me an idiot, but I'm actually starting to understand a lot of things in Simkin :lol: (IT'S TRUE!), but I'll need a lot of help to get friendly with it, so that's why I'm asking all those questions for everything :X

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

Re: HALO Style Weapon System

Post by Juutis » Wed Feb 18, 2009 8:35 pm

This will be the script for the weapon in the 4-th slot for instance. Now, everything works, but the script won't execute the "Do" order. I have no idea why is that, I'm in the 200 texel range of the pawn and I'm pressing the "Q" button, but the console still shows the "Action" order without chaging my weapon. Also, when I get out of the 200 texel range, the console still shows the "Action" order, and I think it should be showing "Standby". Any ideas?
Actually, the script is jumping between the 'StandBy' and 'Action' orders. It just doesn't show that since the only command you have in 'StandBy' is the PlayerDistOrder() command. Try throwing in a Delay() command and the console should show it properly.

As for the script not going into the 'Do' order:

Code: Select all

Self.Think = Do;
Should be:

Code: Select all

self.think = Do;
There's a difference between upper and lower case letters.

In addition, you're missing the ending bracket } for the last if-statement in the 'Do' order.

Oh, and this is the hardest thing:
when I swap the weapon, the old weapon I've just put in the place of the new one should become pickable... I have no idea how to make this for all of the weapons in the game (which are about 20). Will I need a super long script for each of the weapon pickups, describing the other weapons that the pickup weapon can be swaped for?
You could give the pickup pawn a variable that tells which weapon it "is". Then, when the player wants to pick the weapon up you swap the weapons so that the pickup pawn gets the weapon the player has and vice versa. Something like this:

Code: Select all

if(GetAttribute("weaponslot","Player") = 1)
{
   temporary_variable = GetAttribute("weapon1","Player");
   SetAttribute("weapon1",MY_WEAPON,"Player");
   MY_WEAPON = temporary_variable;
}
MY_WEAPON is the variable that contains which weapon the pickup pawn has currently and temporary_variable is just a temporary variable to prevent one of the weapons from getting lost. If you don't have that variable, it would first set the player's weapon to be MY_WEAPON and then set MY_WEAPON to be the player's weapon (which at this point is MY_WEAPON), effectively causing the player's old weapon to disappear.

For the visuals, I recommend using pawn accessories. I think I've mentioned it already. They're just the right things for this kind of stuff. Basically the pawn itself should be invisible and attach a weapon model to it as an accessory. It's then easy to swap these accessories to match the weapon that the pawn currently holds.
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 19, 2009 3:29 pm

Lol, that makes huge sence! How do you think of all this. I didn't realise it could be so easy, using only 2 variables, the temporary_variable takes the weapon# value, then the script changes the weapon of the player using the MY_WEAPON variable and after this is done, the MY_WEAPON variable get's the value from the temporary_variable, simply genious :shock: !

OK, now I have some order execution problems...
the script looks like this:

Code: Select all

{
temporary_variable [0]
WEAPON [4]

	Setup[ ()
	{
		Console(true);
		SetNoCollision(true);
		NewOrder("StandBy"); 
 	} ] 

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

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

	Action[ () 
	{
	self.ThinkTime = 0.1;
		if(self.key_pressed=14) 
		{
		self.think = Give;
		}

		if(self.player_range>200) 
        	{
		HighLevel("StandBy"); 
		return 0;
		}
	} ]
	Give[ ()
{
	self.ThinkTime = 0.1;
		if(GetAttribute("weaponslot","Player") = 1)
		{
  		 temporary_variable = GetAttribute("weapon1","Player");
   		SetAttribute("weapon1",WEAPON,"Player");
   		WEAPON = temporary_variable;
		}
		if(GetAttribute("weaponslot","Player") = 2)
		{
   		temporary_variable = GetAttribute("weapon2","Player");
  		 SetAttribute("weapon2",WEAPON,"Player");
  		 WEAPON = temporary_variable;
		}
		if(GetAttribute("weaponslot","Player") = 3)
		{
  		 temporary_variable = GetAttribute("weapon3","Player");
  		 SetAttribute("weapon3",WEAPON,"Player");
  		 WEAPON = temporary_variable;
		}
		
} ]
}
The script checks if the player is in the range, executes the "Action" order, but when I press "Q", the script should execute the "Give" order, where it will check which weapon slot I'm using and give set the right weapon attribute to 4, but why, when the script could just crash the game :lol: (yeah, the game crashes after I've pressed "Q").
I have the feeling that there's something wrong in this line:

Code: Select all

if(self.key_pressed=14) 
		{
		self.think = Give;
		}
I see nothing wrong here, but I see nothing wrong nowhere in the script, and I think that maybe here's the problem.
Why, you bad script? Shouldn't you execute the "Give" and show in the console if there's a problem :twisted:

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 3:33 pm

self.think = "Give";

:)

***EDIT***
Now that I think of it, it should be:

Code: Select all

if(self.key_pressed=14)
      {
      Give();
      }
So that the script only calls the 'Give' order once.
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 19, 2009 5:39 pm

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.

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.

Post Reply