Author Topic: Easy-To-Code SEXP Request  (Read 4299 times)

0 Members and 1 Guest are viewing this topic.

Offline Dark RevenantX

  • 29
  • anonymity —> animosity
Easy-To-Code SEXP Request
I run on a Mac since my Windows' hard drive and CPU simultaneously died.  It's not that I don't like Macs, it's just that I can't use Freespace 2 from its measley 400mhz (let alone Fred).  I should get my replacement soon, but something bothers me.

I like making "different" styles of missions.  This includes absolutely stupid crap, and actual "good ideas".  I am determened to make a capship mission "work".  Sure, I can put in a Fenris and make it the player's ship, but how are you supposed to do anything worthwhile?  All you can do is move around, and point your beams to where they can fire at your target.  Well, I found a way, but I need a simple SEXP to make it work.  Forgive me if this is already made, it has been a long time since I have done SCP things.

I need two SEXPs, which are

1. A SEXP Function that takes the current targetted object of X ship.  This will allow me to do something like the following: You are in a Fenris and you want to fire your beam at the more damaged Cain to your right, not the Lilith in front of you.  Normally your beams would fire at the closest target both in distance from the turret and distance from the 0º line.  The beam on the Fenris would then target the Lilith.  Since you want to fire at the cain, but remain on your present angle, you would need a SEXP in the mission that tells the beams to fire at whatever is targetted after a specific key is pressed.  As of my experience, this is not possible.
An example would be where the player hits "B", and the beam starts firing at the selected object.  In the above case, the Fenris would start attacking the Cain instead of the Lilith.  This will be used for every significant weapon type (Weapons that are not lasers and not flak cannons).

2. A SEXP property radio-box that makes the SEXP perform its actions EACH AND EVERY TIME THE EVENTS ARE MET, rather than only once.  This helps the first requested SEXP, as you can target ships to your heart's content.  Even chaining 100 duplicate SEXPs together has its disadvantages.  1: it takes a f*ckload of time.  2: after the 100th target, you suddenly are screwed.  3: it will be useful for many missions, not just my crazy experiments.  This will allow me to lock/unlock beams, fire my AAA Beams at that bomber that's screwing my engines, or concentrate all firepower at the Corvette that is blowing away our object of protection.

These SEXPs should be easy to impliment in a FRED2 build, and will definitely help an otherwise retarded idea.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Easy-To-Code SEXP Request
Um. What's wrong with the targeted and every-time SEXPs? :confused: The first one has been there since retail.

Oh and while I'm here never refer to a job as easy unless you've looked at the code first. FS2 can make it very hard to do something you'd think really simple.

For instance a SEXP that makes a ship turn x degrees sounds simple but so far seems to be a ***** to code. Saying it's easy without having looked just pisses off the coders.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Easy-To-Code SEXP Request
I was just about to respond with a devastatingly sarcastic remark on the easiness of coding requested features, but karajorma interceded with a more diplomatic explanation.  Thanks, karajorma. :)

 

Offline Dark RevenantX

  • 29
  • anonymity —> animosity
Easy-To-Code SEXP Request
I have no reason look at the code... I'm on a Mac that can run Freespace for beans.
For some reason, every-time doesn't work with key-pressed for me.  I might try it when I get my new computer.
Also, it has been a long time since I was able to Fred; I had no memory of a get_targetted function, so I assumed that there wasn't any.

I also assumed that it would be easy to get the target of the current player.  It is simply accessing a variable (I think).


I apologise for my complete and utter lack of understanding, it has been... say... six months since I last Fredded.  I also get SEXP commands mixed up with WC3 triggers, as I used to love that game, and I remember many of the trigger actions even after my eight-month-without-any-World Edit mark.

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Easy-To-Code SEXP Request
Code: [Select]
if(Player_ai->target_objnum > 0)
{
     object *objp = Objects[Player_ai->target_objnum];
     if(objp->type == OBJ_SHIP)
     {
          return Ships[objp->instance].ship_name;
     }
}
return "<None>";


That gets the targetted ship's name (minus the framework to implement it as a SEXP) But if you target anything besides a ship (say, an asteroid) then you can't really do anything with SEXPs, because they don't have names. You could do it at the code level, that's about it.

There doesn't seem to be a SEXP that does it currently, although there is a "targeted" sexp that returns true or false depending on if a ship is targeted or not. (It should really be is-targetted...but oh well)

Edit: PRE TAGS.
-C

 

Offline Sesquipedalian

  • Atankharz'ythi
  • 211
