SA-MP Forums Archive
How to add x, y to move object with floatsin, floatcos for current angle. - 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: How to add x, y to move object with floatsin, floatcos for current angle. (/showthread.php?tid=661367)



How to add x, y to move object with floatsin, floatcos for current angle. - bigtigerbeee - 02.12.2018

Код:
CMD:createboard(playerid, params[]) {

    new Float:px, Float:py, Float:pz, Float:pa;
    GetPlayerPos(playerid, px, py, pz);
    GetPlayerFacingAngle(playerid, pa);

    GetXYInFrontOfPlayer(playerid, px, py, 2.0);
    pz -= 1.0;
    pa += 180;
    
    CreateDynamicObject(3077, px, py, pz, 0.0000, 0.0000, pa); // Board Object

    // Calulate X, Y for Text
    pa += 90.0;    
    px = px + (2.0 * floatsin(pa, degrees));
    py = py - (2.0 * floatcos(pa, degrees));

    pz -= 1.3;

    new obj = CreateDynamicObject(19482, px, py, pz + 2.6653, 0.0000, 0.0000, pa);
    SetDynamicObjectMaterialText(obj, 0, "TOP 3 Players", OBJECT_MATERIAL_SIZE_256x256, "Arial", 16, 1, 0xFFFFFFFF, 0, 0);

    obj = CreateDynamicObject(19482, px, py, pz + 2.0553, 0.0000, 0.0000, pa);
    SetDynamicObjectMaterialText(obj, 0, "1. Player 1", OBJECT_MATERIAL_SIZE_256x256, "Arial", 12, 1, 0xFFFFFFFF, 0, 0);

    obj = CreateDynamicObject(19482, px, py, pz + 1.6353, 0.0000, 0.0000, pa);
    SetDynamicObjectMaterialText(obj, 0, "2. Player 2", OBJECT_MATERIAL_SIZE_256x256, "Arial", 12, 1, 0xFFFFFFFF, 0, 0);

    obj = CreateDynamicObject(19482, px, py, pz + 1.2153, 0.0000, 0.0000, pa);
    SetDynamicObjectMaterialText(obj, 0, "3. Player 3", OBJECT_MATERIAL_SIZE_256x256, "Arial", 12, 1, 0xFFFFFFFF, 0, 0);

    return 1;
}
result: It's work every angle




I want to move them into board.

How I can do it ?


Re: How to add x, y to move object with floatsin, floatcos for current angle. - Kane - 02.12.2018

You can use one material text object and use \n.


Re: How to add x, y to move object with floatsin, floatcos for current angle. - bigtigerbeee - 02.12.2018

It can't control space between lines and text size each lines.


Re: How to add x, y to move object with floatsin, floatcos for current angle. - Pottus - 02.12.2018

Check out this.

https://github.com/Pottus/Texture-St.../texviewer.pwn

Line 1030, 1031

Just tweak your offsets.


Re: How to add x, y to move object with floatsin, floatcos for current angle. - bigtigerbeee - 02.12.2018

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Check out this.

https://github.com/Pottus/Texture-St.../texviewer.pwn

Line 1030, 1031

Just tweak your offsets.
Thanks, but It doesn't help anything. I've already done it in my code see above.


Re: How to add x, y to move object with floatsin, floatcos for current angle. - Pottus - 02.12.2018

I see that but your offsets are off you need to align text to board or board to text or both.


Re: How to add x, y to move object with floatsin, floatcos for current angle. - bigtigerbeee - 02.12.2018

I would like this!! And work every player facing.



Re: How to add x, y to move object with floatsin, floatcos for current angle. - Pottus - 02.12.2018

I just told you! Figure out your offsets it's so simple...

1'st Align board to where you want it!
2'nd Align text to board!

It's so damn easy should be completed within 10 trial and error tests.


Re: How to add x, y to move object with floatsin, floatcos for current angle. - bigtigerbeee - 02.12.2018

Код:
CMD:createboard(playerid, params[]) {

    new Float:cbx, Float:cby;
	if (sscanf(params, "ff", cbx, cby)) {
        SendClientMessage(playerid, COLOR_GRAD1,    "USING: /createboard [x] [y]");
	    return 1;
	}
    
    new Float:px, Float:py, Float:pz, Float:pa;
    GetPlayerPos(playerid, px, py, pz);
    GetPlayerFacingAngle(playerid, pa);

    GetXYInFrontOfPlayer(playerid, px, py, 2.0);
    pz -= 1.0;
    pa += 180;
    
    CreateDynamicObject(3077, px, py, pz, 0.0000, 0.0000, pa);

    px += cbx;
    py += cby;

    pa += 90.0;    
    px = px + (2.0 * floatsin(pa, degrees));
    py = py - (2.0 * floatcos(pa, degrees));

    pz -= 1.3;

 	new obj = CreateDynamicObject(19482, px, py, pz + 2.6653, 0.0000, 0.0000, pa);
    SetDynamicObjectMaterialText(obj, 0, "TOP 3 Players", OBJECT_MATERIAL_SIZE_256x256, "Arial", 16, 1, 0xFFFFFFFF, 0, 0);

	obj = CreateDynamicObject(19482, px, py, pz + 2.0553, 0.0000, 0.0000, pa);
	SetDynamicObjectMaterialText(obj, 0, "1. Player 1", OBJECT_MATERIAL_SIZE_256x256, "Arial", 12, 1, 0xFFFFFFFF, 0, 0);

	obj = CreateDynamicObject(19482, px, py, pz + 1.6353, 0.0000, 0.0000, pa);
	SetDynamicObjectMaterialText(obj, 0, "2. Player 2", OBJECT_MATERIAL_SIZE_256x256, "Arial", 12, 1, 0xFFFFFFFF, 0, 0);

	obj = CreateDynamicObject(19482, px, py, pz + 1.2153, 0.0000, 0.0000, pa);
	SetDynamicObjectMaterialText(obj, 0, "3. Player 3", OBJECT_MATERIAL_SIZE_256x256, "Arial", 12, 1, 0xFFFFFFFF, 0, 0);

    return 1;
}

GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
	// Created by ******

	new Float:a;

	GetPlayerPos(playerid, x, y, a);

	if (GetPlayerVehicleID(playerid)) {
	    GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
	}
	else GetPlayerFacingAngle(playerid, a);

	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
}
Sorry, I can't do this. I try it all day


Re: How to add x, y to move object with floatsin, floatcos for current angle. - Pottus - 02.12.2018

Look at the comments!

Код:
	// Calculate position to left of player
	x = (x + 1.75 * floatsin(-fa + -90,degrees));
	y = (y + 1.75 * floatcos(-fa + -90,degrees));

	// Calculate create offset
	if(FlyMode[playerid])
	{
		x = (x + 4.0 * floatsin(-fa,degrees));
		y = (y + 4.0 * floatcos(-fa,degrees));
	}
	else
	{
		x = (x + 2.0 * floatsin(-fa,degrees));
		y = (y + 2.0 * floatcos(-fa,degrees));
	}
1.) Calculate the position of the board first
2.) Calculate offsets for objects that correlates to this postion

I only have one object here, you have multiple so you need to do something like this.

Код:
startx= (startx+ 1.75 * floatsin(-fa + -90,degrees));
starty= (starty+ 1.75 * floatcos(-fa + -90,degrees));

// Calculate offsets for first object
x = (startx + 4.0 * floatsin(-fa,degrees));
y = (starty+ 4.0 * floatcos(-fa,degrees));
Createobject()....

// Calculate offsets for second object
x = (startx + 3.0 * floatsin(-fa,degrees));
y = (starty+ 3.0 * floatcos(-fa,degrees));
Createobject()....

// Calculate offsets for third object
x = (startx + 2.0 * floatsin(-fa,degrees));
y = (starty+ 2.0 * floatcos(-fa,degrees));
Createobject()....
One more thing, check this out. https://pastebin.com/rnnUUCy5

You could also just attach the text objects to the board.