Jump to content

Papyrus - Hunger script - Need help


GomuGomu64

Recommended Posts

Okay. I've managed to get far enough that my script actually runs at run-time (Yay me! :3), but I can't figure out how to make my script decrease a global variable (That is Object Window -> Misc -> Global -> fAAGGHunger) by one every so often, and when the player eats something, it goes up by one.

 

Here is the script :

 

scriptName Hunger extends Quest

int Property fAAGGHunger = 100 auto ;This is the script default when you start a new game or start the plugin.

Event onInit()
debug.MessageBox("Hunger plugin loaded!")
RegisterForUpdate(10)
endEvent                     

Event OnUpdate()
       if fAAGGHunger > 1
               fAAGGHunger -= 1 ; -= means that Hunger = Hunger - 1
       elseif fAAGGHunger == 1 ; This means that the code checks if the value is at 1
               Game.GetPlayer().ModActorValue("health", 0)
	debug.MessageBox("Oh dear. You didn't eat, so you died. Sucks to be you!")
       elseif fAAGGHunger <=10
               debug.MessageBox("Ah, your stomach beckons for bacon. Might be a good idea to eat. You know, being hungry and all.")
       endif
endEvent

Event OnActivate(ObjectReference akActionRef)
       if fAAGGHunger == 99
               fAAGGHunger += 1
               debug.MessageBox("Your belly is full, your mouth tastes fantastic. Life is good.")
       elseif fAAGGHunger == 100
               debug.MessageBox("You have already eaten! You don't want to get indigestion, now.")
       elseif fAAGGHunger == 50
               debug.MessageBox("The gurgling has stopped, but you probably eat more. You fat pig.")
       endif
endEvent

 

The problem for me, is that the OnUpdate() doesn't seem to work. The variable's value doesn't decrease at all, no matter how long you give it.

And another, is that I believe this part

 

Event OnActivate(ObjectReference akActionRef)

 

Isn't actually referring to anything. How would I make it so that the event happens when the player eats something?

Edited by GomuGomu64
Link to comment
Share on other sites

Bump.

 

 

One thing is for sure. Papyrus was the wrong thing to do. Bethesda should have just implemented Lua into the engine, rather than creating a whole new scripting language. They are near identical, but with the fact Lua makes more sense, and more appropriate commands.

 

*Frustration overload*

Link to comment
Share on other sites

I've been looking at my own script, and I think I see where we've both made mistakes. We're trying to treat Global Variables as simple numbers when the game engine doesn't. I'm not sure, but I think if you replace "int Property fAAGGHunger = 100" with "GlobalVariable Property fAAGGHunger Auto" (It is a Global Variable right? I think you said so in your last thread) it will help. Then, instead of" fAAGGHunger -= 1" you can put " float fAAGGHunger = fAAGGHunger.Mod(-1)". Then just put "float fAAGGHunger = fAAGGHunger.Mod(100)" in the OnInit event. I will say I'm not 100% on this, so look here for more. As to the ObjectReference, I think what you've put is just the generic term. akActionref should be Game.GetPlayer() I think, as it is supposed to be the reference that acivated the Object. I don't know what you'd put in ObjectReference, and to be honest you might need to use a different type of event than OnActivate. The script runs on the player right? The OnActivate should be run the food I think. Learning Papyrus is harder than I thought :D.
Link to comment
Share on other sites

I've been looking at my own script, and I think I see where we've both made mistakes. We're trying to treat Global Variables as simple numbers when the game engine doesn't. I'm not sure, but I think if you replace "int Property fAAGGHunger = 100" with "GlobalVariable Property fAAGGHunger Auto" (It is a Global Variable right? I think you said so in your last thread) it will help. Then, instead of" fAAGGHunger -= 1" you can put " float fAAGGHunger = fAAGGHunger.Mod(-1)". Then just put "float fAAGGHunger = fAAGGHunger.Mod(100)" in the OnInit event. I will say I'm not 100% on this, so look here for more. As to the ObjectReference, I think what you've put is just the generic term. akActionref should be Game.GetPlayer() I think, as it is supposed to be the reference that acivated the Object. I don't know what you'd put in ObjectReference, and to be honest you might need to use a different type of event than OnActivate. The script runs on the player right? The OnActivate should be run the food I think. Learning Papyrus is harder than I thought :D.

 

You definitely need to define fAAGGHunger as a GlobalVariable.

 

GlobalVariable Property fAAGGHunger Auto

 

You also need to go into the Script Properties and have it AUTOFILL the global variable for you.

 

In the other thread, I suggested making a temp variable to store values in and then once you are done, call fAAGGHunger.SetValue(tempVariable). Because doing all that work using the actual global value will be less....i dunno, more typing. lol.

 

As for making the script trigger when you eat something. I haven't worked on that yet. I worked with Wiseman on a perk to DISABLE the health effect. While you can attach a script to a perk, and the Creation Kit Wiki says "Script Fragments" are executed if the condition is TRUE, it means only Perk effects that have a script fragment. The Creation Kit doesn't even define any properties, methods, etc, Perk scripts themselves. Long story short...haven't looked into it so not sure what's possible without actually modifying each food item.

 

-MM

 

Edit: Looking into the Creation Kit to help out with a Proof of Concept for one of the Hircine modders, I just noticed that the Food stuff is all triggered via Effects too... you could attach scripts to those base effects rather than to the food.

 

-MM

Edited by MofoMojo
Link to comment
Share on other sites

Just a little note - it's better to use Game.GetPlayer().Kill() command to kill the player instead of Game.GetPlayer().ModActorValue("health",0) - I am not sure that one even does anything.

 

TRO Basic Needs script I am working on uses papyrus fragments attached to food item magic effects (which are basically classed as potions) to attach nutritional value to food items, so I can confirm that works. There aren't that many edible food items, so if you create a standard hunger papyrus script driven effect, it's a breeze to attach that to every food item.

Link to comment
Share on other sites

I think Manshooter is right, the way you've put it there you're modding the actor value by magnitude 0, game.getPlayer().Kill() would be more appropiate. Also, "elseif fAAGGHunger <= 10" is true at the same time as "if fAAGGHunger > 1". I think having

if fAAGGHunger >1
                       if fAAGHunger <=10
                                float fAAGGHunger =  fAAGGHunger.Mod(-1)
                                debug.MessageBox("Ah, your stomach beckons for bacon..."
                       else
                                float fAAGGHunger = fAAGGHunger.Mod(-1)

 

might be better.

Edited by WiseMan999
Link to comment
Share on other sites

@JSHT Nobody has a tutorial. We are all looking at other scripts, and either failing hard, getting a completely un-wanted result, or, if your lucky, a semi-working script.

 

I recommend getting that script dumper program and looking at the scripts. I'm looking in that for possible help with me script.

Link to comment
Share on other sites

This language is really not all that difficult, you just have to understand the types you are using, and the functions that are available to the types you use. The Creation Kit wiki has every class laid out for you and tells you what it extends. If you want to use global variables you use the GlobalVariable type, although I'm not sure for what purpose Gomu needs his variable to be global at all as it is entirely possible to have a Quest variable and reference that instead. It is also recommended when working with literals that you put them in functions to ensure they are thread safe (I'm not sure if you would be externally editing your variable from another thread but it is good practice)

 

The "conditional" keyword used after auto will make the variable available to the VM, allowing it to be accessed from conditional functions such as GetVMQuestVariable

Edited by expired6978
Link to comment
Share on other sites

  • Recently Browsing   0 members

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