Easy-To-Code SEXP Request
Quote
Originally posted by Dark RevenantX
For some reason, every-time doesn't work with key-pressed for me.  
Whenever you use key-pressed, you need to use key-reset afterwards if you want to check for another press of the key.

Like this:
Code: [Select]
everytime
     key-pressed
          T
     < do-something >
     key-reset
          T
Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

The Scroll of Atankharzim | FS2 syntax highlighting

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Easy-To-Code SEXP Request
Quote
Originally posted by Dark RevenantX
I have no reason look at the code... I'm on a Mac that can run Freespace for beans.


I know. I'm just saying that don't say something is easy unless you've looked at the code first (You probably shouldn't say it then either cause you'll simply be told that if it's so easy why don't you do it :D )

Quote
Originally posted by Dark RevenantX
Also, it has been a long time since I was able to Fred; I had no memory of a get_targetted function, so I assumed that there wasn't any.


The SEXP lives in the training SEXP area so many people miss it.

Quote
Originally posted by Dark RevenantX
I also assumed that it would be easy to get the target of the current player.  It is simply accessing a variable (I think).


You can do that now. Check below.


Quote
Originally posted by Dark RevenantX
I apologise for my complete and utter lack of understanding, it has been... say... six months since I last Fredded.  I also get SEXP commands mixed up with WC3 triggers, as I used to love that game, and I remember many of the trigger actions even after my eight-month-without-any-World Edit mark.


I forgot that you don't actually have access to FRED. That makes it a lot harder to check this sort of thing.

Quote
Originally posted by Sesquipedalian
Whenever you use key-pressed, you need to use key-reset afterwards if you want to check for another press of the key.

Like this:
Code: [Select]
everytime
     key-pressed
          T
     < do-something >
     key-reset
          T
[/B]


I suspect that won't work for what Dark RevenantX is up to because he's most likely made the mistake of using one of the 1-4 keys with every-time. Sadly key-reset is completely borked when it comes to almost anything to do with repeating events.

I've made a full write up of the problem here

Quote
Originally posted by WMCoolmon
Code: [Select]
if(Player_ai->target_objnum > 0)
{
     object *objp = Objects[Player_ai->target_objnum];
     if(objp->type == OBJ_SHIP)
     {
          return Ships[objp->instance].ship_name;
     }
}
return "<None>";


That gets the targetted ship's name (minus the framework to implement it as a SEXP) But if you target anything besides a ship (say, an asteroid) then you can't really do anything with SEXPs, because they don't have names. You could do it at the code level, that's about it.

There doesn't seem to be a SEXP that does it currently, although there is a "targeted" sexp that returns true or false depending on if a ship is targeted or not. (It should really be is-targetted...but oh well)

Edit: PRE TAGS. [/B]


Or you could just use

when-argument
-any-of
--Ship 1
--Ship 2
-targetted
--< Argument >

I'm not going to complain about a better version of tagetted though :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Dark RevenantX

  • 29
  • anonymity —> animosity
Easy-To-Code SEXP Request
I believe that won't work, Karajorama.

This is how I want things to work with the key-press:

Billy wants to kill the cruiser flying near him with his TerSlash beams.
Billy targets the cruiser.
Billy then pushes "1" to have the beams target only that cruiser.

When Player hits 1, the game takes the targetted ship of Player and has X turret fire at that ship.  I'm sorta stuck...  Oops, my mistake, I'm ICED IN!!!

The only thing I can request is the key-reset/every-time combo to be fixed in the next few months.
Will the next Fred build include this fix?  If not, oh well, as I have to wait a while before I can get a new Windows-capable computer.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Easy-To-Code SEXP Request
Yeah it will. It won't work with the 1 key because of those key-reset problems which are specific to keys 1-4 but if you choose another key that has no effect on a capship (The ETS keys are a candidate that spring to mind) then you can make it work.

You just have to get inventive with your SEXPs :D

Event 1 - Set fire at my enemy
every-time
--Key-pressed
---< Some Key >
Key-Reset
-< Some Key >
modify-variable
-SelectiveTargetting(0)
-1

Event 2 - Set fire at every bugger
every-time
--Key-pressed
---< Some Other Key >
Key-Reset
-< Some Other Key >
modify-variable
-SelectiveTargetting(0)
-0

Event 3 - Trigger pulled!
every-time
--Key-pressed
---< Key assigned to fire this turret >
Key-Reset
-< Key assigned to fire this turret  >
modify-variable
-Trigger pulled(0)
-1

Event 4 - This turret can fire!
every-time
-and
-- =
---1
---Trigger pulled(0)
-- =
---0
---mod
----mission-time
----< Delay between firings of the beam >
modify-variable
-Trigger pulled(0)
-0
modify-variable
-Fire Turret 1(0)
-1

Event 5 - This turret can't fire!
every-time
-and
-- =
---1
---Trigger pulled(0)
-- not
--- =
----0
----mod
-----mission-time
-----< Delay between firings of the beam >
modify-variable
-Trigger pulled(0)
-0

Event 6 - Fire at target!
every-time-argument
-any-of
--< List of capships present in the mission >
-and
-- =
--- 1
--- SelectiveTargetting(0)
-- =
--- 1
--- Fire Turret 1(0)
--targetted
---< argument >
Fire-beam
-- < Name of beam >
--
modify-variable
-Fire Turret 1(0)
-0


Event 7 - Fire at anyone!
every-time-argument
-random-of
--< List of capships present in the mission >
-and
-- =
--- 0
--- SelectiveTargetting(0)
-- =
--- 1
--- Fire Turret 1(0)
Fire-beam
-- < Name of beam >
--
modify-variable
-Fire Turret 1(0)
-0

Okay, those are the SEXPs. Now the explaination. :)

The first event is easy. It sets a variable which tells the mission whether you want to only fire at your target or at everyone. Event 2 simply resets this variable.

Event 3 is activated whenever you press the key to fire turret 1. It sets a variable telling the mission to check if turret 1 can be fired.

Event 4 checks to see if the turret can fire (This is to stop you pressing the fire key every second and continuously firing at the enemy ship). I've done this very crudely by simply assuming that the ship can fire at time=0 and then every x seconds thereafter (where x is the beam delay). You'd need to come up with a more complex system for doing this as this method only gives you a very narrow window during which the beam can be fired. (Setting a variable in event 6 stating when the beam was fired and then checking if enough time has passed in this event is the best way to go)
If you can fire it sets a variable telling the game to go ahead and fire the turret.

Event 5 simply cleans up if the turret can't fire yet.

Event 6 and 7 are where the beams finally fire. Event 6 fires at the selected target while event 7 chooses a target at random (Again done crudely. There are ways to make it choose a target that is actually in range of the turret but that's for you to sort out :D )


That's one way of handling it. If I was actually FREDding this I could probably simplify this after playing about with the idea a bit (using string variables might reduce the number of events needed. They did for another similarly convoluted mission I made).

To be honest I only wanted to prove that this sort of thing is 100% possible now not that it would be easy to do :D
« Last Edit: April 20, 2005, 05:18:32 pm by 340 »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Dark RevenantX

  • 29
  • anonymity —> animosity
Easy-To-Code SEXP Request
so key-reset does work with most keys? cool!
Kajorama, the trigger-pull thing is not exactly what I wanted, but I think I can code it a different way myself.   Thanks, though!

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Easy-To-Code SEXP Request
Basically I posted to give you ideas rather than do your work for you :) What you'd want requires some complex SEXPing and I would have to test it to get a solution I was happy with.

It just goes to show how versatile the new SEXPs are. :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Dark RevenantX

  • 29
  • anonymity —> animosity
Easy-To-Code SEXP Request
Ive done things much more complex in Wc3's World Editor.

-FOR BEAMS-
(fireable) is automatically set to 1 at the start.  The rest are 0.
Event 1 Will lock all of my ship's beams.
Event 2 (every time)Will detect when the key is pressed.  When it is so, (selective) is set to 1.  Also, the target of the player will be put in the string variable (targetship).
Event 3 (every time)Will detect (selective) being set to 1, and if (fireable) is set to 1, the beam will be fired at (targetship).  Immediatley, it sets (fireable) to 0.
Event 4 (every time)Will detect if (fireable) is at 0, and if so, will wait [beam delay] and turn (fireable) to 1 afterwards.
Event 5 (every time)Will detect when a different key is pressed.  When it is so, (selective) is set to 0.

-FOR TURRETS-
Event 1 (every time)Will detect when key X is pressed.  When it is, (selectivemk2) is set to 1, and the wanted turrets for the player are locked.  Also, the target of the player will be put in the string variable (targetshipmk2).
Event 2 (every time)Will detect if (selectivemk2) is at 1, and if so, and if (fireablemk2) is set to 1, the turrets will be fired at (targetshipmk2).  Immediatley, it sets (fireablemk2) to 0.
Event 3 (every time)Will detect if (fireablemk2) is at 0, and if so, will wait [turret delay] and turn (fireablemk2) to 1.
Event 4 (every time)Will detect when key Y is pressed.  When it is, (selectivemk2) is set to 0, and the wanted turrets for the player are unlocked.

HAH! did the beams in FOUR events!

