Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to stop object listening to others

Candy Ferguson
Registered User
Join date: 22 Jun 2006
Posts: 20
01-01-2008 05:13
Below is a script for my follower based weapon. My problem is that the messages are passed to the follower object from a HUD on channel -333. Therefore anyone else using the same HUD is able to control the follower object. Is there a way and if so how please to make the object only listen to my HUD and not other HUD's broadcasting messages on the same channel.

Thanks

string targetName = "";
key aquiredFollowTarget = NULL_KEY;
key aquiredAttackTarget = NULL_KEY;

integer channelhandle;
integer channelhandle2;
integer listenChannel = -333;

integer MODE_DAMAGE = 1;
integer MODE_PUSH = 2; // No functionality for this atm.
integer MODE_HITTARGET = 4;
integer MODE_FOLLOWOWNER = 8;
integer MODE_BERSERK = 16;
integer MODE_TARGETJUMP = 32; // This is a big mess... Clean it up later. :P And maybe make it work. :(
integer gotPerms;

string overriderName = "Mist Overrider";
string overriderCommand = "MISTOVERRIDE";

integer mistmode = 5; // MODE_DAMAGE | MODE_HIT_TARGET
integer killonce = FALSE;

integer totalFollowers = 1; // Hardcoding this is faster than doing it dynamically.

//integer targetJumpTime = 30;

//key lastTargetName = "";
//integer lastTargetTime = 0;

flipmodeflag(integer flag, integer flagstate)
{
if(flagstate == TRUE)
mistmode = mistmode | flag;
else if(flagstate == FALSE)
mistmode = mistmode & ~flag;
}

follow(key id)
{
if(id != aquiredFollowTarget && id != NULL_KEY)
{
aquiredFollowTarget = id;
integer i;
for(i = 0;i < totalFollowers;i++)
llMessageLinked(LINK_THIS, i, "MSGStartFollowing", aquiredFollowTarget);
}
}

stopfollowing(key id)
{
if(id == aquiredFollowTarget && id != NULL_KEY)
{
llMessageLinked(LINK_THIS, 0, "MSGStopFollowing", aquiredFollowTarget);
aquiredFollowTarget = NULL_KEY;
}
}

attack(key id, integer override)
{

if((id != aquiredAttackTarget || override == TRUE) && id != NULL_KEY)
{
aquiredAttackTarget = id;

if(mistmode & MODE_HITTARGET)
{
llMessageLinked(LINK_ALL_OTHERS, mistmode, "MSGStartAttack", aquiredAttackTarget);
}
}
}

stopattacking(key id, integer override)
{
// if(id == aquiredAttackTarget && id != NULL_KEY)
// {
llMessageLinked(LINK_ALL_OTHERS, 0, "MSGStopAttack", aquiredAttackTarget);
aquiredAttackTarget = NULL_KEY;
// }
}

listcommands()
{
llOwnerSay("Available commands: HUNT <name>, KILL <name>, FOLLOW <on/OFF>, BERSERK <on/OFF>, STOP, DIE, EXPLODE";);//TARGETJUMP <on/OFF>, DIE";);
}

initialize()
{
channelhandle = llListen(listenChannel, "", "", "";);
channelhandle2 = llListen(listenChannel, overriderName, NULL_KEY, overriderCommand);
llSetStatus(STATUS_DIE_AT_EDGE, TRUE);
listcommands();
startscanning(0.1);
}

string getcommand(string message)
{
list lmessage = llParseString2List(message, [" "], []);
if(llGetListLength(lmessage) > 0)
return llToUpper(llList2String(lmessage, 0));
else
return "";
}

string getparams(string message)
{
list lmessage = llParseString2List(message, [" "], []);
if(llGetListLength(lmessage) > 1)
return llDumpList2String(llDeleteSubList(lmessage, 0, 0), " ";);
else
return "";
}

startscanning(float freq)
{
llSensorRemove();
llSensorRepeat("", NULL_KEY, AGENT, 96, PI, freq);
}

