My First Script... Please Help

Post » Mon Jun 18, 2012 7:48 pm

Ok, here we go. I'm diving into the wonderful world of scripting. I'm trying to piece together the syntax and logic as best I can, haha! I'm just wanting to start small, to see if it works. My purpose is to check for specific keywords from the actor getting hit, and also from the weapon that struck them. If a given statement is true, I want to set a variable to a certain value for later use. To begin, I just wanted to test if the script wold return the value of the attacking weapon's keyword... and to display a message box stating that value.

Please forgive my code. It is... a mess to say the least :-P



Scriptname SAWDOnHit extends ObjectReference
{SAWD OnHit Damage Calculation}

Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
bool abBashAttack, bool abHitBlocked)

Keyword property CutR1 auto
Keyword property CutR2 auto
Keyword property CutR3 auto
Keyword property CutR4 auto
Keyword property CutR5 auto
Keyword property CutR6 auto
Keyword property Cut1 auto
Keyword property Cut2 auto
Keyword property Cut3 auto
Keyword property Cut4 auto
Keyword property Cut5 auto
Keyword property Cut6 auto
int ResistCut = 0
int ResistCon = 0
int ResistPen = 0
int Cut = 0
int Con = 0
int Pen = 0


If ( GetActorRef().WornHasKeyword(CutR1) )
ResistCut = 1
ElseIf ( GetActorRef().WornHasKeyword(CutR2) )
ResistCut = 2
ElseIf( GetActorRef().WornHasKeyword(CutR3) )
ResistCut = 3
ElseIf( GetActorRef().WornHasKeyword(CutR4) )
ResistCut = 4
ElseIf ( GetActorRef().WornHasKeyword(CutR5) )
ResistCut = 5
ElseIf( GetActorRef().WornHasKeyword(CutR6) )
ResistCut = 6
Else
ResistCut = 0
EndIf

if akSource.HasKeyword(Cut1)
Cut = 1
ElseIf akSource.HasKeyword(Cut2)
Cut = 2
ElseIf akSource.HasKeyword(Cut3)
Cut = 3
ElseIf akSource.HasKeyword(Cut4)
Cut = 4
ElseIf akSource.HasKeyword(Cut5)
Cut = 5
ElseIf akSource.HasKeyword(Cut6)
Cut = 6
Else
Cut = 0
EndIf



Debug.MessageBox("Hit by cut" + cut)
EndEvent

However, these are the errors I'm getting...

Starting 1 compile threads for 1 files...
Compiling "SAWDOnHit"...
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(7,8): no viable alternative at input 'property'
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(27,1): missing EOF at 'If'
No output generated for SAWDOnHit, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on SAWDOnHit


Any help for a newbie would be much appreciated :-)
Thank you!

NOTE: I have not created the keyword in the mod yet, so I don't know if that would cause the errors.


EDIT: I do have the if statements indented, but it didn't copy/paste it here.

EDIT #2: I did try "If ( GetActorRef().WornHasKeyword(CutR1) == 1 )" and "If ( GetActorRef().WornHasKeyword(CutR1) == True )" but neither made the error change.
User avatar
Alada Vaginah
 
Posts: 3368
Joined: Sun Jun 25, 2006 8:31 pm

Post » Mon Jun 18, 2012 9:24 pm

Try defining your properties outside of the event. After that, you're going to get errors about GetActorRef() since that's only defined for ReferenceAlias scripts. If you're attaching your script to Actors, you can use Self instead. If you want to use Reference Aliases, you'll have make your script extend ReferenceAlias.

Also, you can use code tags to make code more readable. :)
User avatar
Charleigh Anderson
 
Posts: 3398
Joined: Fri Feb 02, 2007 5:17 am

Post » Mon Jun 18, 2012 8:43 pm

Thank you very much! :-)
Ok, I changed it to this, but am still getting an error.

Scriptname SAWDOnHit extends ObjectReference
{SAWD OnHit Damage Calculation}