Basically the only difference is that the turrets will fire even when the targetting is off, while the beams won't.  I have not used SEXPs for four months, and this is an accomplishment, seeing that I had to look at the SEXP's in my head.  I just may be the first person to make a FS2 capship mission be fun for many to play.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Easy-To-Code SEXP Request
Quote
Originally posted by Dark RevenantX
HAH! did the beams in FOUR events!


Well you probably did think about it longer than I did :D
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline StratComm

  • The POFressor
  • 212
  • Cameron Crazy
    • http://www.geocities.com/cek_83/index.html
Easy-To-Code SEXP Request
How are you resolving the CTD involved in trying to display more than a few subsystems?
who needs a signature? ;)
It's not much of an excuse for a website, but my stuff can be found here

"Holding the last thread on a page comes with an inherent danger, especially when you are edit-happy with your posts.  For you can easily continue editing in points without ever noticing that someone else could have refuted them." ~Me, on my posting behavior

Last edited by StratComm on 08-23-2027 at 08:34 PM

 

Offline Dark RevenantX

  • 29
  • anonymity —> animosity
Easy-To-Code SEXP Request
Some cmd lines in SCP screw the subsystem showing, but if you do it right, it should display like 15 correctly.

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Easy-To-Code SEXP Request
I haven't heard a definite answer as to whether or not it's been fixed; I remember I did something with it to try and correct that.

The code is definitely in my latest build if anyone wants to test it.
-C

 

Offline Dark RevenantX

  • 29
  • anonymity —> animosity
Easy-To-Code SEXP Request
Yes, your builds seemed to have fixed it when I was trying capship missions.
Obvously, I can't use support craft.  I will make it so when you push a key, all your weapons will stop firing for about 30 seconds.  After this period, you will gain 15% more health to all your non-weapon subsystems.  Another key will make you stop firing for 45 seconds, and afterwards will give you 30% more health to your weapon subsystems.  This is supposed to make your ship operational, not set to full capacity.  If your engines are killed or your beams are blown up, its going to sacrifice you at least 30 seconds, but not the whole mission.

The first mission will involve you as a Hipocrates.  The mission objectives are to survive to   the jump node and (as the only ship with an anti-cap beam) ensure the safety of the other ships in the case of attack.  You will be between a Zephyrus and a couple Argos at the start of the mission, with a wing of Myrmidons guarding each ship (the Argos count as one).  Alpha wing is assigned to you, and you have control over it and no others.  Soon your group will be attacked from the left, putting the Argos in danger.  The enemies include two wings of Hercules and a Fenris, all of which have just been sent into service.  The Argos will have an AI order to go above you and the Zephyrus to be on the right of the group, but the enemy should be able to destroy them before they get there, provided that you do not intervene.  If an argo is destroyed, command will tell you not to let the other die.  If both are killed, command will yell at you and relieve you of your command, and the mission will end.  If you succeed against the two Hercules wings, the Fenris will start firing its beams, so a kill of its turret before it decides to fire is a good idea.  If for some bizarre reason the Fenris is destroyed before the fighters are, the fighters will kamakaze against... you guessed it, YOU!  They don't do all that much damage, but they are going for your engines, so be careful with the fighters.  The second wave includes a battered leviathan which has 50% health and the subsystems are randomly damaged from 25% to 100%, and on top of all that, it lost its main beam cannon!  However, it has two more wings of Hercules coming your way.  Because they are coming from the front, you should have no problem attacking the Leviathan (which is turned to that it is facing you from the side).  The fighters, however, will be a problem.  Luckily, they are not interested in you... they are interested in the Zephyrus, and if you lose the Zephyrus, not only will you fail the mission if you already lost an Argo, you will also risk losing both you and the Argos to the large gas explosion.  When the Leviathan is knocked to 10%, it will self destruct, and the fighters will jump out.  By now, you should be almost to the Jump node, which is the good news.  The bad news is that a Medusa wing is coming from behind you!  If you didn't stop for repairs, you should be able to avoid a confrontation.  The next mission will either be another Hipocrates mission, or you will be promoted to the captain of the Fenris, GTC Vertigo.  The first mission is all about being in the right place at the right time, but all first missions are easy, arent they?
« Last Edit: April 21, 2005, 07:31:01 pm by 2397 »

 

Offline Trivial Psychic

  • 212
  • Snoop Junkie
