Results 1 to 6 of 6

Thread: Weird script behavior

  1. #1

    Default Weird script behavior

    Hi guys

    I need some of your wisdom, you see, i created a mohaa server side script, everything works except this: (see the bolded text)
     
    //*******************************************************************************************
    // MEDAL OF HONOR ALLIED ASSAULT
    // Select Primary Weapon
    //*******************************************************************************************

    //************************************* Pistol Class *****************************************
    if (self.dmteam == "allies")
    {
    local.colt45 = "models/weapons/colt45.tik"
    local.p38 = "models/weapons/p38.tik"
    local.silencedpistol = "models/weapons/silencedpistol.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.colt45)
    {
    waitframe
    self give local.p38
    self give local.silencedpistol
    self give models/weapons/m2frag_grenade.tik
    self give models/weapons/steilhandgranate.tik
    }
    }
    if (self.dmteam == "axis")
    {
    local.p38 = "models/weapons/p38.tik"
    local.colt45 = "models/weapons/colt45.tik"
    local.silencedpistol = "models/weapons/silencedpistol.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.p38)
    {
    waitframe
    self give local.colt45
    self give local.silencedpistol
    self give models/weapons/steilhandgranate.tik
    self give models/weapons/m2frag_grenade.tik
    }
    }
    //************************************* Rifle Class *****************************************
    if (self.dmteam == "allies")
    {
    local.m1_garand = "models/weapons/m1_garand.tik"
    local.kar98 = "models/weapons/kar98.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.m1_garand)
    {
    waitframe
    self give local.kar98
    self give models/weapons/m2frag_grenade.tik
    self give models/weapons/steilhandgranate.tik
    }
    }
    if (self.dmteam == "axis")
    {
    local.kar98 = "models/weapons/kar98.tik"
    local.m1_garand = "models/weapons/m1_garand.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.kar98)
    {
    waitframe
    self give local.m1_garand
    self give models/weapons/steilhandgranate.tik
    self give models/weapons/m2frag_grenade.tik
    }
    }
    //************************************* Sniper Rifle Class **********************************
    if (self.dmteam == "allies")
    {
    local.springfield = "models/weapons/springfield.tik"
    local.KAR98sniper = "models/weapons/KAR98sniper.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.springfield)
    {
    waitframe
    self give local.KAR98sniper
    self give models/weapons/m2frag_grenade.tik
    self give models/weapons/steilhandgranate.tik
    }
    }
    if (self.dmteam == "axis")
    {
    local.KAR98sniper = "models/weapons/KAR98sniper.tik"
    local.springfield = "models/weapons/springfield.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.KAR98sniper)
    {
    waitframe
    self give local.springfield
    self use local.springfield <- i added "self use" here, with hopes to solve the problem, it didn't work.
    self give models/weapons/steilhandgranate.tik
    self give models/weapons/m2frag_grenade.tik
    }
    }
    //************************************* SMG Class *******************************************
    if (self.dmteam == "allies")
    {
    local.thompsonsmg = "models/weapons/thompsonsmg.tik"
    local.mp40 = "models/weapons/mp40.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.thompsonsmg)
    {
    waitframe
    self give local.mp40
    self give models/weapons/m2frag_grenade.tik
    self give models/weapons/steilhandgranate.tik
    }
    }
    if (self.dmteam == "axis")
    {
    local.mp40 = "models/weapons/mp40.tik"
    local.thompsonsmg = "models/weapons/thompsonsmg.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.mp40)
    {
    waitframe
    self give local.thompsonsmg
    self give models/weapons/steilhandgranate.tik
    self give models/weapons/m2frag_grenade.tik
    }
    }
    //************************************* MG Class ********************************************
    if (self.dmteam == "allies")
    {
    local.bar = "models/weapons/bar.tik"
    local.mp44 = "models/weapons/mp44.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.bar)
    {
    waitframe
    self give local.mp44
    self give models/weapons/m2frag_grenade.tik
    self give models/weapons/steilhandgranate.tik
    }
    }
    if (self.dmteam == "axis")
    {
    local.mp44 = "models/weapons/mp44.tik"
    local.bar = "models/weapons/bar.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.mp44)
    {
    waitframe
    self give local.bar
    self give models/weapons/steilhandgranate.tik
    self give models/weapons/m2frag_grenade.tik
    }
    }
    //************************************* Rocket Launcher Class *******************************
    if (self.dmteam == "allies")
    {
    local.bazooka = "models/weapons/bazooka.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.bazooka)
    {
    self takeall
    self iprint "This weapon is not available, because breaks the Rule#1." 1
    }
    }
    if (self.dmteam == "axis")
    {
    local.panzerschreck = "models/weapons/panzerschreck.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.panzerschreck)
    {
    self takeall
    self iprint "This weapon is not available, because breaks the Rule#1." 1
    }
    }
    //************************************* Shotgun Class ***************************************
    if (self.dmteam == "allies")
    {
    local.shotgun = "models/weapons/shotgun.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.shotgun)
    {
    self takeall
    self iprint "This weapon is not available, because breaks the Rule#1." 1
    }
    }
    if (self.dmteam == "axis")
    {
    local.shotgun = "models/weapons/shotgun.tik"
    waitframe
    local.n = randomint 99999
    self weaponcommand dual targetname ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    if (local.selected_weapon == local.shotgun)
    {
    self takeall
    self iprint "This weapon is not available, because breaks the Rule#1." 1
    }
    }
    //************************************* Spectator Class **************************************
    if (self.dmteam == "spectator")
    {
    self takeall
    }
    end
    ******************************************************************************************

    So, when you select the axis team + the sniper rifle, once you've spawned, it doesn't returns the springfield sniper rifle (it should returns both, the KAR98sniper + springfield), it's weird because the code returns the "KAR98sniper, p38, colt45, silencedpistol, steilhandgranate and the m2frag_grenade" only.
    The above it's not true if you select the allies team.

    I'm going to attach the .pk3 so you can verify it.

    It would be interesting to know what is causing this problem.

    Thanks for reading!
    Attached Files Attached Files
    Last edited by Purple Elephant1au; December 1st, 2018 at 01:41 PM.

  2. #2

    Default

    Please, use code tags next time, so we don't have to download file to see it in order in editor.
    https://www.x-null.net/forums/thread...ight=code+tags

    //************************************* Sniper Rifle Class **********************************
    if (self.dmteam == "allies"){
    local.springfield = "models/weapons/springfield.tik"
    local.KAR98sniper = "models/weapons/KAR98sniper.tik"
    waitframe

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

    if (local.selected_weapon == local.springfield){
    waitframe
    self give local.KAR98sniper
    self give models/weapons/m2frag_grenade.tik
    self give models/weapons/steilhandgranate.tik
    }
    }

    if (self.dmteam == "axis"){
    local.KAR98sniper = "models/weapons/KAR98sniper.tik"
    local.springfield = "models/weapons/springfield.tik" //<- This make problem.
    waitframe

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

    if (local.selected_weapon == local.KAR98sniper){
    waitframe
    self give local.springfield //<- This make problem.
    self use local.springfield //<- This make problem.
    self give models/weapons/steilhandgranate.tik
    self give models/weapons/m2frag_grenade.tik
    }
    }


    Use is meant to get weapon string, like use "MP40", what you had passed to it is path.
    use( String name, [ Integer weapon_hand ] )
    Last edited by Criminal; November 30th, 2018 at 02:14 PM.

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

    Default

    I'd like to add that generally I'd prefer useweaponclass instead of use if you're not giving two weapons of the same class to the player.

  4. #4

    Default

    The problem on this script was the name of the weapon returns in lowercase and name on the script was not the same.

    I have made a clean version of your script and works good:


    main:

    //*******************************************************************************************
    // MEDAL OF HONOR ALLIED ASSAULT
    // Select Primary Weapon
    //*******************************************************************************************

    //************************************* Pistol Class *****************************************

    waitframe

    local.n = randomint(999)
    self weaponcommand dual "targetname" ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    //Weapons
    local.colt45 = "models/weapons/colt45.tik"
    local.p38 = "models/weapons/p38.tik"
    local.silencedpistol = "models/weapons/silencedpistol.tik"
    local.axis_grenade = "models/weapons/steilhandgranate.tik"
    local.allies_grenade = "models/weapons/m2frag_grenade.tik"
    local.m1_garand = "models/weapons/m1_garand.tik"
    local.kar98 = "models/weapons/kar98.tik"
    local.springfield = "models/weapons/springfield.tik"
    local.KAR98sniper = "models/weapons/kar98sniper.tik"
    local.thompsonsmg = "models/weapons/thompsonsmg.tik"
    local.mp40 = "models/weapons/mp40.tik"
    local.bar = "models/weapons/bar.tik"
    local.mp44 = "models/weapons/mp44.tik"
    local.bazooka = "models/weapons/bazooka.tik"
    local.panzerschreck = "models/weapons/panzerschreck.tik"
    local.shotgun = "models/weapons/shotgun.tik"

    if (self.dmteam == "allies")
    {

    if (local.selected_weapon == local.colt45)
    {
    self give local.p38
    self give local.silencedpistol
    self give local.allies_grenade
    self give local.axis_grenade
    }
    }
    if (self.dmteam == "axis")
    {

    if (local.selected_weapon == local.p38)
    {
    self give local.colt45
    self give local.silencedpistol
    self give models/weapons/steilhandgranate.tik
    self give models/weapons/m2frag_grenade.tik
    }
    }

    //************************************* Rifle Class *****************************************
    if (self.dmteam == "allies")
    {

    if (local.selected_weapon == local.m1_garand)
    {

    self give local.kar98
    self give local.allies_grenade
    self give local.axis_grenade
    }
    }
    if (self.dmteam == "axis")
    {

    if (local.selected_weapon == local.kar98)
    {
    self give local.m1_garand
    self give local.axis_grenade
    self give local.allies_grenade
    }
    }
    //************************************* Sniper Rifle Class **********************************
    if (self.dmteam == "allies")
    {

    if (local.selected_weapon == local.springfield)
    {

    self give local.KAR98sniper
    self give local.allies_grenade
    self give local.axis_grenade
    }
    }
    if (self.dmteam == "axis")
    {

    if (local.selected_weapon == local.KAR98sniper)
    {

    self give local.springfield
    self give local.allies_grenade
    self give local.axis_grenade
    }
    }
    //************************************* SMG Class *******************************************
    if (self.dmteam == "allies")
    {

    if (local.selected_weapon == local.thompsonsmg)
    {
    self give local.mp40
    self give local.allies_grenade
    self give local.axis_grenade
    }
    }
    if (self.dmteam == "axis")

    if (local.selected_weapon == local.mp40)
    {

    self give local.thompsonsmg
    self give local.axis_grenade
    self give local.allies_grenade
    }
    }
    //************************************* MG Class ********************************************
    if (self.dmteam == "allies")
    {

    if (local.selected_weapon == local.bar)
    {

    self give local.mp44
    self give local.allies_grenade
    self give local.axis_grenade
    }
    }
    if (self.dmteam == "axis")
    {

    if (local.selected_weapon == local.mp44)
    {
    self give local.bar
    self give local.axis_grenade
    self give local.allies_grenade
    }
    }
    //************************************* Rocket Launcher Class *******************************
    if (self.dmteam == "allies")
    {

    if (local.selected_weapon == local.bazooka)
    {
    self takeall
    self iprint "This weapon is not available, because breaks the Rule#1." 1
    }
    }
    if (self.dmteam == "axis")
    {

    if (local.selected_weapon == local.panzerschreck)
    {
    self takeall
    self iprint "This weapon is not available, because breaks the Rule#1." 1
    }
    }
    //************************************* Shotgun Class ***************************************
    if (self.dmteam == "allies")
    {

    if (local.selected_weapon == local.shotgun)
    {
    self takeall
    self iprint "This weapon is not available, because breaks the Rule#1." 1
    }
    }
    else if (self.dmteam == "axis")
    {

    if (local.selected_weapon == local.shotgun)
    {
    self takeall
    self iprint "This weapon is not available, because breaks the Rule#1." 1
    }
    }
    //************************************* Spectator Class **************************************
    if (self.dmteam == "spectator")
    {
    self takeall
    }

    end

  5. #5

    Default

    And if you want to cut down on lines or make it more manageable I'd probably do something similar to (cos a lot of it is unnecessary):


    //*******************************************************************************************
    // MEDAL OF HONOR ALLIED ASSAULT
    // Select Primary Weapon
    //*******************************************************************************************
    main:
    //store weapons
    group.weapons[smg][1] = "models/weapons/mp40.tik"
    group.weapons[smg][2] = "models/weapons/thompsonsmg.tik"
    group.weapons[mg][1] = "models/weapons/mp44.tik"
    group.weapons[mg][2] = "models/weapons/bar.tik"
    group.weapons[pistol][1] = "models/weapons/p38.tik"
    group.weapons[pistol][2] = "models/weapons/colt45.tik"
    group.weapons[pistol][3] = "models/weapons/silencedpistol.tik"
    group.weapons[rifle][1] = "models/weapons/kar98.tik"
    group.weapons[rifle][2] = "models/weapons/m1_garand.tik"
    group.weapons[sniper][1] = "models/weapons/kar98sniper.tik"
    group.weapons[sniper][2] = "models/weapons/springfield.tik"
    group.weapons[rockets][1] = "models/weapons/panzerschreck.tik"
    group.weapons[rockets][2] = "models/weapons/bazooka.tik"
    group.weapons[shotgun][1] = "models/weapons/shotgun.tik"
    group.weapons[grenades][1] = "models/weapons/steilhandgranate.tik"
    group.weapons[grenades][2] = "models/weapons/m2frag_grenade.tik"

    //get weapon
    waitframe
    local.n = randomint(999)
    self weaponcommand dual "targetname" ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    //give weapons
    if (local.selected_weapon == group.weapons[pistol][1] || local.selected_weapon == group.weapons[pistol][2])
    {
    thread GiveWeapons "pistol" local.selected_weapon
    }
    else if (local.selected_weapon == group.weapons[rifle][1] || local.selected_weapon == group.weapons[rifle][2])
    {
    thread GiveWeapons "rifle" local.selected_weapon
    }
    else if (local.selected_weapon == group.weapons[sniper][1] || local.selected_weapon == group.weapons[sniper][2])
    {
    thread GiveWeapons "sniper" local.selected_weapon
    }
    else if (local.selected_weapon == group.weapons[smg][1] || local.selected_weapon == group.weapons[smg][2])
    {
    thread GiveWeapons "smg" local.selected_weapon
    }
    else if (local.selected_weapon == group.weapons[mg][1] || local.selected_weapon == group.weapons[mg][2])
    {
    thread GiveWeapons "mg" local.selected_weapon
    }
    else if (local.selected_weapon == group.weapons[rockets][1] || local.selected_weapon == group.weapons[rockets][2] || group.selected_weapon == group.weapons[shotgun][1])
    {
    self takeall
    self iprint "This weapon is not available, because breaks the Rule#1." 1
    }
    end

    GiveWeapons local.type local.inv:

    for (local.i = 1; local.i <= group.weapons[local.type].size; local.i++)
    {
    if (group.weapons[local.type][local.i] != local.inv)
    {
    self give group.weapons[local.type][local.i]
    }
    }
    self give group.weapons[grenades][1]
    self give group.weapons[grenades][2]
    end


    Probably not perfect either but just threw it together (i quickly tested it and it works)...

    (Edit) Or:


    //*******************************************************************************************
    // MEDAL OF HONOR ALLIED ASSAULT
    // Select Primary Weapon
    //*******************************************************************************************
    main:
    //store classes
    local.weaponclass[1] = "smg"
    local.weaponclass[2] = "mg"
    local.weaponclass[3] = "pistol"
    local.weaponclass[4] = "rifle"
    local.weaponclass[5] = "sniper"
    local.weaponclass[6] = "rockets"
    local.weaponclass[7] = "special"
    local.weaponclass[8] = "grenades"
    //store weapons
    local.weapons[local.weaponclass[1]][1] = "models/weapons/mp40.tik"
    local.weapons[local.weaponclass[1]][2] = "models/weapons/thompsonsmg.tik"
    local.weapons[local.weaponclass[2]][1] = "models/weapons/mp44.tik"
    local.weapons[local.weaponclass[2]][2] = "models/weapons/bar.tik"
    local.weapons[local.weaponclass[3]][1] = "models/weapons/p38.tik"
    local.weapons[local.weaponclass[3]][2] = "models/weapons/colt45.tik"
    local.weapons[local.weaponclass[3]][3] = "models/weapons/silencedpistol.tik"
    local.weapons[local.weaponclass[4]][1] = "models/weapons/kar98.tik"
    local.weapons[local.weaponclass[4]][2] = "models/weapons/m1_garand.tik"
    local.weapons[local.weaponclass[5]][1] = "models/weapons/kar98sniper.tik"
    local.weapons[local.weaponclass[5]][2] = "models/weapons/springfield.tik"
    local.weapons[local.weaponclass[6]][1] = "models/weapons/panzerschreck.tik"
    local.weapons[local.weaponclass[6]][2] = "models/weapons/bazooka.tik"
    local.weapons[local.weaponclass[7]][1] = "models/weapons/shotgun.tik"
    local.weapons[local.weaponclass[8]][1] = "models/weapons/steilhandgranate.tik"
    local.weapons[local.weaponclass[8]][2] = "models/weapons/m2frag_grenade.tik"

    //get weapon
    waitframe
    local.n = randomint(999)
    self weaponcommand dual "targetname" ("w" + local.n)
    local.selected_weapon = $("w" + local.n).model

    //give weapons
    for (local.i = 1; local.i <= local.weaponclass.size; local.i++)
    {
    for (local.j = 1; local.j <= local.weapons[local.weaponclass[local.i]].size; local.j++)
    {
    if (local.selected_weapon == local.weapons[local.weaponclass[local.i]][local.j])
    {
    if (local.i == 6 || local.i == 7)
    {
    self takeall
    self iprint "This weapon is not available, because breaks the Rule#1." 1
    end
    }
    for (local.l = 1; local.l <= local.weapons[local.weaponclass[local.i]].size; local.l++)
    {
    if (local.weapons[local.weaponclass[local.i]][local.l] != local.selected_weapon)
    {
    self give local.weapons[local.weaponclass[local.i]][local.l]
    }
    }
    end
    }
    }
    }
    end


    I suppose then all you need if you want to use it for SH / BT is add to the weapons array and it will work.
    Last edited by 1337Smithy; December 2nd, 2018 at 08:03 AM.

  6. #6

    Default

    The problem was solved.

    Thanks to every one of you for your insights, i really appreciate it.

Posting Permissions

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