Attach a script to a dialogue

Post » Wed Jun 20, 2012 6:31 pm

Hi all,

For my craft mod, I would like to launch a script that will check the crafting result at a certain point in the dialogue, like

PC "I would like to make some tanning"
NPC "What exactly would like td do ?"
PC "I would like to create leather strips from leather"
NPC "You need leather" if the player doesn't have any leather
or NPC "Here you go" if the player has some leather, and this line starts the script below:
Scriptname newscripttest extends questimport utilityimport fron_utility_functionsmessage property css_craftingtanning_base automessage property css_tanning_LeatherStrips automessage property css_peltandhidesintoleather automiscobject Property leather01 automiscobject Property badleather automiscobject Property LeatherStrips autoglobalvariable property css_tanning_skill auto;Event OnActivate(ObjectReference triggerRef)Function checkTanningResult()string sSkillLevel = Fron_GetSkillLevelName(css_tanning_skill.getvalueint())debug.notification("you are "+ sSkillLevel + " in tanning.")string sResultint xp_gained_4	sResult = css_check_success(5,12,20,css_tanning_skill,-4)	debug.notification(sResult)	game.getPlayer().RemoveItem(leather01)	if sResult == "echec critique"	  xp_gained_4 = XP_gain(sResult,3,6,2,4,1,3,0,1)	  Improve_skill_from_experience(css_tanning_skill,xp_gained_4)	 elseif sResult == "echec"	  xp_gained_4 = XP_gain(sResult,3,6,2,4,1,3,0,1)	  Improve_skill_from_experience(css_tanning_skill,xp_gained_4)	  game.getPlayer().addItem(LeatherStrips,1)	 elseif sResult == "reussite"	  xp_gained_4 = XP_gain(sResult,3,6,2,4,1,3,0,1)	  Improve_skill_from_experience(css_tanning_skill,xp_gained_4)	  int succ_Leather_number = utility.randomint(2,4)	  game.getPlayer().addItem(LeatherStrips,succ_Leather_number)	 elseif sResult == "reussite critique"	  xp_gained_4 = XP_gain(sResult,3,6,2,4,1,3,0,1)	  Improve_skill_from_experience(css_tanning_skill,xp_gained_4)	  int critsucc_badLeather_number = utility.randomint(3,6)	  game.getPlayer().addItem(LeatherStrips,critsucc_badLeather_number)	endifEndFunction

Nothing happens there.

Where should this script go ? Is it ok ?

Thanks in advance, I am stuck :-(
User avatar
Evaa
 
Posts: 3502
Joined: Mon Dec 18, 2006 9:11 am

Post » Wed Jun 20, 2012 7:32 pm

I am pretty mad at Papyrus. Bethesda made so many simple things so complicated (you know, like attaching a script to a dialogue, setting global variables, and so on...) compared to others tools or scripting langages (NWN 2, mount and blade...)
User avatar
Jonathan Egan
 
Posts: 3432
Joined: Fri Jun 22, 2007 3:27 pm

Post » Wed Jun 20, 2012 2:43 pm

I am pretty mad at Papyrus. Bethesda made so many simple things so complicated (you know, like attaching a script to a dialogue, setting global variables, and so on...) compared to others tools or scripting langages (NWN 2, mount and blade...)
It's also about 1000x more powerful. They wouldn't make it more complicated for no reason. Each thing that's harder to do, can do more things.
User avatar
clelia vega
 
Posts: 3433
Joined: Wed Mar 21, 2007 6:04 pm

Post » Wed Jun 20, 2012 10:24 am

your scripts should be attached to your quest in the scripts tab

for each dialogue, if you need to access a particular function, you create a papyrus fragment, declare a property for your script or use getowningquest (if the dialogue is still in the same quest as your attached script) and call your function that is in your script
User avatar
Jonathan Braz
 
Posts: 3459
Joined: Wed Aug 22, 2007 10:29 pm

Post » Wed Jun 20, 2012 3:42 pm

@Alexander: I won't start arguing, because I indeed think that the CK is amazing, just as is this amazing game. However, I still wish some stuff were more straightforward, and that 90% of the mods right now are not either new recipes, graphic overhauls or new item skins, and no new real gameplay systems, like the ones I am trying so hardly to script (check my mining and prospecting skill, or my athletism skill...)

@Amethyst thanks a lot, those are good hints, I will look further in this direction. However, if you could efortlessly post me a simple example would be a great time saver. However, thanks a lot :-)
User avatar
Emma Copeland
 
Posts: 3383
Joined: Sat Jul 01, 2006 12:37 am

Post » Wed Jun 20, 2012 9:58 am

this is attached to the script tab on a quest called "CoolQuest"

Scriptname CoolScript extends questFunction DoCoolStuff(); doing cool stuffEndFunction



in the Player Dialogue of CoolQuest, let's say there is a dialogue like:

(player) Topic Text: So what do you do?

(NPC) Response: I do cool stuff.


then in the papyrus fragments section (End):

pCoolQuest.DoCoolStuff()

but before you write this code, the pCoolQuest needs to be declared as a property first.

in the blank papyrus script window type a ; and compile then hit ok to close the CoolQuest window. (if you don't create the script fragment and declare properties before writing the code, you will get errors saying you need properties, but you cant add properties until a script fragment is generated. its a weird and annoying catch22, but just make a habit of doing the ; to create any fragment from here on out)

reopen the CoolQuest window and go back to the player dialogue. you will see that a new fragment has been created and attached to your dialgue topic.


right click the new script fragment and select edit source

scroll all the way down past the auto generated comments.

you will need to type

CoolScript property pCoolScript auto

go to file save or ctrl S


then hit the properties button.

in the properties window assign the value for pCoolScript (the dropdown will only give you one option CoolQuest because that is the owner of the script you want to declare)


now paste in your function code into the fragment window after you delete your initial ;



depending on what you want your function to do you may need to declare arguments in the parentheses of the function.

like lets say the function makes the NPC equip a sword


so you declare the argument:

Function DoCoolStuff(ObjectReference NPCRef)(NPCRef as Actor).EquipItem(SwordProperty)EndFunction



and back in your dialgue script fragment, you specify the argument:


pCoolScript.DoCoolStuff(akSpeaker)


in this case akSpeaker is a native property to topic fragments (you don't need to declare it as a property) as the NPC who is speaking the response. so now, the NPC who just spoke the line "i do cool stuff" will equip the sword specified in the quest script


it's kind of confusing at first, but you get used to it quick. i actually really like this system with fragments even though i found it frustrating and hated it at first.
User avatar
cutiecute
 
Posts: 3432
Joined: Wed Sep 27, 2006 9:51 am

Post » Wed Jun 20, 2012 10:01 am

Thank you so much. Sigh... :confused:
User avatar
Bellismydesi
 
Posts: 3360
Joined: Sun Jun 18, 2006 7:25 am

Post » Wed Jun 20, 2012 11:50 pm

Hi again,

when you write :
then in the papyrus fragments section (End):


pCoolQuest.CoolFunction()

but before you write this code, the pCoolQuest needs to be declared as a property first.

I assume that pCoolQuest.CoolFunction() is a mistake, and that you really mean pCoolQuest.DoCoolStuff() ?
User avatar
Kit Marsden
 
Posts: 3467
Joined: Thu Jul 19, 2007 2:19 pm

Post » Wed Jun 20, 2012 8:47 am

It works, thank you again so much. No pain no gain I guess. Oh well....
User avatar
Doniesha World
 
Posts: 3437
Joined: Sun Jan 07, 2007 5:12 pm

Post » Wed Jun 20, 2012 1:02 pm

woops, yes that was a typo.

all the times i wrote CoolFunction() was supposed to be DoCoolStuff(). sorry about the confusion
User avatar
Lauren Dale
 
Posts: 3491
Joined: Tue Jul 04, 2006 8:57 am

Post » Wed Jun 20, 2012 11:23 pm

Thanks for editing, it is a nice tut, and will hopefully help others. I will credit you when I release this first tanning skill, woohoo ;-)
User avatar
Tarka
 
Posts: 3430
Joined: Sun Jun 10, 2007 9:22 pm

Post » Wed Jun 20, 2012 10:33 am

Here you go :-)

http://skyrim.nexusmods.com/downloads/file.php?id=14313
User avatar
Farrah Barry
 
Posts: 3523
Joined: Mon Dec 04, 2006 4:00 pm

Post » Wed Jun 20, 2012 7:43 pm

this is attached to the script tab on a quest called "CoolQuest"

Scriptname CoolScript extends questFunction DoCoolStuff(); doing cool stuffEndFunction



in the Player Dialogue of CoolQuest, let's say there is a dialogue like:

(player) Topic Text: So what do you do?

(NPC) Response: I do cool stuff.


then in the papyrus fragments section (End):

pCoolQuest.DoCoolStuff()

but before you write this code, the pCoolQuest needs to be declared as a property first.

in the blank papyrus script window type a ; and compile then hit ok to close the CoolQuest window. (if you don't create the script fragment and declare properties before writing the code, you will get errors saying you need properties, but you cant add properties until a script fragment is generated. its a weird and annoying catch22, but just make a habit of doing the ; to create any fragment from here on out)

reopen the CoolQuest window and go back to the player dialogue. you will see that a new fragment has been created and attached to your dialgue topic.


right click the new script fragment and select edit source

scroll all the way down past the auto generated comments.

you will need to type

CoolScript property pCoolScript auto

go to file save or ctrl S


then hit the properties button.

in the properties window assign the value for pCoolScript (the dropdown will only give you one option CoolQuest because that is the owner of the script you want to declare)


now paste in your function code into the fragment window after you delete your initial ;



depending on what you want your function to do you may need to declare arguments in the parentheses of the function.

like lets say the function makes the NPC equip a sword


so you declare the argument:

Function DoCoolStuff(ObjectReference NPCRef)(NPCRef as Actor).EquipItem(SwordProperty)EndFunction



and back in your dialgue script fragment, you specify the argument:


pCoolScript.DoCoolStuff(akSpeaker)


in this case akSpeaker is a native property to topic fragments (you don't need to declare it as a property) as the NPC who is speaking the response. so now, the NPC who just spoke the line "i do cool stuff" will equip the sword specified in the quest script


it's kind of confusing at first, but you get used to it quick. i actually really like this system with fragments even though i found it frustrating and hated it at first.

This entire post should go on the wiki.
User avatar
Brandon Bernardi
 
Posts: 3481
Joined: Tue Sep 25, 2007 9:06 am


Return to V - Skyrim