Add fake actor weapon
#1

After a long time looking on forum and with help with some guys here i made this script to:

- Get actor position
- Make a match
- And add a weaponobject on actor's hands while actor do a animation

But i got 2 problems:

1- When i get inside the shop, my gta is crashing...
The weapon is coming inside the actor or somelike this crash?

2- The weapon is not adding on hands right using the math, i think i'm doing the math wrong, because when i created in game [EditObject(playerid, weaponobj);]
It's work fine...
Like on this IMG:


But when i did this math:
[ACTOR POS] x[207.732498] y[-98.704498] z[1005.257812] RotX[0] RotY[0] RotZ[0]
[WEAPO POS] X[207.578094] Y[-98.815635] Z[1005.568115] RotX[1.599998] RotY[-0.400000] RotZ[-66.699996]

[NEW POS] X[-0.154404] Y[-0.111137] Z[+-0.310303] RotX[+1.599998] RotY[-0.400000] RotZ[-66.699996]

new Float, 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);

Not work on hands right...


Full code i used:
Код:
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/EditObjec...0.99317084	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;
}
And on createactors:
Код:
	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);
		}
	}
But it's not beeing in the right position...
And i can not take a screenshot because i'm my GTA is crashing everytime i try to see this actors armeds
Reply
#2

Anybody know a way to add a weapon on actor hands...

Actor using animation:
Код:
"GUN" "GUN_STAND"
I search a lot i think its possible to use weapon on hands getting actor pos using this 2 functions:

https://sampwiki.blast.hk/wiki/Floatsin
https://sampwiki.blast.hk/wiki/Floatcos

But idk about match to do this...
Anybody could help me?
Reply
#3

BumP
Reply
#4

new weaponobj = CreateObject(GetGunObjectID(25), x, y, z, 0.0, 0.0, 0.0);
EditObject(playerid, weaponobj);

Blindly creating objects and not destroying them.
Reply
#5

Why you ignoring solution
Reply
#6

You guys are no understanding, he want a way get actor position, and with actor position make maths to calculate weapon position on actor hands using animation:
ApplyActorAnimation(actorid, "GUN", "GUN_STAND", 4.1, 0, 1, 1, 1, 1);
Reply
#7

Im gonna tell you these, drop it right now, its impossible to make it with current actors system.
First, thing is that you can move actor by hitting him. And that position is not synced, not to a server and not to other players.

Second thing is that most actors have different height, and that will mean that you need to get that position for each skin (or at least most of them).

Just use NPC's, actors are not meant for these in first place. Idea of actors is to add some crowd without adding any stress to network or server cpu.
Reply
#8

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
Im gonna tell you these, drop it right now, its impossible to make it with current actors system.
First, thing is that you can move actor by hitting him. And that position is not synced, not to a server and not to other players.

Second thing is that most actors have different height, and that will mean that you need to get that position for each skin (or at least most of them).

Just use NPC's, actors are not meant for these in first place. Idea of actors is to add some crowd without adding any stress to network or server cpu.
NPC just to a script to robbery? Like aim to store? Who do not move?
I dont think its a good idea...

Only a few skins will not get the same pos, and there is a lot filterscript to auto adjust it here on forum...

Animation, OnActorGiveDamage, OnActorDeath (to destroy the object), actors are made exaclty to this...
The only hard part is the math to object pos or set object by object, actor by actor...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)