markyrocks Posted August 28, 2018 Share Posted August 28, 2018 (edited) Scriptname RobotEvent:RobotEvent extends ObjectReference Form Property SweetRollBirthday Auto Const ;this has been turned into a bottle Keyword Property aKeyword Auto Const ActorBase Property aBotBase Auto Const Form Property baseBench Auto Const Keyword Property aBenchKeyword Auto Const Message Property anymessage Auto Const Keyword Property aNewSweetKeyword Auto Const Message Property aTopList Auto Const event Oninit() ;anymessage.show() debug.notification("init event") ;aRegRMTE() endEvent Event OnLoad() debug.notification("onload event") ObjectReference[] BenchRefs = Game.GetPlayer().FindAllReferencesOfType(baseBench, 1500.0) ;finds all benches within 1500 units? debug.notification("should have found BenchRefs") int k = 0 bool break = False while k != BenchRefs.Length || break == False = true if (BenchRefs[k].IsNearPlayer()) _RegForBFDistanceEvent(Game.GetPlayer(), BenchRefs[k], 100.0) ;<<<<<-----------HERE break = True debug.notification("found Benchref") endIf k += 1 endwhile if BenchRefs.Length == 0 ; just here for the debug message if the array comes up empty debug.notification("Benchref.length = 0 ....wtf") endIf EndEvent ;BELOW HERE IS MAINLY WHAT I WANT LOOKED AT function _RegForBFDistanceEvent(ObjectReference akPlayer, ObjectReference bBenchy, float aDistance1) global ScriptObject baBool = akPlayer.CastAs("_RegForDistanceEvent") if baBool Var[] params = new Var[2] params[0] = akPlayer params[1] = bBenchy params[2] = aDistance1 akPlayer.CallFunction("_RegForDistanceEvent", params) endIf endfunction really i had a heck of a time trying to call a function from my main script. I mean geez does it have to be so complicated. I looked at countless examples. I realize theres a learning curve but it didn't seem like I could get any of the examples to work. Just seemed like everything i tried was failing. Anyways i finally got the thing to compile. All the script is really trying to accomplish is go from a object reference script to a script object script. ( these things are killing me but i'm getting it) The point is so that i can call a function that registers for a distance less than event... I know its so such a simple thing but appearently the 2 types of scripts are not compatible...killing me anyway check it out i just want to make sure the thing is actually going to work. Im so tired rn. the biggest if in this whole thing for me is the variable that i called the function on in both scripts. akActor. not really sure if that was the right thing to do . It is an even based off of the player actions. so I hope thats right. Idk take a look. My head is spinning Scriptname RobotEventScriptObject:RobotEventScriptObject extends ScriptObject Const function _RegForDistanceEvent(ObjectReference akPlayer, ObjectReference bBenchy, float aDistance1) global akPlayer.RegisterForDistanceLessThanEvent(akPlayer, bBenchy, aDistance1) ;this could possibly register multiple benches.. debug.notification("ondistancelessthanevent registered") endfunction Event OnDistanceLessThan(ObjectReference akObj1, ObjectReference akObj2, float afDistance) ;/ If other registrations had been done, we would want to check the objects But since we only registered for one we know what it is /; Debug.Trace("Player is now " + afDistance + " units away from the bird - fly away!") endEvent Edited August 28, 2018 by markyrocks Link to comment Share on other sites More sharing options...
Reneer Posted August 28, 2018 Share Posted August 28, 2018 (edited) You're making this way more complicated than it needs to be. You really should do a bit more reading on Papyrus and the various events / functions. In particular the RegisterForRemoteEvent function, if I'm correctly understanding what you're trying to do, would help you greatly here. And please indent your code next time. Edited August 28, 2018 by Reneer Link to comment Share on other sites More sharing options...
markyrocks Posted August 28, 2018 Author Share Posted August 28, 2018 (edited) Basically I'm trying to register a less than distance event. But it wont allow me to do that in a script that extends object reference. I don't believe you can use registerforemoteevent with a distance event. It has it's own registration bc the registerfor remote event wont allow you to pass more than 2 parameters. The ondistancelessthan event requires 3. If I try to registerfordistanceless than event in the object reference script it wont compile. Right now I'm basically learning the Joy's of using various types of events for one sequence of events. They dont all play together. Hence why I made a separate script that extends scriptobject and just call the relevant functions from my main script. I definitely plan on using the 2nd script more but it's very small bc I literally just got everything to compile. Also part of my issue is the ability to turn a form into an object reference. What I have above is where I'm at as far as doing that. If you place an item in the world from the ck the ref is easily put in the properties of the script. I'm attempting to find a workbench that the player can build as they want. The last thing is I've been reading about this language like a mad man. Again things like using certain events on certain types of scripts is a foreign concept to me. . Can I extend or include more than one script in my script? Trust me I'd love that. In autoit its basically the same deal, include whatever parent scripts and you can call functions from them as easy as if the function was written inside of the script. Maybe I'm naive, I never had any formal education with this stuff. I don't even think we had a computer in the house until I was 20 so I had a late start lol. One last thing, this is part of my learning process, I had started out trying to use an onmenuopen event for the same purpose but I hit the same wall of it not being in the correct script type. So I moved on to plan b hit a wall and this is my effort to overcome that. Can I call a function of a parent script directly? If I can how exactly do I do that? Again I've looked at many examples, tried it many different ways and this was what I could get to work. Edited August 28, 2018 by markyrocks Link to comment Share on other sites More sharing options...
Reneer Posted August 28, 2018 Share Posted August 28, 2018 (edited) Can I extend or include more than one script in my script? Trust me I'd love that.No, you can't extend more than one script. But you can include other scripts using the Import keyword (so you can just call Wait instead of Utility.Wait, etc). Here, use this code. If you don't understand something about how it works just ask. Scriptname RobotEvent:RobotEvent extends Objectreference Form Property SweetRollBirthday Auto Const ;this has been turned into a bottle Keyword Property aKeyword Auto Const ActorBase Property aBotBase Auto Const Form Property baseBench Auto Const Keyword Property aBenchKeyword Auto Const Message Property anymessage Auto Const Keyword Property aNewSweetKeyword Auto Const Message Property aTopList Auto Const ObjectReference Property CurrentBench Auto event Oninit() debug.notification("init event") endEvent Event OnLoad() debug.notification("onload event") ObjectReference[] BenchRefs = Game.GetPlayer().FindAllReferencesOfType(baseBench, 4000.0) ;finds all benches within 4000 units? debug.notification("should have found BenchRefs") int k = 0 bool break = False while k < BenchRefs.Length && break == False if (BenchRefs[k].IsNearPlayer()) BenchRefs[k].RegisterForMenuOpenCloseEvent("WorkshopMenu") Self.RegisterForRemoteEvent(BenchRefs[k], "OnMenuOpenCloseEvent") break = True debug.notification("found Benchref") endIf k += 1 endwhile if BenchRefs.Length == 0 ; just here for the debug message if the array comes up empty debug.notification("Benchref.length = 0 ....wtf") endIf EndEvent Event ScriptObject.OnMenuOpenCloseEvent(ScriptObject akSender, string asMenuName, bool abOpening) if (asMenuName == "WorkshopMenu") ; do your stuff here. endif endEvent Edited August 28, 2018 by Reneer Link to comment Share on other sites More sharing options...
SKKmods Posted August 28, 2018 Share Posted August 28, 2018 (edited) RegisterForDistanceLessThanEvent is a script object function, you do not assign it to player and you can't register for it remote as there is no default entity that receives it to intercept. Fully qualified in an extends ObjectReference script it compiles fine looking like: (Self as ScriptObject).RegisterForDistanceLessThanEvent((Self as ObjectReference), Game.GetPlayer(), 500.0) Like casting, pay attention to the Member of: ScriptObject Member of: ObjectReference Script Member of: Actor Script on the description pages to know what attach functions and events to. Edit: for your own sanity do text search on RegisterForDistanceLessThanEvent in Fallout 4\Data\Scripts\Source\Base and see how the base game does this stuff in an ObjectReference script ... PulowskShelterScript.psc for example. Edited August 28, 2018 by SKK50 Link to comment Share on other sites More sharing options...
markyrocks Posted August 28, 2018 Author Share Posted August 28, 2018 (edited) Thanks. I'm pretty sure I've tried using the import keyword. I may have other issues in my script at the time when I tried it but it didn't seem like it did anything when I tried it. Can I see an example of how that works? Again the extra bits of information that you all are adding aren't included in the examples. It doesn't show needing to call these events on variables. I think I'm understanding what is going on here. Edited August 28, 2018 by markyrocks Link to comment Share on other sites More sharing options...
markyrocks Posted August 30, 2018 Author Share Posted August 30, 2018 I just wanted to follow up and say thanks again. I'm an idiot I'll admit it lol. I definitely should have read the entire papyrus primer... I skimmed over the first half of it originally and was just like I know all this blah blah. Which I do have a pretty good understanding of object oriented languages but ya my main problem has been type mismatches and I knew I was working too hard. Basically this mess of code I posted here was consolidated to like 8 lines after I realized I could cast "as" other things that are related... again so dumb I was working way to hard. But ya I went back and read it again on the you all's advice. But I'm actually making some progress besides fighting the keyboard. But ya honestly trying to write 10 lines of code b4 that would actually compile was pretty difficult. Now it takes 5 min and I'm testing. So ya ty both! It's crazy how things can change in a day. Much better now, my eyes are wide open . Link to comment Share on other sites More sharing options...
SKKmods Posted August 30, 2018 Share Posted August 30, 2018 Which is why the CK documentation is so frustrating and unhelpful. Many of the examples are so poorly qualified with shorthand !notation based on implied or tacit knowledge, as to be worse than useless misdirection. (Self as apathy) Link to comment Share on other sites More sharing options...
Evangela Posted August 30, 2018 Share Posted August 30, 2018 (edited) You don't have any right to complain really. You've made exactly ONE edit on the wiki. You've made NO effort to improve it yourself. Edited September 5, 2018 by Rasikko Link to comment Share on other sites More sharing options...
Recommended Posts