Fractal Softworks Forum

Please login or register.

Login with username, password and session length

Author Topic: Shield Type Conversion  (Read 5187 times)

Psiyon

  • Admiral
  • *****
  • Posts: 772
  • Trippy
    • View Profile
Shield Type Conversion
« on: May 05, 2012, 06:17:06 PM »

I've got a feeling I've hit a dead end here, but I'll ask anyway just in case.

I'm trying to make a hullmod that gives a ship shields. As in, it checks to see if they don't have shields, and if it doesn't, it gives them front-facing shields.

It's just a really quick edit of the Omni Shield Emitter script, but here's the code:

Code
	public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
ShieldAPI shield = ship.getShield();
if (shield == null) {
shield.setType(ShieldType.FRONT);
}
}

This returns a fatal: null error whenever you apply the hullmod to the ship ingame.

(Note: all ships with no shields have non-zero dummy values for shield-related things in ship_data.csv.)

So, is there any way to get around this crash, or am I out of luck?

Logged

WKOB

  • Admiral
  • *****
  • Posts: 732
  • Odobenidine Benefactor
    • View Profile
Re: Shield Type Conversion
« Reply #1 on: May 05, 2012, 06:40:30 PM »

Well you could give the ships in question shields but with an arc of 0, then give it the extended shields hull mod.
Logged

Psiyon

  • Admiral
  • *****
  • Posts: 772
  • Trippy
    • View Profile
Re: Shield Type Conversion
« Reply #2 on: May 05, 2012, 06:50:40 PM »

I considered that, but unfortunately right clicking still makes the "raise shields" sounds. I'd also be willing to bet that the AI will become rather annoying by raising and lowering nonexistent shields if that were the case.
Logged

StahnAileron

  • Commander
  • ***
  • Posts: 195
    • View Profile
Re: Shield Type Conversion
« Reply #3 on: May 05, 2012, 09:05:44 PM »

I'm not a modder by any means, but from my internal logic, wouldn't you still need to at least define the base shield arc for the hullmod rather than just giving it a shield? Does the game even have a basic default shield value? All the other shield hullmods use the already existing shield statistics for the given ship.

Would it be easier to just use the Extended Shield hullmod as a basis instead of the Omni-shield hullmod? (Or maybe combine the two to get a basis for the effect you want?)

I do apologize if I make no sense. As I said, I'm no modder. These are just my thoughts considering what little I know of the game and how programming seems to be at times.

EDIT: Geh, nevermind. The "dummy value" statement you made just clicked for me...
« Last Edit: May 05, 2012, 09:07:22 PM by StahnAileron »
Logged

medikohl

  • Admiral
  • *****
  • Posts: 854
    • View Profile
Re: Shield Type Conversion
« Reply #4 on: May 05, 2012, 09:56:05 PM »

Have you tried directing strings of vulgar epithets at it? If so, I'm out of ideas.
Logged
"Captain! You can't call our greatest dreadnought 'The Parrot'"
"Watch me"
Spiral Arms: Ship Sprites for Everyone

Apophis

  • Captain
  • ****
  • Posts: 466
    • View Profile
Re: Shield Type Conversion
« Reply #5 on: May 06, 2012, 08:40:54 AM »

if (shield == null) {shield.setType(ShieldType.FRONT);}
this will always crash, you are using a null pointer (shield)
Logged

Apophis

  • Captain
  • ****
  • Posts: 466
    • View Profile
Re: Shield Type Conversion
« Reply #6 on: May 06, 2012, 08:44:00 AM »

in the API the function that add shields is commented
//void setShield(ShieldType type, float arc);
Logged

Psiyon

  • Admiral
  • *****
  • Posts: 772
  • Trippy
    • View Profile
Re: Shield Type Conversion
« Reply #7 on: May 06, 2012, 08:52:10 AM »

if (shield == null) {shield.setType(ShieldType.FRONT);}
this will always crash, you are using a null pointer (shield)
You sure? This is just a quick edit from the Omni Shield Converter script, which is this by default:

Code
	public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
ShieldAPI shield = ship.getShield();
if (shield != null) {
shield.setType(ShieldType.OMNI);
}
}

I figured that if shield variable equaled null, than that would represent a shieldtype of 'NONE,' since that appears to be the way it's handled above.

As I said before, programming is really not my strong point.

in the API the function that add shields is commented
//void setShield(ShieldType type, float arc);
I noticed that, but I figured it was kind of irrelevant because, in theory, I'd simply be shifting the shield type from 'NONE' to 'FRONT.' It doesn't need an arc or anything else defined because I put values in ship_data.csv for all of that. I guess that one of the only explanations here is that the shield type 'NONE' is handled a bit differently than the other two.
Logged

Apophis

  • Captain
  • ****
  • Posts: 466
    • View Profile
Re: Shield Type Conversion
« Reply #8 on: May 06, 2012, 09:08:33 AM »

if (shield == null) {shield.setType(ShieldType.FRONT);}
this will always crash, you are using a null pointer (shield)
You sure? This is just a quick edit from the Omni Shield Converter script, which is this by default:

Code
	public void applyEffectsAfterShipCreation(ShipAPI ship, String id) {
ShieldAPI shield = ship.getShield();
if (shield != null) {
shield.setType(ShieldType.OMNI);
}
}

ship.getShield() return a pointer to a ShieldAPI class if the type is front or omni, else it returns a null pointer
Logged

Vandala

  • Admiral
  • *****
  • Posts: 1841
  • We need ponies, ponies in spaceships!
    • View Profile
Re: Shield Type Conversion
« Reply #9 on: May 06, 2012, 09:37:42 AM »

Maybe a silly question but do you really need the if statement?

Can't you just tell the shield to become what you want it to become without checking what it is first?

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 24113
    • View Profile
Re: Shield Type Conversion
« Reply #10 on: May 06, 2012, 10:03:23 AM »

Hullmods can't do this right now. It's something I want to add - and tried at one point, but it's tricky and requires some augmentations to the modding API, to make sure it interacts correctly with other shield-affecting mods. I will take another look at it down the line, though.
Logged

Psiyon

  • Admiral
  • *****
  • Posts: 772
  • Trippy
    • View Profile
Re: Shield Type Conversion
« Reply #11 on: May 06, 2012, 10:07:12 AM »

Hullmods can't do this right now. It's something I want to add - and tried at one point, but it's tricky and requires some augmentations to the modding API, to make sure it interacts correctly with other shield-affecting mods. I will take another look at it down the line, though.
I see. Oh well, thanks for the reply.

Maybe a silly question but do you really need the if statement?

Can't you just tell the shield to become what you want it to become without checking what it is first?
Just tried removing the if statement, still crashes. Probably should have done that earlier. Derp.
Logged

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Shield Type Conversion
« Reply #12 on: May 06, 2012, 11:23:09 AM »

Really cool feature would be adding a texture on the shield, so it acts like a texture on the shield, for example, the shield has a texture that looks like hexagonal fit together, something you see on Freelancer shields when they get hit. Same way you got the turret firing effects
Logged