[Help] Need some help with simple scripting.

Post » Tue Jun 19, 2012 11:46 pm

Hello people,

After completing the (Hello world!) tutorial i wanted to experiment with the Papyrus some more. So far i haven't been able to create even the simplest events .. lol.
Like:
bring up the message window on equipping a weapon.

Attached a script to a weapon ....tried different combos and commands .... something like:


Scriptname AlexBladeSecondScript extends ObjectReference
{Second atempt}
Event OnEquipped(Actor akActor)
Debug.MessageBox("I'm equipped!")
endEvent

and

Event OnEquipped(Actor akActor)
if akActor == Game.GetPlayer()
Debug.Trace("We were equipped by the player!")
endIf
endEvent




nothing works ..lol

could anyone show/explain me the right way to do something like this

thanks

Alex




 
 
 
User avatar
lilmissparty
 
Posts: 3469
Joined: Sun Jul 23, 2006 7:51 pm

Post » Tue Jun 19, 2012 7:53 pm

Debug.Trace writes to a log, try using Debug.MessageBox
User avatar
YO MAma
 
Posts: 3321
Joined: Thu Dec 21, 2006 8:24 am

Post » Tue Jun 19, 2012 9:40 pm

thanks Kreij but it doesn′t work either
Scriptname AlexBladeSecondScript extends ObjectReference
{Second atempt}
Event OnEquipped(Actor akActor)
if akActor == Game.GetPlayer()
Debug.messagebox("We were equipped by the player!")
endIf
endEvent
User avatar
cheryl wright
 
Posts: 3382
Joined: Sat Nov 25, 2006 4:43 am

Post » Tue Jun 19, 2012 11:39 pm

ScriptName AlexBladeSecondScript extends ObjectReference{Second attempt}Import Debug?Event OnEquipped(Actor akActor)	If akActor == Game.GetPlayer()?		Debug.MessageBox("We were equipped by the player!")	EndIf?EndEvent
...Perhaps importing Debug will help? Can't recall off-hand if it's a necessity to do so, but I can't think of anything else...
User avatar
Tiffany Castillo
 
Posts: 3429
Joined: Mon Oct 22, 2007 7:09 am

Post » Wed Jun 20, 2012 5:38 am

importing debug and using debug.messagebox is redundant.

the syntax in the original script looks fine, i think the issue could maybe be how you are attaching it to your object?
User avatar
Yung Prince
 
Posts: 3373
Joined: Thu Oct 11, 2007 10:45 pm

Post » Wed Jun 20, 2012 12:33 am

...Perhaps importing Debug will help? Can't recall off-hand if it's a necessity to do so, but I can't think of anything else...
Importing Debug (or any other script) just allows you to call global functions defined in the imported script as though they were defined in the script you're writing, so long as there's no ambiguity in the function call.

Your script does look correct as far as I can tell. How have you set it up in the Creation Kit? Also, just to make sure you haven't missed something simple, you did compile it, right?

Cipscis
User avatar
Janine Rose
 
Posts: 3428
Joined: Wed Feb 14, 2007 6:59 pm

Post » Wed Jun 20, 2012 5:43 am

i did compile it .. i've just attached the script to the weapon in the weapon window... bottom right corner ... tried both persistent and not persistem reference

when i did the tutorial hello world i did not compile the script and it works

thanks for the replies guys
User avatar
Katey Meyer
 
Posts: 3464
Joined: Sat Dec 30, 2006 10:14 pm

Post » Tue Jun 19, 2012 3:55 pm

oki it works now ... it was indeed a silly small thing ... i had to drop the sword from the inventory and pick it up again

thanks again guys :)
User avatar
Jeffrey Lawson
 
Posts: 3485
Joined: Tue Oct 16, 2007 5:36 pm

Post » Wed Jun 20, 2012 3:51 am

oh yeah. then theres that issue as well.

for future reference, any time you test a script, i suggest always starting a new game by COC'ing some cell (i always type coc riverwood) before you load any game.

this will guarantee that you load a fresh game with no traces of save game corruption. then add your test item by console command. because save games will save and load persistent data that are affected by script changes, even scripts that have been compeltely deleted could continue to run in a loaded save
User avatar
Taylor Bakos
 
Posts: 3408
Joined: Mon Jan 15, 2007 12:05 am

Post » Tue Jun 19, 2012 5:53 pm

when i did the tutorial hello world i did not compile the script and it works
You must have compiled that script, or nothing would have happened. It's been a while since I edited a script with the Creation Kit, though. I don't remember, but it may compile your script when you save them, or something.

Interesting to hear that you had to drop the sword first before the script would work. I expect that has something to do with how inventory items are not treated quite the same as conventional http://www.creationkit.com/ObjectReference_Script.

