Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Donate
Collapse

Plutonium

  1. Home
  2. BO2 Modding Support & Discussion
  3. [Help][Dvars] Creating A Simple Dvar Toggle Function -- Not working?

[Help][Dvars] Creating A Simple Dvar Toggle Function -- Not working?

Scheduled Pinned Locked Moved BO2 Modding Support & Discussion
7 Posts 4 Posters 308 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Deicideundefined Offline
    Deicideundefined Offline
    Deicide
    wrote on last edited by Deicide
    #1

    Hey there everyone. I was just wondering why this will not work ingame on Bo2. I'm making this code that- when defined will toggle Dvar to simply 1 or 0. But it seems when defining a dvar in this way, it doesn't work?
    Here is what i mean.

    I just don't really understand what it is that's keeping this from working when it should.. Any help at all would be great.

    /*
    *    Creator : ^1Deicide^7
    *    Project : test
    *    Mode : Multiplayer
    *    Date : 2024/02/20 - 17:50:32   
    */  
    
    #include maps\mp\_utility;
    #include common_scripts\utility;
    #include maps\mp\gametypes\_hud_util;
    #include maps\mp\gametypes\_hud_message;
    
    init()
    {
        level thread onPlayerConnect();
    }
    
    onPlayerConnect()
    {
        for(;;)
        {
            level waittill("connected", player);
            player thread onPlayerSpawned();
        }
    }
    
    onPlayerSpawned()
    {
        self endon("disconnect");
        level endon("game_ended");
        for(;;)
        {
            self waittill("spawned_player");
            setDvar("r_poisonFX_debug_enable",0); //If set to 1, will have the player's vision wavy and very unpleasing to the eye.
            //self thread Toggleloop();
            self thread Toggleloop2();
        }
    }
    Toggleloop()
    {
        self endon("disconnect");
        level endon("game_ended");
        for(;;)
        {
            //self LobbySetter("r_poisonFX_debug_enable");
            //self LobbySetter2("r_poisonFX_debug_enable");
            //self LobbySetter3();
            //self LobbySetter4(); // does nothing since no dvar is defined
            self LobbySetter4("r_poisonFX_debug_enable");
            wait 2;
        }
    }
    Toggleloop2() //WORKS
    {
        self endon("disconnect");
        level endon("game_ended");
        for(;;)
        {
            setDvar("r_poisonFX_debug_enable",1);
            wait 2;
            setDvar("r_poisonFX_debug_enable",0);
            wait 2;
        }
    }
    
    LobbySetter(c)
    {
        self endon("disconnect");
        level endon("game_ended");
        dvar = getDvar(c); //local variable "dvar" = getDvar(|c parameter|).
        if(dvar == "" || dvar == 0) //If the dvar is an empty string or 0/false, continue..
        {
            self iPrintln("ON"); //Toggles on infinitely
            setDvar(dvar,1); //Should be setting the dvar to 1 -- DOESN'T WORK
        }
        else //Never occurs because...? 
        {
            self iPrintln("OFF");
            setDvar(dvar,0);
        }
    }
    LobbySetter2(c)
    {
        self endon("disconnect");
        level endon("game_ended");
        dvar = "r_poisonFX_debug_enable"; //local variable "dvar" = defined string
        if(getDvar(dvar) == "" || getDvar(dvar) == 0) //If the dvar is empty or 0/false, continue..
        {
            self iPrintln("ON"); //Toggles on infinitely
            setDvar(dvar,1); //Should be setting the dvar to 1 --WORKS, STILL INFINITELY TOGGLES ON
        }
        else //Never occurs because...? 
        {
            self iPrintln("OFF");
            setDvar(dvar,0);
        }
    }
    LobbySetter3(c)
    {
        self endon("disconnect");
        level endon("game_ended");
        if(getDvar("r_poisonFX_debug_enable") == "" || getDvar("r_poisonFX_debug_enable") == 0) //If the dvar is empty or 0/false, continue..
        {
            self iPrintln("ON"); //Toggles on infinitely
            setDvar("r_poisonFX_debug_enable",1); //Should be setting the dvar to 1 --WORKS, STILL INFINITELY TOGGLES ON
        }
        else //Never occurs because...? 
        {
            self iPrintln("OFF");
            setDvar("r_poisonFX_debug_enable",0);
        }
    }
    LobbySetter4(c) //just trying anything at this point lol
    {
        self endon("disconnect");
        level endon("game_ended");
        if(IsDefined(c))
        {
            if(getdvarfloat(c) > getdvarint(c)) //check to determine if dvar is float or not
                var = getdvarfloat(c);
            else
                var = getdvarint(c);
        }
        else return;
        
        if(var == "" || var == 0) //If the dvar int/float is an empty string or 0/false, continue..
        {
            self iPrintln("ON"); //Toggles on infinitely
            setdvar(var, 1); //Does not work.
        }
        else //Never occurs because...? 
        {
            self iPrintln("OFF");
            setDvar(var,0);
        }
    }
    
    1 Reply Last reply
    0
    • chicken emojiundefined Offline
      chicken emojiundefined Offline
      chicken emoji
      wrote on last edited by
      #2

      I think you have to use strings like this

      LobbySetter(dvar)
      {
          if(getDvar(dvar) == "0")
          {
      	setDvar(dvar, "1");
      	self iPrintln("ON");
          } 
          else 
          {
      	setDvar(dvar, "0");
      	self iPrintln("OFF");
          }
      }
      
      Deicideundefined 1 Reply Last reply
      1
      • Resxtundefined Offline
        Resxtundefined Offline
        Resxt Plutonium Staff
        wrote on last edited by
        #3

        If it's always set to either 0 or 1 then this might work

        if (GetDvarInt("r_poisonFX_debug_enable")
        {
        // code when it's set to 1
        }
        else
        {
        // code when it's set to 1
        }
        
        1 Reply Last reply
        1
        • Deicideundefined Offline
          Deicideundefined Offline
          Deicide
          replied to chicken emoji on last edited by Deicide
          #4

          chicken emoji said in [Help][Dvars] Creating A Simple Dvar Toggle Function -- Not working?:

          I think you have to use strings like this

          LobbySetter(dvar)
          {
              if(getDvar(dvar) == "0")
              {
          	setDvar(dvar, "1");
          	self iPrintln("ON");
              } 
              else 
              {
          	setDvar(dvar, "0");
          	self iPrintln("OFF");
              }
          }
          

          I just tested this out and it worked. If the values are in quotations the toggle functionality runs as it should.
          If they are ran without the quotations, we end up with Black Ops 2 having a problem.

          So if you try a toggle function like me, do not do

          if(getDvar(dvar) == 0) 
          

          Do this instead.

          if(getDvar(dvar) == "0")
          

          Unsure if this is a compiler issue or not. But this is strange to me. Still, thank you so much! 🙂 Hate that i didn't try that sooner... Lol

          chicken emojiundefined JezuzLizardundefined 2 Replies Last reply
          0
          • chicken emojiundefined Offline
            chicken emojiundefined Offline
            chicken emoji
            replied to Deicide on last edited by
            #5

            Deicide I assume if you use GetDvarInt it returns it as an int like Resxt showed

            1 Reply Last reply
            1
            • JezuzLizardundefined Offline
              JezuzLizardundefined Offline
              JezuzLizard Plutonium Staff
              replied to Deicide on last edited by
              #6

              Deicide Turn on developer dvar to see script errors, it would have caught this mistake because you were comparing string to int. When a script error occurs the result is always undefined and because undefined is truthy in GSC that would explain why you were getting confused.

              Deicideundefined 1 Reply Last reply
              1
              • Deicideundefined Offline
                Deicideundefined Offline
                Deicide
                replied to JezuzLizard on last edited by
                #7

                JezuzLizard Will do! Thank you so much. Ill remember to do that from now on.

                1 Reply Last reply
                0

                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Donate