Ship Systems Information

More
19 years 1 month ago #12724 by Joco
Replied by Joco on topic Ship Systems Information
Deathscript interception: how to do it?

This is my current little ponder. It would seem to be a good capability to have. Especially if you want to have a global new facility like a salvagable debri from killed ships.

So, anyone done this before?

My current idea is to periodically check all ship sims within a certain range of the player (or within the current system?) and trap in an array like structure the sims handle and the original deathscript string reference and replace said property on the sim with the new handler.

Now this assumes you can start a task from just a string refernce from within POG.

Interested in peoples thoughts.

Cheers,
Joco.

Please Log in or Create an account to join the conversation.

More
19 years 1 month ago #12725 by MajorTom
Replied by MajorTom on topic Ship Systems Information
You can set the deathscript when you create the sim:
For Example:
Code:
hship mini_gunstar; hsim new_gunstar; new_gunstar = iSim.Cast( Sim.Create( "ini:/sims/multiplayer/mini_gunstar_wr","Gunstar 8ty8") ); mini_gunstar= iShip.Cast( new_gunstar ); iSim.SetStandardSensorVisibility ( mini_gunstar, true ); iSim.SetIndestructable( mini_gunstar, false ); Object.SetStringProperty( mini_gunstar, "death_script", "iteamfortress_wr.ObjectDeath" );

Since it is just an object property you should be able to grab it
and change it (afaik) at any other time:

