Try this one out, it runs with the same "exec global/rifles_only.scr" after level waittill spawn, so you shouldn't have to change anything in the map script.
For this script, all players can only have snipers or rifles, and each player is given both team's snipers or rifles.
If they choose a different weapon class, the weapon is removed as soon as their hand isn't empty anymore and inventory >= 1.
That should prevent most "player::Sentient::deactivateWeapon, Tried to deactivate a non-active weapon in hand 0" errors, but if you see 2+ errors after a player died, he's probably trying his hardest to drop an MG, Bazooka, etc after he spawns, before the weapon is removed (very small chance that he succeeds, if at all).
Whenever a player dies with both rifles (or inventory >= 3, when players in this script start with 4), both rifles or snipers are dropped, and the extra dropped weapon can be picked up or provide ammo.
Whenever a player dies with only one rifle/sniper, or with < 3 inventory items, only one other rifle/sniper drops. Two rifles should still drop if the player threw all his grenades.
I didn't add the "drop the opposite team's rifle or sniper if you drop the weapon without dying".
Since players already spawn with both team's rifles or snipers, it would get out of control if people keep dropping 2 rifles for each drop, then one person could drop 4 rifles when he only has 2 in his inventory.
Raw test code from mohdm1.scr below:
Code:
main:
// set scoreboard messages
setcvar "g_obj_alliedtext1" "Southern France"
setcvar "g_obj_alliedtext3" ""
setcvar "g_obj_axistext1" "Created by:"
setcvar "g_obj_axistext2" "Searingwolfe"
setcvar "g_obj_axistext3" ""
setcvar "g_scoreboardpic" "mohdm1"
setcvar "cheats" "1"
setcvar "thereisnomonkey" "1"
setcvar "maxentities" "2000"
setcvar "fraglimit" "0"
setcvar "timelimit" "20"
setcvar "g_gametype" "2"
removeclass PlayerIntermission // remove screen change right before map changes; fade to black instead (rare server crash fix).
level waittill prespawn
//*** Precache Dm Stuff
exec global/DMprecache.scr
level.script = maps/dm/mohdm1.scr
exec global/ambient.scr mohdm1
exec global/door_locked.scr::lock
setcvar "r_fastsky" "0"
$world farplane 150000
$world farplane_color ( 0.6784 0.8353 0.9686 )
level waittill spawn
thread rifles_only
end
rifles_only:
while($player.size < 1) { waitframe }
while($player.size >= 1)
{
for(local.i = 1; local.i <= $player.size; local.i++)
{
if($player[local.i] != NULL && $player[local.i].dmteam != "spectator")
{
if(isalive $player[local.i] && $player[local.i].weaponheld == NIL)
{
$player[local.i].weaponheld = waitthread get_player_weapon $player[local.i]
$player[local.i].teamm = $player[local.i].dmteam // using "teamm", since "team" is already used by mohaa
$player[local.i].do_once = 0
$player[local.i].dontdropweapon = 0
}
if(isalive $player[local.i] && $player[local.i].do_once != 1)
{
$player[local.i].do_once = 1
if($player[local.i].weaponheld != NIL && $player[local.i].weaponheld != "models/weapons/kar98.tik" && $player[local.i].weaponheld != "models/weapons/kar98sniper.tik" && $player[local.i].weaponheld != "models/weapons/m1_garand.tik" && $player[local.i].weaponheld != "models/weapons/springfield.tik")
{
$player[local.i] take $player[local.i].weaponheld // without waiting a few seconds before "take [weapon]" or "takeall", console prints "player::Sentient::DeactivateWeapon, Tried to deactivate a non-active weapon in hand 0"
$player[local.i].dontdropweapon = 0 // but if you see these messages spamming after a player died, he's probably trying his hardest to drop an MG or rocket launcher when he's not supposed to.
$player[local.i] give models/weapons/springfield.tik; $player[local.i] give models/weapons/kar98sniper.tik
$player[local.i] useweaponclass rifle
$player[local.i] primarydmweapon sniper
$player[local.i].weaponheld = NIL
}
if($player[local.i].weaponheld == "models/weapons/kar98.tik") { $player[local.i] give models/weapons/m1_garand.tik }
if($player[local.i].weaponheld == "models/weapons/kar98sniper.tik") { $player[local.i] give models/weapons/springfield.tik }
if($player[local.i].weaponheld == "models/weapons/m1_garand.tik") { $player[local.i] give models/weapons/kar98.tik }
if($player[local.i].weaponheld == "models/weapons/springfield.tik") { $player[local.i] give models/weapons/kar98sniper.tik }
}
if(!isalive $player[local.i] || $player[local.i].dmteam != $player[local.i].teamm)
{
if(!isalive $player[local.i] && $player[local.i].weaponheld != NIL) { $player[local.i] thread dropweapon }
$player[local.i].weaponheld = NIL
}
if(isalive $player[local.i] && $player[local.i].inventory.size < 3) { $player[local.i].dontdropweapon = 1 } // if all grenades are thrown, inventory decreases by 1 so don't spawn an extra rifle if 2+ guns are missing from inventory.
}
if($player[local.i] != NULL && $player[local.i].dmteam == "spectator") { $player[local.i].weaponheld = NIL }
}
waitframe
}
thread rifles_only
end
dropweapon:
if(self.dontdropweapon == 1) { end }
if(self.weaponheld == "models/weapons/kar98sniper.tik") { local.weapdrop = spawn script_model "model" "models/weapons/springfield.tik" }
if(self.weaponheld == "models/weapons/springfield.tik") { local.weapdrop = spawn script_model "model" "models/weapons/kar98sniper.tik" }
if(self.weaponheld == "models/weapons/kar98.tik") { local.weapdrop = spawn script_model "model" "models/weapons/m1_garand.tik" }
if(self.weaponheld == "models/weapons/m1_garand.tik") { local.weapdrop = spawn script_model "model" "models/weapons/kar98.tik" }
local.weapdrop.origin = self gettagposition "Bip01 R Hand"
local.weapdrop.angles = ( 0 0 90 )
local.weapdrop solid
local.weapdrop physics_on
local.weapdrop.velocity = (angles_toforward ( 0 (self.viewangles[1] - 45) 0 )) * 200 // items & weapon models cannot have physics or velocity, only script_models
local.r = randomint(181) // 0 to 180
local.weapdrop rotatey (local.r - 90) // randomize rotatey from -90 to 90.
local.origin = local.weapdrop.origin
waitframe
while(local.weapdrop != NULL && local.origin[2] != NIL)
{
if(local.weapdrop.origin[2] < local.origin[2]) { local.origin = local.weapdrop.origin }
waitframe
if(local.weapdrop.origin[2] >= local.origin[2]) { break } // this also stops the weapon from bouncing off the ground
}
local.weapitem = spawn local.weapdrop.model // spawn a weapon that can be picked up or granted ammo, delete the script_model
local.weapitem.origin = local.weapdrop.origin
local.weapitem.angles = local.weapdrop.angles
local.weapitem thread removeold
local.weapdrop remove
end
removeold:
local.c = 0
while(self != NULL && local.c < 30) { wait 1; local.c++ } // wait 30 seconds, then remove the weapon if it was never picked up
self remove
end
get_player_weapon local.player:
while(local.player != NULL && local.player.inventory.size < 1 && (local.player getactiveweap 0) != NIL) { waitframe } // prevent "player::Sentient::DeactivateWeapon, Tried to deactivate a non-active weapon in hand 0" errors
if(local.player == NULL) { end }
local.team = local.player.dmteam
local.maxframes = 30
local.numframes = 0
local.weapon = NULL
local.tname = "mefgun" + local.player.entnum
while(local.player != NULL && local.player.dmteam == local.team)
{
local.player weaponcommand dual targetname local.tname
local.weapon = $(local.tname)
if(local.weapon != NULL || local.numframes > local.maxframes)
{
break
}
waitframe
local.numframes++
}
if(local.weapon != NULL)
{
local.weapon.targetname = NIL
local.weaponheld = local.weapon.model
}
end local.weaponheld