main local.trigorigin local.soundorigin local.targetname local.name local.horn local.setsize1 local.setsize2: local.trig = spawn trigger_use local.trig.origin = local.trigorigin if(local.setsize1 == NIL || local.setsize2 == NIL) { local.trig setsize ( -30 -30 -30 ) ( 30 30 30 ) } if(local.setsize1 != NIL && local.setsize2 != NIL) { local.trig setsize local.setsize1 local.setsize2 } local.trig setthread engine_onoff_horn local.trig.engine = 0 // holds the truck trigger's current state (engine off/on: 0 or 1). local.trig.horn = local.horn // 0 = no horn, 1 = honk while vehicle is on only, 2 = honk while on or off local.trig.name = local.name // some vehicles (tanks, planes, halftracks) do not have horns. local.trig.targetname = local.targetname local.engine = spawn script_model targetname (local.targetname) local.engine model "static/indycrate.tik" // need a model for script_models to do "loopsound". local.engine.origin = local.soundorigin local.engine notsolid local.engine.scale = 0.001 //local.engine hide // loopsound does not work if script_model is hidden; use .scale = 0.001 instead. end engine_onoff_horn: local.player = parm.other local.team = local.player.dmteam // dmteam checks probably not needed, but helps prevent triggering if player changes team or goes to spectator. local.holdtimer = 0 while(local.player.useheld == 1 && local.player.dmteam == local.team && isalive local.player) { if(local.holdtimer == 0) { local.player stopwatch 3 // begin counting when USE key is held. } if(local.holdtimer >= 60) // 20 loops/sec * 3 seconds = 60. { local.player stopwatch 0 if(self.engine == 0) { local.player iprint (self.name + " has turned on.") $(self.targetname) playsound (self.name + "_ignitionstart") wait 1 $(self.targetname) loopsound (self.name + "_idleloop") } if(self.engine == 1) { local.player iprint (self.name + " has turned off.") $(self.targetname) stoploopsound $(self.targetname) playsound (self.name + "_ignitionstop") wait 1 } self.engine++ if(self.engine > 1) { self.engine = 0 } end } local.holdtimer++ local.team = local.player.dmteam // if player is still alive, then make player's dmteam = local.team. wait 0.05 // 20 while-loop increments per second. } if((self.engine == 1 || self.horn == 2) && local.holdtimer <= 20 && self.horn != 0) // if player releases USE key within 1 second while engine is on, or while off if self.horn = 2 { local.player iprint ("Honking the " + self.name + " horn.") $(self.targetname) playsound truckhorn } local.player stopwatch 0 if(self.engine == 0 && self.horn != 2) { local.player iprint ("Hold USE for 3 seconds to turn on the " + self.name) } if(self.engine == 0 && self.horn == 2 && local.holdtimer > 20) { local.player iprint ("Hold USE for 3 seconds to turn on the " + self.name + ", or hold USE for 1 second to honk the horn.") } if(self.engine == 1 && self.horn != 0 && local.holdtimer > 20) { local.player iprint ("Hold USE for 3 seconds to turn off the " + self.name + ", or hold USE for 1 second to honk the horn.") } if(self.engine == 1 && self.horn == 0) { local.player iprint ("Hold USE for 3 seconds to turn off the " + self.name) } end