Skip to content
  • 0 Unread 0
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Collapse

Plutonium

  1. Home
  2. BO2 Modding Support & Discussion
  3. I need a function for my script, which turns a certain action on and off when pressing a button

I need a function for my script, which turns a certain action on and off when pressing a button

Scheduled Pinned Locked Moved BO2 Modding Support & Discussion
5 Posts 2 Posters 667 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • alejandrodarzundefined Offline
    alejandrodarzundefined Offline
    alejandrodarz
    wrote on last edited by
    #1

    This is my script, as you can see I had to put the same function by directing buttons one to turn on and another to turn it off because I don't know what I should do to use only one button, join my script in 1 only and it will turn on when press a button and pressing that button again turns it off.

    NightVisionON()

    {

    self endon("disconnect");
    
    self iprintlnbold("^2Presiona [{+actionslot 4}] para activar visión de Infectado");
    
    
    for(;;)
    
    {
    
    	if(self actionslotfourbuttonpressed())
    
    	{
    
    	self setinfraredvision(true);
    
        }
    	
    wait 0.01;
    	
    }
    

    }

    NightVisionOFF()

    {

    self endon("disconnect");
    
    
    for(;;)
    
    {
    
    	if(self  actionslotonebuttonpressed())
    
    	{
    
    	self setinfraredvision(false);
    
        }
    	
    wait 0.01;
    	
    }
    

    }

    Cahzundefined 1 Reply Last reply
    0
    • alejandrodarzundefined alejandrodarz

      This is my script, as you can see I had to put the same function by directing buttons one to turn on and another to turn it off because I don't know what I should do to use only one button, join my script in 1 only and it will turn on when press a button and pressing that button again turns it off.

      NightVisionON()

      {

      self endon("disconnect");
      
      self iprintlnbold("^2Presiona [{+actionslot 4}] para activar visión de Infectado");
      
      
      for(;;)
      
      {
      
      	if(self actionslotfourbuttonpressed())
      
      	{
      
      	self setinfraredvision(true);
      
          }
      	
      wait 0.01;
      	
      }
      

      }

      NightVisionOFF()

      {

      self endon("disconnect");
      
      
      for(;;)
      
      {
      
      	if(self  actionslotonebuttonpressed())
      
      	{
      
      	self setinfraredvision(false);
      
          }
      	
      wait 0.01;
      	
      }
      

      }

      Cahzundefined Offline
      Cahzundefined Offline
      Cahz
      VIP
      wrote on last edited by
      #2

      alejandrodarz

      NightVisionToggle()
      {
      	level endon("game_ended");
      	self endon("disconnect");
      	self iprintlnbold("^2Presiona [{+actionslot 4}] para activar visión de Infectado");
      	for(;;)
      	{
      		if(self actionslotfourbuttonpressed())
      		{
      			if (!isDefined(self.nightvision))
      			{
      				self.nightvision = true;
      				self setinfraredvision(true);
      			}
      			else
      			{
      				self.nightvision = undefined;
      				self setinfraredvision(false);
      			}
          	        }
      		wait 0.05;
      	}
      }
      

      using the isDefined(variable) you can create a variable on the player and use that as the check for the toggle. Hopefully this makes sense

      alejandrodarzundefined 2 Replies Last reply
      0
      • Cahzundefined Cahz

        alejandrodarz

        NightVisionToggle()
        {
        	level endon("game_ended");
        	self endon("disconnect");
        	self iprintlnbold("^2Presiona [{+actionslot 4}] para activar visión de Infectado");
        	for(;;)
        	{
        		if(self actionslotfourbuttonpressed())
        		{
        			if (!isDefined(self.nightvision))
        			{
        				self.nightvision = true;
        				self setinfraredvision(true);
        			}
        			else
        			{
        				self.nightvision = undefined;
        				self setinfraredvision(false);
        			}
            	        }
        		wait 0.05;
        	}
        }
        

        using the isDefined(variable) you can create a variable on the player and use that as the check for the toggle. Hopefully this makes sense

        alejandrodarzundefined Offline
        alejandrodarzundefined Offline
        alejandrodarz
        wrote on last edited by
        #3

        Cahz I speak Spanish and when translating it I understood something like

        if(isdefined(self setinfraredvision))
            if(self actionslotonebuttonpressed())
        	{
                self setinfraredvision(false);
            }
        
        1 Reply Last reply
        0
        • Cahzundefined Cahz

          alejandrodarz

          NightVisionToggle()
          {
          	level endon("game_ended");
          	self endon("disconnect");
          	self iprintlnbold("^2Presiona [{+actionslot 4}] para activar visión de Infectado");
          	for(;;)
          	{
          		if(self actionslotfourbuttonpressed())
          		{
          			if (!isDefined(self.nightvision))
          			{
          				self.nightvision = true;
          				self setinfraredvision(true);
          			}
          			else
          			{
          				self.nightvision = undefined;
          				self setinfraredvision(false);
          			}
              	        }
          		wait 0.05;
          	}
          }
          

          using the isDefined(variable) you can create a variable on the player and use that as the check for the toggle. Hopefully this makes sense

          alejandrodarzundefined Offline
          alejandrodarzundefined Offline
          alejandrodarz
          wrote on last edited by
          #4

          Cahz Thank you very much for helping me again, very kind of you. I already did it, I am going to leave the code here in case someone is interested or is looking for the same goal as me.

          1 Reply Last reply
          0
          • alejandrodarzundefined Offline
            alejandrodarzundefined Offline
            alejandrodarz
            wrote on last edited by
            #5

            Remember call night vision

            NightVision()

            {

            self endon("disconnect");
            
            self iprintlnbold("^2Presiona [{+actionslot 4}] para activar visión de Infectado");
            
            
            for(;;)
            
            {
            
            	if(self actionslotfourbuttonpressed())
                
            	{
            
            	self InfraredVision();
            
                }
            	
            wait 0.01;
            	
            }
            

            }

            InfraredVision()
            {
            if (!IsDefined(self.InfraredVision))
            {
            self.InfraredVision = true;
            self setinfraredvision(true);
            self IPrintLn("InfraredVision: ^2Enabled");
            }
            else
            {
            self.InfraredVision = undefined;
            self setinfraredvision(false);
            self IPrintLn("InfraredVision: ^1Disabled");
            }
            }

            1 Reply Last reply
            0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

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