Ok, I don't get this, and I hope some one else can think of a solution because my attempts to fix this have turned into me staring at the cog for long periods of time as of late.
When the player dies, or throws his weapon, I create a backpack powerup. Then I set the model to the appropriate gun model and use setthinguserdata() to reflect the ammo that the player had for that gun. It works fine locally, but it always comes up as zero on the other computers on the network. I even tried using a trigger but that doesn't seem to do anything. Here are the important bits of the cog. (Abridged somewhat, but still really long...)
from item_dropweapon.cog
curWeapon = GetCurWeapon(player);
// check for unpullable weapons
if( (curWeapon == 1) || (curWeapon == 10) || (curWeapon == 0))
return;
PulledWeapon = CreateBackpack(player);
setthingmodel(PulledWeapon, weapon[curWeapon]); // pass weapon type as model
// Turn off gravity for the thing
//ClearPhysicsFlags(PulledWeapon, 0x1);
ApplyForce(PulledWeapon, VectorScale(VectorNorm(VectorAdd(GetThingLVec(player), VectorSet(0, 0, 1))), 10));
SetCollideType(PulledWeapon, 0);
SetTimerEx(.2, 1, PulledWeapon, 0);
// Duplicate for internet games
if (IsMulti())
SetTimerEx(.25, 1, PulledWeapon, 0);
packmodel = GetThingModel(PulledWeapon);
if(packmodel == weapon11)
{
weaponbin = 131;
ammobin = 131;
maxammotoss = 1;
}
else
if( (packmodel == weapon2) || (packmodel == weapon12) )
{
ammobin = 141;
weaponbin = 122;
maxammotoss = 64;
}
else
if(packmodel == weapon3)
{
ammobin = 142;
weaponbin = 123;
maxammotoss = 64;
}
else
if(packmodel == weapon13)
{
ammobin = 142;
weaponbin = 133;
maxammotoss = 64;
}
else
if(packmodel == weapon4)
{
ammobin = 124;
weaponbin = 999;
maxammotoss = 3;
}
else
if(packmodel == weapon14)
{
ammobin = 134;
weaponbin = 999;
maxammotoss = 3;
}
else
if(packmodel == weapon5)
{
ammobin = 155;
weaponbin = 999;
maxammotoss = 3;
}
else
if(packmodel == weapon15)
{
ammobin = 144;
weaponbin = 999;
maxammotoss = 3;
}
else
if( (packmodel == weapon6) || (packmodel == weapon16) )
{
ammobin = 143;
weaponbin = 126;
maxammotoss = 16;
}
else
if(packmodel == weapon7)
{
ammobin = 15;
weaponbin = 999;
maxammotoss = 3;
}
else
if(packmodel == weapon17)
{
ammobin = 91;
weaponbin = 999;
maxammotoss = 3;
}
else
if(packmodel == weapon8)
{
ammobin = GetWeaponBin(8);
weaponbin = 158;
maxammotoss = 6;
}
else
if(packmodel == weapon18)
{
ammobin = GetWeaponBin(8);
weaponbin = 157;
maxammotoss = 6;
}
else
if( (packmodel == weapon19) || (packmodel == weapon9) )
{
ammobin = 146;
weaponbin = 129;
maxammotoss = 64;
}
else
if(packmodel == weapon20)
{
ammobin = 156;
weaponbin = 140;
maxammotoss = 8;
}
ammoingun = GetInv(player, ammobin);
if(ammoingun > maxammotoss) // only allow a certain amount of ammo to be tossed
ammoingun = maxammotoss;
if(weaponbin != 999)
ChangeInv(player, weaponbin, -1.0); // take the gun away
ChangeInv(player, ammobin, -ammoingun);
SetThingUserData(PulledWeapon, ammoingun); // pass ammo amount as user data
if(IsMulti())
{
ID = 88777700; //broadcast for multiplayer
SendTrigger(-1, ID, PulledWeapon, ammoingun, player, 0);
}
if(weaponbin != 999)
SelectWeapon(player, 1);
else
{
if(GetInv(player, ammobin) < 1)
SelectWeapon(player, 1);
}
return;
also from item_dropweapon.cog:
# ........................................................................................
trigger:
If(GetParam(2) == player) return;
if( (GetSourceRef() == 88777700) )
{
SetThingUserData(GetParam(0), GetParam(1));
}
return;
and from pow_backpack_m.cog:
# ........................................................................................
taken:
player = GetSourceRef();
powerup = GetSenderRef();
//jkPrintUNIString(player, 200);
// Do effects.
PlaySoundLocal(pickupsnd, 1, 0, 0);
AddDynamicTint(player, 0.0, 0.0, 0.2);
// Pickup the backpack
// PickupBackpack(player, powerup);
packmodel = GetThingModel(powerup);
JkStringClear();
if(packmodel == weapon11)
{
//jkPrintUNIString(player, 131);
jkStringConcatUniString(131);
weaponbin = 131;
ammobin = 131;
}
else
if( (packmodel == weapon2) || (packmodel == weapon12) )
{
//jkPrintUNIString(player, 122);
jkStringConcatUniString(122);
ChangeInv(player, GetWeaponBin(12), 1.0); // special case bin
weaponbin = 122;
ammobin = 141;
}
else
if(packmodel == weapon3)
{
//jkPrintUNIString(player, 123);
jkStringConcatUniString(123);
weaponbin = 123;
ammobin = 142;
}
else
if(packmodel == weapon13)
{
//jkPrintUNIString(player, 133);
jkStringConcatUniString(133);
weaponbin = 133;
ammobin = 142;
}
else
if(packmodel == weapon4)
{
//jkPrintUNIString(player, 124);
jkStringConcatUniString(124);
weaponbin = 999;
ammobin = 124;
}
else
if(packmodel == weapon14)
{
//jkPrintUNIString(player, 134);
jkStringConcatUniString(134);
weaponbin = 999;
ammobin = 134;
}
else
if(packmodel == weapon5)
{
//jkPrintUNIString(player, 125);
jkStringConcatUniString(125);
ChangeInv(player, GetWeaponBin(5), 1.0); // special case bin
weaponbin = 999;
ammobin = 155;
}
else
if(packmodel == weapon15)
{
//jkPrintUNIString(player, 135);
jkStringConcatUniString(135);
ChangeInv(player, GetWeaponBin(5), 1.0); // special case bin
weaponbin = 999;
ammobin = 144;
}
else
if( (packmodel == weapon6) || (packmodel == weapon16) )
{
//jkPrintUNIString(player, 126);
jkStringConcatUniString(126);
weaponbin = 126;
ammobin = 143;
}
else
if(packmodel == weapon7)
{
//jkPrintUNIString(player, 15);
jkStringConcatUniString(15);
//SetInv(player, GetWeaponBin(7), 1.0);
weaponbin = 127;
ammobin = 15;
}
else
if(packmodel == weapon17)
{
//jkPrintUNIString(player, 91);
jkStringConcatUniString(91);
//SetInv(player, GetWeaponBin(17), 1.0);
weaponbin = 137;
ammobin = 91;
}
else
if(packmodel == weapon8)
{
//jkPrintUNIString(player, 127);
jkStringConcatUniString(127);
//SetInv(player, GetWeaponBin(8), 1.0);
weaponbin = 158;
ammobin = GetWeaponBin(8);
}
else
if(packmodel == weapon18)
{
//jkPrintUNIString(player, 137);
jkStringConcatUniString(137);
SetInv(player, GetWeaponBin(18), 1.0);
weaponbin = 157;
ammobin = GetWeaponBin(8);
}
else
if( (packmodel == weapon19) || (packmodel == weapon9) )
{
//jkPrintUNIString(player, 129);
jkStringConcatUniString(129);
weaponbin = 129;
ammobin = 146;
}
else
if(packmodel == weapon20)
{
//jkPrintUNIString(player, 140);
jkStringConcatUniString(140);
weaponbin = 140;
ammobin = 156;
}
else
return;
ammoamount = GetThingUserData(powerup);
JkStringConcatAsciiString(" ( ");
//jkStringConcatFlex(ammoamount);
jkStringConcatInt(ammoamount);
JkStringConcatAsciiString(" )");
JkStringOutput(-1, -1);
if(weaponbin != 999)
ChangeInv(player, weaponbin, 1.0);
//if(ammoamount < 1)
// ChangeInv(player, ammobin, 1.0);
//else
ChangeInv(player, ammobin, ammoamount);
// New ammo is already assigned, so this is like a autopickup/autoreload mix,
// it will select the best weapon overall with all the stuff in the backpack
// taken into account.
autopickup = GetAutoPickup();
autoselect_weapon = AutoSelectWeapon(player, 0);
if(autopickup & 1)
{
if( !((autopickup & 2) && ((autoselect_weapon == 4) || (autoselect_weapon == 8) || (autoselect_weapon == 9)) ))
{
if(!((autopickup & 4) && (GetWeaponPriority(player, GetWeaponBin(GetCurWeapon(player)), 0) >= GetWeaponPriority(player, autoselect_weapon, 0) )))
{
if(!((autopickup & 8) && (GetWeaponBin(GetCurWeapon(player)) == jkGetMultiParam(1))))
{
SelectWeapon(player, autoselect_weapon);
Return;
}
}
}
}
Return;
When the player dies, or throws his weapon, I create a backpack powerup. Then I set the model to the appropriate gun model and use setthinguserdata() to reflect the ammo that the player had for that gun. It works fine locally, but it always comes up as zero on the other computers on the network. I even tried using a trigger but that doesn't seem to do anything. Here are the important bits of the cog. (Abridged somewhat, but still really long...)
from item_dropweapon.cog
curWeapon = GetCurWeapon(player);
// check for unpullable weapons
if( (curWeapon == 1) || (curWeapon == 10) || (curWeapon == 0))
return;
PulledWeapon = CreateBackpack(player);
setthingmodel(PulledWeapon, weapon[curWeapon]); // pass weapon type as model
// Turn off gravity for the thing
//ClearPhysicsFlags(PulledWeapon, 0x1);
ApplyForce(PulledWeapon, VectorScale(VectorNorm(VectorAdd(GetThingLVec(player), VectorSet(0, 0, 1))), 10));
SetCollideType(PulledWeapon, 0);
SetTimerEx(.2, 1, PulledWeapon, 0);
// Duplicate for internet games
if (IsMulti())
SetTimerEx(.25, 1, PulledWeapon, 0);
packmodel = GetThingModel(PulledWeapon);
if(packmodel == weapon11)
{
weaponbin = 131;
ammobin = 131;
maxammotoss = 1;
}
else
if( (packmodel == weapon2) || (packmodel == weapon12) )
{
ammobin = 141;
weaponbin = 122;
maxammotoss = 64;
}
else
if(packmodel == weapon3)
{
ammobin = 142;
weaponbin = 123;
maxammotoss = 64;
}
else
if(packmodel == weapon13)
{
ammobin = 142;
weaponbin = 133;
maxammotoss = 64;
}
else
if(packmodel == weapon4)
{
ammobin = 124;
weaponbin = 999;
maxammotoss = 3;
}
else
if(packmodel == weapon14)
{
ammobin = 134;
weaponbin = 999;
maxammotoss = 3;
}
else
if(packmodel == weapon5)
{
ammobin = 155;
weaponbin = 999;
maxammotoss = 3;
}
else
if(packmodel == weapon15)
{
ammobin = 144;
weaponbin = 999;
maxammotoss = 3;
}
else
if( (packmodel == weapon6) || (packmodel == weapon16) )
{
ammobin = 143;
weaponbin = 126;
maxammotoss = 16;
}
else
if(packmodel == weapon7)
{
ammobin = 15;
weaponbin = 999;
maxammotoss = 3;
}
else
if(packmodel == weapon17)
{
ammobin = 91;
weaponbin = 999;
maxammotoss = 3;
}
else
if(packmodel == weapon8)
{
ammobin = GetWeaponBin(8);
weaponbin = 158;
maxammotoss = 6;
}
else
if(packmodel == weapon18)
{
ammobin = GetWeaponBin(8);
weaponbin = 157;
maxammotoss = 6;
}
else
if( (packmodel == weapon19) || (packmodel == weapon9) )
{
ammobin = 146;
weaponbin = 129;
maxammotoss = 64;
}
else
if(packmodel == weapon20)
{
ammobin = 156;
weaponbin = 140;
maxammotoss = 8;
}
ammoingun = GetInv(player, ammobin);
if(ammoingun > maxammotoss) // only allow a certain amount of ammo to be tossed
ammoingun = maxammotoss;
if(weaponbin != 999)
ChangeInv(player, weaponbin, -1.0); // take the gun away
ChangeInv(player, ammobin, -ammoingun);
SetThingUserData(PulledWeapon, ammoingun); // pass ammo amount as user data
if(IsMulti())
{
ID = 88777700; //broadcast for multiplayer
SendTrigger(-1, ID, PulledWeapon, ammoingun, player, 0);
}
if(weaponbin != 999)
SelectWeapon(player, 1);
else
{
if(GetInv(player, ammobin) < 1)
SelectWeapon(player, 1);
}
return;
also from item_dropweapon.cog:
# ........................................................................................
trigger:
If(GetParam(2) == player) return;
if( (GetSourceRef() == 88777700) )
{
SetThingUserData(GetParam(0), GetParam(1));
}
return;
and from pow_backpack_m.cog:
# ........................................................................................
taken:
player = GetSourceRef();
powerup = GetSenderRef();
//jkPrintUNIString(player, 200);
// Do effects.
PlaySoundLocal(pickupsnd, 1, 0, 0);
AddDynamicTint(player, 0.0, 0.0, 0.2);
// Pickup the backpack
// PickupBackpack(player, powerup);
packmodel = GetThingModel(powerup);
JkStringClear();
if(packmodel == weapon11)
{
//jkPrintUNIString(player, 131);
jkStringConcatUniString(131);
weaponbin = 131;
ammobin = 131;
}
else
if( (packmodel == weapon2) || (packmodel == weapon12) )
{
//jkPrintUNIString(player, 122);
jkStringConcatUniString(122);
ChangeInv(player, GetWeaponBin(12), 1.0); // special case bin
weaponbin = 122;
ammobin = 141;
}
else
if(packmodel == weapon3)
{
//jkPrintUNIString(player, 123);
jkStringConcatUniString(123);
weaponbin = 123;
ammobin = 142;
}
else
if(packmodel == weapon13)
{
//jkPrintUNIString(player, 133);
jkStringConcatUniString(133);
weaponbin = 133;
ammobin = 142;
}
else
if(packmodel == weapon4)
{
//jkPrintUNIString(player, 124);
jkStringConcatUniString(124);
weaponbin = 999;
ammobin = 124;
}
else
if(packmodel == weapon14)
{
//jkPrintUNIString(player, 134);
jkStringConcatUniString(134);
weaponbin = 999;
ammobin = 134;
}
else
if(packmodel == weapon5)
{
//jkPrintUNIString(player, 125);
jkStringConcatUniString(125);
ChangeInv(player, GetWeaponBin(5), 1.0); // special case bin
weaponbin = 999;
ammobin = 155;
}
else
if(packmodel == weapon15)
{
//jkPrintUNIString(player, 135);
jkStringConcatUniString(135);
ChangeInv(player, GetWeaponBin(5), 1.0); // special case bin
weaponbin = 999;
ammobin = 144;
}
else
if( (packmodel == weapon6) || (packmodel == weapon16) )
{
//jkPrintUNIString(player, 126);
jkStringConcatUniString(126);
weaponbin = 126;
ammobin = 143;
}
else
if(packmodel == weapon7)
{
//jkPrintUNIString(player, 15);
jkStringConcatUniString(15);
//SetInv(player, GetWeaponBin(7), 1.0);
weaponbin = 127;
ammobin = 15;
}
else
if(packmodel == weapon17)
{
//jkPrintUNIString(player, 91);
jkStringConcatUniString(91);
//SetInv(player, GetWeaponBin(17), 1.0);
weaponbin = 137;
ammobin = 91;
}
else
if(packmodel == weapon8)
{
//jkPrintUNIString(player, 127);
jkStringConcatUniString(127);
//SetInv(player, GetWeaponBin(8), 1.0);
weaponbin = 158;
ammobin = GetWeaponBin(8);
}
else
if(packmodel == weapon18)
{
//jkPrintUNIString(player, 137);
jkStringConcatUniString(137);
SetInv(player, GetWeaponBin(18), 1.0);
weaponbin = 157;
ammobin = GetWeaponBin(8);
}
else
if( (packmodel == weapon19) || (packmodel == weapon9) )
{
//jkPrintUNIString(player, 129);
jkStringConcatUniString(129);
weaponbin = 129;
ammobin = 146;
}
else
if(packmodel == weapon20)
{
//jkPrintUNIString(player, 140);
jkStringConcatUniString(140);
weaponbin = 140;
ammobin = 156;
}
else
return;
ammoamount = GetThingUserData(powerup);
JkStringConcatAsciiString(" ( ");
//jkStringConcatFlex(ammoamount);
jkStringConcatInt(ammoamount);
JkStringConcatAsciiString(" )");
JkStringOutput(-1, -1);
if(weaponbin != 999)
ChangeInv(player, weaponbin, 1.0);
//if(ammoamount < 1)
// ChangeInv(player, ammobin, 1.0);
//else
ChangeInv(player, ammobin, ammoamount);
// New ammo is already assigned, so this is like a autopickup/autoreload mix,
// it will select the best weapon overall with all the stuff in the backpack
// taken into account.
autopickup = GetAutoPickup();
autoselect_weapon = AutoSelectWeapon(player, 0);
if(autopickup & 1)
{
if( !((autopickup & 2) && ((autoselect_weapon == 4) || (autoselect_weapon == 8) || (autoselect_weapon == 9)) ))
{
if(!((autopickup & 4) && (GetWeaponPriority(player, GetWeaponBin(GetCurWeapon(player)), 0) >= GetWeaponPriority(player, autoselect_weapon, 0) )))
{
if(!((autopickup & 8) && (GetWeaponBin(GetCurWeapon(player)) == jkGetMultiParam(1))))
{
SelectWeapon(player, autoselect_weapon);
Return;
}
}
}
}
Return;