Page 2 of 6 FirstFirst 1234 ... LastLast
Results 11 to 20 of 52

Thread: Give Weapon (but only once?)

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

    Default

    Quote Originally Posted by Zappa View Post
    i wouldn't recommend to use the spawn event for a weapon mod. it's buggy when playing in objective mode
    It isn't, in objective/round based modes, spawn event isn't called upon every round start. There is a specific event for that case named "intermission". Which is basically same as spawn but for every round start. You can read up the docs too to grasp it.

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

    Default

    The spawn event is called on each spawn in an objective round. The only exception is the start of a new map, the players are already spawned, but you can get around that by having a connectted event ( which happens on new map) and check if player is already on a team, therefore they must of been playing the previous map, so trigger the spawn event. A

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




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

    Default

    Quote Originally Posted by Purple Elephant1au View Post
    The spawn event is called on each spawn in an objective round. The only exception is the start of a new map, the players are already spawned, but you can get around that by having a connectted event ( which happens on new map) and check if player is already on a team, therefore they must of been playing the previous map, so trigger the spawn event. A
    Sounds about right. Guess I mixed them up.
    Good to know purple.

  4. #14

    Default

    Quote Originally Posted by Purple Elephant1au View Post
    The spawn event is called on each spawn in an objective round. The only exception is the start of a new map, the players are already spawned, but you can get around that by having a connectted event ( which happens on new map) and check if player is already on a team, therefore they must of been playing the previous map, so trigger the spawn event. A
    not only that, in obj when all players join one team while the game is in the "Waiting for Players" status, the spawn event will just not work at all, even if you respawn 100 times

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

    Default

    Quote Originally Posted by Zappa View Post
    not only that, in obj when all players join one team while the game is in the "Waiting for Players" status, the spawn event will just not work at all, even if you respawn 100 times
    Strange works for me, because when I test mods that use the spawn event, there is only me in the server which is in OBJ mode, so the spawn event works fine for me

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




  6. #16

    Default

    Quote Originally Posted by Purple Elephant1au View Post
    Strange works for me, because when I test mods that use the spawn event, there is only me in the server which is in OBJ mode, so the spawn event works fine for me
    try it with multi clients and you will see what i mean.
    it's like the spawn event won't be active untill the "Waiting for Players" status is gone

  7. #17

    Default

    Great suggestions. I think the easiest to implement is a player variable assigned on each "give" and reassigned on death.

    Re: spawn event glitching - I noticed something similar when using your weapon switch mod, PE. When I join the server alone, doing rcon restart does not trigger the weapon mod for use. When I type kill in console and spawn again, weapon mod works fine. I need to test with multiple players for rcon restart glitch.

  8. #18

    Default

    Hmm..

    Spawn event in spawn.scr called from dmprecache.scr:


    spawn local.player:
    if(local.player == NULL || local.player.dmteam == spectator)
    end

    local.player.freshspawn = 1
    iprintln "freshspawn 1"
    wait 11
    local.player.freshspawn = 0
    iprintln "freshspawn 0"

    end


    I know this works on spawn because I see the "freshspawn 0/1" message under my compass.

    In my weaponswap.scr exec'd from mike_torso.scr I have this:


    main:
    if(local.player.freshspawn == 1)
    {
    iprintln "fresh 1 in wep"
    // ----- ----- ----- -----
    // ALLIES
    // ----- ----- ----- -----

    if(self.dmteam == "allies")
    {
    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
    }
    }
    }
    }
    }


    local.player.freshspawn isn't passed over to this script (my iprintln never shows). How do I get around this?

  9. #19

    Default

    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.
    Last edited by 1337Smithy; January 3rd, 2019 at 06:09 AM.

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

    Default

    Quote Originally Posted by Zappa View Post
    try it with multi clients and you will see what i mean.
    it's like the spawn event won't be active untill the "Waiting for Players" status is gone
    Just tested on my server with 3 players all on allies, it was working fine for me, also added a simple println to the player on the spawn event and it triggered every time along with my weapon mod.


    Quote Originally Posted by [cB]SplatterGuts View Post
    Re: spawn event glitching - I noticed something similar when using your weapon switch mod, PE. When I join the server alone, doing rcon restart does not trigger the weapon mod for use. When I type kill in console and spawn again, weapon mod works fine. I need to test with multiple players for rcon restart glitch.
    Just tested it on my server and it works fine for me, could maybe be how your server is set up, might have too many mods loading and it the event doesnt get registered fast enough the first time.

    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
  •