Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

SetPrimitiveParamsAdv v1.0

Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
06-17-2004 21:03
1.75 is NOT SL 1.5 compatible expect a new version shortly (probably after 1.5.2 as i want the build tools to stablize).

-----------------------------------------

Version 1.75
SetPrimitiveParamsAdv is a that adds extra functionality to llSetPrimitiveParams(). I wrote it mainly so i could use a single short statement to set all the paramaters of a prim via the PRIM_TYPE_ADV. It's fully expandable to add your own types. The constants can have their values changed without effecting the code (just don't change them unless you know what will happen as they will override any other constant on that value). To disable a constant just set it negative (ie multiply by -1). We do enforce types even though it's not totaly nessesary. It returns an integer that is an error code.

I've been using this in conjunction with auto rezzers.

i'm teetering on the edge of adding flags for more physical operations. My current stance on the issue is that you should use the remote access script pin flag and send it another script.

New flags are:
  1. PRIM_TYPE_ADV
  2. PRIM_POS
  3. PRIM_STATUS
  4. PRIM_SCRIPT_PIN
  5. PRIM_SLEEP
  6. PRIM_JITTER
  7. PRIM_TEXTURE_ANIM
  8. PRIM_TARGET_OMEGA
  9. PRIM_CREATE_LINK
  10. PRIM_BREAK_LINK
  11. PRIM_NAME
  12. PRIM_SHOUT
  13. PRIM_EMAIL
  14. PRIM_XMLRPC
  15. PRIM_TEXT
  16. PRIM_DIE
  17. PRIM_STRIP


CODE
[PRIM_TYPE_ADV, PRIM_TYPE_*, v cut, f hollow, f twist, v topsize, v topshear, v advanced_cut, float flag]
[PRIM_POS,vector position]
[PRIM_STATUS, integer flags, integer enabled]
[PRIM_SCRIPT_PIN, integer pin]
[PRIM_SLEEP, float sleep]
[PRIM_JITTER, float sleep]
[PRIM_TEXTURE_ANIM, integer mode, integer face, integer sizex, integer sizey, float start, float length, float rate]
[PRIM_TARGET_OMEGA, vector axis, float spinrate, float gain]
[PRIM_CREATE_LINK, key target, integer root]
[PRIM_BREAK_LINK, integer link_number]
[PRIM_NAME, string name]
[PRIM_SHOUT, integer chan, string message]
[PRIM_EMAIL, string address, string subject, string message]
[PRIM_XMLRPC]
[PRIM_TEXT, string text, vector color, float alpha]
[PRIM_DIE]
[PRIM_STRIP]


PRIM_TEXT sets the floating text over the prim.

PRIM_DIE causes the prim to die.

PRIM_STRIP removes the active script from the prim.

PRIM_JITTER changes the prim's size then changes it back. This can help stablize the physics engine.

PRIM_SLEEP causes a sleep to take place between executing blocks of code. This can help stablize the physics engine.

PRIM_COMM was removed, i saw little reason for it and it simplified the code a bunch.

PRIM_NAME sets the object name

PRIM_SCRIPT_PIN sets the remote access pin for the object.

PRIM_TYPE_ADV is a replacement for PRIM_TYPE as it chains multiple PRIM_TYPE calls togeather to let you make a prim with all the attributes you want.
The "flag" variable should always be greater then zero. A good value is 1. Flag is used as a spacer between calls, and at this point SL is not stable enought to support disabling this.
llSleep(llAbs(flag))
if(flag>0) jitter;

CODE
//Version 1.75
//Coded by Strife Onizuka
//Released under LGPL (GNU Lesser General Public License)
//http://www.gnu.org/copyleft/lesser.html

//PRIM_POS is a little buggy with multiple sims.

//to override a default flag just set the flag you want it to override with it's value.
//so to replace PRIM_TYPE with PRIM_TYPE_ADV just set PRIM_TYPE_ADV=PRIM_TYPE
//don't set any of the new flags equal to each other.
//if PRIM_JITTER==PRIM_SLEEP then both will become jitter.

//these flags are currentlly located around the defalut flag table that LSL uses
//free flags are [9,10,11,12,13,14,15,16,20,20+]
//we are using [9,10,11,12,13,14,15,16, 20,21,22,23,24,25,26,27,28]


integer PRIM_POS=9; //don't use to send to exact sim boarders
integer PRIM_TYPE_ADV=10;
integer PRIM_STATUS=11;

