1 //originally written by Davide Byron
2 //this code is released under the GPLv3
4 // Reacts to E_AVATAR_POSITION, E_TOUCH_ID and E_COLLISION_TYPE event
5 // when a touch event is catched the creature begins to play and
6 // activates a timer to determine the game duration
7 // on every avatar position event the creature will try to run away
9 // and on a collision event it will declare the avatar winner
10 // if the timer reaches it's event the creature win and will declare it
12 // WARNING: creature must be full physical to use this (and this script will turn it so)
14 // this gaming script is a early experiment to see how people could get involved
15 // in creature social life. more scripts like this will come in the future.
17 //dedicated to Mealea, thanks for the passion you put into things and for being able to pass it on to me :)
20 integer E_AGENT_POSITION
= 1;
21 integer E_TOUCH_ID
= 7;
22 integer R_MOD_ENERGY
= 11;
23 //cage boundaries expressed in region absolute coords
24 integer CAGE_MIN_X
= 1;
25 integer CAGE_MAX_X
= 249;
26 integer CAGE_MIN_Y
= 1;
27 integer CAGE_MAX_Y
= 249;
28 integer CAGE_MIN_Z
= 1;
29 integer CAGE_MAX_Z
= 100;
36 //how far the creature can go with a single step
38 //max time to get to the target point
40 //how long does the game last
41 float GameDuration
= 120.0;
45 //avatar wich is playing with us
47 //energy gain for victory and loss
48 float VictoryEnergy
= 100.0;
49 float DefeatEnergy
= 40.0;
53 //generates a random float number ranging from -range to range
54 float myRand( float range
)
56 float sign
= llFrand(2.1);
57 float random
= llFrand( range
+ 0.1 );
67 //deny moving out of a definite cage
68 //mostly used for debug
69 vector checkCageLimit( vector pos
)
71 if( pos
.x
< CAGE_MIN_X
)
73 if( pos
.x
> CAGE_MAX_X
)
75 if( pos
.y
< CAGE_MIN_Y
)
77 if( pos
.y
> CAGE_MAX_Y
)
79 if( pos
.z
< CAGE_MIN_Z
)
81 if( llGround( pos
- llGetPos() ) > pos
.z
)
82 pos
.z
= llGround( pos
- llGetPos() ) + 0.1;
83 if( pos
.z
> CAGE_MAX_Z
)
92 //function that will calculate the movement needed to escape from
93 //a target in a given axis it's limited by the creature max step value
94 float runawayFromTarget(float creaturePos
, float targetPos
)
96 //determine if we need to move forward or backward in the axis
97 float direction
= targetPos
- creaturePos
;
100 //flee as far as you can!!!
101 creaturePos
= creaturePos
- MaxStep
;
105 //flee as far as you can!!!
106 creaturePos
= creaturePos
+ MaxStep
;
118 on_rez(integer param
)
128 //collisions are required here.
129 llSetStatus(STATUS_PHANTOM
, FALSE
);
130 llSetStatus(STATUS_PHYSICS
, TRUE
);
131 //instruct the avatars
132 llSetText("Touch me and try to catch me!", <llFrand(1.1),llFrand(1.1),llFrand(1.1)>, 1.0);
139 link_message( integer sender_num
, integer num
, string str
, key id
)
141 //if the avatar is in sight, try to run away
142 if( num
== E_AGENT_POSITION
&& AvatarKey
!= "")
144 vector targetPosition
= (vector)str
;
145 vector newPosition
= llGetPos();
147 //determine the new position
148 newPosition
.x
= runawayFromTarget( newPosition
.x
, targetPosition
.x
);
149 newPosition
.y
= runawayFromTarget( newPosition
.y
, targetPosition
.y
);
150 newPosition
.z
= newPosition
.z
+ myRand(MaxStep
);
151 newPosition
= checkCageLimit( newPosition
);
153 llLookAt( newPosition
, Force
, Dump
);
155 llMoveToTarget( newPosition
, Speed
);
158 //if the avatar touches us, the game starts if we're not already playing...
159 if( num
== E_TOUCH_ID
&& AvatarKey
== "")
161 llShout(0, "Let's see if you can catch me human! You got " + (string)GameDuration
+ " seconds");
163 //just in case other script have overruled us...
164 llSetStatus(STATUS_PHANTOM
, FALSE
);
165 llSetStatus(STATUS_PHYSICS
, TRUE
);
166 llSetTimerEvent(GameDuration
);
173 //in case the avatar don't touch the creature within the given time
177 llShout(0, "I won, you're too slow human!");
179 //and get a lot of energy for this
180 llMessageLinked(LINK_SET
, R_MOD_ENERGY
, (string)VictoryEnergy
, "");
188 //if a collision occurs
189 collision_start(integer numberDetected
)
192 if( AvatarKey
!= "" )
195 for( ; i
< numberDetected
; i
++)
197 //if one of the colliders is the avatar we're playing with
198 if( llDetectedKey(i
) == AvatarKey
)
201 llSay(0, "You won! Very fast human art thou");
203 //but the creature get a bit of energy anyway
204 llMessageLinked(LINK_SET
, R_MOD_ENERGY
, (string)DefeatEnergy
, "");