Content Scripting Python Sit
From RexWiki
Preface
This page shows how to create a script which can be used to set the sitting values for prims dynamically using rex tab's data field. You can use the same script for all prims and just modify the rex data to change the parameters.
To use this script:
- Make sure server is down
- Add the python class from below to "\rexserver\ScriptEngines\PythonScript\Samples" folder to a file named samplesit.py
- Open "\rexserver\ScriptEngines\PythonScript\Samples\__init__.py" file and add samplesit.py to the end of the list
- Start servers
- Create a prim and define "samplesit.Sit" for it's Class Name.
- Add to Rex tab-> Data the correct parameters (see below). Remember to press the Set button below the Data to set it.
- Stop editing the prim.
- Touch the primitive to update the parameters to it.
- Sit on the prim to test the parameters
- If not happy with the parameters, go back to step 6
As a side note, the sit data parameters are also set to the primitive when the server is started (see below in the python script the function EventCreated). So you don't have to go touching all your sit objects when the server starts.
Rex data
The following text is a sample for Rex tab->Data. If you set these values to a standard cude prim you created, the avatar should sit on top of it quite well.
Can you sit on me?
Please sit.
1 0.2 0.2 1
0.0 0.0 1.1
0 0 180
Parameter descriptions line by line are as follows:
- Line 1: Text on top of the prim
- Line 2: Sit text inside the revolver menu
- Line 3: Top text color R,G,B,A
- Line 4: Location offset X,Y,Z
- Line 5: Rotation offset (rotations around the 3 axes in Z, Y, X order) in degrees.
Python script
The following python script should be added to a file named samplesit.py.
import rxactor
import sys
import clr
asm = clr.LoadAssemblyByName('OpenSim.Region.ScriptEngine.Common')
Vector3 = asm.OpenSim.Region.ScriptEngine.Common.LSL_Types.Vector3
class Sit(rxactor.Actor):
def GetScriptClassName():
return "samplesit.Sit"
def EventCreated(self):
super(self.__class__,self).EventCreated()
print "samplesit.Sit EventCreated"
self.SetValues()
def EventTouch(self,vAvatar):
self.SetValues()
def SetValues(self):
# Parse rex prim data separated by any white space character
myfreedata = self.rexGetPrimFreeData()
paramlistlines = myfreedata.splitlines()
ontoptext = paramlistlines[0]
sittext = paramlistlines[1]
tempparams = paramlistlines[2].split()
ontopcolor = Vector3(float(tempparams[0]),float(tempparams[1]),float(tempparams[2]))
ontopalpha = float(tempparams[3])
del tempparams[:]
tempparams = paramlistlines[3].split()
sitlocationoffset = Vector3(float(tempparams[0]),float(tempparams[1]),float(tempparams[2]))
del tempparams[:]
tempparams = paramlistlines[4].split()
sitrotationoffset = self.llEuler2Rot(Vector3(float(tempparams[0]),float(tempparams[1]),float(tempparams[2]))*0.01745329238)
# Set values
self.llSetText(ontoptext,ontopcolor,ontopalpha)
self.llSetSitText(sittext)
self.llSitTarget(sitlocationoffset, sitrotationoffset)
|