Blockland Forums > Modification Help
Teleporting self to a random player with light key
<< < (2/3) > >>
Slicksilver:
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: ---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.

--- End code ---

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.
YourBuddyBill:
Thanks! I think I can figure out the 'face player' thing myself. Thanks a ton!
Slicksilver:

--- Quote from: YourBuddyBill on February 17, 2012, 07:40:43 PM ---Thanks! I think I can figure out the 'face player' thing myself. Thanks a ton!

--- End quote ---
I actually updated it again. I forgot to get a new player if the originally selected one hasn't spawned.
YourBuddyBill:

--- Quote from: Slicksilver on February 17, 2012, 07:46:12 PM ---I actually updated it again. I forgot to get a new player if the originally selected one hasn't spawned.

--- End quote ---
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.
YourBuddyBill:
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?
Navigation
Message Index
Next page
Previous page

Go to full version