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:

HALO Style Weapon System

Post by metal_head »

Remeber that "More,More,More!" topic I posted about the weapon system, well, that's really cool and actually helped me a lot in making my game, because I have a lot of weapons, so this script that Juutis wrote there helpet me get all the weapons in the game while making it. But now I've come to a point where I decided to change something, and it's the weapon system again :oops: .





http://www.realityfactory.info/forum/vi ... f=8&t=3830
There Dante said:
you could make an Ultra-realistic weapon system using the default one... which means that the player can only have 2 or 3 weapons in the same time. It would be, for example: a slot for rifles, another one for heavy weapons and explosives, and another one for guns... dont be affraid of putting various weapons in the same slot... the player will just have to throw the weapon before taking another!
When I was making the game then, I didn't wanted to be so reallistic, but now I really need to make something like this.

NOW, I don't want anybody to write a script for me, I just need help arround what should be scripted and what should the scripts do.

Now, here's what I want and here's what I think it can be done:
I want the player to have 3 slots, and in theese three slots to be able to put every weapon, so that way you can put 3 absolutely the same weapons (which is not a good Idea, cuz when the ammo is out :X :lol: , but let's leave this to the person who plays the game later). I don't want the player to be able to throw the weapons wheneverh he likes, but only when there's a weapon to change the current weapon with. So let's say there's a weapon on the ground, you walk over it, and a flipbook image is displayed (or a HUD element, dunno which is better), whith the picture of the weapon that is on the ground, and when you press TAB, the weapon on the ground to become your current weapon in the slot, and the weapon, you were just holding to become a pickable.

Now what I think it can be done, somebody correct me if I'm wrong, please.
FIrstly for the 3 slots, where you can put any weapon - I have no idea of how to do that, and probably that's the first thing to start with :X
Secondly for the weapon pickup - well, I can make the weapon on the ground not an attribute, but a pawn, it will detect if the player is near it and then check if the TAB button is pressed (that reminds me of the gen1car.s), but then what should this pawn do? I think it should add the new weapon attribute and take the other weapon attribute from the player.

So I think this will need maybe two scripts? One for the weapon pickups that will be pawns and one for the weapon slots where you can put any weapon in slot 1, any weapon in slot 2 and any weapon in slot 3 (but only one weapon in a slot).

I just need to know theese things, and maybe a hint with what to start (scripting) and I'lltry to do something myself, then I'll ask for help :D
Last edited by metal_head on Wed Feb 18, 2009 7:29 pm, edited 1 time in total.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: OK, Changing Plans.

Post by Juutis »

Yes, you are correct that you'll need one script for the weapon pickups and one for the slot system.

There are a couple of ways to do this but I think the simplest would be this: Give the player all weapons by default. Say, you have 5 weapons in slots 1-5, let the player have them all but disable the keys for changing the weapon. That way you can make a system that has its own way of checking what weapons the player has and which is armed. You can use attributes to save which weapon is in which slot. Like 'weapon1' tells which weapon is in the slot 1, 'weapon2' for slot 2 and 'weapon3' for slot 3. And finally an attribute that tells which of these slots is currently active, let's call that 'weaponslot'. What these attributes do is they refer to the built-in weapon slots (weapons 1-5). Then write a script that decides which weapon should be armed based on these attributes. Like:

weapon1 = 3
weapon2 = 1
weapon3 = 5
weaponslot = 1

Using pretty simple if-else statements it should see that the slot 1 is active, so arm the weapon in 'weapon1' with SetPlayerWeapon().

If you get this done then it's really easy to create the weapon pickups as you only have to change the three attributes (weapon1, weapon2, weapon3). Just check if the player is near enough and that TAB is pressed and then modify the attribute of the currently active slot.

Hope you got what I mean. If I were you I'd start with only one slot and get the system working before expanding it to three slots.
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 »

Hope you got what I mean. If I were you I'd start with only one slot and get the system working before expanding it to three slots.
You explained it really good, but I didn't get that wit the attributes:
so you say that if I got a total of 5 weapons in the game, I have to make an attribute that has 5 points or whatever are they called, right?The current slot will be detecting what is the value of the attribute and by that it will know what weapon to arm, right?
but that's only for one slot, I didn't get how can I make this for the three slots.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: OK, Changing Plans.

Post by Juutis »

The attributes are the core of this whole system. Actually they could be normal variables in a script but then it wouldn't work if you save and load the game. I'll try to explain it again:

OK, let's assume we have a total of five weapons again in the built-in weapon slots 1-5. I'll give examples:

Weapon slot 1: knife
Weapon slot 2: pistol
Weapon slot 3: shotgun
Weapon slot 4: machine gun
Weapon slot 5: sniper rifle

These are the weapons that can be assigned to the scripted weapon slots. And there are three scripted weapon slots. So the attribute 'weapon1' tells which of the five weapons is in the first scripted slot. 'weapon2' tells which is in the second, and 'weapon3' tells which is in the third slot. And the attribute 'weaponslot' tells which of these three scripted slots is activated. So, the example I used earlier:

weapon1 = 3
weapon2 = 1
weapon3 = 5
weaponslot = 1

This would mean that the first scripted slot has the shotgun, the second slot has the knife and the third slot has the sniper. Additionally, the first slot is active. So the slot system script should call the command SetPlayerWeapon(3), or more generally: SetPlayerWeapon(GetAttribute("weapon1","Player")).

If 'weaponslot' had a value of 2 the script would call SetPlayerWeapon(GetAttribute("weapon2","Player")).

Starting to make sense?
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 »

Yep, so now I'm starting to think for the algorithm for all this :lol: I'm starting to work on something, though that it will not be correct, so I'll post it for you to tell me where I'm wrong
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 »

Sorry for the double post, but I got some troubble in the begining:

I couldn't figure out how to make the algorith :X I mean taht I don't know with what to start with and what the script should actually do. I'm not asking you guys to script something for me, but to help me solve the the what-should-the-script-do problem. I started making the attribute pawn script, wich is easier to me, because I know what to do to make the script work, but here I got some difficulties, I got everything Juutis said, but I don't know what should I start with to make this a script. This is my biggest problem, in school we study Pascal (because I'm a beginner) I got an "A",but it's still hard, and not the langage is hard (this is the lames language I've used :D:D) but the algorithm I have to think of for the program to work.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: OK, Changing Plans.

Post by Juutis »

First make a setup order to hide the pawn from the level, disable gravity and collision etc. Then start thinking about the main routine. It should check if any of the attributes ('weapon1', 'weapon2', 'weapon3') has changed since the last time it checked and then change the weapon. It should also check if the keys 1-3 (or whatever keys you are using for swapping between the three weapons) are pressed and then again change the weapon based on that.
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 »

Code: Select all

{
QUARK_GUN                  [0]
HEAVY_BOLTER               [1]
	Prepare[ ()
	{
	Console(true);
	LolLevel('start');
	} ]

	start[()
	{
	if(GetAttribute("weapon1","Player") = 0)
	{
	SetPlayerWeapon(QUARK_GUN);
	}

	else
	{
	if(GetAttribute("weapon1","Player) = 1)
	{
	SetPlayerWeapon(HEAVY_BOLTER);
	}
	}
	}]
}
OK,this is just and example of what's in my head, I'm pretty sure that that's not correct, but would that work if I check like that for every case of the attribute "weapon1" after that - "weapon2" and like that, also how I'm going to make the slot changing?

I was thinking for that:
The command IsKeyDown();
For example this "start" order will be for the first slot, but if another key is pressed (IsKeyDown), the script to switch to another order, which will be representing the second slot. Would that work and have I done at least something correct in this tiny piece of script I made myself?
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: OK, Changing Plans.

Post by Juutis »

For example this "start" order will be for the first slot, but if another key is pressed (IsKeyDown), the script to switch to another order, which will be representing the second slot.
Actually, yes. Great idea. I thought about putting everything in one order but splitting the script into many orders will probably be simpler and more effective.

OK,this is just and example of what's in my head, I'm pretty sure that that's not correct, but would that work if I check like that for every case of the attribute "weapon1" after that - "weapon2" and like that
You see, that's why we have the attributes. They tell you directly which weapons are armed in the slots. Right now you're doing something like this:

Code: Select all

if(a = 1)
{
     b = 1;
}

if(a = 2)
{
     b = 2;
}

if(a = 3)
{
     b = 3;
}
etc...
Which is just waste of time and effort. This does exactly the same thing:

Code: Select all

b = a;
So you can replace the endless if-else statements with a single:

Code: Select all

SetPlayerWeapon(GetAttribute("weapon1","Player"));
:wink:
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 »

Wow, I didn't think I can make this with just the SetPlayerWeapon(); command :shock: !

So I made something, but I have a problem, the script doesn't work :lol: Now maybe I could have fixed it if the console was appearing, but not even the console appears. Here's the script, can you tell me where I went wrong?

Code: Select all

{
Prepare[ ()
{
Console(true);
NewOrder("Slot1");
} ]

Slot1[ ()
{
SetPlayerWeapon(GetAttribute("weapon1","Player"));
if(IsKeyDown(19))
{
NewOrder("Slot2");
}
} ] 

Slot2[ ()
{
SetPlayerWeapon(GetAttribute("weapon2","Player"));
if(IsKeyDown(20))
{
NewOrder("Slot3");
}
} ]

Slot3[ () 
{
SetPlayerWeapon(GetAttribute("weapon3","Player"));
if(IsKeyDown("18"))
{
NewOrder("Slot1");
}
} ]
 
}
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: OK, Changing Plans.

Post by Juutis »

You should do this stuff in low level. There's no such commands as SetPlayerWeapon() or IsKeyDown() in high level.
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 »

oh, silly me... I forgot about this.

Code: Select all

{
Prepare[ ()
{
Console(true);
LowLevel("Slot1");
} ]

Slot1[ ()
{
SetPlayerWeapon(GetAttribute("weapon1", "Player"));
if(IsKeyDown(19))
{
LowLevel("Slot2");
}
} ] 

Slot2[ ()
{
SetPlayerWeapon(GetAttribute("weapon2", "Player"));
if(IsKeyDown(20))
{
LowLevel("Slot3");
}
} ]

Slot3[ () 
{
SetPlayerWeapon(GetAttribute("weapon3", "Player"));
if(IsKeyDown("18"))
{
LowLevel("Slot1");
}
} ]
 
}
What I've done is wrong, right, because it didn't change anything :(
Am I forgetting something?
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: OK, Changing Plans.

Post by Juutis »

If you're not seeing the console at all then there's something really wrong about the script. Or your pawn setup. And I don't see any errors that critical in the script so make sure you've got the script name right and 'Prepare' in the SpawnOrder field.

And BTW, the command for jumping between orders in low level is:

Code: Select all

self.think = <name of order>;
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 »

Thanks, it was the encoding of the scirpt file, I changed it to ANSI and it worked! Now I got another problem... When the level starts, the weapon that the order "Slot1" holds gets picked and it only does this, the script doesn't respond when I'm pressing the keys for the other two slots... I have no idea why. Can you help me a little bit more with this?

Oh, and thanks for the self.think tip, I didn't know it!
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: OK, Changing Plans.

Post by Juutis »

Here's something to get you (properly) started:

Code: Select all

Slot1[ ()
{
     self.ThinkTime = 0.0;

     if(IsKeyDown(19))
     {
          SetPlayerWeapon(GetAttribute("weapon2","Player"));
          self.think = "Slot2";
          return 0;
     }
     if(IsKeyDown(20))
     {
          SetPlayerWeapon(GetAttribute("weapon3","Player"));
          self.think = "Slot3";
          return 0;
     }
} ] 
Every low level command should have a 'self.ThinkTime = ... ' line. That defines how many seconds must pass before the order can be executed again. For example, 'self.ThinkTime = 0.1;' would mean that the order is executed 10 times a second. In this case you should put it to 0 so the order is executed every frame and you don't miss any keystrokes.

You should also add a 'return 0;' line when you jump to another order. This stops the execution of the old order and jumps immediately. Otherwise the old order will be finished before jumping to the new one.

What this order should do is check if the Y or U keys are pressed and then change the weapon and switch to run 'Slot2' or 'Slot3'. Note that you don't have to change the weapon every time the order is executed. Only when the weapon actually changes. That is, when the player activates another weapon slot.

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