Perhaps if you get your spawn event working properly you could just move it all in there.
Otherwise, you just use self.freshspawn in your weaponswap script. Remember, scripts exec'd from state files have the self object set as player automatically by the engine. It won't recognise local.player as a variable because it's local to that other thread, unless you define it here as well (local.player = self). local.player variable in the spawn function points to the player entity, and self in weaponswap does the same, so you can access the same properties with self.property.
The reason we use local(dot)player is because local is equal to the current thread and we are giving it a property just like game entities. In this case, giving it the property of .player So technically we don't really create variables.
If you want it level wide you use level.variable, and so on.
Looking at your script, if you have separate sections for allies and axis you may have a huge amount of duplicate code (maybe it would be worth providing it all so we can help make it more manageable).
Something like this would mean no team checks needed, it just uses the weapons assigned to the team:
main:
if(self.freshspawn == 0)
end
iprintln "fresh 1 in wep"
// if you are pedantic, you could have these only defined once as part of the level object
local.rifle[allies] = "models/weapons/m1_garand.tik"
local.sniper[allies] = "models/weapons/springfield.tik"
local.smg[allies] = "models/weapons/thompsonsmg.tik"
local.mg[allies] = "models/weapons/bar.tik"
local.bazooka[allies] = "models/weapons/bazooka.tik"
local.grenade[allies] = "models/weapons/m2frag_grenade.tik"
local.rifle[axis] = "models/weapons/kar98.tik"
local.sniper[axis] = "models/weapons/kar98sniper.tik"
local.smg[axis] = "models/weapons/mp40.tik"
local.mg[axis] = "models/weapons/mp44.tik"
local.bazooka[axis] = "models/weapons/panzerschreck.tik"
local.grenade[axis] = "models/weapons/steilhandgranate.tik"
local.shotgun = "models/weapons/shotgun.tik"
waitframe
local.n = randomint 99999
self weaponcommand dual targetname ("w" + local.n)
local.weap = $("w" + local.n).model
if(local.weap == local.rifle[self.dmteam])
{
if(getcvar(cb_rifle_allow) == "1")
{
self give local.weap
self use local.weap
waitframe
self give local.grenade[self.dmteam]
//if(getcvar(cb_rifle_give) == "1")
// {
// self give local.m1_garand
// }
if(getcvar(cb_sniper_give) == "1")
{
self give local.sniper[self.dmteam]
}
if(getcvar(cb_smg_give) == "1")
{
self give local.smg[self.dmteam]
}
if(getcvar(cb_mg_give) == "1")
{
self give local.mg[self.dmteam]
}
if(getcvar(cb_rocket_give) == "1")
{
self give local.bazooka[self.dmteam]
}
if(getcvar(cb_shotgun_give) == "1")
{
self give local.shotgun
}
}
}
Also, be careful as a player could die and respawn during that arbitrary wait and have their freshspawn flag set to 0 at any point if more than one thread is running.
So perhaps something like (even if this is for testing, to stop any confusion):
spawn local.player:
if(local.player == NULL || local.player.dmteam == spectator)
end
local.player.freshspawn = 1
iprintln "freshspawn 1"
// wait for the length of 11 seconds or as long as the player is alive (and not NULL)
for (local.i = 0; local.i < 11 && isAlive local.player && local.player.dmteam != spectator; local.i++)
wait 1
local.player.freshspawn = 0
iprintln "freshspawn 0"
end
Unless of course I'm missing something inherent to Reborn.
EDIT: Assuming you'll be doing these checks for each weapon class, here is a script I did elsewhere modified a bit for you. I've included comments to help you out but if you remove them it's quite compact:
main:
local.player = self
if(local.player.freshspawn == 0)
end
iprintln "fresh 1 in wep"
// set class names
// must correspond to cvars (e.g. cb_'rifle'_allow or cb_'rocket'_give etc..)
local.weaponclass[1] = "rifle"
local.weaponclass[2] = "sniper"
local.weaponclass[3] = "smg"
local.weaponclass[4] = "mg"
local.weaponclass[5] = "rocket"
local.weaponclass[6] = "grenade"
local.weaponclass[7] = "shotgun"
// set model names
local.weapon[local.weaponclass[1]][allies] = "models/weapons/m1_garand.tik"
local.weapon[local.weaponclass[2]][allies] = "models/weapons/springfield.tik"
local.weapon[local.weaponclass[3]][allies] = "models/weapons/thompsonsmg.tik"
local.weapon[local.weaponclass[4]][allies] = "models/weapons/bar.tik"
local.weapon[local.weaponclass[5]][allies] = "models/weapons/bazooka.tik"
local.weapon[local.weaponclass[6]][allies] = "models/weapons/m2frag_grenade.tik"
local.weapon[local.weaponclass[7]][allies] = "models/weapons/shotgun.tik"
local.weapon[local.weaponclass[1]][axis] = "models/weapons/kar98.tik"
local.weapon[local.weaponclass[2]][axis] = "models/weapons/kar98sniper.tik"
local.weapon[local.weaponclass[3]][axis] = "models/weapons/mp40.tik"
local.weapon[local.weaponclass[4]][axis] = "models/weapons/mp44.tik"
local.weapon[local.weaponclass[5]][axis] = "models/weapons/panzerschreck.tik"
local.weapon[local.weaponclass[6]][axis] = "models/weapons/steilhandgranate.tik"
local.weapon[local.weaponclass[7]][axis] = "models/weapons/shotgun.tik"
waitframe
local.weap_targetname = "w" + local.player.entnum
local.player weaponcommand dual targetname local.weap_targetname
local.weap = $(local.weap_targetname).model
// find the player's weapon class
for (local.i = 1; local.i <= local.weaponclass.size; local.i++)
{
if (local.weapon[local.weaponclass[local.i]][local.player.dmteam] == local.weap && local.weaponclass[local.i] != "grenade")
{
// we've found the player's weapon class
// now check if we are allowed to proceed
local.allowcvar = "cb_" + local.weaponclass[local.i] + "_allow"
iprintln local.allowcvar " is " (getcvar(local.allowcvar))
if (getcvar(local.allowcvar) == "1")
{
// we are allowed to proceed
// give the player their own weapon? (is this needed)
local.player give local.weap
local.player use local.weap
// now loop over the other weapons
for (local.j = 1; local.j <= local.weaponclass.size; local.j++)
{
if (local.weaponclass[local.j] != "grenade")
{
// not a grenade
// check to see if we are allowed to give this specific weapon class
local.givecvar = "cb_" + local.weaponclass[local.j] + "_give"
if (getcvar(local.givecvar) == "1")
{
// we are allowed to give this weapon class
// make sure it isn't our current weapon
if (local.weapon[local.weaponclass[local.j]][local.player.dmteam] != local.weap)
{
// it isn't our current weapon so give the specific team weapon to us
local.player give local.weapon[local.weaponclass[local.j]][local.player.dmteam]
}
}
}
else
{
// a grenade
// we give grenades by default, no checks needed
local.player give local.weapon[local.weaponclass[local.j]][local.player.dmteam]
}
}
}
break
}
}
// clear targetname so we can reuse
$(local.weap_targetname).targetname = NULL
end
So it accounts for all the cvars you may want, all the weapons and their classes. It should just work for your weaponswap script as I quickly tested it myself.