Easy-To-Code SEXP Request
Too bad we can't code in class-specific support ships.  For example, you want your fighter escort to be able to call in standard support ships, but how often do you see transports being called in to repair cap-ships... quite often.  An Elysium would probably be ideal in size as a cap-ship support ship for anything between a Faustus and a Deimos, while anything larger would need an Argo.  Vasudan cap-ships could call in an Isis, but that's only about the same size as their figher support ship, so I'd reccomend a Satis for cruisers and corvettes, then revert to Argos for destroyers and larger.  You'd also only want the player to be able to call in one, or possibly 2 of them in a mission.  Come to think of it, it might be doable.

Have 3 or so transports labelled as reinforcements.  The player can call them in and order them to dock with a ship, but they only have the equipment, parts, and personnel to repair one ship each.  Lets say that some of the ships in your convoy are Vasudan, so perhaps one of the reinforcement transports is Vasudan, with a cargo of repair supplies.  Then have an event for each ship like this:

Vasudan Repair
-when-argument
--any-of
---Convoy Vasudan 1
---Convoy Vasudan 2
---Convoy Vasudan 3
--has-docked-delay
---Vasudan Repair 1
---< argument >
---1
---15
--transfer-cargo
---Vasudan Repair 1
---< argument >
--repair-subsystem
---< argument >
---engine
---100
{multiple repairs for various generic subsystems}

All the player has to do is target a dammaged convoy ship and order the repair ship to capture it.  Then have another event chained to the every-time one, that simply orders the repair ship to undock, followed by another chained event to warp out.  This ensures that it can't be used more than once.

The problem would be if the player wishes their cap-ship repaired, as there is no "dock-with-me" player order for anything other than a coded support ship.  The only thing I can think of would be an event like this:

Player Repair order
-every-time-argument
--any-of
---Terran repair 1
---Terran repair 2
---Terran repair 3
--and
---targetted
----< argument >
---is-cargo
----repair supplies
----< argument >
---key-pressed
----(what ever key you think works)
---add-goal
----< argument >
----ai-dock
-----Player's ship
-----repair ships dockpoint
-----player's dockpoint
-----89

Then, as long as the repair event (much like the earlier one) has the player's ship included in it, it should repair the player ship as needed.  I wish that the repairs could be done in 10% incriments though a chained repeating event, but arguments don't span between events.  It can probably be improved somewhat.  Unlike fighter rearming, once the repair ship is docked, the dockee can resume course at full speed.  Unfortunately, we'd also need a mission flag similar to that which disallows support ships, but one that disallows them for the player ONLY.  That way, escort fighters can repair and rearm as needed.

Later!
The Trivial Psychic Strikes Again!

  

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Easy-To-Code SEXP Request
Quote
Originally posted by Trivial Psychic
Player Repair order
-every-time-argument
--any-of
---Terran repair 1
---Terran repair 2
---Terran repair 3
--and
---targetted
----< argument >
---is-cargo
----repair supplies
----< argument >
---key-pressed
----(what ever key you think works)
---add-goal
----< argument >
----ai-dock
-----Player's ship
-----repair ships dockpoint
-----player's dockpoint
-----89

Then, as long as the repair event (much like the earlier one) has the player's ship included in it, it should repair the player ship as needed.  I wish that the repairs could be done in 10% incriments though a chained repeating event, but arguments don't span between events.  It can probably be improved somewhat.  Unlike fighter rearming, once the repair ship is docked, the dockee can resume course at full speed.  Unfortunately, we'd also need a mission flag similar to that which disallows support ships, but one that disallows them for the player ONLY.  That way, escort fighters can repair and rearm as needed.

Later!


That's some nice SEXPing TP :D Arguments can't be spanned between SEXPs but there's nothing to stop you from adding this to the bottom of that SEXP above  

modify-variable
Dock-Support-ShipTo(Dummy)
< argument >

You'd need to put in a ship called dummy miles away from the action because SEXPs can use a string variable to substitute for a ship only if the initial value is an existing ship.

Then you use

-not
--String-Equals
---Dock-Support-ShipTo(Dummy)
---Dummy

As part of the trigger for the SEXP that starts transferring hitpoints over to the ship in question like this.


repair-subsystem
-Dock-Support-ShipTo(Dummy)
--Hull

 What I'd probably do is have a variable  hitpointsRepairableByShipA(30) and slowly deincrement it every time the SEXP was triggered. When the pool of available healing was exhausted I'd set Dock-Support-ShipTo vack to dummy in another SEXP.

Do things this way and you could have the hitpoints go up by 1% every 5 seconds etc :)
« Last Edit: April 22, 2005, 02:25:09 am by 340 »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Trivial Psychic

  • 212
  • Snoop Junkie
Easy-To-Code SEXP Request
Stupid sexp question, what the hell is a "string" used for anyway?
The Trivial Psychic Strikes Again!