Post: Looped setOrigin instability
11-23-2015, 03:14 AM #1
BullyWiiPlaza
Climbing up the ladder
(adsbygoogle = window.adsbygoogle || []).push({}); The following code works but it freezes quickly when it is active. Can you tell why? I really don't get why some scripts have weird side-effects. I froze 3 times because of this so clearly it must be messed up somehow ResistTheSun
    toggleStalking(player)
{
self.stalking = booleanOpposite(self.stalking); // Custom helper function
printToggleState("Stalking", self.stalking); // Custom helper function

if(self.stalking)
{
self thread stalkPlayer(player);
}
else
{
self notify("stopStalking");
}
}

stalkPlayer(player)
{
self endon("disconnect");
self endon("stopStalking");

while(true)
{
if(isAlive(player))
{
ownOrigin = player.origin + (0, 0, 150);
self setOrigin(ownOrigin);
}

wait 0.1;
}
}
(adsbygoogle = window.adsbygoogle || []).push({});
11-26-2015, 03:01 PM #2
anthonything
Space Ninja
Instead of setting your own origin over and over again, you could always make a struct at the position over the players head and use playerlinkto to link yourself to the object. Then just have a script to move the object if the player isnt at the same spot.

The following user thanked anthonything for this useful post:

BullyWiiPlaza
11-26-2015, 03:48 PM #3
BullyWiiPlaza
Climbing up the ladder
Originally posted by anthonything View Post
Instead of setting your own origin over and over again, you could always make a struct at the position over the players head and use playerlinkto to link yourself to the object. Then just have a script to move the object if the player isnt at the same spot.

That's a great suggestion but can you also assist with some code please? I also wrote a basic script below to illustrate the idea to make it easier for you but it's not complete I believe. Thank you Smile

    stopStalkingPlayer()
{
self notify("stopStalking");
self unlink();
}

stalkPlayer(player)
{
self endon("disconnect");
self endon("stopStalking");

stalkingPosition = spawn("script_model", getPlayerStalkingPosition(player));
self setOrigin(stalkingPosition.origin);
self linkTo(stalkingPosition);

thread onPlayerSpawnedContinueStalking(player);

while(true)
{
if(isAlive(player))
{
stalkingPosition moveTo(getPlayerStalkingPosition(player));
}

wait 0.1;
}
}

getPlayerStalkingPosition(player)
{
return player.origin + (0, 0, 100);
}

onPlayerSpawnedContinueStalking(player)
{
self endon("disconnect");
self endon("stopStalking");

player waittill("spawned_player");
wait 0.1;

self setOrigin(getPlayerStalkingPosition(player));
}
11-27-2015, 04:05 AM #4
Im_YouViolateMe
NextGenUpdate Elite
I would set the player angles to match the angles of the person you are stalking. So that way they are looking forward.
11-27-2015, 03:29 PM #5
BullyWiiPlaza
Climbing up the ladder
Originally posted by YouViolateMe View Post
I would set the player angles to match the angles of the person you are stalking. So that way they are looking forward.

Well, it didn't do anything:
    self setPlayerAngles(player.angles);

Maybe because of
    moveTo()


Anyway, I got the code working. It's nice but I'm not happy that I can't look down and shoot the stalked person. If anyone knows how to fix this, it would be great Gobble

    toggleStalking(player)
{
self.stalking = booleanOpposite(self.stalking);
printToggleState("Stalking", self.stalking);

if(self.stalking)
{
self thread stalkPlayer(player);
}
else
{
stopStalkingPlayer();
}
}

stopStalkingPlayer()
{
self notify("stopStalking");
self unlink();
}

stalkPlayer(player)
{
self endon("disconnect");
self endon("stopStalking");

position = getPlayerStalkingPosition(player);
stalkingPosition = spawn("script_model", position);
self setOrigin(stalkingPosition.origin);

thread onPlayerSpawnedContinueStalking(player);

while(true)
{
if(isAlive(player))
{
self linkTo(stalkingPosition); // Preventing unlinking when dying
position = getPlayerStalkingPosition(player);
stalkingPosition moveTo(position, 0.01);
// self setPlayerAngles(player.angles);
}

wait 0.1;
}
}

getPlayerStalkingPosition(player)
{
return player.origin + (0, 0, 100);
}

onPlayerSpawnedContinueStalking(player)
{
self endon("disconnect");
self endon("stopStalking");

player waittill("spawned_player");
wait 0.1;

position = getPlayerStalkingPosition(player);
self setOrigin(position);
}

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo