Tanelorn 0 Posted December 10, 2002 Howdy all. Tanelorn here with another brain twister for ya. I am using tons of encapsulated scripts in my mod, since there are so many special behaviors for all my units. Well wouldn't you know it, the time has come for me to need more than one script to be run at unit initialization. Rather than have TONS of scripts in my scripts folder that are solely designed to be run for a particular unit, I am trying to keep all the hassle in the config file and shovel it out from there. It's a great idea, in fact, it looks darn near perfect. My problem: I have no idea how to do it! I'm running into syntax errors left and right when I try to cram two script calls in one event handler. Any ideas? I've tried tons of combinations. I'll bet there's one that will work if we put our heads together. Heres a sample of a non-working config snippet: // this event handler allows the vehicle to continuously regenerate it's ammunition class eventhandlers   {      init =      {        [_this select 0, "TA_VTOL_EMG"] exec "\ta_units\scripts\reload_freegun.sqs";        [_this select 0, "TA_EMG_Gun"] exec "\ta_units\scripts\reload_freegun.sqs";      };   }; Share this post Link to post Share on other sites
suma 8 Posted December 10, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Tanelorn @ Dec. 10 2002,03:00)</td></tr><tr><td id="QUOTE">My problem: I have no idea how to do it! I'm running into syntax errors left and right when I try to cram two script calls in one event handler. Heres a sample of a non-working config snippet: class eventhandlers   {      init =      {        [_this select 0, "TA_VTOL_EMG"] exec "\ta_units\scripts\reload_freegun.sqs";        [_this select 0, "TA_EMG_Gun"] exec "\ta_units\scripts\reload_freegun.sqs";      };   };<span id='postcolor'> Elementary, dear Watson. Use one very long line instead: class eventhandlers   {      init = "[_this select 0, ""TA_VTOL_EMG""] exec ""\ta_units\scripts\reload_freegun.sqs"";[_this select 0, ""TA_EMG_Gun""] exec ""\ta_units\scripts\reload_freegun.sqs""";   }; Share this post Link to post Share on other sites
DragoFire 0 Posted December 10, 2002 0--></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Suma @ Dec. 10 2002,180)</td></tr><tr><td id="QUOTE"></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Tanelorn @ Dec. 10 2002,03<!--emo&)</td></tr><tr><td id="QUOTE">My problem: I have no idea how to do it! I'm running into syntax errors left and right when I try to cram two script calls in one event handler. Heres a sample of a non-working config snippet: class eventhandlers   {      init =      {        [_this select 0, "TA_VTOL_EMG"] exec "\ta_units\scripts\reload_freegun.sqs";        [_this select 0, "TA_EMG_Gun"] exec "\ta_units\scripts\reload_freegun.sqs";      };   };<span id='postcolor'> Elementary, dear Watson. Use one very long line instead: class eventhandlers   {      init = "[_this select 0, ""TA_VTOL_EMG""] exec ""\ta_units\scripts\reload_freegun.sqs"";[_this select 0, ""TA_EMG_Gun""] exec ""\ta_units\scripts\reload_freegun.sqs"""   };<span id='postcolor'> Ok we know you can call a script. And i know you can script an event within the CPP without calling a script! But the problem I have is how do you add your scripted event into the "CLASS Eventhandler", I know it's done by the </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> addEventHandler ["foldwings",{}]<span id='postcolor'> But where does this sit in the CPP, is in the "cfgvehicle" or somewhere else?? This is what I've got at the moment, just waiting to figure-out the "addeventhandler" problem. </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">class EventHandlers {gear = "if (_this Select 1) then {(_this Select 0) Animate [""LtGear"", 0]; (_this Select 0) Animate [""RtGear"", 0]; (_this Select 0) Animate [""NoseGear"", 0]} else {(_this Select 0) Animate [""LtGear"", 1]; (_this Select 0) Animate [""RtGear"", 1]; (_this Select 0) Animate [""NoseGear"", 1]}"; foldwings = "if (_this Select 1) then {(_this Select 0) Animate [""Ltouterwing"", 0]; (_this Select 0) Animate [""Rtouterwing"", 0]} else {(_this Select 0) Animate [""Ltouterwing"", 1]; (_this Select 0) Animate [""Rtouterwing"", 1]}"; };}; };<span id='postcolor'> Once I know this I can finish the folding wings and the tailhook for my model. DragoFire Share this post Link to post Share on other sites
TYsiEK 0 Posted December 10, 2002 You mean this is a line from config.cpp ? If yes, i can use VTOL script in "INIT" . Cool. Share this post Link to post Share on other sites
suma 8 Posted December 10, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (DragoFire @ Dec. 10 2002,08:09)</td></tr><tr><td id="QUOTE">This is what I've got at the moment, just waiting to figure-out the "addeventhandler" problem. Once I know this I can finish the folding wings and the tailhook for my model.<span id='postcolor'> You can add event handlers only for events that are known by the game engine. List of those is available in command reference (Scripting topics). You can also implement your own "custom" animations bound to action menu. This has been discussed in several topics already. Now please let this topic go back to its original topic, and it is "Multiple scripts run from one event handler". If you have questions regarding other topics, feel free to create a new topic. Share this post Link to post Share on other sites
DragoFire 0 Posted December 10, 2002 The "addeventhandle" has been around since 1.85 as I understand, but I can't seem to find where it goes in the CPP. Once it's found, I'd say there will be a lot of people adding custom animations with their own action commands. DragoFire Share this post Link to post Share on other sites
brsseb 0 Posted December 10, 2002 0--></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Suma @ Dec. 10 2002,090)</td></tr><tr><td id="QUOTE">You can add event handlers only for events that are known by the game engine. List of those is available in command reference (Scripting topics).<span id='postcolor'> Ok, this is somewhat confusing; Since your saying that we can only use event handlers that the engine nows and that all of those are listed in the Comref. Well, where did DragoFire get his "foldwings"-event from then? I cant find that  in the ComRef? Or is that event somewhat derived from the event signaling engine on/off? brsseb Share this post Link to post Share on other sites
suma 8 Posted December 10, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (brsseb @ Dec. 10 2002,14:17)</td></tr><tr><td id="QUOTE">Ok, this is somewhat confusing ... Well, where did DragoFire get his "foldwings"-event from then? I cant find that  in the ComRef?<span id='postcolor'> Yes, it is confusing. I will try to make it clear. DragoFire got his "foldwings" from thin air and he is now surprised it is not working. Now the confusion grows, because some people start to think he got it working. No, he did not. The confusion will be completely solved once DragoFire realizes he can do his folding wings using custom animation, not using event handler. Share this post Link to post Share on other sites
brsseb 0 Posted December 10, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Suma @ Dec. 10 2002,15:47)</td></tr><tr><td id="QUOTE"></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (brsseb @ Dec. 10 2002,14:17)</td></tr><tr><td id="QUOTE">Ok, this is somewhat confusing ... Well, where did DragoFire get his "foldwings"-event from then? I cant find that  in the ComRef?<span id='postcolor'> Yes, it is confusing. I will try to make it clear. DragoFire got his "foldwings" from thin air and he is now surprised it is not working. Now the confusion grows, because some people start to think he got it working. No, he did not. The confusion will be completely solved once DragoFire realizes he can do his folding wings using custom animation, not using event handler.<span id='postcolor'> Thank god for that. Though I had missed out on something big there. Btw, any chance for move event handlers in the next few patches? brsseb Share this post Link to post Share on other sites
DragoFire 0 Posted December 10, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (brsseb @ Dec. 11 2002,03:55)</td></tr><tr><td id="QUOTE"></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Suma @ Dec. 10 2002,15:47)</td></tr><tr><td id="QUOTE"></span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (brsseb @ Dec. 10 2002,14:17)</td></tr><tr><td id="QUOTE">Ok, this is somewhat confusing ... Well, where did DragoFire get his "foldwings"-event from then? I cant find that  in the ComRef?<span id='postcolor'> Yes, it is confusing. I will try to make it clear. DragoFire got his "foldwings" from thin air and he is now surprised it is not working. Now the confusion grows, because some people start to think he got it working. No, he did not. The confusion will be completely solved once DragoFire realizes he can do his folding wings using custom animation, not using event handler.<span id='postcolor'> Thank god for that. Though I had missed out on something big there. Btw, any chance for move event handlers in the next few patches? brsseb<span id='postcolor'> What had happen is a follows. Due to the major LACK of information about CPP scripting, in regards to eventhandles and animations, other than what some of us have found, by trial and error. I went looking for anything that might allow me to add a event to my model. The only thing I found that looked like it might work was the "addeventhandle", but is listed was in the comref at www.flashpoint1985.com . It made sense to me that this could allow you to add a "NEW" "eventhandle" to a model's CPP, as there is no where is says it isn't possible. But from what Suma's saying this isn't true. I've been talking to a large number of mod/modelmakers about the CPP and it's still a big unknown to most of us, a few of us know a large amount about areas of the CPP, but not the complete CPP setup in great detail. If possible Suma can you provide us (being the Modelmakers/ModMakers) a better defined guide to the model's CPP configation, I know this maybe a big ask, but I don't know anyone who has a full and complete knownledge of the CPP's, it's just been a guessing game so far, and I think it'd go down great with everyone. I look forward to your feedback. DragoFire Share this post Link to post Share on other sites
Tanelorn 0 Posted December 10, 2002 As the Zerth Dak'kon would say, DragoFire is seeing with "Vanquilar's Eye". It's such a classic. If you want the whole story, you must play Planescape Torment. But the gist of it is... when you want something badly, you tend to see everything in the perspective of your goal. You become narrow-minded due to your strong desires, and are easily fooled by things that are illogical but seem to bring you closer to reaching your goal. This tunnel-vision mental state is called "Seeing with Vanquilar's Eye". Vanquilar was betrayed and killed, by the way. In any case, THANK YOU VERY MUCH SUMA! I too saw with Vanquilar's eye, as I put strong emphasis on clean looking code. I didn't realize that I couldn't break up the code sections like I do for other parts of the config file. My desire to keep the code clean (no code long enough to wrap across the screen) kept me from realizing my errors in syntax. Thanks for setting me straight Suma. THis is a real life-saver. Now if I can only figure out how to make a vehicle with a turret that doesn't raise dust clouds, the KBOT will be mine! Share this post Link to post Share on other sites
bn880 5 Posted December 11, 2002 BTW people, it's "addEventHandler" with the 'r'. Looks like Suma solver your troubles by his first post. Share this post Link to post Share on other sites
The Sharpshooter 0 Posted December 11, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Tanelorn @ Dec. 10 2002,19:54)</td></tr><tr><td id="QUOTE">As the Zerth Dak'kon would say, DragoFire is seeing with "Vanquilar's Eye". It's such a classic. If you want the whole story, you must play Planescape Torment™. But the gist of it is... when you want something badly, you tend to see everything in the perspective of your goal. You become narrow-minded due to your strong desires, and are easily fooled by things that are illogical but seem to bring you closer to reaching your goal. This tunnel-vision mental state is called "Seeing with Vanquilar's Eye". Vanquilar was betrayed and killed, by the way. In any case, THANK YOU VERY MUCH SUMA! I too saw with Vanquilar's eye, as I put strong emphasis on clean looking code. I didn't realize that I couldn't break up the code sections like I do for other parts of the config file. My desire to keep the code clean (no code long enough to wrap across the screen) kept me from realizing my errors in syntax. Thanks for setting me straight Suma. THis is a real life-saver. Now if I can only figure out how to make a vehicle with a turret that doesn't raise dust clouds, the KBOT will be mine!<span id='postcolor'> So you teach the ways of the Zerthimon ? Great game Planescape. Now lets keep ontopic: My question is: When I add an EventHandler to a unit(in the config.cpp) this means it will run the script the whole mission. Adding multiple units that have eventhandlers attached + all the scripting the mission will have and the units, ect. will make the mission heavyer, won´t it ? I mean much heavyer, or the EventHandlers don´t use much CPU ? Hope you understand my question. Share this post Link to post Share on other sites
Tanelorn 0 Posted December 11, 2002 This post is 3 tiered. =P -- TIER 1: answer to sharpshooter: It will depend on your scripts, but yes, for every unit you place, those scripts will run. You can get around CPU burden by using lots of @ statements so the script only runs when something happens and is paused the rest of the time. Using loops would be bad. Also, of course, if it's just a script that runs once and exits, you won't have any CPU burden. -- TIER 2: cleaning up the code Now that since 1.85 we can use {} to enclose strings, I am able to use this cleaner version of SUMA's code. Unfortunately I can't break it up further. // this event handler allows the vehicle to continuously regenerate it's ammunition class eventhandlers { init = "[_this select 0, {TA_VTOL_EMG}] exec {\ta_units\scripts\reload_freegun.sqs};[_this select 0, {TA_EMG_Gun}] exec {\ta_units\scripts\reload_freegun.sqs}"; }; -- TIER 3: SHarpshooter and Zerthimon I loved Dak'kon and the GithZerai so much that I can repeat all the teachings of the Wheel of Zerthimon nearly word for word. I also created the WHeel of Zerthimon out of ireregularly cut sheet metal plates, polyethylene molds and a few other knickknacks . It had locking mechanisms in the center that allowed you to remove the plates and turn them about to read the scriptures. If you didn't know the sequences the scriptures were garbage because each scripture was engraved across several different plates. The history of the Gith races is one of the most incredible stories from the AD&D monsteous manual and later elaborated in Planescape itself. I liked him so much I roleplayed a GithZerai for about 3 years in an AD&D campaign. He was on a hopeless quest to discover the long lost history of the Gith races before their capture by the Illythid. I even perfected my speech to sound like a GithZerai (on top of speaking the Kant, of course). My character was able to guide us through certain parts of YsGaard, Ghenna and Avernus (Baator). Briefly hit the Abyss but even the toughest cutters steer clear of that place. Heh heh, good fun. Share this post Link to post Share on other sites
DragoFire 0 Posted December 11, 2002 I've been chatting with "Sefe" (many thanks), and here's what he had to say. </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE"> The problem was that you tried to define an event handler for a "foldwings" event. There is no such event. You can only define event handlers for a set of predefined eventhandlers. 'AddEventHandler' is a scripting command. It's not a valid section of the config.cpp file. I have defined 'UserAction' section that lets you add custom actions to the action menu. The CPP structure must be more readable and resembles the block structure of the config file. You should stick to this or a similar structure of the config file. This lets you keep track of the classes and subclasses which will be a huge timesaver on the event of certain errors in the config file, eg. if you forget a closing bracket. Furthermore, remove all property definition from already defined base classes. In older OFP-versions they can do damage and in newer versions they are simply ignored. Another thing is that your group definitions are pointless. From the point of view of the mission editor, groups with only one units are not only useless (groups make sense for special formations, eg. with my M3A2 addon there comes a group "Mechanized cavalry platoon" which consists of 4 M3A2 CFVs), they also clutter up the group listing, especially when they don't use the predefined sides and sections (eg. west->armoured) but define new ones. Just imagine how the group listing would look like if every addon maker would add a new group or even new sides or sections with his addons. IMO, group definitions don't make any sense for air units at all, even if there's more than one unit in a group. I'd recommend to remove all group definitions. <span id='postcolor'> As you can see I've got alot of good advise from "Sefe". And here's what he showed he on how to add new animation; </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> class CfgVehicles { class All {}; class AllVehicles: All {}; class Air: AllVehicles {}; class Plane: Air {}; class A10: Plane {}; class DrF_A6E_ATG: A10 { class Animations { class Ltouterwing { type="rotation"; animPeriod=2; selection="lt outerwing"; axis="lt wing axis"; angle0=0; angle1=2.25; }; class Rtouterwing { type="rotation"; animPeriod=2; selection="rt outerwing"; axis="rt wing axis"; angle0=0; angle1=-2.25; }; class LtGear { type="rotation"; animPeriod=2; selection="lt gear"; axis="axis gear lt"; angle0=0; angle1=-1.6; }; class RtGear { type="rotation"; animPeriod=2; selection="rt gear"; axis="axis gear rt"; angle0=0; angle1=-1.6; }; class NoseGear { type="rotation"; animPeriod=2; selection="nose gear"; axis="axis gear nose"; angle0=0; angle1=-2.0; }; }; class EventHandlers { gear = "if (_this Select 1) then {(_this Select 0) Animate [""LtGear"", 0]; (_this Select 0) Animate [""RtGear"", 0]; (_this Select 0) Animate [""NoseGear"", 0]} else {(_this Select 0) Animate [""LtGear"", 1]; (_this Select 0) Animate [""RtGear"", 1]; (_this Select 0) Animate [""NoseGear"", 1]; (_this Select 0) animate [""Ltouterwing"", 0]; (_this Select 0) animate [""Rtouterwing"", 0]}"; }; class UserActions { class FoldWings { displayName = "Fold wings"; position = "mph"; radius = 20; condition = "(this AnimationPhase ""Ltouterwing"" < 0.5) and ((Speed this) < 60)"; statement="this animate [""Ltouterwing"", 1]; this animate [""Rtouterwing"", 1]"; }; class UnfoldWings { displayName = "Unfold wings"; position = "mph"; radius = 20; condition = "this AnimationPhase ""Ltouterwing"" >= 0.5"; statement="this animate [""Ltouterwing"", 0]; this animate [""Rtouterwing"", 0]"; }; }; <span id='postcolor'> Note this is all located in the cfgvehicle area of the CPP. Here's it in action; And the real thing; I hope that what I've found is of help to others. DragoFire Share this post Link to post Share on other sites
The Sharpshooter 0 Posted December 11, 2002 Great work DragoFire with your Addon, it´s getting really nice. Damn I love this new kind of animations and this EventHandlers, they should have been in OFP like 3 patches ago. TIER1:About the scripts for EventHandlers. I have a script that checks the Helicopter position and raises or lowers the gears if convenient. It´s practically the same script that did Colonel_Klink for his Animated Canopy: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">; ################################################# ; # syntax: [OBJECT] exec "Gear.sqs"; ; # ; # OBJECT: ; # Aircraft object ; # ; ################################################# ; **************** VARIABLES ****************** _Helo1 = _this select 0 ; **************** MAIN LOOP ****************** ; check speed and altitude of aircraft ; this will work for both player and AI controlled aircraft ; _z = _pos select 2 equates to getting the plane's altitude ; when at rest the canopy will always be open even when empty or when ai are in the plane ; mainloop tests the aircrafts altitude and speed #Mainloop _pos = GetPos _helo1; _z = _pos select 2; ?(speed _helo1>=25 or _z >=15):goto "raisegears" ?(speed _helo1<=25 and _z <=10 or _z <=10):goto "lowergears" goto "mainloop" #raisegears _helo1 animate ["maingear",1]; _helo1 animate ["rightgear",1]; _helo1 animate ["leftgear",1] goto "mainloop" #lowergears _helo1 animate ["maingear",0]; _helo1 animate ["rightgear",0]; _helo1 animate ["leftgear",0] goto "mainloop" ; **************** END OF MAIN LOOP ***************<span id='postcolor'> Can anyone help me improve it ? TIER3: Cool Tanelorn. I´m waiting for the game master to finish reading the Planescape books so we can begin our first adventure in the world of planescape. Now you have encouraged me to play a Githzerai A remeber this from Torment: In enduring grow strong! PD: MODs and Suma please don´t kill us for talking about Planescape Share this post Link to post Share on other sites
DragoFire 0 Posted December 11, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (The Sharpshooter @ Dec. 11 2002,13:36)</td></tr><tr><td id="QUOTE">Great work DragoFire with your Addon, it´s getting really nice. Damn I love this new kind of animations and this EventHandlers, they should have been in OFP like 3 patches ago. TIER1:About the scripts for EventHandlers.  I have a script that checks the Helicopter position and raises or lowers the gears if convenient. It´s practically the same script that did Colonel_Klink for his Animated Canopy: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">; ################################################# ; # syntax: [OBJECT] exec "Gear.sqs"; ; # ; # OBJECT: ; # Aircraft object ; # ; ################################################# ; **************** VARIABLES ****************** _Helo1 = _this select 0 ; **************** MAIN LOOP ****************** ; check speed and altitude of aircraft ; this will work for both player and AI controlled aircraft ; _z = _pos select 2 equates to getting the plane's altitude ; when at rest the canopy will always be open even when empty or when ai are in the plane ; mainloop tests the aircrafts altitude and speed #Mainloop _pos = GetPos _helo1; _z = _pos select 2; ?(speed _helo1>=25 or _z >=15):goto "raisegears" ?(speed _helo1<=25 and _z <=10 or _z <=10):goto "lowergears" goto "mainloop" #raisegears _helo1 animate ["maingear",1]; _helo1 animate ["rightgear",1]; _helo1 animate ["leftgear",1] goto "mainloop" #lowergears _helo1 animate ["maingear",0]; _helo1 animate ["rightgear",0]; _helo1 animate ["leftgear",0] goto "mainloop" ; **************** END OF MAIN LOOP ***************<span id='postcolor'> Can anyone help me improve it ? TIER3: Cool Tanelorn. I´m waiting for the game master to finish reading the Planescape books so we can begin our first adventure in the world of planescape. Now you have encouraged me to play a Githzerai A remeber this from Torment: In enduring grow strong! PD: MODs and Suma please don´t kill us for talking about Planescape <span id='postcolor'> Sharpshooter if you have a close look a my evenhandler you'll notice there's "NO" exec of any script listed anywhere, every things done within the "CPP" itself. If you get a chance have a look at the doc "Custom landing gear for planes" by Sefe at OFPEC, then with that and what I post just before you should be able to have your landing-gear controlled by the pilot and not the by the automatic way. If I can help just contact me. DragoFire Share this post Link to post Share on other sites
Tanelorn 0 Posted December 11, 2002 Good job DragoFire. I would add some scripts to the addon and use an init event handler to run them. In these scripts I would have the wings automatically fold when your altitude is 0 and speed is less than 10 kph. It saves trouble of people having to do it manually. However, manually is more realistic of course. Then again, you will have to take pains to make the AI fold their wings at the right time, so the automated method works well there. Oh Sharpshooter, if your DM will let you play a GithZerai, do it! You'll get 5% magic resistance every level after 3rd! My character got (due to an awesome random treasure roll by the DM ) a cloak of protection +5 in a 5th level adventure. With that and his magic resistance, he consistantly shrugged off all kinds of dangers while the rest of the party feared for their lives. On top of that, GZ are wanderers, so your outer planes lore will be quite extensive. They can also planewalk at will, which is an incredible ability (but is more dangerous than teleportation like Baatezu and Ti'nnari have). THe downside is that you must be chaotic, and I mean CHAOTIC! GithZerai value personal freedom over everything else, so they refuse to be bound by anything, even friendship. Share this post Link to post Share on other sites
The Sharpshooter 0 Posted December 11, 2002 TIER3:Tanelorn we will continue by PM otherwise the mods will close this topic. TIER1:DragoFire I now that you don´t use any external script for your actions, that´s because you use actions instead of "automating" the animation and you do that by checking the animation steps. But for my chopper I want it to lower and raise automatically at certain altitude and at certain speed, I don´t think this can be done in the cpp. So I need you to help me improve that script so it won´t burn much CPU power. The reasons because I want the Gears to be automated is: 1- When you are on the ground and you raise the gears, the model doesn´t fall like in planes, it stays there like the gears are down. 2- The action that you define always stays on top and it sometimes annoys the player, because it is something they are not accustomed to. This doesn´t happen with planes because by EventHandler you check the action "Gear up" and "Gear down" which doesn´t exist on Choppers. I think it´s pretty reasonable...if someone knows another method please tell me. Share this post Link to post Share on other sites
colonel_klink 0 Posted December 11, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">But for my chopper I want it to lower and raise automatically at certain altitude and at certain speed, I don´t think this can be done in the cpp. So I need you to help me improve that script so it won´t burn much CPU power. The reasons because I want the Gears to be automated is: 1- When you are on the ground and you raise the gears, the model doesn´t fall like in planes, it stays there like the gears are down. 2- The action that you define always stays on top and it sometimes annoys the player, because it is something they are not accustomed to. This doesn´t happen with planes because by EventHandler you check the action "Gear up" and "Gear down" which doesn´t exist on Choppers.<span id='postcolor'> Sharpshooter. From my understanding of game programming the main loop in that script should not use any more cpu than what OFP uses to check the position of the joystick during the game or to check if the 'E' key is depressed to move the player forward. However, because this is a continous check (and a loop within the main gaming loop) I could be wrong in this. I have been searching for other ways of utilising this, especially for AI controlled helicopters and other vehicles, but it seems the scripting method seems to be the only option. (At the moment) Share this post Link to post Share on other sites
suma 8 Posted December 11, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (The Sharpshooter @ Dec. 11 2002,03:36)</td></tr><tr><td id="QUOTE">Can anyone help me improve it ?<span id='postcolor'> I think I can. Insert single line ~0.001 somewhere in the loop body. This is an old advice, but it seems it is still not commonly know. Explanation will follow below the code. </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">; ################################################# ; # syntax: [OBJECT] exec "Gear.sqs"; ; # ; # OBJECT: ; # Aircraft object ; # ; ################################################# ; **************** VARIABLES ****************** _Helo1 = _this select 0 ; **************** MAIN LOOP ****************** ; check speed and altitude of aircraft ; this will work for both player and AI controlled aircraft ; _z = _pos select 2 equates to getting the plane's altitude ; when at rest the canopy will always be open even when empty or when ai are in the plane ; mainloop tests the aircrafts altitude and speed #Mainloop ~0.001 _pos = GetPos _helo1; _z = _pos select 2; ?(speed _helo1>=25 or _z >=15):goto "raisegears" ?(speed _helo1<=25 and _z <=10 or _z <=10):goto "lowergears" goto "mainloop" #raisegears _helo1 animate ["maingear",1]; _helo1 animate ["rightgear",1]; _helo1 animate ["leftgear",1] goto "mainloop" #lowergears _helo1 animate ["maingear",0]; _helo1 animate ["rightgear",0]; _helo1 animate ["leftgear",0] goto "mainloop" ; **************** END OF MAIN LOOP ***************<span id='postcolor'> Explanation: without the ~0.001 whenever the script interpreter executes the script, the main loop is repeated until max. allowed number of commands is executed (which is 100 command). With the ~0.001 added the behaviour is different. Once script interpreter executes this line, it stop this script and continues with other scripts and the game simulation itself. In the next simulation frame time is checked, and unless the time necessary for the frame is lower than 0.001 (which is always the case unless you are running with fps higher than 1000), it sees it is already time to continue execution of the script. Even if fps would be higher than 1000, no harm would be done, only script would not be execcuted for one or more frames. Share this post Link to post Share on other sites
suma 8 Posted December 11, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Tanelorn @ Dec. 11 2002,02:58)</td></tr><tr><td id="QUOTE">-- TIER 2: cleaning up the code Now that since 1.85 we can use {} to enclose strings, I am able to use this cleaner version of SUMA's code. Unfortunately I can't break it up further. class eventhandlers  {    init = "[_this select 0, {TA_VTOL_EMG}] exec {\ta_units\scripts\reload_freegun.sqs};[_this select 0, {TA_EMG_Gun}] exec {\ta_units\scripts\reload_freegun.sqs}";  };<span id='postcolor'> -- TIER 2: If you read command reference, you are probably aware this is not recommended practice. By enclosing string in {} brackets you give a hint to the interpreter the string is a code to be executed. This information is ignored by current script intepreter, but if you want to create your addon "portable" and compatible with our future products, I would stick to double quotes instead. Share this post Link to post Share on other sites
suma 8 Posted December 11, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (The Sharpshooter @ Dec. 11 2002,01:39)</td></tr><tr><td id="QUOTE">When I add an EventHandler to a unit(in the config.cpp) this means it will run the script the whole mission. Adding multiple units that have eventhandlers attached + all the scripting the mission will have and the units, ect. will make the mission heavyer, won´t it ? I mean much heavyer, or the EventHandlers don´t use much CPU ?<span id='postcolor'> It really depends on what event are you talking about. Properly implemented event handlers have nearly zero overhead, because they are executed only when even is detected. If you are talking about permanent script started from "init" event handler (or from any other handler), then yes, there will be exactly the same overhead with this script as with any other script. Be sure to use at least ~0.001 trick to if you need to use permanent scripts. Share this post Link to post Share on other sites
The Sharpshooter 0 Posted December 11, 2002 Thanks to all of you ! You have been very helpful! Suma from now on I will use the ~0.001. When I get to my computer I will try all this stuff and tell you what happened. Thanks. Share this post Link to post Share on other sites
The Sharpshooter 0 Posted December 11, 2002 Well I tested it, and it worked great. I don´t know if it uses less CPU, but as there were no crashes and the answer came form Suma I can only say that the script is better. I added another command to the script. This time it is for checking when the heli is going backwards at a speed greater than -25, when it is true it raises the gears. And I added another few improvements. Here is the final Script: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">; ################################################# ; # syntax: [OBJECT] exec "Gear.sqs"; ; # ; # OBJECT: ; # Aircraft object ; # ; ################################################# ; **************** VARIABLES ****************** _Helo1 = _this select 0 ; **************** MAIN LOOP ****************** ; check speed and altitude of aircraft ; this will work for both player and AI controlled aircraft ; _z = _pos select 2 equates to getting the plane's altitude ; when at rest the canopy will always be open even when empty or when ai are in the plane ; mainloop tests the aircrafts altitude and speed #Mainloop ~0.001 _pos = GetPos _helo1; _z = _pos select 2; ?(speed _helo1>=25 or speed _helo1<=-25 or _z >=5):goto "raisegears" ?(speed _helo1<=25 and _z <=10 or _z <=3):goto "lowergears" goto "mainloop" #raisegears _helo1 animate ["maingear",1]; _helo1 animate ["rightgear",1]; _helo1 animate ["leftgear",1] goto "mainloop" #lowergears _helo1 animate ["maingear",0]; _helo1 animate ["rightgear",0]; _helo1 animate ["leftgear",0] goto "mainloop" ; **************** END OF MAIN LOOP *************** <span id='postcolor'> If anyone can test it with another heli and give me feedback if anything went wrong, I would be grateful... Share this post Link to post Share on other sites