The ObjectDeath funktion as an example:
Code:
task ObjectDeath( hsim sim ) { hship last_attacker; string message, object_name; htask delay; int frag_value; int dropit; hfaction aggressor_faction, object_faction; hship player=iShip.FindPlayerShip(); hsim bomb; atomic { object_faction = iSim.Faction( iSim.Cast(sim) ); last_attacker = iShip.Cast( iSim.LastAttacker(iSim.Cast(sim)) ); aggressor_faction = iSim.Faction( last_attacker ); object_name= Object.StringProperty( sim, "name" ); // update the score of out attacker ( increment by frag_value ) if ( iSim.Type(sim) == T_CargoPod ) { dropit = Math.RandomInt(1, 5); if ( aggressor_faction != object_faction ) { roMPUtils.increment_frags ( last_attacker, roMPUtils.get_frag_value(sim) ); } else roMPUtils.decrement_frags ( last_attacker, roMPUtils.get_frag_value(sim) ); if (dropit <= 3 ) roMPUtils.SpawnKilledPodPowerUps (sim); else { message = iMPUtils.MakeDeathMessage( last_attacker, sim ); //delay = start roMPUtils.delay_broadcast_message( sim, message, BMT_Event, 2.0 ); bomb = Sim.Create ( "ini:/sims/8km_am_explosion_wr", "big Big" ); Sim.PlaceAt ( bomb, sim ); start iDeathScript.Explosives( iSim.Cast(sim) ); Sim.Destroy( iSim.Cast(sim) ); //Task.Detach( delay ); return; } } if ( object_name == "Gunstar 8ty8" ) { if (object_faction == iFaction.Find(Text.Field("mp_flag_team_b", FT_Text))) ServerOnUserMessage( 154, last_attacker, none, " Beta Gunstar destroyed" ); else ServerOnUserMessage( 156, last_attacker, none, "Alpha Gunstar destroyed" ); bomb = Sim.Create ( "ini:/sims/1_5km_am_explosion_wr", "Lil Bigi" ); Sim.PlaceAt ( bomb, sim ); start iDeathScript.Explosives( iSim.Cast(sim) ); Sim.Destroy( iSim.Cast(sim) ); //Task.Detach( delay ); return; } start iDeathScript.Explosives( iSim.Cast(sim) ); Sim.Destroy( iSim.Cast(sim) ); Task.Detach( delay ); } }

So you see, you can do "anything" once you are in the death script.
like for example create an antimatter explosion, replace the sim
ith another and silently remove it, or even start other tasks.

Something I discovered: If you do want the dead sim to be removed
from the Hud Contact list the moment it dies you need to call the
function:
"start iDeathScript.Explosives( iSim.Cast(sim) );"
before you Sim.Destroy it.
Otherwise, the Sim will explode and visually disappear but the
contact will remain in the contact list for several seconds.
Edit:
That means the Target assist won't switch automatically to
the next nearest target and you'll keep firing at the dead sim
for a while until the game culls the dead sim)
/ Edit




Iwar2 Multiplayer Fan Site

Please Log in or Create an account to join the conversation.

More
19 years 1 month ago #12726 by Joco
Replied by Joco on topic Ship Systems Information
Yeah - just as I figured.

From what I am seeing I don't think Flux has all the facilities I need to truely insert a hook in front a pre-setup death script attribute. The inability to call functions by reference and with params is a sod. I can't see how you can do a pass-through capability without it.

However, doing a debri package with appropriate supporting functions for could still be an interesting little project.

Please Log in or Create an account to join the conversation.

More
19 years 1 month ago #12727 by MajorTom
Replied by MajorTom on topic Ship Systems Information
Yes, afaik you can only call a (self written) script function and flux automatically (only) passes the hsim handle for the object.

You could however add a custom string object property to the ship (with any additional params you might need) that you then read in your death script function. Alternativly add other (int, float, ect.) custom object properties that the deathscript function can perhaps use directly.

yes, that might be a fun project, you could for example create some debris sims in your death script function by reading url's of ship specific chunks of debris from the ships ini file (or a special ini file you might make for that purpose).

Iwar2 Multiplayer Fan Site

Please Log in or Create an account to join the conversation.

More
19 years 1 month ago #12730 by Joco
Replied by Joco on topic Ship Systems Information

Originally posted by MajorTom

Yes, afaik you can only call a (self written) script function and flux automatically (only) passes the hsim handle for the object.


Just to clarify - you are refering to the deathscript call here - yes?
Or does Task.Start(string func_name); also operate like that?

Please Log in or Create an account to join the conversation.

More
19 years 1 month ago #12782 by MajorTom
Replied by MajorTom on topic Ship Systems Information

Originally posted by Joco

Originally posted by MajorTom

Yes, afaik you can only call a (self written) script function
and flux automatically (only) passes the hsim handle for the object.


Just to clarify - you are refering to the deathscript call here - yes?
Or does Task.Start(string func_name); also operate like that?


Sorry, I was traveling the past week and couldn't respond earlier.

No, not the "deathscript call" but yes, I was refering to the death
script functionality: the death script is called by
flux on the event of a sim death and it passes the hsim handle to
the death script task defined in the object property of the sim.
If you don't set a custom script the default is used. The deathscript is therefore very versatile, but as the name says it
is only triggered when a sim dies.

Btw, you can change it dynamically at any time and assign your own
custom death script by calling:
Object.SetStringProperty(theSim, "death_script", "mypackage.myfunction");
(for example if you wanted to change the death script for sims that
were pre-created by other (iTraffic) scripts.

The Task.Start call doesn't allow an argument and returns no value so it is different from the death script function.

You could achieve what (I think) you are looking for with a work
around that is much like the death script function: You can attach custom string properties to any sim with for example:
Object.AddStringProperty (mysim, "package_name" ,"mypackage.myfunction");

You can then (dependent on whatever circumstances) poll for the existence of the property "package_name" and use the value of that property to trigger your function with a Task.Start call. i.e:

Task.Start ((Object.StringProperty( mysim, "package_name"));

The only difference between that and the death script property is
that you would have to provide your own event based polling task.
(I assume flux just polls the game for dead sims and passes them
to the death script in much the same manner)

Obviously, if you only had a few different functions you wanted to
trigger, you could make life easier and simply attach a custom Int
property to your sims. Then, on the polling event, you could pass arguments to a switch function and set up each "case" as a seperate
function (script) in itself. Using the object.IntProperty of the
sim to differentiate between the scripts defined in each "case".

You can even use the Object.Property package to set up a whole matrix
of parameters and values if you wish.


Iwar2 Multiplayer Fan Site

Please Log in or Create an account to join the conversation.