Jump to content

Dividing controls one one vehicle between multiple avatars


Leo1452
 Share

You are about to reply to a thread that has been inactive for 910 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I want to make a tank that seats two avatars. llAvatarOnLinkSitTarget(1) will drive the tank while llAvatarOnLinkSitTarget(2) will control the turret. I have separate scripts handle the driving and turret. The driving script only calls llRequestPermissions() on the driver avatar while the turret script only calls llRequestPermissions() on the turret avatar. I also add if-statements above all controls to make sure the key of the avatar's control is coming from the appropriate avatar. I'm clearly still missing something because both scripts still respond to the controls of both avatars. Can someone help me?

 Both scripts are in the same prim.

The driver script has these pieces to handle control:

llRequestPermissions(llAvatarOnLinkSitTarget(1), PERMISSION_TAKE_CONTROLS);

run_time_permissions(integer k)
    {
        if(k & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);
        }
    }

control(key n, integer l, integer e)
    {
        if(llAvatarOnLinkSitTarget(1) != NULL_KEY && n == llGetPermissionsKey())
		{
		}
	}

The turret script has these pieces:

llRequestPermissions(llAvatarOnLinkSitTarget(2), PERMISSION_TAKE_CONTROLS);

run_time_permissions(integer k)
    {
        if(k & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ML_LBUTTON, TRUE, FALSE);
        }
    }

control(key n, integer l, integer e)
    {
        if(llAvatarOnLinkSitTarget(2) != NULL_KEY && n == llGetPermissionsKey())
		{
		}
	}
Edited by Leo1452
code might help
Link to comment
Share on other sites

22 minutes ago, Leo1452 said:

 both scripts still respond to the controls of both avatars

 

without seeing your script then am not sure what the issue might be

a way to help see what might be happening is to check the value of key id in the control event parameters against the id of the agent for which the script has permission

control (key id, integer level, integer edge)
{
   if (id != llGetPermissionsKey())
   {
       llOwnerSay("control id is not the same as script permissions id")
   }
}

 

Link to comment
Share on other sites

38 minutes ago, Mollymews said:

 

without seeing your script then am not sure what the issue might be

a way to help see what might be happening is to check the value of key id in the control event parameters against the id of the agent for which the script has permission

control (key id, integer level, integer edge)
{
   if (id != llGetPermissionsKey())
   {
       llOwnerSay("control id is not the same as script permissions id")
   }
}

 

Both scripts are in the same prim.

The driver script has these pieces to handle control:

llRequestPermissions(llAvatarOnLinkSitTarget(1), PERMISSION_TAKE_CONTROLS);

run_time_permissions(integer k)
    {
        if(k & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);
        }
    }

control(key n, integer l, integer e)
    {
        if(llAvatarOnLinkSitTarget(1) != NULL_KEY && n == llGetPermissionsKey())
		{
		}
	}

The turret script has these pieces:

llRequestPermissions(llAvatarOnLinkSitTarget(2), PERMISSION_TAKE_CONTROLS);

run_time_permissions(integer k)
    {
        if(k & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ML_LBUTTON, TRUE, FALSE);
        }
    }

control(key n, integer l, integer e)
    {
        if(llAvatarOnLinkSitTarget(2) != NULL_KEY && n == llGetPermissionsKey())
		{
		}
	}

When I add your code to test it, "control id is not the same as script permissions id" never happens. I sat two avatars from different viewers, but no matter which avatar I control from, it registers as the driver sending controls.

Link to comment
Share on other sites

replicating the issue

two scripts

link two prims

put both script(1) and script(2) in the same prim. Sit two avatars in different viewers on the same computer

both scripts will accept control inputs from either viewer with the focus

stick script(1) and script(2) into different prims

script(1) will only accept control inputs from viewer(1). Script(2) will only accept control inputs from viewer(2)

/

/ script 1

default
{
    state_entry()
    {
        llLinkSitTarget(1,<0.0,0.0,0.5>,ZERO_ROTATION);
        llLinkSitTarget(2, <0.0,0.0,0.5>,ZERO_ROTATION);
    }

    changed(integer change)
    {
        if(change & CHANGED_LINK)
        {
            key agent = llAvatarOnLinkSitTarget(1);
            if (agent)
            {
                llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS);
            }
            else
            {
                llReleaseControls();   
            }
        }
    }
    
    run_time_permissions(integer perms)
    {
        if (perms & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);    
        }  
    }
    
    control(key id, integer level, integer edge)
    {
        llWhisper(0, llDumpList2String(["script 1", id, level, edge], " "));     
    }
}
// script 2
default
{
    changed(integer change)
    {
        if(change & CHANGED_LINK)
        {
            key agent = llAvatarOnLinkSitTarget(2);
            if (agent)
            {
                llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS);
            }
            else
            {
                llReleaseControls();   
            }
        }
    }
    
    run_time_permissions(integer perms)
    {
        if (perms & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ML_LBUTTON, TRUE, FALSE);    
        }  
    }
    
    control(key id, integer level, integer edge)
    {
        llWhisper(0, llDumpList2String(["script 2", id, level, edge], " "));      
    }
}

ps add

is a interesting effect this - both scripts in the root prim

as could control two avatars (the driver and the gunner) from the same RL keyboard.  Using the "C" and "E" keys as control keys to distinguish between the two. Example:

driver: level = W,A,S,D.  E + W,A,S,D. (8 controls)

gunner: level = C + W,A,S,D. LMB. (5 controls)

 

Edited by Mollymews
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

On 9/25/2021 at 4:39 AM, Mollymews said:

replicating the issue

two scripts

link two prims

put both script(1) and script(2) in the same prim. Sit two avatars in different viewers on the same computer

both scripts will accept control inputs from either viewer with the focus

stick script(1) and script(2) into different prims

script(1) will only accept control inputs from viewer(1). Script(2) will only accept control inputs from viewer(2)

/

/ script 1

default
{
    state_entry()
    {
        llLinkSitTarget(1,<0.0,0.0,0.5>,ZERO_ROTATION);
        llLinkSitTarget(2, <0.0,0.0,0.5>,ZERO_ROTATION);
    }

    changed(integer change)
    {
        if(change & CHANGED_LINK)
        {
            key agent = llAvatarOnLinkSitTarget(1);
            if (agent)
            {
                llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS);
            }
            else
            {
                llReleaseControls();   
            }
        }
    }
    
    run_time_permissions(integer perms)
    {
        if (perms & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);    
        }  
    }
    
    control(key id, integer level, integer edge)
    {
        llWhisper(0, llDumpList2String(["script 1", id, level, edge], " "));     
    }
}
// script 2
default
{
    changed(integer change)
    {
        if(change & CHANGED_LINK)
        {
            key agent = llAvatarOnLinkSitTarget(2);
            if (agent)
            {
                llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS);
            }
            else
            {
                llReleaseControls();   
            }
        }
    }
    
    run_time_permissions(integer perms)
    {
        if (perms & PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ML_LBUTTON, TRUE, FALSE);    
        }  
    }
    
    control(key id, integer level, integer edge)
    {
        llWhisper(0, llDumpList2String(["script 2", id, level, edge], " "));      
    }
}

ps add

is a interesting effect this - both scripts in the root prim

as could control two avatars (the driver and the gunner) from the same RL keyboard.  Using the "C" and "E" keys as control keys to distinguish between the two. Example:

driver: level = W,A,S,D.  E + W,A,S,D. (8 controls)

gunner: level = C + W,A,S,D. LMB. (5 controls)

 

So I got around to trying the scripts in separate prims, they still interfere with each other. Do you have any other suggestions?

Link to comment
Share on other sites

8 hours ago, Leo1452 said:

So I got around to trying the scripts in separate prims, they still interfere with each other. Do you have any other suggestions?

i am not able to replicate the behaviour you are observing when the scripts are in different prims

can only suggest that you do a test harness with two link prims. Stick script (1) in the root prim and script (2) in the linked prim

when the avatar on the root prim uses the controls then it should whisper/say... script 1.  and the avatar on the linked prim should whisper/say... script 2.  Each also saying the id of each avatar. Without any cross-talk

if the test harness is working as expected then replicate this in your script

if not then am not sure why it wouldn't on your computer. If it doesn't then it could be some hardware difference which I don't know about

i did the test using two instances of the Linden viewer. I don't know what the result might be with a TPV

but if you continue to experience cross-talk then you may have to go with the C+ method to distinguish between the gunner and driver. Example:

control(key id, integer level, integer edge)
{
   integer ctrl = 0;  // driver
   if ((level & CONTROL_DOWN) || (edge & CONTROL_DOWN)) // C key
      ctrl = 1;       // gunner

   if (ctrl == 1)  // gunner
   {
       if (level & CONTROL_ML_LBUTTON)  // C + left mousebutton
          ... fire cannon ...
   
       ...

   }
   else  // driver
   {
       if (level & CONTROL_FWD)  // W
          ... drive tank forward ...

       ...

   }
}

ps add

it might be that there may be more than 2 sit targets defined in the linkset, which may be confusing matters. Once set a sit target becomes a property of the prim.  So you might want to clear them all out of the linkset by looping thru all the prims in the linkset and set them to null and then set the link sit targets for the driver and gunner

 

Edited by Mollymews
  • Like 2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 910 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...