SA-MP Forums Archive
Class help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Class help (/showthread.php?tid=621055)



Class help - StrikerZ - 06.11.2016

PHP код:
        SetPlayerTeamFromClass(playerid,classid);
        
SetPlayerPos(playerid,1558.1510,-1370.1229,330.0528);
        new 
Float:X,Float:Y,Float:Z,Float:A,Float:R=4;
        
GetPlayerPos(playerid,X,Y,Z);
        
GetPlayerFacingAngle(playerid,A);
        new 
Float:CX,Float:CY,Float:CZ;
        
CX=X+(R*floatsin(-A,degrees));
        
CY=Y+(R*floatcos(-A,degrees));
        
CZ=Z+1;
        
SetPlayerCameraPos(playerid,CX,CY,CZ);
        
SetPlayerCameraLookAt(playerid,1558.1510,-1370.1229,330.0528); 
These are the onplayerrequestclass code. Well the problem is that the camerpos coords are wrong. But if i execute the onplayerrequestclass again then the coords are right. Basically this function get's late to be executed. Any thing wrong?


Re: Class help - Killa[DGZ] - 06.11.2016

Change this,
PHP код:
CX=X+(R*floatsin(-A,degrees));
CY=Y+(R*floatcos(-A,degrees)); 
To this,
PHP код:
+= (Rfloatsin(-Adegrees));
+= (floatcos(-Adegrees));
SetPlayerCameraPos(playeridXYZ+1.0); 
An remove those few unnecessary float values eg: CX, CY, CZ


Re: Class help - StrikerZ - 06.11.2016

Same problem. Occurs on login too


Re: Class help - Killa[DGZ] - 06.11.2016

Thats very strange isn't it,

Try fixing the float R value up which is currently set to an integer value '4', but it should be a float value '4.0'.

Maybe try using SetPlayerFacingAngle before GetPlayerFacingAngle?


Re: Class help - StrikerZ - 06.11.2016

The problem is that. The position at which the camera is or the player is it sets the coords at the same place instead of to positions i want


Re: Class help - Killa[DGZ] - 06.11.2016

Here man, I made this just for you!

PHP код:
}
stock SetPlayerToLookAtSelf(playeridFloat:range)
{
    new 
Float:XFloat:YFloat:ZFloat:A;
    
GetPlayerPos(playeridXYZ);
    
GetPlayerFacingAngle(playeridA);
    
SetPlayerCameraLookAt(playeridXYZ);
    
+= (range floatsin(-Adegrees));
    
+= (range floatcos(-Adegrees));
    
SetPlayerCameraPos(playeridXYZ);
    return 
1;

Simply set your position wherever you like and use it

Example,
PHP код:
SetPlayerTeamFromClass(playerid,classid);
SetPlayerPos(playerid,1558.1510,-1370.1229,330.0528);
SetPlayerToLookAtSelf(playerid4.0); 



Re: Class help - Threshold - 06.11.2016

Why are you using GetPlayerPos when you already have the coordinates that the player is going to be put on? SetPlayerPos probably hasn't been fully executed by the time you use GetPlayerPos, so the coordinates are a somewhat delayed version.

PHP код:
        SetPlayerTeamFromClass(playerid,classid); 
        
SetPlayerPos(playerid1558.1510, -1370.1229330.0528);
        
// SetPlayerFacingAngle(playerid, ...); ?
        
new Float:A// Remove if using SetPlayerFacingAngle
        
GetPlayerFacingAngle(playeridA); // If you're going to use SetPlayerFacingAngle, use the angle from that instead.
        
SetPlayerCameraPos(playerid1558.1510 + (floatsin(-A,degrees)), -1370.1229 + (floatcos(-A,degrees), 330.0528 1.0); 
        
SetPlayerCameraLookAt(playerid1558.1510, -1370.1229330.0528); 
Though there is a lazy but clean way of doing this, which could be helpful if you decide that you want to change these coordinates in the future.

PHP код:
    new 
        
Float:pX 1558.1510,
        
Float:pY = -1370.1229,
        
Float:pZ 330.0528,
        
Float:pA 0.0
    
;
    
SetPlayerTeamFromClass(playerid,classid); 
    
SetPlayerPos(playeridpXpYpZ);
    
SetPlayerFacingAngle(playeridpA);
    
SetPlayerCameraPos(playeridpX + (4.0 floatsin(-pAdegrees)), pY + (4.0 floatcos(-pAdegrees)), pZ 1.0); 
    
SetPlayerCameraLookAt(playeridpXpYpZ); 



Re: Class help - StrikerZ - 06.11.2016

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Why are you using GetPlayerPos when you already have the coordinates that the player is going to be put on? SetPlayerPos probably hasn't been fully executed by the time you use GetPlayerPos, so the coordinates are a somewhat delayed version.

PHP код:
        SetPlayerTeamFromClass(playerid,classid); 
        
SetPlayerPos(playerid1558.1510, -1370.1229330.0528);
        
// SetPlayerFacingAngle(playerid, ...); ?
        
new Float:A// Remove if using SetPlayerFacingAngle
        
GetPlayerFacingAngle(playeridA); // If you're going to use SetPlayerFacingAngle, use the angle from that instead.
        
SetPlayerCameraPos(playerid1558.1510 + (floatsin(-A,degrees)), -1370.1229 + (floatcos(-A,degrees), 330.0528 1.0); 
        
SetPlayerCameraLookAt(playerid1558.1510, -1370.1229330.0528); 
Though there is a lazy but clean way of doing this, which could be helpful if you decide that you want to change these coordinates in the future.

PHP код:
    new 
        
Float:pX 1558.1510,
        
Float:pY = -1370.1229,
        
Float:pZ 330.0528,
        
Float:pA 0.0
    
;
    
SetPlayerTeamFromClass(playerid,classid); 
    
SetPlayerPos(playeridpXpYpZ);
    
SetPlayerFacingAngle(playeridpA);
    
SetPlayerCameraPos(playeridpX + (4.0 floatsin(-pAdegrees)), pY + (4.0 floatcos(-pAdegrees)), pZ 1.0); 
    
SetPlayerCameraLookAt(playeridpXpYpZ); 
What is R in here?