Jump to content

Script help.


Will58448

Recommended Posts

I'm trying to complie a script and getting error: no viable alternative at input 'if'

Still trying to learn about scripting and not sure what this means. Script is as follows:

 

Scriptname FoodPoisoningScript extends ActiveMagicEffect

 

SPELL Property FoodPoisoningSpell Auto

Actor Property PlayerRef Auto

 

Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) native

if akBaseObject.HasKeyword(FoodPoisoning)

PlayerRef.AddSpell(FoodPoisoningSpell, false)

endif

EndEvent

 

 

Link to comment
Share on other sites

I've made those changes, but it's still failing to complie with the same error message.

 

Scriptname FoodPoisoningScript extends ActiveMagicEffect
SPELL Property FoodPoisoningSpell Auto
Actor Property PlayerRef Auto
Keyword Property FoodPoisoning Auto
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference) native
If (akBaseObject.HasKeyword(FoodPoisoning))
PlayerRef.AddSpell(FoodPoisoningSpell, false)
Endif
EndEvent
Link to comment
Share on other sites

Ditch the "native".

 

Also, if a Property is not expected to change at runtime, it is good advice to make it Const. Keywords and Spells for example are very unlikely to change at runtime, so:

 

Spell Property FoodPoisoningSpell Auto Const

Keyword Property FoodPoisoning Auto Const

 

Difference: A property without the 'Const' will be baked into player's save and can be changed at runtime, even by another script. A property with the 'Const' must be filled in CK, will always be loaded from the plugin and cannot change at runtime (read-only).

 

I don't think you need the Actor property either, because you can:

 

Game.GetPlayer().AddSpell(FoodPoisoningSpell, false)

 

On a second thought, you probably want to apply the spell to the actor that equipped the object, and not to the player. Least player ends up with food poisoning whenever some NPC equips your object. I'm however afraid that I don't know enough about magic effects to be of any further help.

Link to comment
Share on other sites

Actor.OnObjectEquipped is a Skyrim function that is not supported in Fallout4, the equivalent is Actor.OnItemEquipped which is not generated by the ActiveMagicEffect script.

 

What it is you are actually trying to achieve ?

 

eg: when the player eats an ingestible/potion that is poisoned apply a poison spell ... in which case the simple solution is to use ObjectReference.OnEquipped attached to the object ...

Link to comment
Share on other sites

Basically I was trying to make it so eating raw meat would give the player a 'disease', in this case food poisoning. I did actually manage to get it working by making a script to equip a potion with the disease effects, when the player ate certain items.

However, I couldn't find a way to dispel the effect through certain chems. Even using keywords in the dispel section of the magic effect.

I read online that dispel wouldn't work as the effect didn't come from a spell, it came from a potion.

Therefore I tried to apply the disease as a spell rather than adding a potion effect.

 

I should probably go back to the tutorials and keep learning, this is my first time playing around with scripts!

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...