Posts Tagged ‘Ghost’

Friendly Ghost Ducks

April 18th, 2009

I was aiming to produce an autonomous  dynamic enviroment developer tool for open sim.  As I had no idea what this would include I decided to start small and took the duck model supplied by Chris H and added a little script.

The first iteration  randomly chooses a direction (North, South, East or West)  and moves one meter. This repeated every second. I had to introduce a 270m boundary otherwise the ducks had a habit of trying to change sims.

float x = 82;
float y = 237.682;
float z = 22.5;
float period = 1;
float noMove = 10;
float touchCount =0;
default
{
timer()
{
list dice = [0,1,2,3,4];
integer rand = llList2Integer(llListRandomize(dice, 1),0);
vector xyz_angles = <0,0,0>;
integer i=0;
for( i=0;i<noMove;i++) {
if (rand == 0)
{
x=x+period/noMove;
if (x < 92)
{
xyz_angles = <0,0,180>;
}
else {
x=x-period/noMove;
x=x-period/noMove;
xyz_angles = <0,0,0>;
}
}
else if (rand ==1) {
x=x-period/noMove;
if (x > 71)
{
xyz_angles = <0,0,0>;
}
else {
x=x+period/noMove;
x=x+period/noMove;
xyz_angles = <0,0,180>;
}
}
else if (rand == 2) {
y=y-period/noMove;
if (y > 226)
{
xyz_angles = <0,0,90>;
}
else {
y=y+period/noMove;
y=y+period/noMove;
xyz_angles = <0,0,270>;
}
}
else if (rand==3) {
xyz_angles = <0,0,270>;
y=y+period/noMove;
if (y < 247)
{
xyz_angles = <0,0,270>;
}
else {
y=y-period/noMove;
y=y-period/noMove;
xyz_angles = <0,0,90>;
}
}
//llSay(0,(string)x+” “+(string)y+” “+(string)z);
vector angles_in_radians = xyz_angles*DEG_TO_RAD;
rotation rot_xyzq = llEuler2Rot(angles_in_radians);
llSetRot(rot_xyzq);
llSleep(period/noMove);
llSetPos(<x,y,z>);
}
}
state_entry()
{
llSetTimerEvent(period+0.5);
llSetText(” “,<1, 0, 0>,1);
}
touch_start(integer total_number)
{

string soughtName = llDetectedName(0);;
touchCount = touchCount + 1;
}
}

The second (and current) iteration of Duck allows them to be more interactive. If you talk while near the duck, it becomes scared of you (-1 modifier) however if you touch it it likes you (+1 modifier). The distance and direction it moves is connected to the accumulated modifier. If the modifier is positive it moves towards  you, if it is negative it moves away from you.

float x = 82;
float y = 237.682;
float z = 22.5;
float period = 4;
float noMove = 10;
float touchCount =0;
vector location;
string name;
list likesName = [];
list likesOpinions = [];
integer listen_handle ;
default
{
sensor( integer vIntFound )
{
if (vIntFound < 1   )
{
name = “”;
}
integer vIntCounter = 0;
location = llDetectedPos( vIntCounter ) ;
name = llDetectedName(vIntCounter);
}
timer()
{
vector oldLocation = location;
list dice = [0,1,2,3,4];
float oldPeriod = period;
llSensor( “”, “”, AGENT, 5, PI );
if (name != “”){
integer indx = llListFindList(likesName,name);
if (indx == -1) {
indx = 1;
}
integer like = llList2Integer(likesOpinions,indx);
if (like > 10 ) {
like = 10;
}
period = 15;
y = y-(y-location.y)/noMove*like;
x = x-(x-location.x)/noMove*like;
llSetPos(<x,y,z>);
//llOwnerSay(”Walking towards “+name+” “+(string)x+” “+(string)y+” “+(string)z);
name = “”;
}
else {
period = oldPeriod;
integer rand = llList2Integer(llListRandomize(dice, 1),0);
vector xyz_angles = <0,0,0>;
integer i=0;
for( i=0;i<noMove;i++) {
if (rand == 0)
{
x=x+period/noMove;
if (x < 92)
{
xyz_angles = <0,0,180>;
}
else {
x=x-period/noMove;
x=x-period/noMove;
xyz_angles = <0,0,0>;
}
}
else if (rand ==1) {
x=x-period/noMove;
if (x > 71)
{
xyz_angles = <0,0,0>;
}
else {
x=x+period/noMove;
x=x+period/noMove;
xyz_angles = <0,0,180>;
}
}
else if (rand == 2) {
y=y-period/noMove;
if (y > 226)
{
xyz_angles = <0,0,90>;
}
else {
y=y+period/noMove;
y=y+period/noMove;
xyz_angles = <0,0,270>;
}
}
else if (rand==3) {
xyz_angles = <0,0,270>;
y=y+period/noMove;
if (y < 247)
{
xyz_angles = <0,0,270>;
}
else {
y=y-period/noMove;
y=y-period/noMove;
xyz_angles = <0,0,90>;
}
}
//llSay(0,(string)x+” “+(string)y+” “+(string)z);
vector angles_in_radians = xyz_angles*DEG_TO_RAD;
rotation rot_xyzq = llEuler2Rot(angles_in_radians);
llSetRot(rot_xyzq);
llSleep(period/noMove);
llSetPos(<x,y,z>);
}
}
}
state_entry()
{
llSetPos(<x,y,z>);
llSetTimerEvent(period+0.5);
llSetText(” “,<1, 0, 0>,1);
listen_handle = llListen(0, “”, llGetOwner(), “”);
}
touch_start(integer total_number)
{
string soughtName = llDetectedName(0);
integer indx = llListFindList(likesName,soughtName);
if (indx == -1 ) {
likesName = llListInsertList(likesName, [soughtName], llGetListLength(likesName));
indx = llListFindList(likesName,soughtName);
}
integer mod = llList2Integer(likesOpinions,indx) + 1;
if (mod ==0) {
mod =1;
}
likesOpinions = llListReplaceList(likesOpinions,[mod],indx,indx);
llOwnerSay(soughtName +” likeness is set to “+mod);
touchCount = touchCount + 1;
}
listen( integer channel, string name, key id, string message )
{
string soughtName = name;
llSay(0,soughtName + ” just spoke and scared me”);
integer indx = llListFindList(likesName,soughtName);
if (indx == -1 ) {
likesName = llListInsertList(likesName, [soughtName], llGetListLength(likesName));
indx = llListFindList(likesName,soughtName);
}
integer mod = llList2Integer(likesOpinions,indx) – 1;
if (mod ==0) {
mod = -1;
}
likesOpinions = llListReplaceList(likesOpinions,[mod],indx,indx);
llOwnerSay(soughtName +” likeness is set to “+mod);
}
}

Not sure what will be done next, feedback is welcome