new Float:x, Float:y, Float:z; GetActorPos(actorid, x, y, z);
ApplyActorAnimation(actorid, "SHOP, "ROB_Loop_Threat", 4.0, 1, 0, 0, 0, 0);
stock GetWeaponModel(weaponid) { switch(weaponid) { case 1: return 331; case 2..8: return weaponid+331; case 9: return 341; case 10..15: return weaponid+311; case 16..18: return weaponid+326; case 22..29: return weaponid+324; case 30,31: return weaponid+325; case 32: return 372; case 33..45: return weaponid+324; case 46: return 371; } return 0; }
I would spawn the gun with CreateObject and set its position to fit in the actor's hands. The hands must remain still obviously.
|
new Float:x, Float:y, Float:z; GetActorPos(actorid, x, y, z);
ApplyActorAnimation(actorid, "SHOP, "ROB_Loop_Threat", 4.0, 1, 0, 0, 0, 0);
CreateDynamicObject(GetGunObjectID(GunID), x+???, y+???, z+???, 80.0, 0.0, 0.0, -1);
//you need vx,vy,vz (weapon offset)
CreateActorWeapon(actorid,weaponid,Float:vx,Float:vy,Float:vz){
new Float:x,Float:y,Float:z,
Float:tx,Float:ty,Float:tz
Float:rx,Float:rz,Float:angle;
GetActorPos(actorid,x,y,z);
GetActorFacingAngle(actorid,angle);
ShiftVectorToRotation(vx,vy,vz,rx,rz);
GetPointInFront3D(x,y,z,rx,CompRotationFloat(angle+rz),VectorSize(vx,vy,vz),tx,ty,tz);
CreateDynamicObject(GetGunObjectID(weaponid),tx,ty,tz,80.0,0.0,angle,-1);
}
How to get the modifier? Spawn the actor (ax, ay, az) and the gun (gx, gy, gz) at the exact same coordinates then move the gun so it fits into his hands. X modifier is ax-gx, y modifier is ay-gy, z modifier is az-gz. This is valid when the facing angle of the actor is set to 0. If you want to change the facing angle you will have to do more math. |
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ) { new Float:oldX, Float:oldY, Float:oldZ, Float:oldRotX, Float:oldRotY, Float:oldRotZ; GetObjectPos(objectid, oldX, oldY, oldZ); GetObjectRot(objectid, oldRotX, oldRotY, oldRotZ); if(!playerobject) // If this is a global object, sync the position for other players { if(!IsValidObject(objectid)) return 1; SetObjectPos(objectid, fX, fY, fZ); SetObjectRot(objectid, fRotX, fRotY, fRotZ); } if(response == EDIT_RESPONSE_FINAL) { // The player clicked on the save icon // Do anything here to save the updated object position (and rotation) new string[128]; format(string, sizeof(string), "fX[%f] fY[%f] fZ[%f] fRotX[%f] fRotY[%f] fRotZ[%f]", fX, fY, fZ, fRotX, fRotY, fRotZ ); SendClientMessage(playerid, COLOR_GREY, string); } if(response == EDIT_RESPONSE_CANCEL) { //The player cancelled, so put the object back to it's old position if(!playerobject) //Object is not a playerobject { SetObjectPos(objectid, oldX, oldY, oldZ); SetObjectRot(objectid, oldRotX, oldRotY, oldRotZ); } else { SetPlayerObjectPos(playerid, objectid, oldX, oldY, oldZ); SetPlayerObjectRot(playerid, objectid, oldRotX, oldRotY, oldRotZ); } } return 1; }
CMD:actorweapon(playerid, params[]) { // https://sampwiki.blast.hk/wiki/EditAttachedObject ~ https://sampwiki.blast.hk/wiki/EditObject if(admin[playerid] < 1337) return 0; new actorid; if(sscanf(params,"i", actorid)) return SendClientMessage(playerid, -1, "Use: /actorweapon [actorid]"); if(IsValidActor(actorid)) { new Float:x, Float:y, Float:z; GetActorPos(actorid, x, y, z); new string[128]; format(string, sizeof(string), "[ACTOR POS] x[%f] y[%f] z[%f] RotX[0] RotY[0] RotZ[0]", x, y, z); SendClientMessage(playerid, COLOR_GREY, string); new weaponobj = CreateObject(GetGunObjectID(25), x, y, z, 0.0, 0.0, 0.0); EditObject(playerid, weaponobj); } return 1; }
CreateActor(142, -28.9448,-186.8204,1003.5469, 0.0); CreateActor(142, 1.9909,-30.7009,1003.5494, 357.6201); CreateActor(223, 207.7325,-98.7045,1005.2578, 178.9347); CreateActor(29, 203.6479,-40.7589,1001.8047, 181.8473); CreateActor(141, 161.4051,-80.0589,1001.8047, 180.1522); CreateActor(205, 375.6144,-65.7069,1001.5078, 140.8397); CreateActor(85, 501.8527,-21.4871,1000.6797, 90.2779); CreateActor(155, 373.9646,-117.2686,1001.4995, 180.2793); new actstring[128]; for(new a; a< GetActorPoolSize()+1; ++a) { if(IsValidActor(a)) { SetActorVirtualWorld(a, 0); SetActorInvulnerable(a, false); SetActorHealth(a, 10); new Float:x, Float:y, Float:z; GetActorPos(a, x, y, z); CreateObject(GetGunObjectID(25), x-0.154404, y-0.111137, z-0.310303, 1.599998, -0.400000, -66.699996); } }