2021-03-07, 02:30 PM
(This post was last modified: 2021-03-08, 01:15 AM by annety.)
Based on this actor:
Code: // 24-7
CreateDynamicActor(bizzid, 17, 142, -29.0206,-186.8182,1003.5469,1.6775);
With editdynamic object i found a formula to get the weapon position based on actor position?(to put the weapon in actor hands):
Code: ? ? // created [15:21:57] x[-29.020599] y[-186.818206] z[1003.546875] RotX[0] RotY[0] RotZ[0]
? ? new Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz;
? ? GetDynamicActorPos(actorid, x, y, z);
? ? // moved [15:23:45] x[-28.945550] y[-186.275421] z[1003.882324] rx[0.000000] ry[-3.300002] rz[98.899940]
? ? x = 1.0;
? ? x -= 0.924951;
? ? y = 0.542785;
? ? z = 0.335449;
? ? rx = 0.0;
? ? ry = -3.300002;
? ? rz = 98.899940;
? ? DestroyDynamicObject(ActorInfo[actorid][actorGun]);
? ? ActorInfo[actorid][actorGun] = CreateDynamicObject(GetGunObjectID(24), x, y, z, rx, ry, rz);
For this actor it become amazing:
I did think that it gonna work with all other actores, but didn't:
Code: // pizza
CreateDynamicActor(bizzid, 5, 155, 374.7394,-117.2788,1001.4922,180.5908);
Code: // alambra
CreateDynamicActor(bizzid, 17, 194, 501.6993,-20.4994,1000.6797,88.5219);
Anybody more experienced could help me to make the weapon works on all actor like the first one (24/7)?
Would be an amazing feature to all servers do in some way put a weapon on actor hands based on his position...
(i know about npc, i want fix this way to put this weapons for actors)
Why don't you just give the NPC an actual weapon, equip the weapon and then do the animation...?
You forgot the angle, unfortunately what you've found is the offset for one very specific angle. However, since you've found the offset for one angle, converting to others isn't too hard if you know trigonometry.
(2021-03-07, 04:28 PM)Y_Less Wrote: You forgot the angle, unfortunately what you've found is the offset for one very specific angle.? However, since you've found the offset for one angle, converting to others isn't too hard if you know trigonometry.
Did u know how to?
Or can u give a way?
something to read? something to test?
What is the angle there in the code that i have to work with?
I gave you the information already - trigonometry. You should have done it in school, but you can look it up anyway.
rz = 98.899940;
This is the angle. You have to change it using GetDynamicActorFacingAngle(actorid, rz);
2021-03-21, 06:47 PM
(This post was last modified: 2021-03-21, 06:47 PM by annety.)
(2021-03-10, 10:38 AM)Radical Wrote: rz = 98.899940;
This is the angle. You have to change it using GetDynamicActorFacingAngle(actorid, rz);
I tried:
Code: ? ? // created [15:21:57] x[-29.020599] y[-186.818206] z[1003.546875] RotX[0] RotY[0] RotZ[0]
? ? // moved [15:23:45] x[-28.945550] y[-186.275421] z[1003.882324] rx[0.000000] ry[-3.300002] rz[98.899940]
? ? // http://www.calculadoraonline.com.br/basica
? ? new Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz;
? ? GetDynamicActorPos(actorid, x, y, z);
? ? x = 1.0;
? ? x -= 0.924951;
? ? y = 0.542785;
? ? z = 0.335449;
? ? rx = 0.0;
? ? ry = 3.300002;
? ? // angle to hands
? ? new Float:tmpRZ;
? ? GetDynamicActorFacingAngle(actorid, tmpRZ); // 1.677500
? ? new Float:base = 100.57744; // 98.899940.677500 = 100.57744
? ? rz = base - tmpRZ; // 98.899940
? ? //
? ? DestroyDynamicObject(ActorInfo[actorid][actorGun]);
? ? ActorInfo[actorid][actorGun] = CreateDynamicObject(GetGunObjectID(24), x, y, z, rx, ry, rz);
It looks better, but its not like the original actor...
Original Actor:
How it was:
How it is now:
anybody could help with something?
it could be useful for a lot other people who want theirs actors react on robbery :(
2021-04-20, 02:53 PM
(This post was last modified: 2021-04-20, 02:54 PM by AbyssMorgan.)
Here are simple code for that, only you need get offset and rotation for object
Create actor on center of map with angle = 0.0 and position 0.0,0.0,actor_z then create object on her hand or something.
Simple calculating after this process:
Code: offset_x = object_x
offset_y = object_y
offset_z = object_z - actor_z
rx = object_rx
ry = object_ry
rz = object_rz
Code: /*
#include <3DTryg> //https://www.burgershot.gg/showthread.php?tid=1898&highlight=3DTryg
*/
CreateDynamicActorWeapon(actorid,objectid,Float:offset_x,Float:offset_y,Float:offset_z,Float:rx,Float:ry,Float:rz){
new Float:x,Float:y,Float:z,
Float:tx,Float:ty,Float:tz,
Float:angle;
GetDynamicActorPos(actorid,x,y,z);
GetDynamicActorFacingAngle(actorid,angle);
ShiftOffsetToPosition(x,y,z,0.0,0.0,angle,offset_x,offset_y,offset_z,tx,ty,tz);
CreateDynamicObject(objectid,tx,ty,tz,rx,ry,Tryg3D::CompressRotation(rz橸));
}
CreateActorWeapon(actorid,objectid,Float:offset_x,Float:offset_y,Float:offset_z,Float:rx,Float:ry,Float:rz){
new Float:x,Float:y,Float:z,
Float:tx,Float:ty,Float:tz,
Float:angle;
GetActorPos(actorid,x,y,z);
GetActorFacingAngle(actorid,angle);
ShiftOffsetToPosition(x,y,z,0.0,0.0,angle,offset_x,offset_y,offset_z,tx,ty,tz);
CreateDynamicObject(objectid,tx,ty,tz,rx,ry,Tryg3D::CompressRotation(rz橸));
}
(2021-04-20, 02:53 PM)AbyssMorgan Wrote: Here are simple code for that, only you need get offset and rotation for object
Create actor on center of map with angle = 0.0 and position 0.0,0.0,actor_z then create object on her hand or something.
Simple calculating after this process:
Code: offset_x = object_x
offset_y = object_y
offset_z = object_z - actor_z
rx = object_rx
ry = object_ry
rz = object_rz
Code: /*
#include <3DTryg> //https://www.burgershot.gg/showthread.php?tid=1898&highlight=3DTryg
*/
CreateDynamicActorWeapon(actorid,objectid,Float:offset_x,Float:offset_y,Float:offset_z,Float:rx,Float:ry,Float:rz){
new Float:x,Float:y,Float:z,
Float:tx,Float:ty,Float:tz,
Float:angle;
GetDynamicActorPos(actorid,x,y,z);
GetDynamicActorFacingAngle(actorid,angle);
ShiftOffsetToPosition(x,y,z,0.0,0.0,angle,offset_x,offset_y,offset_z,tx,ty,tz);
CreateDynamicObject(objectid,tx,ty,tz,rx,ry,Tryg3D::CompressRotation(rz橸));
}
CreateActorWeapon(actorid,objectid,Float:offset_x,Float:offset_y,Float:offset_z,Float:rx,Float:ry,Float:rz){
new Float:x,Float:y,Float:z,
Float:tx,Float:ty,Float:tz,
Float:angle;
GetActorPos(actorid,x,y,z);
GetActorFacingAngle(actorid,angle);
ShiftOffsetToPosition(x,y,z,0.0,0.0,angle,offset_x,offset_y,offset_z,tx,ty,tz);
CreateDynamicObject(objectid,tx,ty,tz,rx,ry,Tryg3D::CompressRotation(rz橸));
}
Oh man, ty so much...
But that last parameters:
Code: Float:offset_x,Float:offset_y,Float:offset_z,Float:rx,Float:ry,Float:rz
What is it?
sorry my dumb...
ty so much to try to help, a lot people can use this :)
on position 0 is under floor...
result of /actorweapon -> OnPlayerEditDynamicObject
Code: created [15:21:57] x[-29.020599] y[-186.818206] z[1003.546875] RotX[0] RotY[0] RotZ[0] a[%f]
moved [15:23:45] x[-28.945550] y[-186.275421] z[1003.882324] rx[0.000000] ry[-3.300002] rz[98.899940]
how should be /test?
Code: CMD:test(playerid) {
new Float:offset_x = object_x;
new Float:offset_y = object_y;
new Float:offset_z = object_z - actor_z;
new Float:rx = object_rx;
new Float:ry = object_ry;
new Float:rz = object_rz;
new actorid = 1001;
new gunid = 24;
CreateDynamicActorWeapon(actorid,gunid,offset_x,offset_y,offset_z,rx,ry,rz);
return true;
}
Code: CMD:actorweapon(playerid, params[]) {
new actorid; // 1001 = primeiro npc
if(sscanf(params,"i", actorid)) return SendClientMessage(playerid, -1, "Use: /actorweapon [actorid]");
if(IsValidDynamicActor(actorid)) {
ApplyDynamicActorAnimation(actorid, "PED","ARRESTgun", 4.1, 0, 0, 0, 1, 0);
new Float:x, Float:y, Float:z, Float:a;
GetDynamicActorPos(actorid, x, y, z);
GetDynamicActorFacingAngle(actorid, a);
new string[128];
format(string, sizeof(string), "[ACTOR POS] x[%f] y[%f] z[%f] RotX[0] RotY[0] RotZ[0] a[%f]", x, y, z, a);
SendClientMessage(playerid, COLOR_GREY, string);
if(IsValidDynamicObject(EditingDynamicObjectID[playerid])) { DestroyDynamicObject(EditingDynamicObjectID[playerid]); }
new weaponobj = CreateDynamicObject(GetGunObjectID(24), x, y, z, 0.0, 0.0, 0.0);
EditingDynamicObjectID[playerid] = weaponobj;
EditDynamicObject(playerid, EditingDynamicObjectID[playerid]);
}
return 1;
}
public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
if(response == EDIT_RESPONSE_FINAL || response == EDIT_RESPONSE_CANCEL)
{
new string[128];
format(string, sizeof(string), "x[%f] y[%f] z[%f] rx[%f] ry[%f] rz[%f]", x, y, z, rx, ry, rz );
SendClientMessage(playerid, COLOR_GREY, string);
}
}
you can easy get offset from object editor by using this function when you actor is on z_angle 0.0
Code: x,y,z - actor position
tx,ty,tz - object position
rx = 0.0, ry = 0.0,rz = 0
ShiftPositionToOffset(Float:x,Float:y,Float:z,Float:rx,Float:ry,Float:rz,&Float:offset_x,&Float:offset_y,&Float:offset_z,Float:tx,Float:ty,Float:tz);
|