Keyword property CutR1 auto
Keyword property CutR2 auto
Keyword property CutR3 auto
Keyword property CutR4 auto
Keyword property CutR5 auto
Keyword property CutR6 auto
Keyword property Cut1 auto
Keyword property Cut2 auto
Keyword property Cut3 auto
Keyword property Cut4 auto
Keyword property Cut5 auto
Keyword property Cut6 auto
int ResistCut = 0
int ResistCon = 0
int ResistPen = 0
int Cut = 0
int Con = 0
int Pen = 0



If ( Self.WornHasKeyword(CutR1) == True )
ResistCut = 1
ElseIf ( Self.WornHasKeyword(CutR2) == True )
ResistCut = 2
ElseIf( Self.WornHasKeyword(CutR3) == True )
ResistCut = 3
ElseIf( Self.WornHasKeyword(CutR4) == True )
ResistCut = 4
ElseIf ( Self.WornHasKeyword(CutR5) == True )
ResistCut = 5
ElseIf( Self.WornHasKeyword(CutR6) == True )
ResistCut = 6
Else
ResistCut = 0
EndIf



Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
bool abBashAttack, bool abHitBlocked)





if ( akSource.HasKeyword(Cut1) == True )
Cut = 1
ElseIf ( akSource.HasKeyword(Cut2) == True )
Cut = 2
ElseIf ( akSource.HasKeyword(Cut3) == True )
Cut = 3
ElseIf ( akSource.HasKeyword(Cut4) == True )
Cut = 4
ElseIf ( akSource.HasKeyword(Cut5) == True )
Cut = 5
ElseIf ( akSource.HasKeyword(Cut6) == True )
Cut = 6
Else
Cut = 0
EndIf



Debug.MessageBox("Hit by cut" + cut)
EndEvent

Gives the following error...

Starting 1 compile threads for 1 files...
Compiling "SAWDOnHit"...
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(25,1): missing EOF at 'If'
No output generated for SAWDOnHit, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on SAWDOnHit
User avatar
Lindsay Dunn
 
Posts: 3247
Joined: Sun Sep 10, 2006 9:34 am

Post » Tue Jun 19, 2012 1:09 am

This bit:
If ( Self.WornHasKeyword(CutR1) == True )ResistCut = 1ElseIf ( Self.WornHasKeyword(CutR2) == True )ResistCut = 2ElseIf( Self.WornHasKeyword(CutR3) == True )ResistCut = 3ElseIf( Self.WornHasKeyword(CutR4) == True )ResistCut = 4ElseIf ( Self.WornHasKeyword(CutR5) == True )ResistCut = 5ElseIf( Self.WornHasKeyword(CutR6) == True )ResistCut = 6ElseResistCut = 0EndIf
should also be inside the Event.
User avatar
Donald Richards
 
Posts: 3378
Joined: Sat Jun 30, 2007 3:59 am

Post » Mon Jun 18, 2012 8:05 pm

Thank you again, haha! But it seems when I did it...

Scriptname SAWDOnHit extends ObjectReference
{SAWD OnHit Damage Calculation}

Keyword property CutR1 auto
Keyword property CutR2 auto
Keyword property CutR3 auto
Keyword property CutR4 auto
Keyword property CutR5 auto
Keyword property CutR6 auto
Keyword property Cut1 auto
Keyword property Cut2 auto
Keyword property Cut3 auto
Keyword property Cut4 auto
Keyword property Cut5 auto
Keyword property Cut6 auto
int ResistCut = 0
int ResistCon = 0
int ResistPen = 0
int Cut = 0
int Con = 0
int Pen = 0


Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
bool abBashAttack, bool abHitBlocked)

If ( Self.WornHasKeyword(CutR1) == True )
ResistCut = 1
ElseIf ( Self.WornHasKeyword(CutR2) == True )
ResistCut = 2
ElseIf( Self.WornHasKeyword(CutR3) == True )
ResistCut = 3
ElseIf( Self.WornHasKeyword(CutR4) == True )
ResistCut = 4
ElseIf ( Self.WornHasKeyword(CutR5) == True )
ResistCut = 5
ElseIf( Self.WornHasKeyword(CutR6) == True )
ResistCut = 6
Else
ResistCut = 0
EndIf