integer PRIM_SCRIPT_PIN=12;
integer PRIM_SLEEP=13;

integer PRIM_JITTER=14;
integer PRIM_TEXTURE_ANIM=15;
integer PRIM_TARGET_OMEGA=16;

integer PRIM_BREAK_LINK=20;
integer PRIM_CREATE_LINK=21;

integer PRIM_NAME=22;

integer PRIM_SHOUT=23;
integer PRIM_EMAIL=24;
integer PRIM_XMLRPC=25; //i'm not coding this one... currently throws error code 4xxx.

integer PRIM_TEXT=26;
integer PRIM_DIE=27; //finaly found a reason to add this.
integer PRIM_STRIP=28;

integer PRIM_DAMAGE=-42;

integer ADVANCED_CUT_ON_ALL_PRIMS=FALSE;
integer SPPAI; //set to equal 2 to silence message.

//[PRIM_TYPE_ADV, PRIM_TYPE_*, v cut, f hollow, f twist, v topsize, v topshear, v advanced_cut, float flag]
//llSleep(llAbs(flag))
//if(flag>0) jitter;
//
//[PRIM_POS,vector position]
//[PRIM_STATUS, integer flags, integer enabled]
//[PRIM_SCRIPT_PIN, integer pin]
//[PRIM_SLEEP, float sleep]
//[PRIM_JITTER, float sleep]
//[PRIM_TEXTURE_ANIM, integer mode, integer face, integer sizex, integer sizey, float start, float length, float rate]
//[PRIM_TARGET_OMEGA, vector axis, float spinrate, float gain]
//[PRIM_CREATE_LINK, key target, integer root]
//[PRIM_BREAK_LINK, integer link_number]
//[PRIM_NAME, string name]
//[PRIM_SHOUT, integer chan, string message]
//[PRIM_EMAIL, string address, string subject, string message]
//[PRIM_XMLRPC] //not implemented will throw error code 4xxx
//[PRIM_TEXT], string text, vector color, float alpha
//[PRIM_DIE],
//
//return codes
//0 == no problems
//yxxx
//xxx == the position in the list the error was found at. counting starts at 1
//y table
//1 == bad flag type
//2 == unrecognized flag
//3 == data type match failure
//4 == xml-rpc not implemented
//5 == unrecognized prim type
//6 == PERMISSION_CHANGE_LINKS permission needed

//don't modify these except through addflag.
list types;
list badflags;
list ruletypes;
list shapes=[5,5,5,3,6,4,0];


list VecMod(vector v,float d)
{
vector a=v/d;
a.x=llFloor(a.x)*d;
a.y=llFloor(a.y)*d;
a.z=llFloor(a.z)*d;
v-=a;
return [a,v];
}

float rs()
{
return llFrand(0.11)+0.9;
}

//flag is the value that identifies the type in the list.
//rt is the types of the paramaters for the flag.
//passing a negative number as the first entry disables the check,
//the negative number needs to be the number of paramaters.
//giving a negative number will assume it's on hte badflags list.
//for a normal check just use a list of the types of the paramaters.
addflag(integer flag, list rt)
{
integer a=llListFindList(types,[flag]);
integer b;
if(llList2Integer(rt,0)>0)
{
integer d;
for(d=llGetListLength(rt);d;d--)
b=b*8+llList2Integer(rt,d - 1);
}
else
b=llList2Integer(rt,0);
if(-1==a)
{
ruletypes+=b;
types+=flag;
}
else
ruletypes = llListInsertList( llDeleteSubList( ruletypes, a, a ), , a);
}

evilflag(integer flag)
{
if(-1==llListFindList(badflags,[flag]))
badflags+=flag;
}

saylist(list a)
{
integer b=1;
b=-llGetListLength(a)+1;
if(b!=1)
{
string c=llList2String(a,0);
while (b) c+=","+llList2String(a,b++);
llSay(0,c);
}
}

