Jump to content

Code to get an object based on distance


SMB92

Recommended Posts

Here is an example:

Â

Let's say you have two actors, lets call them actor1 and actor2. Both have same script. Let's call it TestScript. Script is registered for player distance and is using busy state when player steps close enough.

Â

Player steps close to actor1 and then 0.5s later steps close to actor2. Actor1 makes TestScript instance 1 and goes to busy state. Actor2 makes script instance 2 but it has NO idea that Testscript instance 1 is in busy state, so both works like they have no idea other one exists. The only way to make them affect same things is to try them both change same globalvariable or access/change property on another script, or both try change players actor value etc..

Â

What I think you might want to do is: Have your normal script, then that script calls function in Quest script and that quest script is using states, busy state. So, same example, now Actor2 is calling function, but the quest script is in busy state and nothing happens.

Yeah I'm at a loss as to why I'm seeing this happen, but yeah I was headed to toward quest with states but I was of the thinking I needed the script to get a marker for me to act as the "spawnpoint".

 

So many ways to skin a cat lol

Link to comment
Share on other sites

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I see, but can youÃÂ please clarify what was notÃÂ working es expected.ÃÂ The only thing I want toÃÂ say. I don`t why it works so and I don`t have a logical explanation now, but ifÃÂ ÃÂ you callÃÂ randomintÃÂ in exactly the the sameÃÂ moment of time,ÃÂ it canÃÂ cause some kind of bug sometimes.ÃÂ I remember this from an experiment withÃÂ changing settlersÃÂ hairstyles when using the randomint ended up so that onlyÃÂ the first settler gotÃÂ a new hairstyle and all others got the same hairstyle.ÃÂ To avoid this I used utilty.Wait(utility.RandomFloat(0, 5)) and then untility.RandomInt .ÃÂ

Then that would explain a lot of things. The variables that I store to get the amount of npcs and types of npcs are randomint determined. Not sure what to say about the timers i seen doing the same (cancelling each other to favor only one).

 

Timer idea is great but I still suspect I will see said bug :(

Link to comment
Share on other sites

Normally It should not happen with timers. Also, note please that in the example I used randomfloat , it was important to use randomfloat for the waiting, not the randomint. The bug happened with randomint. But I really don`t know why. I tested it intentionally. But timers work fine on my experince...maybe the problem was rerlated to something else. An error or failed function in a script can cause some other functions to fail.

Link to comment
Share on other sites

in order to diagnose what is going wrong with your mod you would really need to upload it somewhere so people could take a look at it. There is only so much we can figure out through the forums and by looking at code. The issue at hand is that the behavior you are describing is, to put it one way, completely antithetical to how Papyrus is designed. If the behavior you are experiencing was the norm neither Skyrim nor Fallout 4 would function at all.

Link to comment
Share on other sites

in order to diagnose what is going wrong with your mod you would really need to upload it somewhere so people could take a look at it. There is only so much we can figure out through the forums and by looking at code. The issue at hand is that the behavior you are describing is, to put it one way, completely antithetical to how Papyrus is designed. If the behavior you are experiencing was the norm neither Skyrim nor Fallout 4 would function at all.

Has to be that randomint firing at the same time. But will randomfloat do the same thing?

 

All thats in there is the globals for the script, xmarkerheading I duplicated to attach it to, and a quest for the startup message boxes. I'll upload the esp when i get home from work.

Link to comment
Share on other sites

Has to be that randomint firing at the same time. But will randomfloat do the same thing?

 

All thats in there is the globals for the script, xmarkerheading I duplicated to attach it to, and a quest for the startup message boxes. I'll upload the esp when i get home from work.

Yes, but that doesn't explain the timer issues you are experiencing. Edited by Reneer
Link to comment
Share on other sites

 

Has to be that randomint firing at the same time. But will randomfloat do the same thing?

 

All thats in there is the globals for the script, xmarkerheading I duplicated to attach it to, and a quest for the startup message boxes. I'll upload the esp when i get home from work.

Yes, but that doesn't explain the timer issues you are experiencing.

 

I haven't used a timer on the markers since I moved to using a formlist with an individual timer, I'll test that again this afternoon. With them I had 2 markers with same script (at the time script was very very basic), but only one ever pushed out an NPC, I kinda figured because timerIDs are the same (On wiki it reads they are individual per script, but I just assumed that meant the one script and not individual to multi instances.)

Link to comment
Share on other sites

 

 

Has to be that randomint firing at the same time. But will randomfloat do the same thing?

 

All thats in there is the globals for the script, xmarkerheading I duplicated to attach it to, and a quest for the startup message boxes. I'll upload the esp when i get home from work.

Yes, but that doesn't explain the timer issues you are experiencing.

 

I haven't used a timer on the markers since I moved to using a formlist with an individual timer, I'll test that again this afternoon. With them I had 2 markers with same script (at the time script was very very basic), but only one ever pushed out an NPC, I kinda figured because timerIDs are the same (On wiki it reads they are individual per script, but I just assumed that meant the one script and not individual to multi instances.)

 

I did not mean to use randomfloat instead of randomint. But creating a random pause before running randomint fixed me hairstyle script. Just in this case randomint does not fire in the exactly same moment.

Link to comment
Share on other sites

 

Â

Â

Has to be that randomint firing at the same time. But will randomfloat do the same thing?

 

All thats in there is the globals for the script, xmarkerheading I duplicated to attach it to, and a quest for the startup message boxes. I'll upload the esp when i get home from work.

Yes, but that doesn't explain the timer issues you are experiencing.

Â

I haven't used a timer on the markers since I moved to using a formlist with an individual timer, I'll test that again this afternoon. With them I had 2 markers with same script (at the time script was very very basic), but only one ever pushed out an NPC, I kinda figured because timerIDs are the same (On wiki it reads they are individual per script, but I just assumed that meant the one script and not individual to multi instances.)

Â

 I did not mean to use randomfloat instead of randomint. But creating a random pause before running randomint fixed me hairstyle script. Just in this case randomint does not fire in the exactly same moment. Â

So do you think randomfloat would do the same? I like your timer workaround but I feel like users would still make bug reports about it happening from time to time.

 

On a separate note, the FindRandomReferenceOfTypeFromRef, if I make my own marker will it pickup any ref with my base marker or will it pick up any marker. From the wiki I assume it will get my base object not just the type in general (which is what i want.) Might as well ask seems educated people are here :)

Link to comment
Share on other sites

 

 

Â

Â

Has to be that randomint firing at the same time. But will randomfloat do the same thing?

 

All thats in there is the globals for the script, xmarkerheading I duplicated to attach it to, and a quest for the startup message boxes. I'll upload the esp when i get home from work.

Yes, but that doesn't explain the timer issues you are experiencing.

Â

I haven't used a timer on the markers since I moved to using a formlist with an individual timer, I'll test that again this afternoon. With them I had 2 markers with same script (at the time script was very very basic), but only one ever pushed out an NPC, I kinda figured because timerIDs are the same (On wiki it reads they are individual per script, but I just assumed that meant the one script and not individual to multi instances.)

Â

 I did not mean to use randomfloat instead of randomint. But creating a random pause before running randomint fixed me hairstyle script. Just in this case randomint does not fire in the exactly same moment. Â

So do you think randomfloat would do the same? I like your timer workaround but I feel like users would still make bug reports about it happening from time to time.

 

On a separate note, the FindRandomReferenceOfTypeFromRef, if I make my own marker will it pickup any ref with my base marker or will it pick up any marker. From the wiki I assume it will get my base object not just the type in general (which is what i want.) Might as well ask seems educated people are here :smile:

 

I don`t have all answers. Just my experince. You can try and test , this is very easy to add a line to the script and test how it works. Some things can be checked only by testing.

 

FindRandomReferenceOfTypeFromRef will look for something you give it as an example. It should be a game id. It will look only for instances of this base object(game id).

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...