if ( akSource.HasKeyword(Cut1) == True )
Cut = 1
ElseIf ( akSource.HasKeyword(Cut2) == True )
Cut = 2
ElseIf ( akSource.HasKeyword(Cut3) == True )
Cut = 3
ElseIf ( akSource.HasKeyword(Cut4) == True )
Cut = 4
ElseIf ( akSource.HasKeyword(Cut5) == True )
Cut = 5
ElseIf ( akSource.HasKeyword(Cut6) == True )
Cut = 6
Else
Cut = 0
EndIf



Debug.MessageBox("Hit by cut" + cut)
EndEvent

...I ended up with a boatload of errors :-P

Starting 1 compile threads for 1 files...
Compiling "SAWDOnHit"...
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(27,11): WornHasKeyword is not a function or does not exist
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(27,33): cannot compare a none to a bool (cast missing or types unrelated)
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(29,15): WornHasKeyword is not a function or does not exist
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(29,37): cannot compare a none to a bool (cast missing or types unrelated)
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(31,14): WornHasKeyword is not a function or does not exist
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(31,36): cannot compare a none to a bool (cast missing or types unrelated)
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(33,14): WornHasKeyword is not a function or does not exist
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(33,36): cannot compare a none to a bool (cast missing or types unrelated)
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(35,15): WornHasKeyword is not a function or does not exist
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(35,37): cannot compare a none to a bool (cast missing or types unrelated)
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(37,14): WornHasKeyword is not a function or does not exist
F:\Skyrim\Data\Scripts\Source\temp\SAWDOnHit.psc(37,36): cannot compare a none to a bool (cast missing or types unrelated)
No output generated for SAWDOnHit, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on SAWDOnHit
User avatar
Jonathan Braz
 
Posts: 3459
Joined: Wed Aug 22, 2007 10:29 pm

Post » Tue Jun 19, 2012 4:24 am

>.> Have it extend Actor. My bad... should've caught that earlier.
User avatar
bimsy
 
Posts: 3541
Joined: Wed Oct 11, 2006 3:04 pm

Post » Mon Jun 18, 2012 6:53 pm

LoL, that actually seemed to work! Thank you so much!!! :-D
User avatar
Arnold Wet
 
Posts: 3353
Joined: Fri Jul 07, 2006 10:32 am

Post » Tue Jun 19, 2012 7:55 am

Update:

Ok, I modified my script a bit. I added the keyword "Cut1" to my iron sword. I then attacked the actor with the script. I was hoping the message box would list "Hit by cut 1".... but it said "Hit by cut 0" instead. I changed the initial value of "cut" to 10. The box still said it was "Hit by cut 0"... so I removed the final else statement from the earlier tries. It now says "Hit by cut 10"

I suppose that's telling me that it is not catching the sword's keyword. "Cut1" should be setting the value of the "Cut" variable to 1, correct?

Scriptname SAWDOnHit extends Actor
{SAWD OnHit Damage Calculation}

Keyword property CutR1 auto
Keyword property CutR2 auto
Keyword property CutR3 auto
Keyword property CutR4 auto
Keyword property CutR5 auto
Keyword property CutR6 auto
Keyword property Cut1 auto
Keyword property Cut2 auto
Keyword property Cut3 auto
Keyword property Cut4 auto
Keyword property Cut5 auto
Keyword property Cut6 auto
int ResistCut = 10
int ResistCon = 0
int ResistPen = 0
int Cut = 10
int Con = 0
int Pen = 0


Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
bool abBashAttack, bool abHitBlocked)

If ( Self.WornHasKeyword(CutR1) == True )
ResistCut = 1
ElseIf ( Self.WornHasKeyword(CutR2) == True )
ResistCut = 2
ElseIf( Self.WornHasKeyword(CutR3) == True )
ResistCut = 3
ElseIf( Self.WornHasKeyword(CutR4) == True )
ResistCut = 4
ElseIf ( Self.WornHasKeyword(CutR5) == True )
ResistCut = 5
ElseIf( Self.WornHasKeyword(CutR6) == True )
ResistCut = 6
EndIf

if ( akSource.HasKeyword(Cut1) == True )
Cut = 1
ElseIf ( akSource.HasKeyword(Cut2) == True )
Cut = 2
ElseIf ( akSource.HasKeyword(Cut3) == True )
Cut = 3
ElseIf ( akSource.HasKeyword(Cut4) == True )
Cut = 4
ElseIf ( akSource.HasKeyword(Cut5) == True )
Cut = 5
ElseIf ( akSource.HasKeyword(Cut6) == True )
Cut = 6
EndIf



Debug.MessageBox("Armor resists cut " + ResistCut + " Hit by cut " + Cut)
EndEvent
User avatar
Bloomer
 
Posts: 3435
Joined: Sun May 27, 2007 9:23 pm

Post » Tue Jun 19, 2012 8:08 am

I think what's happening is that it's checking the Actor itself for the keyword. You want the keyword attached to the weapon. Look into this function: http://www.creationkit.com/GetEquippedWeapon_-_Actor
User avatar
kirsty williams
 
Posts: 3509
Joined: Sun Oct 08, 2006 5:56 am

Post » Mon Jun 18, 2012 10:12 pm

Ah, ok, I thought that's what "akSource" was for... to point to the weapon that hit the scripted actor.

Any suggestion on how to implement the new function? Something like...

GetEquippedWeapon(akSource).HasKeyword(Cut1)

Or would I use "akAggressor"? Haha, I'm starting to get confused... again ;-P

Thank you!


EDIT:

Or would it be "akSource.GetEquippedWeapon()"? If I used "akAggressor" instead, and if it was dual-wielding, how could it tell which weapon was the striking weapon?
User avatar
Jaki Birch
 
Posts: 3379
Joined: Fri Jan 26, 2007 3:16 am

Post » Tue Jun 19, 2012 6:32 am

Actually... it should just be akSource.HasKeyword(). I forgot what akSource represented. You were right the first time.

Something else I missed in my tiredness:
if (akSource.HasKeyword(Cut1) == True)
can be written as:
if ( akSource.HasKeyword(Cut6) )
since HasKeyword() will return true or false. If it returns true, it's executed. If it returns false, it checks the next thing in line. There's no need to compare to true. That applies to both of your if-else-if chains.
User avatar
Racheal Robertson
 
Posts: 3370
Joined: Thu Aug 16, 2007 6:03 pm

Post » Mon Jun 18, 2012 9:50 pm

Thank you... I'll try it out :-)
User avatar
Nice one
 
Posts: 3473
Joined: Thu Jun 21, 2007 5:30 am

Post » Tue Jun 19, 2012 1:51 am

Ok, here's the current script. It ALWAYS returns the initial value for the variables still... in this case, 10.

Scriptname SAWDOnHit extends Actor
{SAWD OnHit Damage Calculation}

Keyword property CutR1 auto
Keyword property CutR2 auto
Keyword property CutR3 auto
Keyword property CutR4 auto
Keyword property CutR5 auto
Keyword property CutR6 auto
Keyword property Cut1 auto
Keyword property Cut2 auto
Keyword property Cut3 auto
Keyword property Cut4 auto
Keyword property Cut5 auto
Keyword property Cut6 auto
int ResistCut = 10
int ResistCon = 0
int ResistPen = 0
int Cut = 10
int Con = 0
int Pen = 0


Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, \
bool abBashAttack, bool abHitBlocked)

If ( Self.WornHasKeyword(CutR1) )
ResistCut = 1
ElseIf ( Self.WornHasKeyword(CutR2) )
ResistCut = 2
ElseIf ( Self.WornHasKeyword(CutR3) )
ResistCut = 3
ElseIf ( Self.WornHasKeyword(CutR4) )
ResistCut = 4
ElseIf ( Self.WornHasKeyword(CutR5) )
ResistCut = 5
ElseIf ( Self.WornHasKeyword(CutR6) )
ResistCut = 6
EndIf

