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();
}
}
}
Code: Select all
#include maps\mp\_weapon_pickup;
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);
Made by Rezil(with a tweak or two by Drofder)