Jump to content

Using random percent


senterpat

Recommended Posts

I wrote this script, an attempt to make a "random" encounter, I did copy the base of the script from a perk effect script, and I still don't understand what the "short rv" does. Anyways when I go into game to try this out, it doesn't work (I set it up to try and make it a sure thing that they'd spawn with the below script) no npcs spawn. Can someone help me figure out this randompercent or point me to a good script to look at, or a tutorial.

 

 

 

script type: effect 

 

Scn myscript

 

Short rv

 

Begin gamemode

 

If player.isinterior == 0

Set rv to getrandompercent

Endif

 

If rv>0

Player.placeatme (npc name) 1

Elseif rv<=0 

Player.placeatme (npc name) 1

Endif

End

Edited by senterpat
Link to comment
Share on other sites

From what I can make out "rv" means whatever the script writer wants it to, which sets it to become a random number in this script. Can someone confirm this, I looked at the geck page about declaring variables, but don't really understand it. I'm also wondering if there is something I can put in that mean do nothing, i.e. :

If rv>0

(do nothing)

Edited by senterpat
Link to comment
Share on other sites

In 'Effect' type scripts, you should only use ScriptEffectStart / ScriptEffectUpdate / ScriptEffectFinish block types.

By what way are you calling this script? A token? An equipped item?

 

I would suggest you create a 'dummy' quest to call the script. Something like:

 

script type: Quest

Scn myscript

Short rv
short doonce

Begin gamemode

    if (doonce == 0) && (player.isinterior == 0)
         set doonce to 1 // you'd have to reset this if you wish the encounter to happen more than once
         Set rv to getrandompercent
         If rv > 0
              Player.placeatme (npc name) 1
         elseif rv <= 0 
              Player.placeatme (npc name) 1
         Endif
    Endif

End

Edited by pluramon
Link to comment
Share on other sites

set doonce to 0

 

also, 'Short rv' declares a local variable, named rv, of type 'short' (-32,000 to +32,000 or so). Without that, trying to access RV just gives an error as geck would not know what you mean by rv, Or it would, if geck gave errors.

Link to comment
Share on other sites

Awesome, that script worked perfectly and taught me some stuff I didnt know. Kudos to both of you. I do have a couple other questions I could fun out about with trial and error, but if you have the time it'd save me some hours.

 

1. Is there a limit to how many times you can use && to add additional conditions?

2. If two mods have a script on an object I.e. both have a script on a magazine, would that be a serious conflict, or would it be resolved in the load order?

3. I'm currently using (player.additem f 0) to tell the script "do nothing" is there a better command to use for that? Will this affect performance?

Thanks again for all yalls help.

Link to comment
Share on other sites

1) No, Only the limit of 32,000 characters in a scripts source.

2) No, it would be a minor conflict, the last loaded mod would have its script attached to the misc item while the other mod would be overridden. This would likey just make whatever feature the other mod had not work, your game will still likey run fine.

3) ... Why are you telling a script to 'do nothing'? One would assume that.. nothing would work just as well. You can also just return from a script early...

Link to comment
Share on other sites

I need to tell the script to do nothing when I use random percent, I.e.:

Scn myscript

 

Short rnd

 

Begin gamemode

 

Set rnd to getrandompercent

If rnd > 1

(do nothing)

if rnd <= 1

Player.placeatme stuff 1

 

Is leaving the space empty optional? I assumed that the geck needed a function after stating a condition.

 

Edit: o I think I see what your saying, just don't use the rnd>1 line at all. Which I should have figured out sooner. Anyways, thanks a lot for all your help.

Edited by senterpat
Link to comment
Share on other sites

  • Recently Browsing   0 members

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