if ( akSource.HasKeyword(Cut1) )
Cut = 1
ElseIf ( akSource.HasKeyword(Cut2) )
Cut = 2
ElseIf ( akSource.HasKeyword(Cut3) )
Cut = 3
ElseIf ( akSource.HasKeyword(Cut4) )
Cut = 4
ElseIf ( akSource.HasKeyword(Cut5) )
Cut = 5
ElseIf ( akSource.HasKeyword(Cut6) )
Cut = 6
EndIf



Debug.MessageBox("Armor resists cut " + ResistCut + " Hit by cut " + Cut)
EndEvent


I've applied the keyword "Cut1" to an iron sword I'm using. I've applied the keyword "CutR1" to the armor the scripted actor has on. So I would think the values should be set to 1 for each.

I've even gone so far as apply the keywords to the actor itself to see if the script was checking the actor's keywords instead. I've also worn the very same armor as the target just in case the script was checking the player's keywords.

Do I need to put the keyword I'm searching for in quotes inside the script?
User avatar
Ricky Rayner
 
Posts: 3339
Joined: Fri Jul 13, 2007 2:13 am

Post » Mon Jun 18, 2012 9:06 pm

Just to make sure... have you filled the properties?
User avatar
brandon frier
 
Posts: 3422
Joined: Wed Oct 17, 2007 8:47 pm

Post » Mon Jun 18, 2012 5:55 pm

Filled them in what way?

I may be completely off base, but what I've done is created the Keyword in the CK Keyword list. I then added them to the appropriate items (Cut1 for the attacking sword, CutR1 for the struck actor's armor). I added the script to the actor I am striking.

The above is the entire script, so I may be missing a step?

Then again, do keywords from the CK keyword list have anything to do with keywords in scripts?
User avatar
Trista Jim
 
Posts: 3308
Joined: Sat Aug 25, 2007 10:39 pm

Post » Mon Jun 18, 2012 10:44 pm

Try opening the properties for the script and filling the properties from there.

Do that from whatever object you have the script attached do. You can either right-click the script and hit "Edit Properties" or just highlight the script and hit the "Properties" button.

In the window that pops up, you should see all your keyword properties. If there are no icons next to them, then they aren't filled. Just click on one of them and then hit the Auto-Fill.
User avatar
Cool Man Sam
 
Posts: 3392
Joined: Thu May 10, 2007 1:19 pm

Post » Tue Jun 19, 2012 12:30 am

Oh, thank you! I'll go check now! :-D
User avatar
Tammie Flint
 
Posts: 3336
Joined: Mon Aug 14, 2006 12:12 am

Post » Mon Jun 18, 2012 6:44 pm

AHA!!! That did it! Thank you so very much! :-D
User avatar
James Baldwin
 
Posts: 3366
Joined: Tue Jun 05, 2007 11:11 am

Post » Mon Jun 18, 2012 11:28 pm

Yeah, that properties thing kicked my butt in my first few scripts :)
User avatar
Juanita Hernandez
 
Posts: 3269
Joined: Sat Jan 06, 2007 10:36 am

Post » Tue Jun 19, 2012 7:12 am

Indeed! Thank you again :-)
I didn't see anything about that in the wiki. I guess I should study more :-P

Well, I think the TRICKY part is over... I hope. Now comes the fun calculation phase! :-P

Hmm, somehow, I do believe this thread may not have completed its purpose yet ;-)


EDIT:

Just getting a second opinion. Do you know if there's a way to get the base AR of a piece of armor or the base Damage of a weapon from a script?

Say I want to get the base damage value of "akSource" in the above script?
User avatar
Neil
 
Posts: 3357
Joined: Sat Jul 14, 2007 5:08 am


Return to V - Skyrim