Mapping CoD4 ( tuto )
300 : How to add pickable weapons on a map?
Only scripts are needed, use radiant only to find out weapons positions.
Add a script _pickable_weapons.gsc
First, add a file called :
maps/mp/_pickable_weapons.gsc
Paste this in your file :
spawn_weapon( classname, origin, angles ) {
if( !isdefined( classname ) || !isdefined( origin ) )
return undefined;
if( !isdefined( angles ) )
angles = (0,0,0);
flags = 4;
height = (0,0,5);
weapon = spawn( classname, origin+height, flags );
weapon.targetname = "weapon_pickup";
weapon.angles = angles;
return weapon;
}
weapons_pickup() {
pickups = getentarray( "weapon_pickup", "targetname" );
for( i = 0; i < pickups.size; i++ ) {
thread trackPickup( pickups[i] );
wait 0.02;
}
}
trackPickup( pickup ) {
classname = pickup.classname;
origin = pickup.origin;
angles = pickup.angles;
spawnflags = pickup.spawnflags;
isWeapon = false;
weapname = undefined;
respawnTime = undefined;
if( issubstr( classname, "weapon_" ) ) {
isWeapon = true;
weapname = pickup maps\mp\gametypes\_weapons::getItemWeaponName();
respawnTime = level.respawnTime;
}
while( true ) {
player = undefined;
if( isWeapon ) {
pickup setPickupStartAmmo( weapname );
while( true ) {
pickup waittill( "trigger", player, dropped );
player givemaxammo(weapname);
if( !isdefined( pickup ) )
break;
assert( !isdefined( dropped ) );
}
if( isdefined( dropped ) ) {
dropDeleteTime = 5;
if( dropDeleteTime > respawnTime )
dropDeleteTime = respawnTime;
dropped thread delayedDeletion( dropDeleteTime );
}
}
wait respawnTime;
pickup = spawn( classname, origin, spawnflags );
pickup.angles = angles;
}
}
setPickupStartAmmo( weapname ) {
curweapname = weapname;
altindex = 0;
while( altindex == 0 || (curweapname != weapname && curweapname != "none") ) {
allammo = weaponStartAmmo( curweapname );
clipammo = weaponClipSize( curweapname );
reserveammo = 0;
if( clipammo >= allammo ) {
clipammo = allammo;
} else {
reserveammo = allammo - clipammo;
}
curweapname = weaponAltWeaponName( curweapname );
altindex++;
}
}
delayedDeletion( delay ) {
self thread delayedDeletionOnSwappedWeapons( delay );
wait delay;
if( isDefined( self ) ) {
self notify("death");
self delete();
}
}
delayedDeletionOnSwappedWeapons( delay ) {
self endon("death");
while( true ) {
self waittill( "trigger", player, dropped );
if( isdefined( dropped ) )
break;
}
dropped thread delayedDeletion( delay );
}
Find positions in your map
Using radiant, determine spawnable weapons position (X, Y, Z) and angles (optionally, default (0,0,0) works well).
Call script from your map gsc
In your maps/mp/mp_xxx.gsc, add the following:
main() {
....
thread init_weapons();
}
// WEAPONS
init_weapons() {
level.respawnTime = 10;
maps\mp\_zipline::spawn_weapon( "weapon_rpg_mp", (X1, Y1, Z1), (AX1,AY1,AZ));
maps\mp\_zipline::spawn_weapon( "weapon_ak47_mp", (X2, Y2, Z2), (0,0,0));
...
thread maps\mp\_zipline::weapons_pickup();
}
Add script to your zone file
Do not forget to add this rawfile,maps/mp/_pickable_weapons.gsc to your zone file.
Enjoy :)
Tuto by Efaya