Alright, I have a "small" problem here. The dummyThing that represents the player will not move around the emplaced gun when it rotates along a horizontal (XY in JED) plane. I need ideas or reasons why.
The template
This is the last thing I need to get some emplaced guns working. PS, using SetThingPos() for the same template works in another cog.
Code:
# Jedi Knight Cog Script
#
# CLASS_EMPLACED.COG
#
# CLASS WEAPON Script - Emplaced Gun
#
# [DP]
#
symbols
thing emplaced
flex acc=3
flex fireWait=0.15
int clipsize=100
int tracerper=5
int warning=10
sound fireSound=92FS.wav
sound outSound=concuss1.wav
template projectile=+bullet50cal
template projectileT=+bullet50tracer
flex offsetdist=.1
keyframe standingAnim=50calstand.key
thing player local
thing dummything local
int mode local
int holsterTrack local
int rounds local
int reloading local
int dummy local
int inUse=0 local
int canFire=1 local
vector tempVec local
vector randVect local
template dummytpl=dummyplayer local
template chdummy=+chdummy local
message startup
message activated
message trigger
message timer
message pulse
end
# ========================================================================================
code
Startup:
rounds = clipsize;
Return;
# ........................................................................................
Pulse:
If(GetThingHealth(player) <= 0) Return;
dummy = FireProjectile(player, chdummy, -1, -1, '0 0 0', '0 0 0', 0,0,0,0);
tempVec = GetThingLVec(dummy);
If(VectorDot(tempVec, GetThingLVec(player)) < .707)
{
// Players LVec is only X,Y
// Since all LVecs distance = 1
// (x, y)1, 1 is a 45 angle
If(VectorZ(tempVec) > 0)
tempVec = VectorAdd(GetThingLVec(player), '0 0 1');
Else
tempVec = VectorAdd(GetThingLVec(player), '0 0 -1');
tempVec = VectorNorm(tempVec);
}
SetThingLook(emplaced, tempVec);
DestroyThing(dummy);
tempVec = VectorScale(GetThingLVec(player), -offsetdist);
tempVec = VectorAdd(tempVec, GetThingPos(emplaced));
SetThingPos(player, tempVec);
SetThingPos(dummyThing, tempVec);
SetThingLook(dummyThing, GetThingLVec(player));
Return;
# ........................................................................................
Activated:
If(!inUse)
{
player = GetSourceRef();
SetInv(player, 10, 1);
SelectWeapon(player, 10);
inUse = 1;
canFire = 1;
SendMessageEx(GetInvCog(player, 10), User2, emplaced, 0, 0, 0);
AttachThingToThing(player, emplaced);
ClearPhysicsFlags(player, 0x1);
SetThingCurGeoMode(player, 0);
dummyThing = FireProjectile(emplaced, dummytpl, -1, -1, VectorSet(0, -offsetdist, 0), '0 0 0', 0,0,0,0);
SetThingModel(dummyThing, GetThingModel(player));
PlayKey(dummyThing, standingAnim, 1, 0x0);
}
Else If(GetSourceRef() == player)
{
call backoff;
}
Return;
# ........................................................................................
Timer:
If(GetSenderID() == 0 && canFire)
{
If(rounds <= 0)
{
PlaySoundThing(outSound, emplaced, 1.0, -1, -1, 0x80);
Return;
}
randvect = VectorSet((.5-Rand())*acc, (.5-Rand())*acc, 0);
If(IsThingCrouching(player)) randvect = VectorScale(randvect, .9);
// PlayMode(player, 8);
SendTrigger(-1, 10, 0, 0.02, 0.1, 0);
If((rounds % tracerper == 0 || rounds <= warning))
SendTrigger(-1, 11, emplaced, projectileT, VectorX(randvect), VectorY(randvect));
Else
SendTrigger(-1, 11, emplaced, projectile, VectorX(randvect), VectorY(randvect));
// SendTrigger(-1, 10, 0.0135, 0.09, 0.02, 0);
// SendTrigger(-1, 12, player, case, 0, 0);
rounds = rounds - 1;
PlaySoundThing(fireSound, emplaced, 1, -1, -1, 0x80);
SetInv(player, 14, (rounds/clipsize)*400);
KillTimerEx(0);
SetTimerEx(fireWait, 0, 0, 0);
}
Return;
# ........................................................................................
Trigger:
If(GetSourceRef() != 15) Return;
If(GetParam(0) != player) Return;
If(GetParam(2) != emplaced) Return;
If(player == -1) Return;
If(GetParam(3) == 1)
{
SetActorFlags(player, 0x84000);
SetPulse(0.003);
SetInv(player, 14, (rounds/clipsize)*400);
SetInv(player, 13, 6/7*200);
Return;
}
If(GetParam(3) == 2)
{
call backoff;
Return;
}
If(GetParam(1) >= 0)
{
SetTimerEx(fireWait, 0, 0, 0);
canFire = 1;
}
Else
{
canFire = 0;
If(rounds <= 0) call reload;
}
Return;
# ........................................................................................
BackOff:
If(!inUse) Return;
ClearActorFlags(player, 0x84000);
SetPulse(0);
SetInv(player, 10, 0);
SelectWeapon(player, AutoselectWeapon(player, 1));
DetachThing(player);
SetPhysicsFlags(player, 0x1);
SetThingCurGeoMode(player, GetThingGeoMode(player));
If(dummyThing != -1) DestroyThing(dummyThing);
dummyThing = -1;
player = -1;
InUse = 0;
Return;
# ........................................................................................
Reload:
rounds = clipsize;
SetInv(player, 14, (rounds/clipsize)*400);
Return;
end
The template
Code:
dummyplayer _ghoststructure model3d=ky.3do size=0.268712 movesize=0.268712 puppet=cr.pup
This is the last thing I need to get some emplaced guns working. PS, using SetThingPos() for the same template works in another cog.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms
Completed
Judgement Day (HLP), My level pack
SATNRT, JK Pistol Mod, Aliens TC, Firearms
Completed
Judgement Day (HLP), My level pack