Results 1 to 5 of 5

Thread: replacing weapons

  1. #1

    Default replacing weapons

    Hey !

    I see this to get a return on the weapon model -

    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.weap = $("w" + local.n).model
    any idea how I can get a return on the players weapon class choice?

    im using Sorrid's player states...

    Iv'e tried self.useweaponclass -

    if(self.useweaponclass == smg)
    nothing

  2. #2

    Default

    there is no built-in to get the weapon class
    what you can do is do a "switch (local.weap)" and then assign a class to a local.weaponclass variable depending on the weapon

  3. #3

    Default

    OK thanks,
    what I have works, but I was hoping to make it a little faster!

  4. #4

    Default

    I'm working on a Cyber Attack / Search & Destroy mod for MOHAA and have the same issue: finding a player's current dmweapon type. Mefy had a thread to do exactly this in his old spectator.scr file for Freeze Tag. Here's my current script threads:

    Code:
    get_player_weaponclass local.player: //local.player.mef_weaponclass = waitthread get_player_weaponclass local.player
    
    	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.weaponclass = level.mef_weaponclasses[local.weapon.model]
    	}
    end local.weaponclass
    
    //-----------------------------------------------------------------------------
    
    setup_weapon_classes:
    
    	// Allied Assault
    	local.classes["models/weapons/m1_garand.tik"] = "rifle"
    	local.classes["models/weapons/kar98.tik"] = "rifle"
    	local.classes["models/weapons/thompsonsmg.tik"] = "smg"
    	local.classes["models/weapons/mp40.tik"] = "smg"
    	local.classes["models/weapons/bar.tik"] = "mg"
    	local.classes["models/weapons/mp44.tik"] = "mg"
    	local.classes["models/weapons/springfield.tik"] = "sniper"
    	local.classes["models/weapons/kar98sniper.tik"] = "sniper"
    	local.classes["models/weapons/bazooka.tik"] = "heavy"
    	local.classes["models/weapons/panzerschreck.tik"] = "heavy"
    	local.classes["models/weapons/shotgun.tik"] = "shotgun"
    
    	// Spearhead
    	local.classes["models/weapons/fg42.tik"] = "rifle"
    	local.classes["models/weapons/mosin_nagant_rifle.tik"] = "rifle"
    	local.classes["models/weapons/enfield.tik"] = "rifle"
    	local.classes["models/weapons/svt_rifle.tik"] = "sniper"
    	local.classes["models/weapons/g43.tik"] = "sniper"
    	local.classes["models/weapons/ppsh_smg.tik"] = "smg"
    	local.classes["models/weapons/sten.tik"] = "smg"
    	local.classes["models/weapons/kar98_mortar.tik"] = "shotgun"
    
    	// Breakthrough
    	local.classes["models/weapons/delisle.tik"] = "shotgun"
    	local.classes["models/weapons/it_w_carcano.tik"] = "rifle"
    	local.classes["models/weapons/uk_w_l42a1.tik"] = "sniper"
    	local.classes["models/weapons/it_w_moschetto.tik"] = "smg"
    	local.classes["models/weapons/it_w_breda.tik"] = "mg"
    	local.classes["models/weapons/uk_w_vickers.tik"] = "mg"
    	local.classes["models/weapons/uk_w_piat.tik"] = "heavy"
    	local.classes["models/weapons/us_w_minedetector.tik"] = "landmine"
    	local.classes["models/weapons/gr_w_minedetector.tik"] = "landmine"
    end local.classes
    
    //-----------------------------------------------------------------------------
    
    give_weapons local.mef_weaponclass: // replaces $player[local.i] primarydmweapon local.mef_weaponclass
    
    	waitframe
    	if(self.dmteam == "allies") // give them weapons, then do stufftext command "useweaponclass" to pull out a weapon.
    	{
    		if(local.mef_weaponclass == "rifle") { self give models/weapons/m1_garand.tik; self give models/weapons/colt45.tik; self give models/weapons/m2frag_grenade.tik; self stufftext "useweaponclass rifle" }
    		if(local.mef_weaponclass == "sniper") { self give models/weapons/springfield.tik; self give models/weapons/colt45.tik; self give models/weapons/m2frag_grenade.tik; self stufftext "useweaponclass rifle" }
    		if(local.mef_weaponclass == "smg") { self give models/weapons/thompsonsmg.tik; self give models/weapons/colt45.tik; self give models/weapons/m2frag_grenade.tik; self stufftext "useweaponclass smg" }
    		if(local.mef_weaponclass == "mg") { self give models/weapons/bar.tik; self give models/weapons/colt45.tik; self give models/weapons/m2frag_grenade.tik; self stufftext "useweaponclass mg" }
    		if(local.mef_weaponclass == "heavy") { self give models/weapons/bazooka.tik; self give models/weapons/colt45.tik; self give models/weapons/m2frag_grenade.tik; self stufftext "useweaponclass heavy" }
    		if(local.mef_weaponclass == "shotgun") { self give models/weapons/shotgun.tik; self give models/weapons/colt45.tik; self give models/weapons/m2frag_grenade.tik; self stufftext "useweaponclass heavy" }
    		if(local.mef_weaponclass == NIL) { self give models/weapons/bar.tik; self give models/weapons/colt45.tik; self give models/weapons/m2frag_grenade.tik; self stufftext "useweaponclass mg" }
    	}
    	if(self.dmteam == "axis")
    	{
    		if(local.mef_weaponclass == "rifle") { self give models/weapons/kar98.tik; self give models/weapons/p38.tik; self give models/weapons/steilhandgranate.tik; self stufftext "useweaponclass rifle" }
    		if(local.mef_weaponclass == "sniper") { self give models/weapons/kar98sniper.tik; self give models/weapons/p38.tik; self give models/weapons/steilhandgranate.tik; self stufftext "useweaponclass rifle" }
    		if(local.mef_weaponclass == "smg") { self give models/weapons/mp40.tik; self give models/weapons/p38.tik; self give models/weapons/steilhandgranate.tik; self stufftext "useweaponclass smg" }
    		if(local.mef_weaponclass == "mg") { self give models/weapons/mp44.tik; self give models/weapons/p38.tik; self give models/weapons/steilhandgranate.tik; self stufftext "useweaponclass mg" }
    		if(local.mef_weaponclass == "heavy") { self give models/weapons/panzerschreck.tik; self give models/weapons/p38.tik; self give models/weapons/steilhandgranate.tik; self stufftext "useweaponclass heavy" }
    		if(local.mef_weaponclass == "shotgun") { self give models/weapons/shotgun.tik; self give models/weapons/p38.tik; self give models/weapons/steilhandgranate.tik; self stufftext "useweaponclass heavy" }
    		if(local.mef_weaponclass == NIL) { self give models/weapons/mp44.tik; self give models/weapons/p38.tik; self give models/weapons/steilhandgranate.tik; self stufftext "useweaponclass mg" }
    	}
    end
    I've tried adding "$player[local.i].mef_weaponclass = waitthread get_player_weaponclass $player[local.i]" inside of a $player.size for-loop that checks their current dmweapon anytime the player is alive. Didn't work out as intended.
    If the current weapon that the player is holding is either a pistol, grenade, or nothing, the player's "mef_weaponclass" will be NIL. Not sure how Mefy did it originally, but you have to keep running the "get_player_weaponclass" thread until it isn't NIL anymore,
    and as soon as it's not NIL, stop running/checking for the player's dmweapon class. Whenever you respawn the player but he doesn't have weapons (like getting melted in Freeze Tag),
    Mefy did a "$player[local.i] primarydmweapon $player[local.i].mef_weaponclass" command, but that gets annoying after seeing the "your weapon will change when you respawn" message a bunch of times.
    So instead of "primarydmweapon", the "give_weapons" thread just gives the players everything they need. More examples below for using these threads in a map script:

    Code:
    main:
    ...
    level waittill spawn
    ...
    thread player_status
    level.mef_weaponclasses = waitthread setup_weapon_classes
    ...
    end
    
    respawn_player local.i local.mef_weaponclass: // local.mef_weaponclass keeps memory of the player's dmweapon, in case the player's dmweapon suddenly becomes NIL
    
    	wait 2.5
    	$player[local.i] respawn
    	$player[local.i].weapcheck = 0
    	if($player[local.i].mef_weaponclass == NIL) { $player[local.i] thread give_weapons local.mef_weaponclass }
    end
    
    player_status:
    
      while(1)
      {
    	for(local.i = 1; local.i <= $player.size; local.i++)
    	{
    		if(isalive $player[local.i] && $player[local.i].dmteam != "spectator")
     		{
    			if($player[local.i].weapcheck != 1 || $player[local.i].mef_weaponclass == NIL) { $player[local.i].mef_weaponclass = waitthread get_player_weaponclass $player[local.i] }
    			$player[local.i].weapcheck = 1
    		}
    		if(!isalive $player[local.i])
     		{
    			thread respawn_player local.i $player[local.i].mef_weaponclass
     		}
    	}
    	waitframe
      }
    end
    Last edited by Searingwolfe; January 7th, 2023 at 12:00 PM. Reason: Code was wrong

  5. #5
    Purple Developer Purple Elephant1au's Avatar
    Join Date
    Feb 2012
    Location
    Australia
    Posts
    1,269

    Default

    Have you tried looking into the players inventory to see which weapons they have?
    https://x-null.net/wiki/index.php?ti...nds#.inventory

    Purple's Playground
    OBJ :
    103.29.85.127:12203
    xfire: purpleelephant1au
    email: purpleelephant1au@gmail.com
    skydrive: PurpleElephantSkydrive




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •