Respawning Weapons

Tutorials for Call of Duty 2 mapping

Moderator: Core Staff

Post Reply
User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Respawning Weapons

Post by Rezil » July 11th, 2010, 10:15 pm

Alright time for another quick tutorial, this time concerning respawning weapons and picking them up.

1. Mapping

Create a brush roughly the size of the player and make a trigger_multiple or a trigger_use_touch out of it. Give it these key/value pairs:

Key: targetname
Value: weapon_pickup_*

where * is the name of the weapon you want to pick up. After you've done that, right-click on the 2d grid and add a script_model. Use any model(it will be changed by a script anyway) and place it in the center of the trigger. Give it the following key/value pairs:

Key: targetname
Value: weapon_origin_*

where * is the name of the weapon you want to pick up. That's it for the mapping, save and compile.

2. Scripting

Save the following script as _weapon_pickup.gsc :

Code: Select all

/*
										Scripted by: Rezil
										--------------------------------
										Contact detail:
										
										xfire: saberteeth
										e-mail: Rezil@CoDJumper.com
										--------------------------------
										If you have any questions, either add me on xfire or
										send me en e-mail.
										--------------------------------
										
										Weapon picking up and respawning logic
-------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------------------
										Requirements:
										- At least one trigger named "weapon_pickup_*", where * is the name of the weapon(not the weapon xmodel)
									 (!)- At least one script_model named "weapon_origin_*", where * is the name of the weapon(not the weapon xmodel)
										- The ammount of triggers and script_models has to be the same
										--------------------------------
										How it works:
										
										- Call setupWeaponForPickup somewhere in your main level script,
										somewhere near the begining. 
										- 'weapon_name' is the name of the weapon you will actually 
										   shoot(eg. 'mp44_mp' or 'luger_mp')
										- 'weapon_xmodel' is the path to the model which represents the
										   weapon. Has to be a string(eg. "xmodel/weapon_kar98")
										- 'delay' is the delay in seconds after which the weapon will respawn(optional)
*/

setupWeaponForPickup(weapon_name, weapon_xmodel, delay)
{
	precachemodel(weapon_xmodel);
	trig = getentarray("weapon_pickup_" +weapon_name,"targetname");
	org = getentarray("weapon_origin_" +weapon_name,"targetname");
	if(org.size == trig.size) //same ammount of origins and triggers, otherwise you get errors
	{
		for(i=0;i<org.size;i++)
		{
			trig[i] thread WeaponPickup(org[i], weapon_name, weapon_xmodel, delay);
			
		}
	}
}

WeaponPickup(o, weapon, xmodel, delay)
{
	while(1)
	{
		o setmodel(xmodel);
		o notsolid(); //already true, just not sure about all script_models
		self waittill("trigger", user);
		c_weap = user getcurrentweapon();
		if(user hasweapon(weapon)) 
		{ //user already has that weapon, so keep the model showing and only max out the ammo
				user givemaxammo(weapon); 
				wait 10; //to prevent unlimited ammo while staying inside the trigger
				o playsound("weapon_maxammo"); 
		}
		else 
		{
			user takeweapon(c_weap);
			user giveweapon(weapon);
			user switchtoweapon(weapon);
			o playsound("weapon_pickup");
			
			o hide();
			self maps\mp\_utility::TriggerOff();
			
			if(isdefined(delay))
			{
				wait delay;
			}
			
			self maps\mp\_utility::TriggerOn();
			o playsound("weapon_respawned");
			o show();
		}
	}
}
Then, in your main function of your map add the following line at the very top:

Code: Select all

#include maps\mp\_weapon_pickup;
and call the function setupWeaponForPickup(weapon_name, weapon_xmodel, delay). Weapon_name is the name of the weapon you are going to pick up(for example 'mp44_mp'), weapon_xmodel is the path to the model that's going to replace the script_model you created earlier. It has to be a string(for example "xmodel/weapon_mp44"). Lastly, there's an optional delay which determines how long it will take for the weapon to respawn.

