shadowsyllvet Posted July 21, 2012 Share Posted July 21, 2012 (edited) Can anyone tell me why this worksscn SpellQuestTemplate ;script activates quest ;quest adds spells short HasReadOnce begin onEquip player ;if reading from inventory if HasReadOnce == 0 StartQuest [QuestID] set HasReadOnce to 1 endif end begin onActivate ;if reading from game world activate ;activate book menu if isActionRef player if HasReadOnce == 0 StartQuest [QuestID] set HasReadOnce to 1 endif endif endand this doesn't?scn SpellBookTemplate ;script adds spells short HasReadOnce begin onEquip ;if reading from inventory if HasReadOnce == 0 player.addspell [spell EditorID] set HasReadOnce to 1 endif end begin onActivate ;if reading from game world activate ;activate book menu if isActionRef player if HasReadOnce == 0 player.addspell [spell EditorID] set HasReadOnce to 1 endif endif endBoth scripts are attached to books.[Edit]no longer using getSelf Edited July 22, 2012 by shadowsyllvet Link to comment Share on other sites More sharing options...
theuseless Posted July 22, 2012 Share Posted July 22, 2012 (edited) For starters I see that there is a quest which handles the addition of spells to the player. If you could post the quest script as well it would help. If you are cloning this script for multiple uses, it might be easier to handle the variables and the scripting in the quest like they did. I assume you are using some vanilla code and modifying it. Usually they code the way they do for a reason. I have had trouble getting activators to add spells in the past, but haven't tried books. Maybe it is hard coded to be compliant in quest scripts only. Please post the quest data here and maybe a little more of a description of what you want them for (even a vague one). I will check back later and see if I can help any more. theuseless -edit- Also I like to clean up the code they left all sloppy. It looks terrible. Sure you can see where some blocks start and stop, but clean code is good code. Edited July 22, 2012 by theuseless Link to comment Share on other sites More sharing options...
shadowsyllvet Posted July 22, 2012 Author Share Posted July 22, 2012 (edited) The only thing in my quest script was thisscn QuestSpelltome0001 begin GameMode player.addspell [spell EditorID] stopquest QuestSpelltome0001 end Edited July 22, 2012 by shadowsyllvet Link to comment Share on other sites More sharing options...
theuseless Posted July 22, 2012 Share Posted July 22, 2012 (edited) Well, if you are replicating the effect from a working script, keep the script as close to the original as possible. I would reccomend using the book to fire a quest, just like they did. I would make a quest, name it (questname here), mark it as initially disabled. Make a script to attatch to it, named (questnameScript here). Then simply copy the code supplied, making the alterations you need. I find the game to very buggy at best. Sometimes I can call a ref in a script by its variable name (example: ref prisoner). Sometimes I need to call the reference directly (example: calling the prisoner as tUL665tharnstPrisonerAref). I don't know why it works to define a ref then use it in code, and others you have to long hand it. I have written codes with the same functions (nearly identical code). Sometimes it works to define a ref variable, sometimes it doesn't. What I'm trying to get at is that if they used the extra time to write the code to a quest, there is probably a reason. Just make a quest for the book to interact with. It should solve all your issues. -edit- I use the program called Notepad++. You can get oblivion script highlighter like it shows on this forum. You can do search and replace functions too. This makes it a lot easier to write and modify cloned scripts. Edited July 22, 2012 by theuseless Link to comment Share on other sites More sharing options...
shadowsyllvet Posted July 22, 2012 Author Share Posted July 22, 2012 (edited) all of my book use scripts to call a quest into activation. but the thing i have noticed is that if i use addspell inside of ANY if statement regardless of quest, object, or effect script and regardless of any begin block it will not run, compiles but it effectivly ends the script. nothing after addpsell works either scn script begin gameMode if GlobalVarDoOnce == 1 message"this DOES print" player.addspell spell'this does not happen' message "this does not print" message "neither does this" set GlobalVarDoOnce to 2'this does not happen' endif end begin onEquip player set GlobalVarDoOnce to 1 end using the console command show GlobalVarDoOnce returns 1 so i know the onEquip block works EDIT-I have finished the scripts for my mod and it all worksbut I would still like to know why I cant get addspell to work inside of an if statement and as to using vanilla script: i'm not, both scripts are mine.I read one of the tutorials on tescs wiki and the rest i got from tescs wiki explanations of functions and commands.a semester of c++ helps too. tried to clean the code up a little Edited July 22, 2012 by shadowsyllvet Link to comment Share on other sites More sharing options...
theuseless Posted July 22, 2012 Share Posted July 22, 2012 (edited) scn SpellQuestTemplate ;script activates quest <------- says right there what the script is designed to do ;quest adds spells <--------- I am sure there is a reason for that. short HasReadOnce begin onEquip player ; this should only run when equipped to the player, from inventory if HasReadOnce == 0 StartQuest [QuestID] ; this is where the meat and potatoes are. The quest handles the addition of the spell. set HasReadOnce to 1 endif end begin onActivate player ; when the player picks the book up from in world activate ;make the player open the book to read if HasReadOnce == 0 StartQuest [QuestID] set HasReadOnce to 1 endif end xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ;you can even define the variables in the quest script, such as below: scn SpellQuestTemplateScript begin onEquip player if (QuestID).HasReadBook1 == 0 ;you can simply change the variable by switching out the number, ie HasReadBook2 StartQuest [QuestID] set (QuestID).HasReadBook1 to 1 endif end begin onActivate player activate if (QuestID).HasReadBook1 == 0 StartQuest [QuestID] set (QuestID).HasReadBook1 to 1 endif end ;Now you can make the quest, I would make it for the second example I listed. The script would be as follows: scn QuestSpelltome0001 short HasReadBook1 short HasReadBook2 short HasReadBook3 short HasReadBook4 short HasReadBook5 short HasReadBook1,000,000 ;for example begin GameMode ;This will run every frame. Make sure the quest is disabled so this does not cause LAG if HasReadBook1 == 1 player.addspell [spell_1 EditorID] set HasReadBook1 to 2 ; this will ensure the spell is not added as a redundancy elseif HasReadBook2 == 1 player.addspell [spell_2 EditorID] set HasReadBook2 to 2 elseif HasReadBook3 == 1 player.addspell [spell_3 EditorID] set HasReadBook3 to 2 elseif HasReadBook1,000,000 == 1 player.addspell [spell_1,000,000 EditorID] set HasReadBook1,000,000 to 2 endif stopquest QuestSpelltome0001 end I will sometimes use a bit of code to add gold to the player. It will show you where the script runs and where it is not running. I add it as such: scn QuestSpelltome0001script short HasReadBook1 short HasReadBook2 short HasReadBook3 short HasReadBook4 short HasReadBook5 short HasReadBook1,000,000 ;for example begin GameMode if HasReadBook1 == 1 player.addspell [spell_1 EditorID] set HasReadBook1 to 2 player.additem gold001 1 ;<----------------- adds to the 1's slot elseif HasReadBook2 == 1 player.addspell [spell_2 EditorID] set HasReadBook2 to 2 player.additem gold001 10 ;<----------------- adds to the 10's slot elseif HasReadBook3 == 1 player.addspell [spell_3 EditorID] set HasReadBook3 to 2 player.additem gold001 100 ;<----------------- adds to the 100's slot elseif HasReadBook1,000,000 == 1 player.addspell [spell_1,000,000 EditorID] set HasReadBook1,000,000 to 2 player.additem gold001 1000 ;<----------------- adds to the 1,000's slot endif stopquest QuestSpelltome0001 player.additem gold001 10000 ;<----------------- adds to the 10,000's slot end This will tell you that if you have not read any of the books, yet the quest activates, it will add gold in the amount of 10,000. If you have read only the third book (to set HasReadBook3 to 1), you should get 10,100. If you then read the first book, it should add 10,001 gold. It is crude but tells you what part of the script works. If you get a gold amount of say 3, you know that the script where it adds gold once (player.additme gold001 1) ran 3 times. This shouldn't occur in this script, but it can in others. You can define a valueless, weightless object, but I don't do this to cheat. I use this as a simple way to make a check. Any modder can make a container with a billion gold. That isn't the point of this snippet. Again, get Notepad++ with oblivion script syntax highlighter if you don't use it already. -edit- If you look up tutorials on using C basic, you can get some cool tricks. Just remember that in C languages an object is a script. In Oblivion syntax, an object is the mesh (or quest, etc) which has a script attatched to it. Edited July 22, 2012 by theuseless Link to comment Share on other sites More sharing options...
Recommended Posts