ItsMods

Full Version: How We Make A Toggle?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Any one can make a tutorial on how to make a toggle on/off?
(07-25-2011, 14:25)Scripts18 Wrote: [ -> ]Any one can make a tutorial on how to make a toggle on/off?

Something like

Code:
Trigger_function()
{
      trigger.is.on = 0
      if usebuttonpressed() && trigger.is.on = 0
      {
            //do stuff here
            trigger.is.on = 1
      }
      else if usebuttonpressed() && trigger.is.on = 1
      {
            // do stuff
            trigger.is.on = 0
      }

Should look something like this, but thats definately wrong because i dont know the right comments atm, but it should be something similiar to this Big Grin
(07-25-2011, 14:34)prisma Wrote: [ -> ]
(07-25-2011, 14:25)Scripts18 Wrote: [ -> ]Any one can make a tutorial on how to make a toggle on/off?

Something like

Code:
Trigger_function()
{
      trigger.is.on = 0
      if usebuttonpressed() && trigger.is.on = 0
      {
            //do stuff here
            trigger.is.on = 1
      }
      else if usebuttonpressed() && trigger.is.on = 1
      {
            // do stuff
            trigger.is.on = 0
      }

Should look something like this, but thats definately wrong because i dont know the right comments atm, but it should be something similiar to this Big Grin

thx but any one can show me a working toggle so I can learn from it :S
I learn easier when I look at a working one
Instead of [Tutorial] choose [Request].
PHP Code:
ThirdPerson()
{
    
self setClientDvar("cg_thirdpersonRange"150);
    
self setClientDvar("cg_thirdpersonAngle"356);

    if(
self.thirdperson == "off")
    {
        
self setClientDvar("cg_thirdperson"1);
        
self.thirdperson "on";
    
    }
    else
    {
        
self setClientDvar("cg_thirdperson"0);
        
self.thirdperson "off";
    }


Just call this function whenever you need the toggle to be activated.
(07-25-2011, 15:22)Madnesslink5 Wrote: [ -> ]
PHP Code:
ThirdPerson()
{
    
self setClientDvar("cg_thirdpersonRange"150);
    
self setClientDvar("cg_thirdpersonAngle"356);

    if(
self.thirdperson == "off")
    {
        
self setClientDvar("cg_thirdperson"1);
        
self.thirdperson "on";
    
    }
    else
    {
        
self setClientDvar("cg_thirdperson"0);
        
self.thirdperson "off";
    }


Just call this function whenever you need the toggle to be activated.

but how I desactivate after?
where do you need to add these lines, just in _rank.gsc beneath OnPlayerSpawn?
(07-25-2011, 17:18)Kipiop Wrote: [ -> ]where do you need to add these lines, just in _rank.gsc beneath OnPlayerSpawn?

:S Im asking for a tutorial
add to init

Code:
//set the variable so it doesnt error when we want to use it.
self.thirdperson = 0;

add to on spawned


Code:
//start the thread
self thread thirdperson();

//print the keybind we are using
self iPrintLn("^8Press ^7 [{+actionslot 3}] ^8 to toggle third person!");


Add this anywhere in ur on spawned file

Code:
ThirdPerson()
{
    self endon ( "death" );

//begin loop til you die
    while( true )
    {
//wait a while so it doesnt freeze up as an endless loop
        wait 0.08;
//designate a key to be pushed
        if( self ActionSlotThreeButtonPressed() )
        {
//setting dvars that dont matter no matter what we toggle
    self setClientDvar("cg_thirdpersonRange", 150);
    self setClientDvar("cg_thirdpersonAngle", 356);

// check iff the dvar is off or on - first time round it will be 0 and skip this.
    if(self.thirdperson == "off")
    {
//our first option in the toggle..
        self setClientDvar("cg_thirdperson", 1);
        self.thirdperson = "on";
    
    }
// set variable to off so next time around it toggles the above option
    else
    {
//our second option in the toggle..
        self setClientDvar("cg_thirdperson", 0);
        self.thirdperson = "off";
    }
  }
}
}


Each time you hit action slot 3, what ever its bound to which will display when you spawn, it will toggle them(if they are the right dvars).. not sure any of these dvars work in BO its just an example.
^to the above, it does work. Took the code out of my mod Tongue
Pages: 1 2 3