So if I wanted a luger to respawn every 5 seconds, I'd do this:

Code: Select all

setupWeaponForPickup("luger_mp", "xmodel/weapon_luger", 5);
That's it, have fun with the script and be sure to credit where appropriate!

Made by Rezil(with a tweak or two by Drofder)
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Respawning Weapons

Post by Rezil » July 11th, 2010, 11:52 pm

List of weapon names you can use:

bar_mp
bren_mp
colt_mp
defaultweapon_mp
enfield_mp
enfield_scope_mp
g43_mp
greasegun_mp
kar98k_mp
kar98k_sniper_mp
luger_mp
m1carbine_mp
m1garand_mp
mosin_nagant_mp
mosin_nagant_sniper_mp
mp40_mp
mp44_mp
panzerfaust_mp
panzerschreck_mp
pps42_mp
ppsh_mp
shotgun_mp
springfield_mp
sten_mp
svt40_mp
thompson_mp
tt30_mp
webley_mp
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

eisenhower
CJ Wannabe
CJ Wannabe
Posts: 2
Joined: April 18th, 2011, 2:06 pm

Re: Respawning Weapons

Post by eisenhower » April 18th, 2011, 3:55 pm

Hi,

I have tried to use your tutorial. I followed all your steps but it didnt work.
When I am in the game i want to pick up the weapon by pressing f (use).
Nothing happens i dont get a panzerschreck; the panzerschreck(script_model) disappears and after
5 seconds its back.

I want to have a panzerschreck in my map that respawns.

I made a trigger and i inserted a script model.

==========

Code: Select all

classname  trigger_use_touch
targetname weapon_pickup_panzerschreck_mp

Code: Select all

classname  script_model
model  xmodel/weapon_panzerschreck
origin 33 1240 16
targetname  weapon_origin_panzerschreck_mp
==========

Here is my main level script

Code: Select all

#include maps\mp\_weapon_pickup;

main()
{

maps\mp\_load::main();

setExpFog(0.0001, 0.55, 0.6, 0.55, 0);
// setCullFog(0, 16500, 0.55, 0.6, 0.55, 0);
ambientPlay("ambient_mp_farmtown");

game["allies"] = "american";
game["axis"] = "german";
game["attackers"] = "allies";
game["defenders"] = "axis";
game["american_soldiertype"] = "normandy";
game["german_soldiertype"] = "normandy";

setCvar("r_glowbloomintensity0", ".25");
setCvar("r_glowbloomintensity1", ".25");
setcvar("r_glowskybleedintensity0",".3");

setupWeaponForPickup("panzerschreck_mp", "xmodel/weapon_panzerschreck", 5);

}
Do you know whats the problem?

Maybe it is something about the weapon name

weapon_panzerschreck or weapon_panzerschreck_mp or panzerschreck_mp?? I dont know it...

eisenhower
CJ Wannabe
CJ Wannabe
Posts: 2
Joined: April 18th, 2011, 2:06 pm

Re: Respawning Weapons

Post by eisenhower » April 18th, 2011, 5:35 pm

I guess its something with the name, I did instead of panzerschreck a mp44 and now it works, so now its just gambling wich weapon name works..

No help needed anymore :)

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Respawning Weapons

Post by Rezil » April 18th, 2011, 6:47 pm

Some weapons have to be precached, such as the panzershreck, which is why it didn't work for you.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

User avatar
Badeendnl
CJ Fan
CJ Fan
Posts: 133
Joined: April 11th, 2011, 4:05 pm

Re: Respawning Weapons

Post by Badeendnl » April 18th, 2011, 10:11 pm

does this also work for cod4?

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Respawning Weapons

Post by Rezil » April 19th, 2011, 1:51 am

Badeendnl wrote:does this also work for cod4?
Yes, but you'll have to change the weapon and model names to be compatible with the guns and models in cod4.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests