Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 6 Guests
Online:

LATEST FORUM THREADS

»
warfare
CoD4 Map + Mod Releases
Voting menu on maps
CoD+UO General
Hauling 911
CoDBO3 General

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 2
Category: CoD2 Scripting
Scripting and coding with Call of Duty 2.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: switch light on/off
kalieck
General Member
Since: Aug 9, 2006
Posts: 161
Last: Feb 14, 2009
[view latest posts]
Level 4
Category: CoD2 Scripting
Posted: Wednesday, Aug. 27, 2008 12:05 pm
hey guys!

Is it possible to switch lights on/off called by a trigger or something?

thx for help, kAl
Share |
Sevenz
General Member
Since: Apr 24, 2006
Posts: 2390
Last: May 10, 2013
[view latest posts]
Level 8
Category: CoD2 Scripting
Posted: Wednesday, Aug. 27, 2008 02:11 pm
Tutorial located in CoD:UO Mapping section:

http://www.modsonline.com/Tutorials-read-292.html

Code:
/* ======================================================================
   Light control script by WHC_Grassy
   Created: September 07, 2005 
   Version 2
   Added either On or Off inital light states (global to all lights in map)
   Added sound and light switch model usage
   
   (see comments and notes below)
   
   
   What is this? :
   It's a script I wrote to allow players to be able to turn on/off
   lights in mp maps. It has been tested in UO but should also work in COD.
   I have tried to make it universal so anyone can use it in their own map.
   
   How does it work? :
   By simple illusion, it actually moves the light radiating model
   out of the play area, and hides the light_on xmodel, and shows
   the light_off xmodel. And of course the reverse when turned on again.
   This creates the illusion of the light being switched
   on and off :)
   
   Some advice :
   The light radiated from the script_models is a workaround due to
   the fact that the game dosn't support control of real lights.
   Unfortunatly the script_models we have to use dont radiate light
   as well as a normal light entity would, it's advisable to keep the light
   values fairly low otherwise it will radiate right through walls, floors
   and roofs and look nasty.
   Only use them for effect in enclosed areas like tunnels, cellars
   underground, and have other lighting not too far away,
   say around a corner of a tunnel, or in an adjacent roon of a cellar.

   What you need to do in your map :
   You can have any number of lights and models but don't go overboard here!
   
   -------------------------------------------------------------------------------------------------------
   Example for a room with two lights and two triggers (one each end of the room near doors for eg)
   
   Place your triggers (trigger_use) where you want them and give them both
   key: targetname  value: lighttrigger
   key: script_noteworthy  value: room1
   
   If you want a model to represent the light switch you can make one out brushes
   and define it as a script_brushmodel or use an existing xmodel and define it
   as a script_model. You can have any number of models coresponding to the triggers
   and just follow the same naming convention. The script will still work ok if no models
   are found, but you wont get a sound played when triggered.
   key: targetname  value: lightswitch
   key: script_noteworthy  value:room1
   
   Now place your xmodels of the light_on type and give them both
   key: targetname  value: lightonmodel
   key: script_noteworthy  value: room1
   And change them into script_models, dont leave them as misc_models!
   
   Next place in the same position as the on models your xmodel light_off types and give them these keys,
   key: targetname  value: lightoffmodel
   key: script_noteworthy  value: room1
   And change them into script_models, dont leave them as misc_models!
   
   Now for the actual lights, create two script_models and position them on the light xmodels, then select
   each in turn and give them these keys and values.
   Key: targetname  value: light
   Key: script_noteworthy  value: room1
   Key: light  value: 50
   Note* I recomend you stay below 100 for light value or it will show through everything
   
   Get the picture here?
   All the above are related to each other by the script_noteworthy keys they contain.
   Only the targetnames need to be different.
   -------------------------------------------------------------------------------------------------------

   To start this script use;
   level thread maps\mp\light_control::main();
   from your maps .gcs file
   
   Of course make sure this script is in the same place as your maps .bsp and .gsc :-)
   
   NOTE: the default distance this script moves the light entitys below the map is 1000 units,
            if your lights are located high in your map and you have areas below the map and you
            can still see them when they have beem moved by this script then just increase the
            value of level.dist from 1000 to whatever you need to stop them being seen.
            
 If you have problems you can usually get me in the forums of modsonline.
 Enjoy! Grassy
  ==============================================================*/

  
main() {

level.dist = 1000;     //increase this value if needed


//   thread init_lights();              // to start your map with lights ON use this line


      thread start_lights_off();     // to start your map with lights OFF use this line

}



init_lights() { 

  lightoff = getentarray ("lightoffmodel","targetname"); 
  if ( isdefined(lightoff)) {
     for (i = 0; i < lightoff.size; i++) {
        lightoff[i] hide();                                                           //hide the off models
     }   
  }

  lightswitch = getentarray ("lighttrigger","targetname");            //get all trigger_use brushes 
  if ( isdefined(lightswitch)) {

       for (i = 0; i < lightswitch.size; i++) {

        if(lightswitch[i].script_noteworthy == "room1")
           lightswitch[i] thread light_handler(false);                     //monitor triggers

       if(lightswitch[i].script_noteworthy == "bunker")                 //Not used - example only
         lightswitch[i] thread light_handler(false);                       //maybe for lights in a bunker somewhere? :)

// Just add more lines like the examples above to include more lights starting in the ON state

     }
  }
}



start_lights_off() { 

  lighton = getentarray ("lightonmodel","targetname"); 
  if ( isdefined(lighton)) {
     for (i = 0; i < lighton.size; i++) {
        lighton[i] hide();                                                           //hide the on models
     }   
  }


  lightswitch = getentarray ("lighttrigger","targetname"); 
  if ( isdefined(lightswitch)) {

       for (i = 0; i < lightswitch.size; i++) {

        if(lightswitch[i].script_noteworthy == "room1")
        {
           lightswitch[i] thread hide_lights(true);                         //hide the light entity
           lightswitch[i] thread light_handler2(true);                    //monitor triggers
        }
        

       if(lightswitch[i].script_noteworthy == "bunker")        //
       {                                                                     // Not used
         lightswitch[i] thread hide_lights(true);                  // This is an example of another
         lightswitch[i] thread light_handler2(true);             // entry for another location
       }                                                                    //

// Just add more lines exactly like the example lines above to include more lights starting in the OFF state.

   }
 }
}










//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//-----------------------No need to touch these threads below----------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------





hide_lights(state) { 

  self.id = self.script_noteworthy;

  if(state == true)
  {
     state = false;
     lights = getentarray ("light","targetname"); 
     if(isdefined(lights)) {
     for (i = 0; i < lights.size; i++) {
        lights[i].id = lights[i].script_noteworthy;
        if (lights[i].id == self.id) {
           distdown = 0 - level.dist;
           temp1 = spawn ("script_origin", lights[i].origin + (0, 0, distdown));
           lights[i] moveto (temp1.origin,0.1,0.1,0);
           temp1 delete();
        }
     }
   }
  lightoff = getentarray ("lightoffmodel","targetname"); 
     if(isdefined(lightoff))  {
        for (i = 0; i < lightoff.size; i++)   {
           lightoff[i].id = lightoff[i].script_noteworthy;
           if (lightoff[i].id == self.id)
              lightoff[i] show();
        }
     }
  lighton = getentarray ("lightonmodel","targetname"); 
     if(isdefined(lighton))   {
        for (i = 0; i < lighton.size; i++) {
           lighton[i].id = lighton[i].script_noteworthy;
           if (lighton[i].id == self.id)
              lighton[i] hide();
        }
     }
  }

  else if(state == false)
  {
     state = true;
     lights = getentarray ("light","targetname"); 
     if(isdefined(lights)) {
     for (i = 0; i < lights.size; i++) {
        lights[i].id = lights[i].script_noteworthy;
        if(lights[i].id == self.id) {
           distup = 0 + level.dist;
           temp2 = spawn ("script_origin", lights[i].origin + (0, 0, distup));
           lights[i] moveto (temp2.origin,0.1,0.1,0);
           temp2 delete();
        }
     }
   }
  lighton = getentarray ("lightonmodel","targetname"); 
     if(isdefined(lighton))   {
        for (i = 0; i < lighton.size; i++) {
           lighton[i].id = lighton[i].script_noteworthy;
           if (lighton[i].id == self.id)
              lighton[i] show();
        }
     }
  lightoff = getentarray ("lightoffmodel","targetname"); 
     if(isdefined(lightoff))  {
        for (i = 0; i < lightoff.size; i++)   {
           lightoff[i].id = lightoff[i].script_noteworthy;
           if (lightoff[i].id == self.id)
              lightoff[i] hide();
        }
     }
  }
}
//end of hide_lights thread


light_handler2(state)
{ 

while(1) {
  self waittill ("trigger");

  self.id = self.script_noteworthy;

    
  //if you have switch models in the map with this targetname and script_noteworthy values this will play a sound on it.
  ent = getentarray("lightswitch", "targetname");
  if(isDefined(ent))  {
     for (a = 0; a < ent.size; a++) {
        ent[a].id = ent[a].script_noteworthy;
        if (ent[a].id == self.id)
          ent[a] playsound("switch");
      }
  }
      

  if(state == false)
  {
     state = true;
     lights = getentarray ("light","targetname"); 
     if(isdefined(lights)) {
     for (i = 0; i < lights.size; i++) {
        lights[i].id = lights[i].script_noteworthy;
        if (lights[i].id == self.id) {
           distdown = 0 - level.dist;
           temp1 = spawn ("script_origin", lights[i].origin + (0, 0, distdown));
           lights[i] moveto (temp1.origin,0.1,0.1,0);
           temp1 delete();
        }
     }
     }

  lightoff = getentarray ("lightoffmodel","targetname"); 
     if(isdefined(lightoff))  {
        for (i = 0; i < lightoff.size; i++)   {
           lightoff[i].id = lightoff[i].script_noteworthy;
           if (lightoff[i].id == self.id)
              lightoff[i] show();
        }
     }
  lighton = getentarray ("lightonmodel","targetname"); 
     if(isdefined(lighton))   {
        for (i = 0; i < lighton.size; i++) {
           lighton[i].id = lighton[i].script_noteworthy;
           if (lighton[i].id == self.id)
              lighton[i] hide();
        }
     }
  }

  else if(state == true)
  {
     state = false;
     lights = getentarray ("light","targetname"); 
     if(isdefined(lights)) {
     for (i = 0; i < lights.size; i++) {
        lights[i].id = lights[i].script_noteworthy;
        if(lights[i].id == self.id) {
           distup = 0 + level.dist;
           temp2 = spawn ("script_origin", lights[i].origin + (0, 0, distup));
           lights[i] moveto (temp2.origin,0.1,0.1,0);
           temp2 delete();
        }
     }
   }
  lighton = getentarray ("lightonmodel","targetname"); 
     if(isdefined(lighton))   {
        for (i = 0; i < lighton.size; i++) {
           lighton[i].id = lighton[i].script_noteworthy;
           if (lighton[i].id == self.id)
              lighton[i] show();
        }
     }
     
  lightoff = getentarray ("lightoffmodel","targetname"); 
     if(isdefined(lightoff))  {
        for (i = 0; i < lightoff.size; i++)   {
           lightoff[i].id = lightoff[i].script_noteworthy;
           if (lightoff[i].id == self.id)
              lightoff[i] hide();
        }
     }
  }

}
}
//end of start_lights_off thread




    



light_handler(state)
{ 

while(1) {
  self waittill ("trigger");

  self.id = self.script_noteworthy;


  //if you have switch models in the map with this targetname and a 
  //script_noteworthy value that matches the triggers this will play a sound on it.
  ent = getentarray("lightswitch", "targetname");
  if(isDefined(ent))  {
     for (a = 0; a < ent.size; a++) {
        ent[a].id = ent[a].script_noteworthy;
        if (ent[a].id == self.id)
          ent[a] playsound("switch");
      }
  }
  
  
  if(state == false)
  {
     state = true;
     lights = getentarray ("light","targetname"); 
     if(isdefined(lights)) {
     for (i = 0; i < lights.size; i++) {
        lights[i].id = lights[i].script_noteworthy;
        if (lights[i].id == self.id) {
           distdown = 0 - level.dist;
           temp1 = spawn ("script_origin", lights[i].origin + (0, 0, distdown));
           lights[i] moveto (temp1.origin,0.1,0.1,0);
           temp1 delete();
        }
     }
     }
     

  lightoff = getentarray ("lightoffmodel","targetname"); 
     if(isdefined(lightoff))  {
        for (i = 0; i < lightoff.size; i++)   {
           lightoff[i].id = lightoff[i].script_noteworthy;
           if (lightoff[i].id == self.id)
              lightoff[i] show();
        }
     }
  lighton = getentarray ("lightonmodel","targetname"); 
     if(isdefined(lighton))   {
        for (i = 0; i < lighton.size; i++) {
           lighton[i].id = lighton[i].script_noteworthy;
           if (lighton[i].id == self.id)
              lighton[i] hide();
        }
     }
  }

  else if(state == true)
  {
     state = false;
     lights = getentarray ("light","targetname"); 
     if(isdefined(lights)) {
     for (i = 0; i < lights.size; i++) {
        lights[i].id = lights[i].script_noteworthy;
        if(lights[i].id == self.id) {
           distup = 0 + level.dist;
           temp2 = spawn ("script_origin", lights[i].origin + (0, 0, distup));
           lights[i] moveto (temp2.origin,0.1,0.1,0);
           temp2 delete();
        }
     }
   }
   
  lighton = getentarray ("lightonmodel","targetname"); 
     if(isdefined(lighton))   {
        for (i = 0; i < lighton.size; i++) {
           lighton[i].id = lighton[i].script_noteworthy;
           if (lighton[i].id == self.id)
              lighton[i] show();
        }
     }
  lightoff = getentarray ("lightoffmodel","targetname"); 
     if(isdefined(lightoff))  {
        for (i = 0; i < lightoff.size; i++)   {
           lightoff[i].id = lightoff[i].script_noteworthy;
           if (lightoff[i].id == self.id)
              lightoff[i] hide();
        }
     }
  }

}
}
//end of light_handler thread


basic idea: move the light out of the visible map, 'cause you can't change it's color or anything else in realtime (at least CoD-CoD2)

http://www.modsonline.com/Forums-top-72729.html
Share |
securiity
General Member
Since: Jan 11, 2009
Posts: 63
Last: May 31, 2009
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Saturday, Jan. 31, 2009 10:45 pm
on a late note looking for problems thats a great script
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty 2 : CoD2 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»