The final solution looks like this, it will switch the players primary weapon.
Player walks into a trigger where a spawned script_model bazooka is and
he trades his current primary weapon for bazooka, or the other way around.
PHP Code:
//chrissstrahl - allow players to switch their weapons
//============================================================================
coop_bazookaSwitch:{
//============================================================================
//iprintlnbold_noloc("coop_bazookaSwitch")
if( parm.other.targetname == "player"){
local.player = parm.other
if( local.player.flags["coop_BaZookaSwitch"] == NIL ){
local.isPrimary = 0
local.primary = waitexec coop_mod/main.scr::getActiveWeapon local.player
for(local.x=0;local.x<4;local.x++){
if(local.player == NULL || local.player.health <= 0){ end }
for(local.y=0;local.y<5;local.y++){
local.type = "heavy"
if(local.y == 0){ local.type = "smg" }
else if(local.y == 1){ local.type = "rifle" }
else if(local.y == 2){ local.type = "mg" }
local.player stufftext ("useweaponclass "+local.type)
waitframe
}
local.primary = waitexec coop_mod/main.scr::getActiveWeapon local.player
local.isPrimary = waitexec coop_mod/main.scr::isPrimaryWeapon local.primary
if(local.isPrimary == 1){
local.player.flags["coop_BaZookaSwitch"] = local.primary
break
}
}
//if no more player
if(local.player == NULL || local.player.health <= 0){ end }
//if the player still does not have a primary weapon stop right here
if( local.isPrimary == 0 ){
local.player iprint ("You need a Primary Weapon in order to Trade your weapon!") 1
end
}
exec coop_mod/main.scr::playerForcePrimary local.player "weapons/bazooka.tik"
}else{
exec coop_mod/main.scr::playerForcePrimary local.player local.player.flags["coop_BaZookaSwitch"]
local.player.flags["coop_BaZookaSwitch"] = NIL
}
}
}end
You don't need stufftext func if you don't want . useweaponclass is a Sentient class function so:
local.player useweaponclass local.type
Oh, thats odd, I tried that, but it didn't work.
I tried again, it works now. Must have been a typo.
Thanks.
I really wish script errors would error out the game.
The amount of time wasted because of a typo when working on such a big project is really a problem.
It would really be useful if it did error out and not keep on going, printing a little tiny error message somewhere in 500 lines of console messages.
Reading all the logfile each time you test the map is really not the right way...
I tend to realise if a change I've made has crashed the script because either the fog isn't there or I don't have any weapons, or if anything else is missing from the main thread like objectives. But yeah having to look through the log can be a pain. It would be nice to give modders/devs an option.
Just adding a date/time stamp to every line in qconsole.log would be huge......
It is a bit different if you work with singleplayer maps that have not been made compatible with coop, and you test them you will get a lot of error messages.
Most of them are very trivial, but some are important and they are sometimes very hard to find.
I would like to make players invisible, but still showing the weapon to the player.
As in viewmodel, visible to the player of the weapon, does anyone have a suggestion, how to do this ?
Add a targetname to the weapon in hand, when you hide the player use the targetname to show the weapon.