SSG Plazmoid 0 Posted January 2, 2003 Thought it would be cool to see smoke and fire tralling from damaged aircraft. Like most of what goes on in multiplayer it's not as simple as you first think. As each client needs to draw the smoke each client needs to know what the vehicle object name is, that objects position, etc. Also, vehicle respawn is handled server side only to avoid multiple respawns so how would clients run a script called only by server? So, using Tact's suggestion to my other question of how to do things with respawned vehicles I've gotten smoke working. Need to test it on a dedicated server but I think I've done the scripts in a way that they'll work on dedicated server correctly. First, we need to know all of the vehicles that we'll want smoke added to. For each one you'll need a global variable that is associated with that vehicle in some way Let's say you add 3 choppers to your map - your variable names need to be different than the object names to keep things from getting confusing. on your map you have these named units: chopper1 - in init: [this,"chopper1"] exec "vrs.sqs" chopper2 chopper3 in init.sqs you could have: mychop1 = chopper1 mychop2 = chopper2 mychop3 = chopper3 in vehicle respawn vrs.sqs in addition to reading in the object you need to also read in the other paremter we passed which was a text name of the object name. after the vehicle has been created a call is made to "smoke_master.sqs": </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">[_vcl,_vehicle] exec "smoke_master.sqs"<span id='postcolor'> where _vcl is the vehicle object that was just respawned using _vcl = _type createvehicle [_respawn_xpos,_respawn_ypos,0] and _vehicle is the text name of the original object name. in smoke_master.sqs we need to reassociate the object name back with the text name: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl = _this select 0 _vehicle = _this select 1 ?(_vehicle == "chopper1"): mychop1 = _vcl ?(_vehicle == "chopper2"): mychop2 = _vcl ?(_vehicle == "chopper3"): mychop3 = _vcl<span id='postcolor'> and now we can track that respawned vehicle by using one of our known object names (mychop1, mychop2, mychop3, etc) regardless of being respawned because each time it is respawned the new _vcl object is reassociated with our known object names. Anyhow next trick is for all the clients to watch for some different things like damage. Each client needs a script so we call "smoke_client.sqs" from init (with no parameters). In smoke_client.sqs we have a loop that looks for values to be true or false for each vehicle and if conditions are met to do something. For smoking damaged vehicles each vehicle needs to meet the following conditions: vehicle is damaged more than some amount you specify (I used .5) vehicle is in the air (for aircraft) vehicle is not going backwards (for choppers) to keep smoke out of pilots view smoke isn't already turned on for this vehicle otherwise we would keep launching smoke scripts. </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">#start ~1 ?(getdammage mychop1 >= .5)&&(getpos mychop1 select 2 > 10)&&!(mychop1_smoke):[mychop1] exec "smoke_damage.sqs"<span id='postcolor'> once "smoke_damage.sqs" is called we have to set the smoke variable to true for the appropriate vehicle (to keep smoke_client from launching more smoke scripts). Now we get to the actual drop stuff. For each vehicle type you'll want the smoke to be in a different position depending on the effect you are going for. I wanted it to look like it's coming from the engines so on the biplane the engine is forward of center, on a chopper it's rear and above center, etc. Also on the A10 and SU25 there are two engines so I did dual trails of smoke. next in same file we define the starting and ending color of the smoke or fire. then we loop very quickly drawing the smoke and fire over and over. In the loop we watch for some conditions to be true like if the vehicle has been destroyed or the altitude is below 1 (it landed) or in the case of choppers the speed is equal or less than zero. In any of those cases the script exits after returning the vehicle smoke variable to false so it can work again when conditions are met in smoke_client. Finally it's just a matter of playing with the drop command, your colors, and the offsets to get the look you want. For the fire I wanted little puffs of fire every now and then but not continuously. So in the loop I have a random variable and if it's above a certain value the fire gets drawn in addition to the smoke. For the dual engine aircraft I used a 2nd random variable to randomly select which engine the fire puff came from. It's hard to explain clearly how this all works but hopefully have given a good idea for you. I'll add another message soon with all the source code(s). Plaz Share this post Link to post Share on other sites
bn880 5 Posted January 2, 2003 Heh, smoking damaged vehicles you say? http://members.rogers.com/bn880/captures_TWMN.html IT is extremely simple in multiplayer games... all machines simply have to execute the smoke script (server can skip). One reason for me not promoting such scripts was the fact that all the smoke impacts game performance way too much. Anyway, your moke looks great. Share this post Link to post Share on other sites
SSG Plazmoid 0 Posted January 2, 2003 thanks By not simple I meant that all clients have to execute the script and since I'm calling the smoke script from the server only vehicle respawn script it complicated matters. I'm doing it this way so I get the vehicle object after it's been respawned. If I didn't worry about respawn it would be very simple. Am I making it more complicated than it needs to be? for the performance impact I'm trying to keep the load down as much as possible. There aren't too many aircraft on my maps and they'll smoke only under certain conditions. Also tried to make the delay when looping a little bigger than I normally would in single player so there's less loops. Finally the smoke doesn't hang around too long - 15 seconds. I'll fiddle around with these values if performance is impacted. Also was considering adding a way for a player to turn off smoking vehicles so they don't have to see it if it's a problem. thanks for response (woohoo someone responded to one of my posts). your smoke trail pic looked very cool. Share this post Link to post Share on other sites
bn880 5 Posted January 2, 2003 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (SSG Plazmoid @ Jan. 02 2003,18:25)</td></tr><tr><td id="QUOTE">Am I making it more complicated than it needs to be?<span id='postcolor'> Nah, with respawning there is some extra work to do no matter how you cut it. EDIT: It depends on how the vehicles are respawned... Share this post Link to post Share on other sites
Balschoiw 0 Posted January 2, 2003 you may also have a look on these things: the script packs are done by: Download the packs here: pack1: http://mitglied.lycos.de/gaaelcirlyon/Files/AIR-Sektion-1.zip pack2: http://mitglied.lycos.de/gaaelcirlyon/Files/AIR-Sektion-2.zip pack3: http://mitglied.lycos.de/gaaelcirlyon/Files/AIR-Sektion-3.zip Share this post Link to post Share on other sites
RED 0 Posted January 3, 2003 Nice scripts, it is shame they had to be hosted on tripod though. RED Share this post Link to post Share on other sites
SSG Plazmoid 0 Posted January 10, 2003 Here's the scripts and a demo mission. In the demo just hit radio charlie (0 0 3) which will put some damaged planes in the air flown by AI so you can see the smoke trails and fire. http://www.soldbuysam.com/ofp/drop/smoke_stuff.zip I've added a few things since my first post. Damaged aircraft lose fuel continuously until they run out. You can set the amount of time it takes for fuel to go to zero, I think I used 60 seconds. dual engine aircraft like the A10 and SU25 make dual smoke trails. There are two sets of smoke scripts. One set for destroyed vehicles that makes a fire and smoke where the vehicle was destroyed. Another set that attaches smoke to flying aircraft. The destroyed scripts all start with "destroyed_" and the smoking aircraft scripts start with "smoke_". The main difference between them is the smoking aircraft script gets a vehicle object passed to it and the destroyed vehicle script gets a 2 dimensional position passed to it. The other difference is the destroyed smoke/fire lasts for an amount of time you specify while the aircraft smoke lasts as long as the aircraft is flying or alive. *note: I use x and y for horizontal and z for vetical. For the destroyed smoke/fire I make use of the elapsed time to gradually phase out the smoke and fire rather than seeing a visible line flow up when the smoke stops. As time progresses the fire gets smaller and smaller with the particles lasting a shorter amount of time and the transparency going toward zero. Added a cpubenchmark check in the "smoke_client.sqs" and "destroyed_client.sqs" files. This will force the client script to exit if the cpubenchmark is below some number (I think I used 1500). IF YOU DON'T SEE SMOKE CHECK YOUR CPUBENCHMARK and change the value in those two scripts to something lower than your benchmark. Please let me know what benchmarks can handle the smoke scripts - would be handy to know. Mine is 3800. You may be wondering why is there a server script and client script and actual smoke script? The trouble is how to pass the ID of a respawned vehicle to all the clients since you don't know beforehand what the object ID will be. The trick I made use of is to have the server start a server side script whenever a vehicle is respawned. The server script then waits for @(getdammage _vcl > .5) in the case of the smoking aircraft. The server script for destroyed vehicles waits for @(!alive). If the destroyed condition is true the server script does the following: mydestroyed = mydestroyed + [_vcl]; publicvariable mydestroyed. If the damaged condition is true the server similary does the following: mydamaged = mydamaged + [getpos _vcl select 0, getpos _vcl select 1] and makes the variable public. Meanwhile there's the destroyed and damaged client scripts that are waiting for the count on mydamaged or mydestroyed to be > 0. Once the count is 1 or more the appropriate script springs into action and creates smoke/fire. If anyone has a suggestion how I can improve anything or speed anything up please let me know! Also included in the zip I think is an arty.sqs script which has some experimental formulas for artillery given start and end coordinates. regards, Plaz Share this post Link to post Share on other sites
Doolittle 0 Posted January 10, 2003 Heh, that's neat how you make a tank fire the shell for the artillery. Doolittle Share this post Link to post Share on other sites
Doolittle 0 Posted January 10, 2003 Plaz check this out: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> Â Â MP notes: "Killed" and "Hit" event handlers are executed where given unit is local. All other event handlers are executed on all computers. Events added by addEventHandler may be different on each computer. <span id='postcolor'> So in theory the Server could handle all the vehicle respawning, but when it does, add event handlers in there. Â Then when the plane is damaged to some degree, all clients are sent this information. Â I worry about having to remove events when vehicles are removed. Â Is this necessary? Â If I delete an object, do I need to worry about event handler cleanup for that object? Â (I've asked this before but got no reply.) Doolittle Share this post Link to post Share on other sites
suma 8 Posted January 10, 2003 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Doolittle @ Jan. 10 2003,21:46)</td></tr><tr><td id="QUOTE">If I delete an object, do I need to worry about event handler cleanup for that object?<span id='postcolor'> No, you do not have to. The handlers exist directly "on" the object (as its member variables) and when the object is destroyed, they are destroyed as well. Share this post Link to post Share on other sites
Doolittle 0 Posted January 10, 2003 Excellent! Very nice programming Suma..but that goes without saying. Share this post Link to post Share on other sites
Koolkid101 0 Posted January 10, 2003 If i download this so it shows smoke will it mess up my multiplayer? Share this post Link to post Share on other sites
Doolittle 0 Posted January 11, 2003 Suma, if you don't need to remove event handlers then why do you have this script code in the cool Camel addon: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">? side player == east : vehicle player addEventHandler ["killed",{PlaneWD=true; publicVariable "PlaneWD"; DeadPlanesLocal = DeadPlanesLocal + [(_this select 0)]; DeletePlane = true; (_this select 0) removeAllEventHandlers "killed"}] ? side player == west : vehicle player addEventHandler ["killed",{PlaneED=true; publicVariable "PlaneED"; DeadPlanesLocal = DeadPlanesLocal + [(_this select 0)]; DeletePlane = true; (_this select 0) removeAllEventHandlers "killed"}] <span id='postcolor'> </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> this addEventHandler ["GetIn",{_this exec "WrongPlaneEast.sqs"; (_this select 0) removeAllEventHandlers "GetIn"}]<span id='postcolor'> ..where you remove the handler once it is run? Doolittle (By the way, WrongPlaneEast.sqs script doesn't exist. They had that running on the extra plane in the hangar.) Share this post Link to post Share on other sites
SSG Plazmoid 0 Posted January 11, 2003 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Koolkid101 @ Jan. 10 2003,23:19)</td></tr><tr><td id="QUOTE">If i download this so it shows smoke will it mess up my multiplayer?<span id='postcolor'> Are you asking if you download this smoke will it add something that messes up multiplayer? The answer is no. This isn't an addon just a little more complex use of the drop command that BIS built into the OFP engine. So everything that is needed to see the smoke and fire is already in your game - no addon needed. I just have used the built in commands to help clients see the smoke in multiplayer games. Map editors would need to add these scripts to their maps though. You won't see fire/smoke in other maps unless the author has put in these type of scripts. Doolittle - the hit and killed events will register on the local machine only but all other events will be executed on all of the clients? I think I read it that way. So looking at my handy list of eventhandlers dammaged looks to be the only one that might help in this context. The dammaged eventhandler passes "how much". I wonder if this is the amount of dammage that just happened or the amount of dammage that the object currently has? Aha, I see though. Regardless of the amount of damage (total or just the last little bit) this event would trigger a script to run on all clients? And in that script I could then getdammage _vcl to wake up the smoke/fire/fuel scripts. I notice though that dammaged gets 2 parameters, string: selectionName and scalar: howmuch. What is selectionName? Also did a search and saw Keg's post where he got dammaged to trigger when he shot soldiers legs out. So perhaps dammaged is related to !canmove? Will test. thanks, Plaz Share this post Link to post Share on other sites
Doolittle 0 Posted January 11, 2003 Plaz if you ever wonder what is being passed on an event (like "dammaged") just stick a player sideChat format ["%1", _this] in the beginning of the script. selectionName is where on the body it was hit. Â It's not in english though...you'll see. What's wrong with using "killed"? Â If an object isn't local on a client, why worry about drawing smoke for it? Doolittle Share this post Link to post Share on other sites
Koolkid101 0 Posted January 11, 2003 can i have some smoke? Share this post Link to post Share on other sites
SSG Plazmoid 0 Posted January 12, 2003 the killed event will work for dead stuff where I want the custom fire and smoke to burn for a fixed time. the idea for smoking aircraft though is to begin showing the smoke only after the aircraft is damaged to a certain extent. However it happens I just need to get the new object ID of a respawned vehicle out to the clients before or after damage reaches some threshhold. Share this post Link to post Share on other sites
SSG Plazmoid 0 Posted January 16, 2003 After a little more detailed testing I've discovered that my method of passing vehicle ID to the clients still isn't enough to wake the clients up. Using createvehicle I created 5 A10s. Using createunit I created 5 soldiers and assigned each soldier to an A10. Then I put the planes up in the air and gave them forward velocity. When I tested it locally it worked perfectly. When I tested on a dedicated server connecting as a remote client none of the AI moved into the planes and smoke wasn't visible from any of the planes. This is because I had used ?!(local server):exit in my vehicle creation script so that I didn't get a copy of an A10 per client executing the script. When I took out the local server check I got an extra set of planes. The extra set controlled and spawned by my client had smoke while the server created planes did not. So..... method #1 seems to be a failure. I will try to do vehicle respawn via the setdammage 0 method and avoid the whole business of passing newly created vehicles to the clients. Or, I might try vehiclerespawn via triggers that use createvehicle but this would require a trigger per vehicle. If anyone can get a client side script to operate using a server side created vehicle please let me know how you got it to work. Share this post Link to post Share on other sites
bn880 5 Posted January 16, 2003 Use the init field of the created AI. This is what I did in the newest version of EnemyStack. check CoC Tech downloads I don't have time anymore to explain it in detail, I think you should be able to figure it out. Share this post Link to post Share on other sites