Recommended Posts

How would one force a player to look to a certain direction.

For example:

  • Player spawns and his movement is frozen, but he can look around,
  • He can look away from the original point but is gently forced back to look at the original point.

I home someone understands what I'm looking for 😅

Share this post


Link to post
Share on other sites

maybe that can help you.

ent = spawn( "script_model", self.origin );
self thread ispawnang(ent);
ent.angles = (90,0,90);
ent setmodel( "tag_origin" );
self linkto( ent );

ispawnang(ent){
   while(isDefined(ent)){
   if ( isAlive( self ) )
    {
      self SetPlayerAngles( ent.angles );
      wait 0.05;
    }
    else{break;} 
   }
 }

maybe this is necessary in the end -> ent delete();

Share this post


Link to post
Share on other sites

Tell us a bit more about the background.

If you want to totally freeze a player (no attacking etc) then you should do it through menu.

Share this post


Link to post
Share on other sites
3 hours ago, Viking said:

Tell us a bit more about the background.

If you want to totally freeze a player (no attacking etc) then you should do it through menu.

When a player spawns, until the strattime ends, i want him to be able to look around but his view is always set back to original, hard to explain.

If he looks out of the original point, his view is slowly dragged back to original...

Share this post


Link to post
Share on other sites

Auto center, you would need to define default angles, and then as players move in a loop you would need to check constantly their angles, and slowly with a different loop to set angles slowly, not 1 setangle but rather a lot of set angles that would constantly smooth out back to default.

angles = level.player GetPlayerAngles();

level.player setplayerangles((0,240,0));

Lastly I wouldn't recommend this, you would need a loop that monitors all players, a separate loop with angles for each player and a third loop for the smooth return, a lot of work, bad preformance and not really worth it, players mostly make a ton of sharp movements and if your ready up is like 5 seconds its totally not worth it.

Share this post


Link to post
Share on other sites
Posted (edited)
<player> freezeControls(true);


??

Some day ago I used this function to completely freeze player in my mod. I might be wrong, but it freezes angles too.

Edited by T-Max

Share this post


Link to post
Share on other sites

Uhm.. Untested and straight out of my mind...

CheckAimPosition() {    self endon ("disconnect");    self endon ("death");       forward = anglesToForward(self getPlayerAngles());   While(in strattime, i dont know the variable)    {     curView = anglesToForward(self getPlayerAngles());      If(curView != forward)       self thread ResetAimPosition(curView, forward)   } }  ResetAimPosition(curView, forward)  {    self endon ("disconnect");    self endon ("death");        self notify ("reset_aim");    self endon ("reset_aim");    dif = curView - forward;   For(i=0;i<100;i++) //100 has to be changed maybe     self setPlayerAngles(curView - (dif/100)); }
 

[\Code]

Share this post


Link to post
Share on other sites

The first question to ask is what purpose does this serve? I get the 'what' but not the 'why'. It forces the players to do something and they generally dont like that.  Freezing on prematch is also limiting and forcing players but they are used to that for all games and its normal. It is generally preferable not to interfere with basic player movements unless there is a good reason for it. If you dont need it for the game, dont do it. Otherwise it could be nothing more than an annoying gimmick.

However if you insist on it, since its done on prematch only performance probably shouldnt be an issue since nothing else is going on at the time except the countdown. And yes, freeze controls does everything.

Share this post


Link to post
Share on other sites
Posted (edited)

Sorry, i totally forgot to post the working code 😱

I wasn't sure when you want it to kick in exactly... so add the missing variable/paramter to the while loop and you can use it.

It's tested and works - the only thing i don't like is the hard reset when the loop ends.

Maybe quit the loop a bit before the round starts and add a wait before the unlink.

This way it would move smooth to center before the player can move again.

But that's up to you...

 

I hope you like it - so here you go:

init()
{
	//spawn a global entity where all players are linked to
	//to force the aimpos
	//we don't need an entity per player ;)
	level.forceAimEnt = spawn("script_origin", (0,0,0));

	while(1)
	{
		level waittill("connected", player);
		player thread onSpawn();
	}
}

onSpawn()
{
	while(1)
	{
		self waittill("spawned_player");

		self thread CheckAimPosition();
	}
}

CheckAimPosition()
{
	self endon ("disconnect");
	self endon ("death");

	//don't do it for specs
	if(!isDefined(self.pers["team"]) || (self.pers["team"] != "allies" && self.pers["team"] != "axis"))
		return;

	self linkTo(level.forceAimEnt);

	start = self getPlayerAngles();
	while() //in strattime, i dont know the variable
	{
		curView = self getPlayerAngles();
		
		if(curView != start)
			self thread ResetAimPosition(curView, start);
		
		wait .05;
	}
	
	self unlink();
	self setPlayerAngles(start);
}

ResetAimPosition(curView, start)
{
	self endon ("disconnect");
	self endon ("death");
	
	self notify ("reset_aim");
	self endon ("reset_aim");
	
	steps = 40;	//play around with this value if you don't like it
	dif = curView - start;
	for(i=0;i<steps;i++)
		self setPlayerAngles(curView - (dif/steps));
}

 

Edited by Viking
  • Thanks 1

Share this post


Link to post
Share on other sites
22 hours ago, Viking said:

Sorry, i totally forgot to post the working code 😱

I wasn't sure when you want it to kick in exactly... so add the missing variable/paramter to the while loop and you can use it.

It's tested and works - the only thing i don't like is the hard reset when the loop ends.

Maybe quit the loop a bit before the round starts and add a wait before the unlink.

This way it would move smooth to center before the player can move again.

But that's up to you...

 

I hope you like it - so here you go:


init()
{
	//spawn a global entity where all players are linked to
	//to force the aimpos
	//we don't need an entity per player ;)
	level.forceAimEnt = spawn("script_origin", (0,0,0));

	while(1)
	{
		level waittill("connected", player);
		player thread onSpawn();
	}
}

onSpawn()
{
	while(1)
	{
		self waittill("spawned_player");

		self thread CheckAimPosition();
	}
}

CheckAimPosition()
{
	self endon ("disconnect");
	self endon ("death");

	//don't do it for specs
	if(!isDefined(self.pers["team"]) || (self.pers["team"] != "allies" && self.pers["team"] != "axis"))
		return;

	self linkTo(level.forceAimEnt);

	start = self getPlayerAngles();
	while() //in strattime, i dont know the variable
	{
		curView = self getPlayerAngles();
		
		if(curView != start)
			self thread ResetAimPosition(curView, start);
		
		wait .05;
	}
	
	self unlink();
	self setPlayerAngles(start);
}

ResetAimPosition(curView, start)
{
	self endon ("disconnect");
	self endon ("death");
	
	self notify ("reset_aim");
	self endon ("reset_aim");
	
	steps = 40;	//play around with this value if you don't like it
	dif = curView - start;
	for(i=0;i<steps;i++)
		self setPlayerAngles(curView - (dif/steps));
}

 

Its exactly what i wanted :), thank you very, very much.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.