Cipscis
User avatar
Amie Mccubbing
 
Posts: 3497
Joined: Thu Aug 31, 2006 11:33 pm

Post » Wed Jun 20, 2012 12:44 am

lol it seems that i can't get a grip on papyrus :

could someone translate this into papyrus scripting ? it's a quest script

begin gamemode
if player getequipped katana1 !=0 && weaponout == 1
player.unequip katana1 1 1
player.remove katana1 1 1
player.add katana2 1 1
player.equip katana2 1 1
elseif player getequipped katana2 !=0 && weaponout == 0
player.unequip katana2 1 1
player.remove katana2 1 1
player.add katana1 1 1
player.equip katana1 1 1
endif
end



thanks
Alex
User avatar
I’m my own
 
Posts: 3344
Joined: Tue Oct 10, 2006 2:55 am

Post » Tue Jun 19, 2012 6:21 pm

what actions are you trying to achieve with this script?

maybe start by typing out the logic in plain english the actions you want to have happen (pseudo code is useful for planning out your eventual code)


are you trying to make it so that the quest will equip one of each katana in the players hands?
User avatar
Harry Leon
 
Posts: 3381
Joined: Tue Jun 12, 2007 3:53 am

Post » Wed Jun 20, 2012 2:45 am

GameMode doesn't exist anymore in Papyrus. Instead, the entry point to a script must be a native event, such as http://www.creationkit.com/OnInit. You can use http://www.creationkit.com/RegisterForUpdate_-_Form or http://www.creationkit.com/RegisterForSingleUpdate_-_Form in order to make an http://www.creationkit.com/OnUpdate_-_Form event fire in the future.

By making that event fire at regular intervals, you can have similar functionality to the old "Begin GameMode".

Cipscis

EDIT:

You might benefit from reading this page - http://www.creationkit.com/Differences_from_Previous_Scripting

Cipscis
User avatar
Natasha Callaghan
 
Posts: 3523
Joined: Sat Dec 09, 2006 7:44 pm

Post » Tue Jun 19, 2012 4:57 pm

I'm trying to make a model swap with 2h hand weapon and 1 hand weapon
when sheated it's a 2hand weapon on the back and when the weapon is out it's a 1 hand weapon in your hand
User avatar
Sheeva
 
Posts: 3353
Joined: Sat Nov 11, 2006 2:46 am

Post » Tue Jun 19, 2012 3:57 pm

ah ok.

this is great because i'm actually working on something that is similar as well (when weapon is drawn it is a one-handed dual wield ninja sword, and when sheathed it is a double scabbard in X-formation on the back)

we would probably have similar scripts since i think they would work the same way.



i think the best way to start this is to set up a quest either through the story manager (so that it only fires when your character specifically adds the katana to his inventory) or you could set it up as a quest that starts regardless at game start (but it would be active regardless if the player has the katana or not)


in any case you could start your script by listening for an event: OnEquipped

the onequipped event is looking for the 2-hand katana to be equipped (which will then show the scabbard on the players back)

inside your onequipped event you may need to either use registerforupdate or a while loop.


i personally would prefer to use the while loop, since you need this action to perform in real-time


so, something like


while the 2-hand is equipped

if player has weapon drawn

remove 2-hand weapon
equip 1-hand weapon




the main problem with this is that by swapping meshes using a remove and add, you will not be able to temper the weapon as the stats will reset each time it is added back into the inventory. you also need to take into account the possibilities of other weapons being equipped, or if while you have the 1-hand katana equipped, the player switches to a bow (which forces the 1-hand to unequip), then unequips the bow (which forces the 1-hand back into the hand, but it wont fire the onequipped part of the script again, thus breaking the loop and it will not sheath onto the players back)
User avatar
kennedy
 
Posts: 3299
Joined: Mon Oct 16, 2006 1:53 am

Post » Wed Jun 20, 2012 12:14 am

hmmm .. i wonder if there is a way to transfer the stats to the second weapon ...

btw i started with this lol and the compiler asks me to to define the property(katana1) it seems that it won't let me use the editor id :(



ScriptName AlexBladeSecondScript extends ObjectReference
{Second attempt}
 
Event OnEquipped(Actor akActor)
if (Game.GetPlayer().IsEquipped(katana1)) && IsWeaponOut
Game.GetPlayer().UnEquipItem(katana1)
Game.GetPlayer().RemoveItem(katana1)
Game.GetPlayer().AddItem(katana2)
Game.GetPlayer().EquipItem(katana2)
endif
EndEvent
User avatar
Cat
 
Posts: 3451
Joined: Mon Dec 18, 2006 5:10 am

Post » Tue Jun 19, 2012 2:39 pm

yeah thats a bug. just cut the code after ScriptName AlexBladeSecondScript extends ObjectReference

save, then close the window and reopen. you can declare your properties and re-enter the code


you will need to declare your properties before re-adding the code back in:


weapon property Katana1 auto
weapon property katana2 auto
User avatar
Elle H
 
Posts: 3407
Joined: Sun Aug 06, 2006 3:15 am

Post » Wed Jun 20, 2012 5:16 am

Starting 1 compile threads for 1 files...
Compiling "AlexBladeSecondScript"...
C:\Program Files (x86)\The Elder Scrolls V Skyrim\Data\Scripts\Source\temp\AlexBladeSecondScript.psc(8,32): variable katana1 is undefined
C:\Program Files (x86)\The Elder Scrolls V Skyrim\Data\Scripts\Source\temp\AlexBladeSecondScript.psc(8,45): variable IsWeaponOut is undefined
C:\Program Files (x86)\The Elder Scrolls V Skyrim\Data\Scripts\Source\temp\AlexBladeSecondScript.psc(9,29): variable katana1 is undefined
C:\Program Files (x86)\The Elder Scrolls V Skyrim\Data\Scripts\Source\temp\AlexBladeSecondScript.psc(10,28): variable katana1 is undefined
C:\Program Files (x86)\The Elder Scrolls V Skyrim\Data\Scripts\Source\temp\AlexBladeSecondScript.psc(11,25): variable katana2 is undefined
C:\Program Files (x86)\The Elder Scrolls V Skyrim\Data\Scripts\Source\temp\AlexBladeSecondScript.psc(12,27): variable katana2 is undefined
No output generated for AlexBladeSecondScript, compilation failed.
User avatar
Emerald Dreams
 
Posts: 3376
Joined: Sun Jan 07, 2007 2:52 pm

Post » Tue Jun 19, 2012 8:00 pm

this might actually need several scripts (attached to each weapon), and use the quest script just to control the triggering
User avatar
Roberto Gaeta
 
Posts: 3451
Joined: Tue Nov 06, 2007 2:23 am

Post » Tue Jun 19, 2012 11:50 pm

i'm going to run a quick test to see if i can get something started real quick. brb
User avatar
Cameron Wood
 
Posts: 3384
Joined: Wed Oct 31, 2007 3:01 pm

Post » Wed Jun 20, 2012 4:36 am

Yeah, editorIDs can no longer be used directly in scripts. I've written a tutorial explaining why and what needs to be done instead - http://www.cipscis.com/skyrim/tutorials/editorids.aspx

Cipscis
User avatar
Reanan-Marie Olsen
 
Posts: 3386
Joined: Thu Mar 01, 2007 6:12 am

Post » Tue Jun 19, 2012 11:18 pm

ok ... lol the compiler sees the IsWeaponOut command as a variable lol i attached the script to the weapon .. doesnt work

ScriptName AlexBladeSecondScript extends ObjectReference
{Second attempt}
weapon property AlexSithisNinjato auto
weapon property AlexSithisNinjato2 auto
Event OnEquipped(Actor akActor)
 
 
if (Game.GetPlayer().IsEquipped(AlexSithisNinjato)) && IsWeaponOut == 1
Game.GetPlayer().UnEquipItem(AlexSithisNinjato)
Game.GetPlayer().RemoveItem(AlexSithisNinjato)
Game.GetPlayer().AddItem(AlexSithisNinjato2)
Game.GetPlayer().EquipItem(AlexSithisNinjato2)
endif
EndEvent
User avatar
Tania Bunic
 
Posts: 3392
Joined: Sun Jun 18, 2006 9:26 am

Post » Wed Jun 20, 2012 5:47 am

thnx Cip you're a saver :tongue:
but it still doen't work lol

maybe the event is wrong
User avatar
Umpyre Records
 
Posts: 3436
Joined: Tue Nov 13, 2007 4:19 pm

Post » Tue Jun 19, 2012 6:49 pm

ah nvm guys .. thanks for all of your replies ...
i'm gonna try to learn some more papyrus tomorrow ... by the looks of it it's going to be a pain
User avatar
Eileen Collinson
 
Posts: 3208
Joined: Thu Dec 28, 2006 2:42 am

Post » Tue Jun 19, 2012 11:49 pm

after an initial test, the weapon swapping is not very fluid, it plays draw animations for both weapons, so if you were to swap out the 2-hand for a 1-hand, it animates the 1-hand sword draw unfortunately.
User avatar
Siidney
 
Posts: 3378
Joined: Fri Mar 23, 2007 11:54 pm

Next

Return to V - Skyrim