llShout in collision event
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
05-25-2005 09:10
Hello there, I'm making a tag game. I found Bosozoku Kato's one. But it needs that everybody taking part in wears the tag object each other. So I changed that the tag object itself would follow you when you became "IT". I was helped to make it by several ppl on the sand box. Thank you, all. But I found that I could not have the tag object say (shout) who "IT" was when someone was touched (tackled). The following is my script. // This is a tag game. // Just rez it on ground. It will stick with you. That means you're IT. // Touch (tackle) someone to pass it and run away! ;) // I refferd to Steller Sunshine's "Follow me" and Bosozoku Kato's "Tag" to make this. Thanks. // Seagel Neville
default { on_rez(integer n) { llSetPos(llGetPos() + (<0,0,0.5> * llGetRot())); llResetScript(); llSetPos(llGetPos() + (<0,0,0.5> * llGetRot())); //hehe don't ask me what I'm doing. I'm not sure but I could not help doing this. } state_entry() { vector pos = llGetPos(); llSetStatus(STATUS_ROTATE_Z, TRUE); llSetStatus(STATUS_PHYSICS, TRUE); llSleep(0.1); llMoveToTarget(pos,0.2); llSensorRepeat("","",AGENT,96,2*PI,.2); llSay(0, "Let's play tag! I'll tackle someone. Everybody, run away!"); } collision(integer num_detected) { if((llDetectedType(0) & AGENT)) { llShout(0, "**"+llDetectedName(0)+"** is IT!");
//This is the question part! llShout doesn't work at all. I don't know why. //But this collision event seems to work because the tag object change to //follow the person after bumping.
vector pos = llDetectedPos(0); vector offset =<0,0,1.7>; llMoveToTarget(pos+offset,.2); llSetRot(ZERO_ROTATION); } } sensor(integer total_number) { vector pos = llDetectedPos(0); vector offset =<0,0,1.7>; llMoveToTarget(pos+offset,.2); llSetRot(ZERO_ROTATION); } } Does anyone solve this problem? Thank you.
_____________________
 Seagel Neville 
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
05-25-2005 10:23
Try using the collision_start event rather then the collision one, it may help. ==Chris
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
05-25-2005 11:20
This looks pretty tricky. A mere collision_start would cause it to repeatedly say "I'm IT!", so you would need a conditional to make it only say it once.
How are you going to manage to hand off the flag though?
|
Hiro Turnbull
Freelance Scripter
Join date: 20 Apr 2005
Posts: 24
|
05-25-2005 11:25
I modified your code some but this should help with the collisions and allow you to pass the "TAG" around.
integer CHANNEL = 9999; integer is_it = FALSE;
default { on_rez(integer n) { llResetScript(); llSetPos(llGetPos() + (<0,0,0.5> * llGetRot())); llListen( CHANNEL, "", NULL_KEY, "" ); }
state_entry() { vector pos = llGetPos(); llSetStatus(STATUS_ROTATE_Z, TRUE); llSetStatus(STATUS_PHYSICS, TRUE); llSleep(0.1); llMoveToTarget(pos,0.2); llSensorRepeat("","",AGENT,96,2*PI,.2); llSay(0, "Let's play tag! I'll tackle someone. Everybody, run away!"); }
collision_start(integer num_detected) { if((llDetectedType(0) & AGENT)) { if(is_it == TRUE) { llShout(0, "**"+llDetectedName(0)+"** is IT!"); llShout(CHANNEL, llDetectedKey(0)); vector pos = llDetectedPos(0); vector offset =<0,0,1.7>; llMoveToTarget(pos+offset,.2); llSetRot(ZERO_ROTATION); is_it = FALSE; } } }
sensor(integer total_number) { vector pos = llDetectedPos(0); vector offset =<0,0,1.7>; llMoveToTarget(pos+offset,.2); llSetRot(ZERO_ROTATION); }
listen( integer channel, string name, key id, string message ) { if ( (key) message == llGetOwner() ) { llSetTimerEvent(5); Give the person who just tagged the new IT time to get away } }
timer() { is_it = TRUE; llSetTimerEvent(0); } }
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
05-25-2005 11:40
Ugh. This bit of code is all wrong: listen( integer channel, string name, key id, string message ) { if ( (key) message == llGetOwner() ) { llSetTimerEvent(5); //Give the person who just got tagged time to get away } }
Comments are preceded by "//". Typecasting a message to a key will not make it give you the owner's key. Also, setting a timer event would not pause the script. What you really want is: listen( integer channel, string name, key id, string message ) { if ( id == llGetOwner() ) { llSleep(5); //Give the person who just got tagged time to get away } }
Or, even better, make it only listen for the owner in the first place, by doing this: llListen( CHANNEL, "", llGetOwner(), "" );
Hope that helps...
|
Hiro Turnbull
Freelance Scripter
Join date: 20 Apr 2005
Posts: 24
|
05-25-2005 11:47
From: Keknehv Psaltery Ugh. This bit of code is all wrong: listen( integer channel, string name, key id, string message ) { if ( (key) message == llGetOwner() ) { llSetTimerEvent(5); //Give the person who just got tagged time to get away } }
Comments are preceded by "//". Typecasting a message to a key will not make it give you the owner's key. Also, setting a timer event would not pause the script. What you really want is: listen( integer channel, string name, key id, string message ) { if ( id == llGetOwner() ) { llSleep(5); //Give the person who just got tagged time to get away } }
Or, even better, make it only listen for the owner in the first place, by doing this: llListen( CHANNEL, "", llGetOwner(), "" );
Hope that helps... Type casting the message to a key will give a key. I promise I use it in a script. Here is what happens. The person who is "IT" collides with another person. It the broadcasts on channel 9999 that it collided with key so an so. That key is then received by everyone listening on channel 9999. If the (key) message == llGetOwner(). Then in 5 seconds their is_it flag turns to true. I promise that code works. I use it in a game I created. Plus you don't want to listen to the owner because how do you know if the person colliding with you is_it or not. You want to listen to everyone. Also I am not pausing the script. The only way it broadcasts is if the person colliding is_it. If they are not it it will never broadcast. Thus no spam. As soon as you tag someone you stop broadcasting.
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
05-25-2005 15:48
That almost makes sense. So everyone has one of these tag balls above them?
|
Douglas Callahan
Fresh Prince Of SL
Join date: 2 Jul 2004
Posts: 349
|
05-25-2005 16:17
llDetectedName() gives the name of an OBJECT that comes in contact, if you need the name of the person, do this: llShout(0,"**" + llKey2Name(llDetectedKey(0)) + "** is IT); if it is an object thay is coming in contact with it, and you want the owner of that object, then use: llShout(0,"**" + llKey2Name(llDetectedOwner(0)) + "** is IT);
_____________________
Other than that, Mrs. Lincoln, how was the play?
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
05-25-2005 20:05
Thanks all. Christopher, I've tried aslo "collision_start" but it has not worked, either. Keknehv, thanks for adivice and proceeding. Hiro, I'll try your modified code after coming home. Douglas, that line was the same with Bosozoku's. I made sure that llDetectedName would give us the name of Avatar. And also it is used by collision_start example.
_____________________
 Seagel Neville 
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
05-26-2005 07:20
Hi Hiro, It seems not to work. What is worse is that it was hard for the person to turn to be "IT". BTW, you uses llGetOwner, but I think that the tag object just following is not change owner, isn't it?
_____________________
 Seagel Neville 
|
Hiro Turnbull
Freelance Scripter
Join date: 20 Apr 2005
Posts: 24
|
05-26-2005 09:13
I was thinking that everyone playing would be wearing their own unique object with this script. I mis-understood. My bad.
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
05-26-2005 10:02
It seems to be fundamentally my fault. Collision event doesn't work at all on my code. The tag object changes the person whom it follows when you tackle him, but it just follows the closest person at that time. I mean, it works in trouble by chance! It might be too difficult to let it say who "IT" is on my plan. Though I hated that everybody should wear some special objects, I was told today by someone who was posted my tag object which I lost on the sandbox to be reported abuse. 
_____________________
 Seagel Neville 
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
05-26-2005 11:22
To prevent this sort of thing, make sure that it has a definite bounding box for where it can tag people. Perhaps have two vectors that outline a box that it will not go outside, and then have a function "IsInBox( vector pos )" that will return true if the specified location is within the bounding box.
Also, consider making it return itself to the owner 30 minutes after being rezzed.
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
05-26-2005 21:10
Hello Keknehv, Thank you for caring about this. I know where you're coming from. But the half of this game consists of mischief.  OK, if my hypothesis that the collison event doesn't work at all is right, I don't need that event section any more. But I wonder why llDetectedPos is stable until I tackle someone, that is, I don't know why the target changes by llMoveToTarget. Does this make sense? I don't think so. I can't try it now though. sensor(integer total_number) { vector pos = llDetectedPos(0); vector offset =<0,0,1.7>; string IT = llDetectedName(0); llMoveToTarget(pos+offset,.2); llSetRot(ZERO_ROTATION); llSleep(0.5); if(IT != llDetectedName(0)); { llShout(0, "Now, **"+llDetectedName(0)+"** is IT!"); } }
_____________________
 Seagel Neville 
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
05-27-2005 05:13
sensor(integer total_number) { vector pos = llDetectedPos(0); vector offset =<0,0,1.7>; string IT = llDetectedName(0); llMoveToTarget(pos+offset,.2); llSetRot(ZERO_ROTATION); llSleep(0.5); if(IT != llDetectedName(0)); { llShout(0, "Now, **"+llDetectedName(0)+"** is IT!"); } } That's not quite right. The sensor event is called once every sensor, and the data that it has does not change during the event. On subsequent calls it may change, but not during evaluation. What you really want is to have IT be a global variable (define it in the beginning), and then do this bit of code with a sensor repeat:
string IT;
//Other stuff
sensor(integer total_number) { vector pos = llDetectedPos(0); vector offset =<0,0,1.7>; if(IT != llDetectedName(0)) { IT = llDetectedName(0); llShout(0, "Now, **"+llDetectedName(0)+"** is IT!"); } llMoveToTarget(pos+offset,.2); llSetRot(ZERO_ROTATION); }
|
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
|
05-27-2005 11:13
Hello Keknehv, Thank you very much. It works fine. Just one thing, it doesn't need ";" in the end of "if" line.  I was stuck with it for long time because it could compile without any caution. 
_____________________
 Seagel Neville 
|
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
|
05-27-2005 15:29
Whoops, there is one example of the dangers of posting scripts before trying to make them work 
|