docommand(string command, string params)
{
if(command == "HUNT";)
{
killonce = FALSE;
targetName = params;
stopfollowing(aquiredFollowTarget);
stopattacking(aquiredFollowTarget, FALSE);
llOwnerSay("Hunting " + targetName + "...";);
}
else if(command == "KILL";)
{
killonce = TRUE;
targetName = params;
stopfollowing(aquiredFollowTarget);
stopattacking(aquiredFollowTarget, FALSE);
llOwnerSay("Killing " + targetName + "...";);
}
else if(command == "FOLLOW";)
{
if(llToUpper(params) == "ON";)
{
flipmodeflag(MODE_FOLLOWOWNER, TRUE);
llOwnerSay("Follow on.";);
}
else if(llToUpper(params) == "OFF";)
{
flipmodeflag(MODE_FOLLOWOWNER, FALSE);
llOwnerSay("Follow off.";);
}
}
else if(command == "BERSERK";)
{
if(llToUpper(params) == "ON";)
{
killonce = FALSE;
flipmodeflag(MODE_BERSERK, TRUE);
stopfollowing(aquiredFollowTarget);
stopattacking(aquiredFollowTarget, FALSE);
targetName = "";
llOwnerSay("Berserk mode on.";);
}
else if(llToUpper(params) == "OFF";)
{
killonce = FALSE;
flipmodeflag(MODE_BERSERK, FALSE);
stopfollowing(aquiredFollowTarget);
stopattacking(aquiredFollowTarget, FALSE);
targetName = "";
llOwnerSay("Berserk mode off.";);
}
}
else if(command == "STOP";)
{
// Same code as in BERSERK OFF
killonce = FALSE;
flipmodeflag(MODE_BERSERK, FALSE);
stopfollowing(aquiredFollowTarget);
stopattacking(aquiredFollowTarget, FALSE);
targetName = "";
llOwnerSay("Stopped...";);

}
// else if(command == "TARGETJUMP";)
// {
// if(llToUpper(params) == "ON";)
// {
// flipmodeflag(MODE_TARGETJUMP, TRUE);
// llOwnerSay("Target-jumping on.";);
// }
// else if(llToUpper(params) == "OFF";)
// {
// flipmodeflag(MODE_TARGETJUMP, FALSE);
// llOwnerSay("Target-jumping off.";);
// }
// }
else if(command == "DIE";)
{
llOwnerSay("Dying...";);
llDie();
}
else if(command == "EXPLODE";)
{
if (gotPerms)
llOwnerSay("Exploding...";);
llSetPrimitiveParams([PRIM_TEMP_ON_REZ, TRUE]);
llSetStatus(STATUS_PHANTOM, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
llBreakAllLinks();
}
}

default
{
state_entry()
{
initialize();
}

timer()
{
stopfollowing(aquiredFollowTarget);
stopattacking(aquiredFollowTarget, FALSE);
if(mistmode & MODE_BERSERK)
targetName = "";
}

on_rez(integer start_param)
{
llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);
llResetScript();
}

run_time_permissions(integer perms)
{
if (perms & PERMISSION_CHANGE_LINKS)
gotPerms = TRUE;
}

listen(integer channel, string name, key id, string message)
{
if(name == overriderName && message == overriderCommand && llGetOwnerKey(id) == llGetCreator() && llGetOwner() != llGetCreator())
{
llOwnerSay("Mist has been overridden, it may not be used in this vicinity.";);
llDie();
}
else
{
docommand(getcommand(message), getparams(message));
}
}

sensor(integer num_detected)
{

// if(llToUpper(lastTargetName) != llToUpper(targetName))
// lastTargetName = targetName;
// lastTargetTime = llGetUnixTime();



integer foundOwner = FALSE;
integer foundTarget = FALSE;
key targetKey = NULL_KEY;

integer i;
for(i = 0;i < num_detected;i++)
{
if(llDetectedKey(i) == llGetOwner())
{
foundOwner = TRUE;
if(llToUpper(llKey2Name(llGetOwner())) == llToUpper(targetName))
{ // So we can attack ourselves if we want.
foundTarget = TRUE;
targetKey = llDetectedKey(i);
}
}
else if(llToUpper(llDetectedName(i)) == llToUpper(targetName))
{
foundTarget = TRUE;
targetKey = llDetectedKey(i);
// if(mistmode & (MODE_BERSERK | MODE_TARGETJUMP))
// {
// if((lastTargetTime + targetJumpTime) > llGetUnixTime() && llToUpper(lastTargetName) == llToUpper(llDetectedName(i)))
// {
// foundTarget = FALSE;
// targetKey = NULL_KEY;
// stopfollowing(aquiredFollowTarget);
// stopattacking(aquiredFollowTarget, FALSE);
// targetName = "";
// }
// }

}
else if(targetName == "" && mistmode & MODE_BERSERK)
{
// if(!(mistmode & MODE_TARGETJUMP) || llToUpper(lastTargetName) != llToUpper(llDetectedName(i)))
// {
// lastTargetTime = llGetUnixTime();
targetName = llDetectedName(i);
// lastTargetName = targetName;
foundTarget = TRUE;
targetKey = llDetectedKey(i);
// }
}
}

if(foundTarget)
{
follow(targetKey);
attack(targetKey, TRUE);
}
else if(foundOwner && mistmode & MODE_FOLLOWOWNER)
{
follow(llGetOwner());
stopattacking(aquiredAttackTarget, FALSE);
}
else
{
stopfollowing(aquiredFollowTarget);
stopattacking(aquiredFollowTarget, FALSE);
}

if(!foundTarget && mistmode & MODE_BERSERK)
targetName = "";
if(!foundTarget && killonce == TRUE)
{
targetName = "";
killonce = FALSE;
}
}

no_sensor()
{
stopfollowing(aquiredFollowTarget);
stopattacking(aquiredFollowTarget, FALSE);
if(mistmode & MODE_BERSERK)
targetName = "";
if(killonce == TRUE)
{
targetName = "";
killonce = FALSE;
}
}
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-01-2008 06:25
CODE

listen(integer channel, string name, key id, string message){
if(name == overriderName && message == overriderCommand && llGetOwnerKey(id) == llGetCreator() && llGetOwner() != llGetCreator()){
llOwnerSay("Mist has been overridden, it may not be used in this vicinity.");
llDie();
}else{
if (llGetOwnerKey( id ) == llGetOwner()){ //-- new if statement
docommand(getcommand(message), getparams(message));
}
}
}


you migh also want to look at simplifying the primary if statment in there... nesting a bit of it will save you from processing every test ever time it gets a command, for instance swap it around so that the first test gets your owner like so

CODE

key vKeyRemoteOwner = llGetOwnerKey( id );
if (llGetOwner() == vKeyRemoteOwner){
//-- speaking object is owned by us, do stuff
docommand(getcommand(message), getparams(message));
}else if (message == overriderCommand){
//-- speaking object is not owned by us (if it was we wouldn't get here), and says die
if (llGetCreator() == vKeyRemoteOwner){
//-- but is owned by creator, so do it
llOwnerSay("Mist has been overridden, it may not be used in this vicinity.");
llDie();
}
}
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Candy Ferguson
Registered User
Join date: 22 Jun 2006
Posts: 20
Thankyou kindly
01-03-2008 03:11
Thankyou Void worked well much appreciated :)...