Author Topic: Teleporting self to a random player with light key  (Read 988 times)

All right, so I'm making a "Creepy Player" playertype, and I want it so that when the person playing as the creepy hits their light key (Jet is being used for something else, I'm afraid) it won't trigger their light but instead find a random player in the server (it's target) and warp the creepy to a random point that is six to twenty bricks away from the target player, and have it facing the target player after warping. How do I go about this?

You could use a raycast to search if the player is in a certain range, and if there's more than one, pick a random number for the player, do getPosition on the random player, then use setTransform on the Creepy Player.

Did you read the thing all the way?
See, when you press the light key, it gets a random player anywhere in the server, hereafter reffered to as the 'target'.
It teleports to a point a random small distance from the target.
I can remember no script stuff, so everything I make has to be copied from somewhere.

I can remember no script stuff, so everything I make has to be copied from somewhere.
So in other words you have no idea whatsoever how to make this and what you do make you will have stolen from other people's scripts?

So in other words you have no idea whatsoever how to make this and what you do make you will have stolen from other people's scripts?

More like I have no idea how to make this but I need someone to help me. I can remember some real basic stuff, but I have trouble wrapping my head around most anything else.

If I'm just gonna get flamed, I'll just lock the topic and crawl back to my corner. /outcast

Ignore them. Scripting is harder for some people to learn than others.

I've never been to amazing at geometry in 2d, let alone 3d, so I can't really help you with getting the player to face the 'target'. However, I can help you to warp them nearby.

Code: [Select]
package CreepyPlayer // We're editing a default function. We package this.
{
function serverCmdLight(%client) // When they press their light key
{
if(!isObject(%client.player)) // If they don't have a player
return; // Skip the rest of the code
if(%client.player.getDatablock().getName() !$= "PlayerCreepyData") //If they are not a creepy player
{
parent::serverCmdLight(%client); // Toggle their light
return; // Skip the rest of the code
}
if(clientGroup.getCount() < 2) //If there are no players or only 1 player on the server
return;  // Skip the rest of the script. There is no one to target.
%randomplr = getRandom(0,clientGroup.getCount()); // Get a random number corresponding to a client.
%target = clientGroup.getObject(%randomplr); // Get the client corresponding to the random number above.
if(!isObject(%target.player))
{
for(%i = 1; %i < clientGroup.getCount(); %i++)
{
%randomplr = (%randomplr + 1) % clientGroup.getCount();
if(isObject(clientGroup.getObject(%randomplr).player))
{
%target = clientGroup.getObject(%randomplr); // Set the viable target
%foundtarg = 1; // We have found a viable target
break; // Lets get out of this for loop
}
}
if(!%foundtarg) // If we didn't find a viable target
{
messageClient(%client, '', "No one is spawned!"); // Inform them no one has spawned.
return; // Skip the rest of the function
}
}
if(%target.player.getDatablock().getName() $= "PlayerCreepyData") // If the target is a creepy player
{
for(%test = 1; %test < clientGroup.getCount(); %test++)
{
%check = (%target + %test) % clientGroup.getCount(); // Get the next player (wrap around to beginning)
%checkplr = clientGroup.getObject(%check); // Get the next player's client
if(isObject(%checkplr.player)) // If the target's player exists
{
if(%checkplr.player.getDatablock().getName() !$= "PlayerCreepyData") // If the target ISN'T a creepy player
{
%target = %checkplr; // They are the new target.
%foundplr = 1; // We found a player to use as a target.
break; // Let's get out of this for loop.
}
}
}
}
if(!%foundplr) // If we didn't find a normal player
{
messageClient(%client, '', "No normal players could be found!"); // Tell them!
return; // Skip the rest of the function
}
%distx = getRandom(0, 14) + 6; // Get a number 6-20
%mul = getRandom(0,1); // Negative or positive?
if(%mul == 0) // If negative
%distx *= -1; // Make the number negative
%disty = getRandom(0, 14) + 6;
%mul = getRandom(0,1);
if(%mul == 0)
%disty *= -1;
%distz = getRandom(0, 14) + 6;
%mul = getRandom(0,1);
if(%mul == 0)
%distz *= -1;
%dist = %distx SPC %disty SPC %distz; // make the vector string
%pos = vectorAdd(%dist, %target.player.getTransform()); // Add the target's position in
%client.player.setTransform(%pos); // Move the player to that distance from the target
}
};
activatePackage(creepyPlayer); // Activate the package.

DAMN. That took longer to type up than I figured when I first started. Oh well. I hope it helps you! Fully commentated to hopefully solve all questions.
« Last Edit: February 18, 2012, 01:01:43 PM by Slicksilver »

Thanks! I think I can figure out the 'face player' thing myself. Thanks a ton!

Thanks! I think I can figure out the 'face player' thing myself. Thanks a ton!
I actually updated it again. I forgot to get a new player if the originally selected one hasn't spawned.

I actually updated it again. I forgot to get a new player if the originally selected one hasn't spawned.
Lol, that's ok, I have trouble hosting sometimes and nobody joins my servers for the most part anyway. The creepy player might wind up half-ZAPT-zombie, I like the Smoker special attack (the creepy playertype is one big renderman joke, for the most part) and use it for a shadow tendril. I figured that out for the most part, except for some bizarre item-related glitches, so I might just separate that part from ZAPT with copy+paste.

Well, new problem, now I'm getting syntax errors.


Loading Add-On: Support_Prepper (CRC:-1224997501)
Add-Ons/Support_Prepper/RendermanPlayertype.cs Line: 209 - Syntax error.
>>> Some error context, with ## on sides of error halt:
^^^%distz *= -1;

^^%dist = %distx SPC %disty SPC %distz; // make the vector string

^^%pos = vectorAdd(%dist, %target.player.getTransform()); // Add the target's position in

^^%client.player.setTransform(%pos); // Move the player to that distance from the target

^}

};##
##
activatePackage(creepyPlayer); // Activate the package.



package completelyhidenames

{

^function gameconnection::spawnplayer(%this)

^{

^^Parent::spawnPlayer(%this);

^^%this.player.setName("TEMPPLAYER");

^^%this.player = new Player(newplayer : TEMPPLAYER)
>>> Error report complete.

ADD-ON "Support_Prepper" CONTAINS SYNTAX ERRORS


Why is this a syntax error?

Code: [Select]
for(%i = 1; %i < clientGroup.getCount(); %i++)

Wouldn't this cause it to never target the first player on the server?

Actually, nevermind:

Code: [Select]
%randomplr = getRandom(0,clientGroup.getCount()); // Get a random number corresponding to a client.
-snip-
%randomplr = (%randomplr + 1) % clientGroup.getCount();
« Last Edit: February 18, 2012, 04:34:04 AM by Port »

Well, new problem, now I'm getting syntax errors.

Why is this a syntax error?

I missed a closing bracket about half way through. Fixed.