initSPPAI()
{
types=ruletypes=[];

evilflag(PRIM_SIZE);
evilflag(PRIM_TYPE);
// evilflag(PRIM_XMLRPC);

addflag(PRIM_TYPE,[TYPE_INTEGER]);
addflag(PRIM_MATERIAL,[-1]);

addflag(PRIM_PHYSICS,[-1]);
addflag(PRIM_TEMP_ON_REZ,[-1]);
addflag(PRIM_PHANTOM,[-1]);

addflag(PRIM_POSITION,[-1]);
addflag(PRIM_SIZE,[TYPE_VECTOR]);

addflag(PRIM_ROTATION,[-1]);

addflag(PRIM_TEXTURE,[-5]);
addflag(PRIM_COLOR,[-3]);
addflag(PRIM_BUMP_SHINY,[-3]);

addflag(PRIM_STRIP,[]);
addflag(PRIM_DIE,[]);
addflag(PRIM_XMLRPC,[]);
addflag(PRIM_POS,[TYPE_VECTOR]);
addflag(PRIM_NAME,[TYPE_STRING]);
addflag(PRIM_SLEEP,[TYPE_FLOAT]);
addflag(PRIM_JITTER,[TYPE_FLOAT]);
addflag(PRIM_DAMAGE,[TYPE_FLOAT]);
addflag(PRIM_SCRIPT_PIN,[TYPE_INTEGER]);
addflag(PRIM_BREAK_LINK,[TYPE_INTEGER]);

addflag(PRIM_SHOUT,[TYPE_INTEGER, TYPE_STRING]);
addflag(PRIM_TEXT,[TYPE_STRING, TYPE_VECTOR, TYPE_FLOAT]);
addflag(PRIM_EMAIL,[TYPE_STRING, TYPE_STRING, TYPE_STRING]);

addflag(PRIM_STATUS,[TYPE_INTEGER, TYPE_INTEGER]);
addflag(PRIM_CREATE_LINK,[TYPE_KEY, TYPE_INTEGER]);

addflag(PRIM_TARGET_OMEGA,[TYPE_VECTOR, TYPE_FLOAT, TYPE_FLOAT]);
addflag(PRIM_TEXTURE_ANIM,[TYPE_INTEGER, TYPE_INTEGER, TYPE_INTEGER, TYPE_INTEGER,
TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT]);
addflag(PRIM_TYPE_ADV,[TYPE_INTEGER, TYPE_VECTOR, TYPE_FLOAT, TYPE_FLOAT,
TYPE_VECTOR, TYPE_VECTOR, TYPE_VECTOR, TYPE_FLOAT]);
SPPAI=SPPAI|1;
// saylist(ruletypes);
// saylist(types);
}

list mapper(vector start, vector goal, vector globaloffset)
{
return [start,goal];
}

