Page 1 of 1

Random objects

PostPosted: Tue May 13, 2008 6:41 pm
by D'Lanor
Remember that random Yeesha page in the Neighborhoods? Or the elusive Bahro stone by the Ferry Terminal? Here is how to make random objects like those. This code references two global Cyan Python files (without redistributing them of course).

Step 1. The Alcscript

Code: Select all
<object>:
    logic:
        modifiers:
          - tag: ProxiSensor_Enter
            cursor: nochange
            flags:
              - multitrigger
            activators:
              - type: objectinvolume
                remote: <region>
                triggers:
                  - enter
            conditions:
              - type: volumesensor
                satisfied: true
                direction: enter
            actions:
              - type: pythonfile
                ref: $RandomBool
          - tag: ProxiSensor_Exit
            cursor: nochange
            flags:
              - multitrigger
            activators:
              - type: objectinvolume
                remote: <region>
                triggers:
                  - exit
            conditions:
              - type: volumesensor
                satisfied: true
                direction: exit
            actions:
              - type: pythonfile
                ref: $RandomBool
        actions:
          - type: pythonfile
            tag: RandomBool
            pythonfile:
                file: xRandomBoolChange
                parameters:
                  - type: string
                    value: <object>Vis
                  - type: string
                    value: <object>Enabled
                  - type: string
                    value: <object>Chance
                  - type: string
                    value: <object>Proximity
                  - type: activatorlist
                    refs: ["logicmod:$ProxiSensor_Enter","logicmod:$ProxiSensor_Exit"]
                  - type: bool
                    value: true
                  - type: sceneobject
                    ref: scnobj:<object>
          - type: pythonfile
            tag: BoolShowHide
            pythonfile:
                file: xAgeSDLBoolShowHide
                parameters:
                  - type: string
                    value: <object>Vis
                  - type: bool
                    value: true

Replace <object> with the name of your object and replace <region> with the name of your region, without the <>.
Note the activatorlist under the pythonfilemods. That one was a pain to figure out. :|

You may wonder why we need a region for this. In a multiplayer environment the object could show up right under the nose of another player. A strategically placed region prevents that. As long as there is a player in the region the visibility state of the object will not change.


Step 2. The SDL variables

Code: Select all
STATEDESC MyAge
{
   VERSION 1

# Random objects
    VAR BOOL    <object>Vis[1]       DEFAULT=1  DEFAULTOPTION=VAULT
    VAR BOOL    <object>Enabled[1]   DEFAULT=1  DEFAULTOPTION=VAULT
    VAR BYTE    <object>Chance[1]    DEFAULT=50 DEFAULTOPTION=VAULT
    VAR BOOL    <object>Proximity[1] DEFAULT=0  DEFAULTOPTION=VAULT
}

Again replace <object> with the name of your object, without the <>. You can set the chance variable to any number between 0 and 100.

That is all. There is no need to program any Python script since Cyan has already done that for us. :D


Edit: I could probably turn this into a quickscript that only requires a few lines of input.

Re: Random objects

PostPosted: Wed May 14, 2008 12:54 pm
by D'Lanor
Quickscript submitted. If this is implemented I will move the tutorial to the wiki with this much shorter Alcscript *

Code: Select all
<object>:
    quickscript:
        sdl:
            type: randombool
            region: <region>


* not yet in the trunk so don't try this

Re: Random objects

PostPosted: Wed May 14, 2008 2:20 pm
by Nadnerb
Looks good. Merged. :)

Re: Random objects

PostPosted: Thu May 15, 2008 1:25 am
by Grogyan
Great work :)