Raised This Month: $32 Target: $400
 8% 

Setting player's camera


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Yoi
Junior Member
Join Date: Nov 2018
Location: Russia
Old 11-26-2018 , 00:05   Setting player's camera
Reply With Quote #1

Hello, I am newbie, but I really cant get this problem solved.
I want the player's camera, that I can change any way I want (3rd person for example). I tryed to change every game frame like this:

Code:
public OnGameFrame()
{
	GetClientEyePosition(iClient1,vOrigin);
        GetClientEyeAngles(iClient1, vAngles);
	vAngles1 = vAngles;
	GetAngleVectors(vAngles, vAngles1, NULL_VECTOR, NULL_VECTOR);
	NormalizeVector(vAngles1, vAngles1);
	vOrigin[0] = vOrigin[0]-vAngles1[0]*100;
	vOrigin[1] = vOrigin[1]-vAngles1[1]*100;
	vOrigin[2] = vOrigin[2]-vAngles1[2]*100;
	TeleportEntity(iEntity, vOrigin, vAngles, NULL_VECTOR);//iEntity is a camera
}
it would work perfect... if there werent freezes(maybe works better on 100 tick). But I understood that its a bad idea. Next step I tryed to use SetParent:

Code:
public Action:CreateCamera(iClient, args)
{
	iEntity = CreateEntityByName("point_viewcontrol_survivor");	
        DispatchSpawn(iEntity);
	ActivateEntity(iEntity);
        SetVariantString("!activator"); 
	AcceptEntityInput(iEntity, "SetParent", iClient, iEntity, 0);
        TeleportEntity(iEntity, Float:{ -200.0, 0.0, 70.0}, Float:{ 0.0, 0.0, 0.0}, NULL_VECTOR);
        iCamRef[iClient] = EntIndexToEntRef(iEntity);
        AcceptEntityInput(EntRefToEntIndex(iCamRef[iClient]), "Enable", iClient);
}
It works MUCH better (with some freezes also), but... the rotate point of camera is wrong. The camera rotates around pivot point in the feet. I tryed to google for many days and I didnt find any way to change the rotate point(maybe I am looking bad).
I aslo tryed this code:
Code:
        new hOwnerEntity = GetEntProp(client,Prop_Send,"m_hOwnerEntity");
	SetEntProp(client, Prop_Send, "m_hViewEntity",hOwnerEntity);
	SetEntProp(client, Prop_Send, "m_iObserverMode", 4); // 4 is First person
but I become some kind of spectator and cant shoot and jump.

Maybe its bad idea to use sourcemod for this? Maybe I should use vscript some way? I really dont have any ideas. Pls haelp
Yoi is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 12-04-2018 , 18:13   Re: Setting player's camera
Reply With Quote #2

Maybe it help:
https://forums.alliedmods.net/showthread.php?t=297161

++ (from @Silvers)
Code:
// Hooked 3 times, because each alone is not enough, this creates the smoothest play with minimal movement stutter
SDKHook(client, SDKHook_PostThinkPost, onThinkFunk);
SDKHook(client, SDKHook_PreThink, onThinkFunk);
SDKHook(client, SDKHook_PreThinkPost, onThinkFunk);
Is it L4d1 or 2 ?
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 12-04-2018 at 18:14.
Dragokas is offline
Yoi
Junior Member
Join Date: Nov 2018
Location: Russia
Old 12-06-2018 , 22:49   Re: Setting player's camera
Reply With Quote #3

Thank you for answer. The Lux's plugin was the first thing I explored. My 2nd code from previous post is code I writed after reading Lux's .sp. But the problem is, when I SetParent the camera to player, camera rotates around the foots, not around the center of the player.

I don't really know how to work with SDKHook_PostThinkPost, but I found one function in Lux's plugin:
Code:
public Hook_OnPostThinkPost(iClient)
{
	if(!AreClientCookiesCached(iClient))//block everything until async stuff is done
		return;
	
	
	if(!IsPlayerAlive(iClient) || GetClientTeam(iClient) != 2 || !bClientPov[iClient] || !bShouldBePov(iClient))
	{
		if(!IsValidEntRef(iCamRef[iClient]))
			return;
		
		if(hClientDisableView[iClient] != INVALID_HANDLE)
			return;
			
		hClientDisableView[iClient] = CreateTimer(1.0, DisableView, GetClientUserId(iClient));
		
		DisableCam(iClient);
		return;
	}
	else
	{
		if(!IsValidEntRef(iCamRef[iClient]))
			if(!CreateCamera(iClient))
				return;
		
		static iModelIndex[MAXPLAYERS+1] = {0, ...};		
		if(iModelIndex[iClient] != GetEntProp(iClient, Prop_Data, "m_nModelIndex", 2))
		{
			iModelIndex[iClient] = GetEntProp(iClient, Prop_Data, "m_nModelIndex", 2);
			SetVariantString("eyes");
			AcceptEntityInput(EntRefToEntIndex(iCamRef[iClient]), "SetParentAttachment");
		}
		
		EnableCam(iClient);
	}
}
I must make something like this 3 times? It is possible to make this work for every-game-frame method? (really don't understand what exactly this function does ^^")

My game is L4D2.
Yoi is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 12-08-2018 , 07:03   Re: Setting player's camera
Reply With Quote #4

You have to move code of your "OnGameFrame" to a callback of these 3 SDKs. All SDKs shoud point to the same callback. You can see using example in this plugin.
Executing code on each game frame is a very CPU expensive operation.

As about your second code, here is a description of all "point_viewcontrol_survivor" properties:
https://developer.valvesoftware.com/...ntrol_survivor
You can try something, like "SetLocalOrigin".

Also, isn't
Code:
TeleportEntity(iEntity, Float:{ -200.0, 0.0, 70.0}, Float:{ 0.0, 0.0, 0.0}, NULL_VECTOR);
in your code what you was looking for?
X = -200.0, Y = 0.0, Z = 70.0 ? Try change Y.

Also, some discussion and almost finished L4D1 port of Lux's plugin can be found here. Maybe it can help you somehow.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 12-08-2018 at 07:06.
Dragokas is offline
Yoi
Junior Member
Join Date: Nov 2018
Location: Russia
Old 12-14-2018 , 10:26   Re: Setting player's camera
Reply With Quote #5

I think you don't understand my problem properly - my camera rotates around pivot point. When I making SetParent to player its choosing the axises of pivot from player model. Pivot of player's model located at the foots. So any changes of origin and angles - won't help becase the problem is in the parent. Maybe I can some way attach to the standart camera entity (if it's exist) or any another entity that in the center of player?
My target - is to have custom thirdperson view like in Resident Evil from the shoulder.
P.S. I also tryed those function instead of game frame:
Code:
SDKHook(client, SDKHook_PostThinkPost, onThinkFunk);
SDKHook(client, SDKHook_PreThink, onThinkFunk);
SDKHook(client, SDKHook_PreThinkPost, onThinkFunk);
and it was still laggy.
Yoi is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 12-15-2018 , 09:13   Re: Setting player's camera
Reply With Quote #6

To control third person camera there are ConVars (unfortunately, it's client side only):
Code:
c_thirdpersonshoulderoffset 20.0
c_thirdpersonshoulderaimdist 120.0
c_thirdpersonshoulderdist 40.0
c_thirdpersonshoulderheight 5
cam_ideallag 0
cam_idealyaw -5
cam_idealdist 20
Maybe it will help you.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 12-15-2018 at 09:13.
Dragokas is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode