NexusComa Posted September 25, 2016 Share Posted September 25, 2016 (edited) Scriptname BuyItem Extends ObjectReference ; item activator buy script MiscObject Property Item AutoMiscObject Property Gold001 AutoActor Property PlayerRef AutoInt property Cost Auto Event OnInit() GoToState("Done")EndEvent Event OnActivate(ObjectReference akActionRef) If(akActionRef==(PlayerRef)) If(PlayerRef.GetItemCount(Gold001)>=(Cost)) ; ... PlayerRef.RemoveItem(Gold001, Cost) ;* Take Gold PlayerRef.AddItem(Item, 1) ;* Add Item ... Else Debug.Notification("Not enough gold") Endif Endif GoToState("Done")EndEvent State Done ;do nothingEndState Haven't tested this other than to compile it. But, I think this is a good start.It would still need work however ; ... Maybe setting it as a player owned itemand a test to see if that's not true to set up the buy segment or skip it. Edited September 25, 2016 by NexusComa Link to comment Share on other sites More sharing options...
FrankFamily Posted September 25, 2016 Share Posted September 25, 2016 Don't really see the state or extra properties need, plus that way if you don't have the gold and you activate you can't buy that anymore since it will go to the done state without having been bought, should only change state if bought. But what is indeed actually and i forgot is deleting the activator when the item is bought, since it wouldn't make much sense otherwise. So i edited the script to add that as well as correcting the event. Link to comment Share on other sites More sharing options...
Tobias44142 Posted August 20, 2017 Share Posted August 20, 2017 Why is scripting so cryptic? Like why can't the creation kit wiki just list the scripts and an explanation of what they do along with an example. The samples on here are really bad "(Game.GetPlayer().GetItemCount(Gold) >= 1000)" Am I supposed to use ALL the parentheses? Because copying it like that fails to compile the script. JUST TELL US WHAT WE NEED TO WRITE IN THAT STUPID LITTLE SPACE TO MAKE IT SO IT "player.removeitem f 1000". So it would remove 1000 gold by choosing the "yes" option. Is that so hard? Link to comment Share on other sites More sharing options...
Lisselli Posted August 21, 2017 Share Posted August 21, 2017 (edited) Why is scripting so cryptic? Like why can't the creation kit wiki just list the scripts and an explanation of what they do along with an example. The samples on here are really bad "(Game.GetPlayer().GetItemCount(Gold) >= 1000)" Am I supposed to use ALL the parentheses? Because copying it like that fails to compile the script. JUST TELL US WHAT WE NEED TO WRITE IN THAT STUPID LITTLE SPACE TO MAKE IT SO IT "player.removeitem f 1000". So it would remove 1000 gold by choosing the "yes" option. Is that so hard?The wiki is mostly on auto-pilot. I contribute there a lot, but I'm only one person unfortunately. The problem is that the nature of scripting since the beginning of Skyrim modding has been cryptic. Most of the functions and events were written in a non cryptic way, while the majority of others aren't. When you see examples like that, it is indeed frustrating, because the person who did that expects that the reader will know exactly how to use such a line in a code, and this to me is a bad way to think when editing an article. If you want to make a change, you are free to make an account to help out. I changed the example on that page to be more beginner friendly with details to the best of my understanding on how it should work, along with sample(full) script that tells how to remove all gold from OnActivate or even through a menu: https://www.creationkit.com/index.php?title=GetItemCount_-_ObjectReference#Examples Edited August 21, 2017 by Lisselli Link to comment Share on other sites More sharing options...
foamyesque Posted August 21, 2017 Share Posted August 21, 2017 (edited) I changed the example on that page to be more beginner friendly with details to the best of my understanding on how it should work, along with sample(full) script that tells how to remove all gold from OnActivate or even through a menu: https://www.creationkit.com/index.php?title=GetItemCount_-_ObjectReference#Examples The last script is flawed and way out of scope for a GetItemCount example script. There's a lot of extraneous stuff that doesn't help explain what GetItemCount does, it makes unwarranted assumptions about who the activator is (it's usually the player, but not always), and it has an obsolete comment from when you copied from the steel arrow script directly above it. Why is scripting so cryptic? Like why can't the creation kit wiki just list the scripts and an explanation of what they do along with an example. The samples on here are really bad "(Game.GetPlayer().GetItemCount(Gold) >= 1000)" Am I supposed to use ALL the parentheses? Because copying it like that fails to compile the script. JUST TELL US WHAT WE NEED TO WRITE IN THAT STUPID LITTLE SPACE TO MAKE IT SO IT "player.removeitem f 1000". So it would remove 1000 gold by choosing the "yes" option. Is that so hard? Some pages are worse than others. GetItemCount is pretty simple, though. In the old example script, or in the first post of this thread, the outermost parenthesis are redundant; they don't need to be included, but including them won't hurt. The specific lines to remove 1000 gold from the player would be: MiscObject Property Gold001 Auto Game.GetPlayer().RemoveItem(Gold001, 1000) You'd then need to go into the properties window for that script and fill in the Gold001 property. Hitting the auto-fill button should complete it successfully. If you want to make a check to make sure the player actually has 1000 gold to remove, you could do it thus: MiscObject Property Gold001 Auto Actor PlayerRef = Game.GetPlayer() if PlayerRef.GetItemCount(Gold001) >= 1000 PlayerRef.RemoveItem(Gold001, 1000) endif Strictly speaking, on something this small, you could probably just use two calls to Game.GetPlayer(), but I find the code tends to be more readable with it assigned to a PlayerRef variable. The first post in this thread didn't include the property declaration, so if you simply copied it you would get a compilation error (as you indeed say you did). I assume that the person who posted it simply assumed that the need to declare the property was understood, because it's pretty fundamental to getting Papyrus to do things, but if you're brand new to scripting it could throw you for a loop. Edited August 21, 2017 by foamyesque Link to comment Share on other sites More sharing options...
Lisselli Posted August 21, 2017 Share Posted August 21, 2017 (edited) I changed the example on that page to be more beginner friendly with details to the best of my understanding on how it should work, along with sample(full) script that tells how to remove all gold from OnActivate or even through a menu: https://www.creationkit.com/index.php?title=GetItemCount_-_ObjectReference#Examples The last script is flawed and way out of scope for a GetItemCount example script. There's a lot of extraneous stuff that doesn't help explain what GetItemCount does, it makes unwarranted assumptions about who the activator is (it's usually the player, but not always), and it has an obsolete comment from when you copied from the steel arrow script directly above it. Flawed it maybe and you sound a little burned and you don't need to be. I removed the examples and change accordingly later, however it doesn't make "unwarranted" assumptions. Most of the time people just care about the player, but then people also aren't stupid. You don't need to make unnecessary checks with akActionRef and I told how you can avoid that with GetPlayer(). If all you want is for it to run when the player activates it. If it's not the player, it wont fire. For other objects you obviously need the checks. Furthermore you can even use the PlayerKeyword on the form itself, but no one ever mentions that. Seriously most of you guys think you're the only ones that knows stuff. If you want to talk about flawed, whats with you guys using functions several times to do the same damn thing when it should only be called once? Don't answer that, let the newbie have the slowest script in the world, but you wont tell them that. But then while you were throwing fire at my example, you didn't make an account to go in and change it or add something better. In addition to that, you yourself didn't explain what GetItemCount does. The wiki page in plain sight explains this anyway.. It's just me on that wiki and has been for a long time. No one, not even you shares anything there anymore. One thing I noticed is when someone wants scripting help, often no one who knows their s*** will even answer. And it's only til I pop up that someone says anything, but it's mostly just to one me up. As bad as it sounds, I've often did this on purpose, just so someone can get proper help, and it's worked almost every time. Be honest, the stuff you guys know, you mostly want to keep it to yourself (and that is EXACTLY why the wiki is in the state it is) until you see an opportunity to prove someone wrong. I'm not a programmer, I'm not a developer, and I think you're either one of those. Honestly I dislike both. You carry a cancerous attitude and act as if you can never be wrong. Now I have said my piece, and I apologize the poster I responded to with my "flawed" script, but at least I admit I am wrong. Edited August 21, 2017 by Lisselli Link to comment Share on other sites More sharing options...
soupdragon1234 Posted August 21, 2017 Share Posted August 21, 2017 Why is scripting so cryptic? Like why can't the creation kit wiki just list the scripts and an explanation of what they do along with an example. Er, it does. Its all in the papyrus reference pages. :huh: "(Game.GetPlayer().GetItemCount(Gold) >= 1000)" Am I supposed to use ALL the parentheses? Because copying it like that fails to compile the script. Yes you are because thats how coding languages work. Parentheses follow the function statement because they may or may not pass information to said function. In this case they're internal functions but you can create your own external functions and they work in exactly the same way. n.b. it fails to compile because that fragment doesn't mean anything in itself it includes a conditional thats missing a preceding "If" statement or similar that which would generate a True or False condition i.e. If the player has >= 1000 gold Then do something Else do something else. JUST TELL US WHAT WE NEED TO WRITE IN THAT STUPID LITTLE SPACE TO MAKE IT SO IT "player.removeitem f 1000". So it would remove 1000 gold by choosing the "yes" option. Is that so hard? Examples are generic. To cover all possiblities. As an example. They weren't written with you specifically in mind. You have to extrapolate from whats given, and people are unlikely to want to spoon feed you what you want with that attitude. :armscrossed: If you want to make a check to make sure the player actually has 1000 gold to remove, you could do it thus: MiscObject Property Gold001 Auto Actor PlayerRef = Game.GetPlayer() if PlayerRef.GetItemCount(Gold001) >= 1000 PlayerRef.RemoveItem(Gold001, 1000) endif Strictly speaking, on something this small, you could probably just use two calls to Game.GetPlayer(), but I find the code tends to be more readable with it assigned to a PlayerRef variable. The first post in this thread didn't include the property declaration, so if you simply copied it you would get a compilation error (as you indeed say you did). I assume that the person who posted it simply assumed that the need to declare the property was understood, because it's pretty fundamental to getting Papyrus to do things, but if you're brand new to scripting it could throw you for a loop. Strictly speaking you can just use an actor property for PlayerRef as it exists in the game already so it isn't going to add to the string count and Game.GetPlayer() is slow, calling it twice doubly so. Actor property PlayerRef Autois more efficient. Link to comment Share on other sites More sharing options...
foamyesque Posted August 21, 2017 Share Posted August 21, 2017 (edited) Strictly speaking you can just use an actor property for PlayerRef as it exists in the game already so it isn't going to add to the string count and Game.GetPlayer() is slow, calling it twice doubly so. Actor property PlayerRef Autois more efficient. Sure, but this isn't a script that needs to be hyper-optimized. Edited August 21, 2017 by foamyesque Link to comment Share on other sites More sharing options...
Quibblonian101 Posted July 19, 2019 Share Posted July 19, 2019 id make those items unique activators (shared script) so You can react better to activation and give or not the item if the player has the gold or is sneaking, something like this: Scriptname BuyItem Extends ObjectReference Miscobject property myitem auto; fill with the associated misc item the activator represents. Miscobject property gold auto Event onactivate(ObjectReference akActionRef) If akactivator == game.getplayer() If akactivator.IsSneaking() akactivator.Additem(myitem) DisableNoWait() Delete() Else Int Cost = myitem.getgoldvalue() If akactivator.getgoldamount() >= Cost akactivator.RemoveItem(gold, Cost) akactivator.Additem(myitem) DisableNoWait() Delete() Else debug.notification("You don't have enough gold") Endif Endif Endif Endevent EDIT: added deleting of the activator and corrected the activate event, is objectreference parameter not actor, wrote it on the phone...How would I make it so casting a spell and onhit it removes one gold coin from my inventory? Link to comment Share on other sites More sharing options...
Quibblonian101 Posted July 20, 2019 Share Posted July 20, 2019 This was my attempt: Scriptname CoinshotRemoveCoinScript extends MagicEffect {This script removes 1 gold coin from the player whenever the spell is cast}MiscObject Property Gold001 AutoSpell Property MistbornCoinShot AutoActor Property PlayerRef AutoEvent OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, Bool abPowerAttack, Bool abSneakAttack, Bool abBashAttack, Bool abHitBlocked) If MistbornCoinShot.Cast(PlayerRef, akAggressor) PlayerRef.RemoveItem(Gold001, 1) If PlayerRef.GetItemCount(Gold001) >= 1 Else Debug.Notification("You don't have enough gold") EndIf EndIf EndEvent Link to comment Share on other sites More sharing options...
Recommended Posts