Author Topic: [Help] Leveling System, Code on Spawn, Schedules, Teleportation  (Read 4575 times)

But for some reason, I can't do %client.player. Every time I do, it returns nothing.
Because you're trying to reference the player before it's been created.
parent::spawnPlayer(%this); will call the original version of the code, which is what is creating the player. You need that line before the rest of the code


Edit: I'm also wondering how I'd go about making a player faster while in midair-- air control, basically. You'd walk the normal speeds on ground, but really fast in the air. I have no idea how to approach this, and if the answer is really convoluted then just tell me so.
There's a preexisting datablock field for this, I don't remember the name. .dump a playertype datablock and look around, or I'm pretty sure there's a playertype that already does this that you could look at.

Edit 2: I was working and trying to set up a system so when you hold your light key, your maxForwardSpeed is increased. I couldn't figure out how to do that, since it was a dash between useLight which tells you when it is being pressed and isn't, and servercmdLight which allows you to access the client. So, I thought of the next best thing, schedules. Even through extensive searching, I'm still not quite sure how to format them. Here's my try at it:
This can't be done without a client-side add-on.
useLight is a client-side function, you can't make server-side add-ons referencing it because they'll only work for the host of a listen server

   schedule(5000, 0, evalSlowDown, %client);
    function evalSlowDown(%client)
    {
        %client.player.setmaxForwardSpeed(20);
    }[/tt]
This can be replaced with %client.player.schedule(5000,setmaxForwardSpeed,20);

u wot m(18/2)-1 ?

Off topic: in my head, this evaluated as the result of function m being called with the parameter 9 minus one.

Off topic: in my head, this evaluated as the result of function m being called with the parameter 9 minus one.

http://knowyourmeme.com/memes/u-wot-m8
« Last Edit: April 10, 2015, 05:41:25 PM by elm »

function servercmdcheckpoint(%client)
{
    %player = %client.player;
    %client.checkpoint = %player.getPosition();
    messageClient(%client, '',"\c2Checkpoint set!");
}

Hi guys! Sorry for bumping this, but I'm kinda against creating new topics. I'll just update the title again. I have this code for finding a players position, and then saving it to %client.checkpoint. In the end, it spits out something along the lines of -8.03834 -14.6601 1.43051e-006. These are obviously coordinates, but how would I be able to save their values to %x, %y, and %z respectively? In the long term, my goal is to later teleport the player to their previous coordinates through another command that executes player.setTransform();.

%x = getWord(%pos,0);
%z = getWord(%pos,2);
%y = getWord(%pos,1);

http://knowyourmeme.com/memes/u-wot-m8
I mean yeah, I figured it out after I was like 'the forget.' I just thought it was funny that my head parsed it as code.

Is there any way I can see the default code for /warp?
If not:
How do I figure out the coordinates for the nearest non-air place a client is looking?

containerRayCast( start , end , typemask )

So, start is the player's eyePoint, end is calculated by taking their eyeVector (direction they're looking) and multiplying it by how far you want to search, then add it to their eyePoint because their eyeVector is just the angle, not the angle offset by their position in space. Then, since you want to get the nearest non-air point, use $TypeMasks::ALL for the typemask.

Code: [Select]
%start = %player.getEyePoint();
%scaledEyeVector = vectorScale(%player.getEyeVector(), 100);
%end = vectorAdd(%start, %scaledEyeVector);

%result = containerRayCast(%start, %end, $TypeMasks::ALL);
%point = posFromRayCast(%result);
if(%point $= "")
    // no point found, looking at the sky
else
    // point found, it's at %point

Or, simplified:

Code: [Select]
%point = posFromRayCast(containerRayCast(%player.getEyePoint(), vectorAdd(vectorScale(%player.getEyeVector(), 100), %player.getEyePoint()), $TypeMasks::ALL));
« Last Edit: April 11, 2015, 10:09:06 PM by $trinick »

Thanks trinick! I've been messing around with it, and for some reason the end %point has the exactly same value as %start.
Here's my code:
        else if(%client.power $= "Warp")
        {
            %player = %client.player;
            %start = %player.getEyePoint(); //Starting point of the vector
            %scaledEyeVector = vectorScale(%player.getEyeVector(), 100);
            %end = vectorAdd(%start, %scaledEyeVector); //Ending point
            %result = containerRayCast(%start, %end, $TypeMasks::ALL); //The raycast itself
            %point = posFromRayCast(%result);
            //Extracting the coordinates, so we can teleport the player there.
            %xW = getWord(%point,0);
            %yW = getWord(%point, 1);
            %zW = getWord(%point, 2);
            //Teleports player to those coordinates
            %client.player.setTransform(%xW SPC %yW SPC %zW);
            //So I can see what is going on ;-;
            messageClient(%client, '',"start:" SPC %start);
            messageClient(%client, '',"scaledEyeVector:" SPC %scaledEyeVector);
            messageClient(%client, '',"end:" SPC %end);
            messageClient(%client, '',"result:" SPC %result);
            messageClient(%client, '',"point:" SPC %point);
        }

I have no idea what I'm doing wrong. I'm going to continue messing around with it.
Edit: I think the solution is to teleport the player to %end, still really confused though.
Edit 2: Hahaha, no. %end is apparently "0 0 0".
« Last Edit: April 12, 2015, 09:46:26 PM by Johnny Blockhead »

Add the player as a fourth argument for the containerRaycast function. This will prevent the raycast from hitting the player.

Just being picky here, but they way you're taking X Y and Z to send to the function is useless. You're taking a string of cords (ex: "7 6 3") turning them each into their own variable (ex: X=7 Y=6 Z=3) then turning them back into a string with the "%X SPC %Y SPC %Z" so the end result is (ex:"7 6 3") the same.

Also, set transform applies position and rotation, so since you're only giving it position, it will fill the remaining rotation with "0 0 0 0", resetting your rotation every time

Thanks guys!
You guys cleared that up for me, but I ran into another problem.

                else if(%client.canRocket $= "true")
                {
                    //Spawns a rocket
                    %p = new Projectile()
                    {
                        dataBlock = rocketlauncherprojectile; //I want it to be a rL projectile
                        initialVelocity = 30; //Dunno, should this be higher?
                        //Figuring out where to spawn the thing.
                        %eyePoint ##=## %player.getEyePoint();
                        //I am doing this so that it spawns in front of the player, not hitting him. Is there a more efficient way?
                        %x = getWord(%eyePoint,1);
                        %y = getWord(%eyePoint,2) + 5;
                        %z = getWord(%eyePoint,3);
                        initialPosition = %x SPC %y SPC %z;
                        client = %client;
                        sourceObject = %obj.client.player;
                        sourceClient = %obj.client;
                    };
                }


(sorry for the spacing)
What I am trying to do is spawn a projectile at the place a player is looking. Coming into this I wasn't exactly sure what to do, since trace wasn't helping and I got the syntax for this off of a forum search. (%player = %client.player; is previously stated). I'm getting a syntax error, and also am I approaching this correctly?

You can't declare variables within a new object block like that. Move the lines starting with %eyePoint, %x, %y, and %z above the %p = new Projectile() line.

As for a better way to spawn it in front of the player, you can simply add the player's eye vector to its eye point. If this distance is too long or too short, scale the eye vector first. Use vectorAdd (and vectorScale if need be) to accomplish this with minimal code.

Thanks Amade!
I tried adding %eyepoint and %eyevector, like so:
                    %eyeVector = %player.getEyeVector();
                    %eyePoint = %player.getEyePoint();
                    %result = %eyeVector + %eyePoint;

But the result turned out to be one number, not coordinates. So I pretty much did a bunch of spammy scripting and got:
                    //EyeVector
                    %eyeVector = %player.getEyeVector();
                    %vx = getWord(%eyeVector, 0);
                    %vy = getWord(%eyeVector, 1);
                    %vz = getWord(%eyeVector, 2);
                    //Now for EyePoint
                    %eyePoint = %player.getEyePoint();
                    %px = getWord(%eyePoint, 0);
                    %py = getWord(%eyePoint, 1);
                    %pz = getWord(%eyePoint, 2);
                    //Results!
                    %rx = %px + %vx;
                    %ry = %py + %vy;
                    %rz = %pz + %vz;
                    //Putting it together.
                    %result = %rx SPC %ry SPC %rz;
                    //Spawns a rocket
                    %p = new Projectile()
                    {
                        dataBlock = rocketlauncherprojectile;
                        initialVelocity = 2;
                        initialPosition = %result;
                        client = %obj.client;
                        sourceObject = %obj.client.player;
                        sourceClient = %obj.client;
                    };

This works beautifully (cough), except for the fact that rotation is not taken into account. I'm gonna continue snooping around.