The idea is that on secondary fire, the player creates a turret which can be fired five times before it is deleted. I've planned everything out but there is a problem with the cog which I attach to the turret template. Instead of the actual item created being the turret, the player's thing is placed in that variable. Here is the cog:
Here is the code for the modified bryar pistol cog, which on secondary fire places the new turret. It operates fine, but since the two are connected, I thought one might help the other.
The template is the turret1.3do with the cog added to it. Parent _zwalkstructure.
Thanks in advanced!
Code:
# Jedi Knight Cog Script
#
# BuiltTurret.COG
#
# Cog attached to BuiltTurret Template.
#
#
# This Cog is Not supported by LucasArts Entertainment Co
symbols
message activated
message timer
thing mainturret local
thing player local
template projectile=+concbullet local
int rounds=5 local
int cur_round=0 local
int active=0 local
flex delay=1.0 local
float autoAimZFOV=10 local
float autoAimXFOV=10 local
sound fireSound=turret-1.wav local
end
# ========================================================================================
code
activated:
player=
if(active==1) Return;
active = 1;
if(cur_round < rounds)
{
FireProjectile(mainturret, projectile, fireSound, -1, '0.02683 0.05 0.04', '0 0 0', 1.0, 0x60, autoAimZFOV, autoAimXFOV);
FireProjectile(mainturret, projectile, fireSound, -1, '-0.02683 0.05 0.04', '0 0 0', 1.0, 0x60, autoAimZFOV, autoAimXFOV);
cur_round = cur_round+1;
sleep(delay);
active = 0;
}
else
{
Print("Out of Ammo!");
SetTimer(1);
return;
}
return;
timer:
DestroyThing(mainturret);
Return;
# ........................................................................................
endHere is the code for the modified bryar pistol cog, which on secondary fire places the new turret. It operates fine, but since the two are connected, I thought one might help the other.
Code:
# Jedi Knight Cog Script
#
# WEAP_BRYAR.COG
#
# WEAPON 2 Script - Bryar Pistol
#
# The trusty weapon of Kyle Katarn. This is actually an older modified rifle
# that has been cut down to more of a pistol size. It is very accurate but
# somewhat of a low power weapon. This weapon has only one type of fire.
#
# DragonPhinn here, added the TURRETMAKING portion of this cog.
#
# - Affected by MagSealed sectors/surfaces.
#
# [YB & CYW]
# [HNS]
symbols
model povModel=bryv.3do local
model weaponMesh=bryg.3do local
keyframe mountAnim=bryvmnt.key local
keyframe dismountAnim=bryvdis.key local
keyframe povfireAnim=bryvpst1.key local
keyframe holsterAnim=kyhlstr.key local
sound outSound=pistout1.wav local
sound mountSound=df_bry_ready.wav local
sound dismountSound=PutWeaponAway01.wav local
sound fireSound=pistol-1.wav local
template projectile=+bryarbolt local
template turrettype=buildt
thing player local
thing victim local
thing potential local
flex dot local
flex maxDot local
flex fireWait=0.5 local
flex holsterWait local
flex fireDelay=0.6 local
flex powerBoost local
flex autoAimFOV=30 local
flex autoAimMaxDist=5 local
int weaponIndex local
int trackID=-1 local
int dummy=0 local
int mode local
int holsterTrack local
int bin=11
message activated
message deactivated
message selected
message deselected
message autoselect
message fire
message timer
end
# ========================================================================================
code
fire:
player = GetSourceRef();
if(mode==0)
{
// Check that the player is still alive.
if(GetThingHealth(player) <= 0)
{
Return;
}
// Check Ammo - If we are out, autoselect best weapon.
if(GetInv(player, 11) < 1.0)
{
PlaySoundThing(outSound, player, 1.0, -1.0, -1.0, 0x80);
if(GetAutoSwitch() & 1)
SelectWeapon(player, AutoSelectWeapon(player, 1));
Return;
}
SetPOVShake('0.0 -.003 0.0', '1.0 0.0 0.0', .05, 80.0);
dummy = FireProjectile(player, projectile, fireSound, 8, '0.0135 0.1624 0.0', '0 0 0', 1.0, 0x20, autoAimFOV, autoAimFOV*2);
ChangeInv(player, 11, -1.0);
jkPlayPOVKey(player, povfireAnim, 1, 0x38);
powerBoost = GetInv(player, 63);
ChangeFireRate(player, fireWait/powerBoost);
Return;
}
else
{
if(GetThingHealth(player) <= 0)
{
Return;
}
// Check Ammo - If we are out, autoselect best weapon.
if(GetInv(player, bin) < 1)
{
Print("DEBUG: Bin=");
PrintInt(GetInv(player, bin));
Print("Need More Turret Construction Kits.");
PlaySoundThing(outSound, player, 1.0, -1.0, -1.0, 0x80);
if(GetAutoSwitch() & 1)
SelectWeapon(player, AutoSelectWeapon(player, 1));
Return;
}
Print("DEBUG: Created Turret Type");
CreateThing(turrettype, player);
ChangeInv(player, bin, -1.0);
return;
}
# ........................................................................................
activated:
player = GetSourceRef();
mode = GetSenderRef();
jkSetWaggle(player, '0.0 0.0 0.0', 0);
powerBoost = GetInv(player, 63);
ActivateWeapon( player, fireWait/powerBoost, mode );
Return;
# ........................................................................................
deactivated:
player = GetSourceRef();
mode = GetSenderRef();
jkSetWaggle(player, '10.0 7.0 0.0', 350);
DeactivateWeapon( player, mode );
Return;
# ........................................................................................
selected:
player = GetSourceRef();
// Setup the meshes and models.
jkSetPOVModel(player, povModel);
jkSetWeaponMesh(player, weaponMesh);
SetArmedMode(player, 1);
// Play mounting sound.
PlayMode(player, 41);
PlaySoundThing(mountSound, player, 1.0, -1.0, -1.0, 0x80);
// Play the animation (NOLOOP + UNIQUE + ENDPAUSE).
// The animation is held at the last frame after it is played.
trackID = jkPlayPOVKey(player, mountAnim, 0, 0x14);
jkSetWaggle(player, '10.0 7.0 0.0', 350);
// Clear saber flags, and allow activation of the weapon
jkClearFlags(player, 0x5);
SetCurWeapon(player, 2);
SetMountWait(player, GetKeyLen(mountAnim));
Return;
# ........................................................................................
deselected:
player = GetSourceRef();
weaponIndex = GetSenderRef();
PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
jkPlayPOVKey(player, dismountAnim, 0, 0x18);
holsterWait = GetKeyLen(holsterAnim);
SetMountWait(player, holsterWait);
holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
SetTimerEx(holsterWait, 2, 0.0, 0.0);
if (trackID != -1)
{
jkStopPOVKey(player, trackID, 0);
trackID = -1;
}
jkSetWaggle(player, '0.0 0.0 0.0', 0);
Return;
# ........................................................................................
autoselect:
player = GetSourceRef();
// If the player has the weapon
if(GetInv(player, 2) != 0.0)
{
// If the player has ammo
if(GetInv(player, 11) != 0.0)
{
ReturnEx(500.0);
}
else
{
ReturnEx(-1.0);
}
}
else
{
ReturnEx(-1.0);
}
Return;
# ........................................................................................
timer:
StopKey(player, holsterTrack, 0.0);
Return;
endThe template is the turret1.3do with the cog added to it. Parent _zwalkstructure.
Thanks in advanced!
![http://forums.massassi.net/html/smile.gif [http://forums.massassi.net/html/smile.gif]](http://forums.massassi.net/html/smile.gif)
hope that helps!