integer SetPrimitiveParamsAdv(list rule)
{
// llSay(0,"---";);
if((SPPAI&1)==0) initSPPAI();
integer a;
integer b;
integer c;
integer p;
integer r;
list t;
vector size=llGetScale();
while(a<llGetListLength(rule))
{
if (llGetListEntryType(rule,a)!=TYPE_INTEGER)
return a+1+1000;
b=llList2Integer(rule,a);
c=llListFindList(types,);
if(c==-1)
return a+1+2000;
r=llList2Integer(ruletypes+[0],c);
if(-1==llListFindList(badflags,) && r>=0)
{
llSetPrimitiveParams(t);
t=[];
}
if(r>0)
{
for(c=1;r;r/=8,c++)
if(llGetListEntryType(rule,a+c)!=(r%8))
return c+a+1+3000;
}
else
c=llAbs(r - 1);

if (b==PRIM_DIE)
llDie();
else if (b==PRIM_XMLRPC)
return a+1+4000;
else if(b==PRIM_DAMAGE)
llSetDamage(llList2Float(rule,a+1));
else if (b==PRIM_STRIP)
llRemoveInventory(llGetScriptName());
else if(b==PRIM_NAME)
llSetObjectName(llList2String(rule,a+1));
else if(b==PRIM_SCRIPT_PIN)
llSetRemoteScriptAccessPin( llList2Integer(rule,a+1));
else if(b==PRIM_SHOUT)
llShout(llList2Integer(rule,a+1), llList2String(rule,a+2));
else if(b==PRIM_STATUS)
llSetStatus(llList2Integer(rule,a+1), llList2Integer(rule,a+2));
else if(b==PRIM_EMAIL)
llEmail(llList2String(rule,a+1), llList2String(rule,a+2), llList2String(rule,a+3));
else if(b==PRIM_TEXT)
llSetText(llList2String(rule,a+1), llList2Vector(rule,a+2), llList2Float(rule,a+3));
else if(b==PRIM_TARGET_OMEGA)
llTargetOmega(llList2Vector(rule,a+1), llList2Float(rule,a+2), llList2Float(rule,a+3));
else if(b==PRIM_TEXTURE_ANIM)
llSetTextureAnim(llList2Integer(rule,a+1), llList2Integer(rule,a+2),
llList2Integer(rule,a+3), llList2Integer(rule,a+4),
llList2Float(rule,a+5), llList2Float(rule,a+6), llList2Float(rule,a+7));
else if(b==PRIM_BREAK_LINK || b==PRIM_CREATE_LINK)
{
if ((llGetPermissions()&PERMISSION_CHANGE_LINKS)==0)
return a+1+6000;
else if(b==PRIM_BREAK_LINK)
{
if(!(r=llList2Integer(rule,a+1)))
r=llGetLinkNumber();
llBreakLink(r);
}
else
llCreateLink(llList2Key(rule,a+1), llList2Integer(rule,a+2));
}
else if(b==PRIM_JITTER || b==PRIM_SLEEP)
{
float dkdk=llList2Float(rule,a+1);
if (b==PRIM_JITTER)
{
llSetPrimitiveParams(t+[PRIM_SIZE,size*rs()]);
llSleep(dkdk);
llSetPrimitiveParams([PRIM_SIZE,size]);
t=[];
}
else
llSleep(dkdk);
}
//there is a compiler issue with having many else if's so we have to break it up; god what i would do for a switch.
if(1+llListFindList([ PRIM_DIE, PRIM_XMLRPC, PRIM_STRIP, PRIM_NAME, PRIM_TEXT,
PRIM_SCRIPT_PIN, PRIM_SHOUT, PRIM_TARGET_OMEGA, PRIM_STATUS,
PRIM_EMAIL, PRIM_TEXTURE_ANIM, PRIM_BREAK_LINK, PRIM_CREATE_LINK,
PRIM_DAMAGE, PRIM_JITTER, PRIM_SLEEP],));
//put any custom flags handlers after here.
else if(b==PRIM_POS)
{
vector g=llGetRegionCorner();
vector h;
list i;
list j=mapper(llGetPos(),llList2Vector(rule,a+1),g);
vector m;
for(r=0;r+1<llGetListLength(j);r++)
{
i=VecMod(llList2Vector(j,r+1),256);
h=llVecNorm(llList2Vector(j,r+1) - llList2Vector(j,r))*11;
while(llVecDist(llGetRegionCorner(), g + llList2Vector(i,0))>128)
llSetPrimitiveParams([PRIM_POSITION, llGetPos() + h]);
m=llList2Vector(i,1);
while(llGetPos()!=m)
llSetPrimitiveParams([PRIM_POSITION,m]);
}
}
else if(b==PRIM_TYPE_ADV)
{
r = llList2Integer(rule,a+1);
float twist = llList2Float(rule,a+4);
vector topsize = llList2Vector(rule,a+5);
vector topshear = llList2Vector(rule,a+6);
vector advanced_cut=llList2Vector(rule,a+7);
float flag = llList2Float(rule,a+8);
list f;
list g;
list h=[PRIM_TYPE,r, llList2Vector(rule,a+2), llList2Float(rule,a+3)];
if (1+llListFindList([PRIM_TYPE_BOX, PRIM_TYPE_CYLINDER, PRIM_TYPE_PRISM],[r]))
{
if(advanced_cut.x!=0 || advanced_cut.y!=0)
{
if(ADVANCED_CUT_ON_ALL_PRIMS)
{
f=[PRIM_TYPE,PRIM_TYPE_CYLINDER,<0,1,0>,0.0,0.0,<1,1,0>,<0,0,0>];
g=[PRIM_TYPE,PRIM_TYPE_TORUS,<0,1,0>,0.0,0.0,1.0,<0,0,0>,advanced_cut];
}
else if((SPPAI&2)==0)
{
SPPAI=SPPAI|2;
llSay(0,"Advanced cut is not supported for this prim type at this time :-/";);
}
}
h+=[twist,topsize,topshear];
}
else if (r==PRIM_TYPE_SPHERE)
{
if(twist!=0 || topsize.z != 1 || topshear.z != 1)
f=[PRIM_TYPE,PRIM_TYPE_CYLINDER,<0,1,0>,0.0,twist,topsize,topshear];
h+=[advanced_cut];
}
else if (r==PRIM_TYPE_TORUS)
{
if(topsize.z != 1)
f=[PRIM_TYPE,PRIM_TYPE_CYLINDER,<0,1,0>,0.0,0.0,topsize,<0,0,0>];
h+=[twist,topsize.y,topshear,advanced_cut];
}
else if (r==PRIM_TYPE_TUBE)
{
if(twist!=0 || topsize.z != 1 || topshear.z != 1)
f=[PRIM_TYPE,PRIM_TYPE_CYLINDER,<0,1,0>,0.0,0.0,topsize,topshear];
if(ADVANCED_CUT_ON_ALL_PRIMS)
{
t=f;
f=[PRIM_TYPE,PRIM_TYPE_SPHERE,<0,1,0>,0.0,advanced_cut];
g=[PRIM_TYPE,PRIM_TYPE_CYLINDER,<0,1,0>,0.0,0.0,topsize,topshear];
if (flag>0)
{
f+=[PRIM_SIZE,size*rs()];
g+=[PRIM_SIZE,size*rs()];
}
}
else if((SPPAI&2)==0)
{
SPPAI=SPPAI|2;
llSay(0,"Advanced cut is not supported for this prim type at this time :-/";);
}
h+=[twist,topsize.y];
}
else
return a+2+5000;
if(flag != 0)
{
if(llGetListLength(f))
{
llSetPrimitiveParams(t);//saylist(t);
if(flag>0)
{
f+=[PRIM_SIZE,size*rs()];
h+=[PRIM_SIZE,size*rs()];
}
llSleep(llFabs(flag));
llSetPrimitiveParams(f);//saylist(f);
if(llGetListLength(g))
{
if(flag>0)
g+=[PRIM_SIZE,size*rs()];
llSleep(llFabs(flag));
llSetPrimitiveParams(g);//saylist(g);
}
llSleep(llFabs(flag));
llSetPrimitiveParams(h);//saylist(h);
llSleep(llFabs(flag));
}
else if (llGetListLength(g))
{//no code leads to this but it should still be kept.
if(flag>0)
{
g+=[PRIM_SIZE,size*rs()];
h+=[PRIM_SIZE,size*rs()];
}
llSetPrimitiveParams(t);//saylist(t);
llSleep(llFabs(flag));
llSetPrimitiveParams(g);//saylist(g);
llSleep(llFabs(flag));
llSetPrimitiveParams(h);//saylist(h);
llSleep(llFabs(flag));
}
else
{
if(flag>0)
h+=[PRIM_SIZE,size*rs()];
llSetPrimitiveParams(t);//saylist(t);
llSleep(llFabs(flag));
llSetPrimitiveParams(h);//saylist(h);
llSleep(llFabs(flag));
}
t=f=g=h=[];
if(flag>0)
t=[PRIM_SIZE,size];
}
else
t+=f+g+h;
}// end of PRIM_TYPE_ADV
else
{
if (b==PRIM_SIZE)
size=llList2Vector(rule,a+1);
else if (b==PRIM_TYPE)
c+=llList2Integer(shapes, llList2Integer(rule,a+1));
t+=llList2List(rule,a,a + c - 1);
}
a+=c;
}
if (llGetListLength(t))
llSetPrimitiveParams(t);//saylist(t);
return 0;
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
06-21-2004 16:42
bump and update,

new flags, new structure, and a few new bugs, but most of them i've fixed.

needs testing:
PRIM_TYPE_ADV
PRIM_POS

everything else should work fine.

needs work:
list mapper(vector start, vector goal, vector globaloffset)

it's a function that takes two vectors in the start and goal, with a globaloffset. Returns a list of vectors that form a route between the points. Currently i haven't writen this function, so it just returns the start and goal vectors.

to add your own functions:
  1. Declaire the flag globaly "integer PRIM_CUSTOM=99;
  2. in initSPPAI() add a new addflag(); "addflag(PRIM_CUSTOM,[TYPE_INTEGER,TYPE_VECTOR]);"
  3. patch your code into SetPrimitiveParamsAdv
    [/list=1]

    note:
    there is a limit of 10 variables for a flag. If needed it can be increased to 11.

    1.75 notes:
    PRIM_TYPE_ADV seems to be stable.
    PRIM_POS seems to have a tiny bug in it, gets stuck in the loop (or SL is bugged); might add functionanlity to keep it from looping infinately.
    Changes made to the core from 1.6 to 1.7 seem to have gone over well. (changes were made so single flags that didn't require values would evaluate proplerly, ie die & strip)

    future flags
    PRIM_MESSAGE_LINK
    PRIM_LOCAL_POSITION
    PRIM_LOCAL_ROT
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey