Page 1 of 6 123 ... LastLast
Results 1 to 10 of 52

Thread: Give Weapon (but only once?)

  1. #1

    Default Give Weapon (but only once?)

    Hello again.

    I'm having an issue where when I drop a weapon, the weapon keeps coming back to me. Is there a way to only give the weapon once? Then if you drop if you're SOL unless you pick it back up?

    Here's the script I'm using:


    local.m1_garand = "models/weapons/m1_garand.tik"
    local.springfield = "models/weapons/springfield.tik"
    local.thompsonsmg = "models/weapons/thompsonsmg.tik"
    local.bar = "models/weapons/bar.tik"
    local.bazooka = "models/weapons/bazooka.tik"
    local.shotgun = "models/weapons/shotgun.tik"
    local.kar98 = "models/weapons/kar98.tik"
    local.kar98sniper = "models/weapons/kar98sniper.tik"
    local.mp40 = "models/weapons/mp40.tik"
    local.mp44 = "models/weapons/mp44.tik"
    local.panzerschreck = "models/weapons/panzerschreck.tik"

    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.weap = $("w" + local.n).model

    if(local.weap == local.m1_garand)
    {
    if(getcvar(cb_rifle_allow) == "1")
    {
    self give local.weap
    self use local.weap
    waitframe
    self give models/weapons/m2frag_grenade.tik

    //if(getcvar(cb_rifle_give) == "1")
    // {
    // self give local.m1_garand
    // }
    if(getcvar(cb_sniper_give) == "1")
    {
    self give local.springfield
    }
    if(getcvar(cb_smg_give) == "1")
    {
    self give local.thompsonsmg
    }
    if(getcvar(cb_mg_give) == "1")
    {
    self give local.bar
    }
    if(getcvar(cb_rocket_give) == "1")
    {
    self give local.bazooka
    }
    if(getcvar(cb_shotgun_give) == "1")
    {
    self give local.shotgun
    }
    }

  2. #2

    Default

    where are you calling the script from?

  3. #3

    Default

    Aaaah. Good point. It's called from mike torso


    state RAISE_WEAPON
    {
    movetype legs

    entrycommands
    {
    viewmodelanim pullout
    exec global/weapontrade.scr // Starts Weapon Control Handler


    So every time I "raise weapon" it's going to exec the script. So if I just added this exec to dmprecache, it would only exec on map load? or round start? how does that work? Would it be better to exec on the spawn reborn event so it's forcing the most up-to-date commands when a player spawns?

  4. #4
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    Quote Originally Posted by [cB]SplatterGuts View Post
    Aaaah. Good point. It's called from mike torso


    state RAISE_WEAPON
    {
    movetype legs

    entrycommands
    {
    viewmodelanim pullout
    exec global/weapontrade.scr // Starts Weapon Control Handler


    So every time I "raise weapon" it's going to exec the script. So if I just added this exec to dmprecache, it would only exec on map load? or round start? how does that work? Would it be better to exec on the spawn reborn event so it's forcing the most up-to-date commands when a player spawns?
    player raises weapon -> script gets called -> script gives player weapon -> player raises weapon -> script gets called -> script gives player weapon -> player raises weapon -> ......
    infinite loop m8
    I'd use reborn player spawn handler, or even better, purple elepthant's weapon limiter, no need to re-invent the wheel

  5. #5

    Default

    i wouldn't recommend to use the spawn event for a weapon mod. it's buggy when playing in objective mode
    also there is a lot of old weapon mods that use the raise_weapon state.
    the only thing you have to do is make some checks at the start of the script
    something like:


    main:
    if (self.raising == 1)
    end;

    if (self == NULL || self == NIL || self.dmteam == "spectator" || self.mef_spectator == 1)
    end;

    self.raising = 1;

    //
    // your code here
    //

    self.raising = 0;
    end


    self.raising do the trick

  6. #6

    Default

    Hmm.. If I put this in my trade script though, I still have the same issue. Once we get to the bottom of the script, it's just setting raising to 0 again and I keep getting weapons. I guess if I set raising to 0 in a death event it would work, right?

    When I tried exec'ing the swap script from dmprecache vs the state file (working, but infinitely given weapons) it doesn't work at all... I don't really know why that would be.

  7. #7

    Default

    i see
    the script i posted will only work for a "x weapons only" mod or if you want to disallow a specific weapon
    if you want to give a weapon without taking away the default ones you shuld set raising to 0 in the killed event as you said
    or move the whole script to the spawn event, but as i said, it wouldn't work fine if you play in objective mode

    and scripts called from state files work different than the dmprecache ones, they are already assigned to the player who is executing the state, that's why you can use "self" as the player, without having to make loop through the $player array
    but maybe someone else can explain this better than me

  8. #8

    Default

    Yeah, the self object value is set when a new thread group is created. It's null at the start of map scripts, it's the player whose state file is being called if you create one there, it's whatever you want if you define it in a script, etc... For example:

    $player thread GiveWeapon

    This will assign $player as the self object in GiveWeapon and thus creates a new thread group here. So if you wanted to create another thread inside GiveWeapon that does something to the same player, you don't need to define the self object again, just:
    thread GiveGrenades

    Unless of course you wanted to create a new thread group. The group object is assigned to the current thread group of each thread:
    group.variable1

    This can be accessed from the entire group of threads, so is contained there.

    For your problem, could you use the max_health trick to check for player deaths? So no spawn event checks needed (if that is buggy) and no loops needed.

    if (self.max_health == 100)
    {
    self.max_health = 100.01
    self heal (0.01 * 0.01) // give the player the 0.01 extra health (as a fraction of 1.0 for heal function)

    //your code here
    }


    max_health is reset on death automatically by the game.

    But of course, if the killed event is fine then just do your checks there instead as that is superior.
    Last edited by 1337Smithy; January 2nd, 2019 at 02:09 AM.

  9. #9

    Default

    Is easy to fix this.

    Is like the spawnprotection.

    When you give the weapons to the player, add a variable to him to assume you have give the weapons.

    Next you have to keep checking if is dead and when is dead reset that variable to 0 so you can give the weapons again.

  10. #10

    Default

    Yeah, your last line is the topic of discussion. Checking with loops is redundant if he just uses a killed event to reset the variable.

Posting Permissions

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