Can someone help me here. I store a player's weapon ammo type and amount and then try to restore it, but it fails. If the weapon has NO amount it gets restored with the base ammo amount, not the amount I stored.
Is this code:
the same as the LUA versionCode:var weapon = item.GetHeldEntity() as BaseProjectile; if (weapon != null) { var ammoType = ItemManager.FindItemDefinition(storedItem.ammo); if (ammoType != null) { weapon.primaryMagazine.ammoType = ammoType; weapon.primaryMagazine.contents = storedItem.ammoamount; (item.GetHeldEntity() as BaseProjectile).primaryMagazine.contents = storedItem.ammoamount; (item.GetHeldEntity() as BaseProjectile).primaryMagazine.ammoType = ammoType; } } item.MoveToContainer(loot.inventory, storedItem.slot);
Thanks in advance !Code:if item.ammo then local magazine = itemEntity:GetHeldEntity().primaryMagazine local itemDef = global.ItemManager.FindItemDefinition.methodarray[1]:Invoke(nil, util.TableToArray({item.ammo.name})) magazine.ammoType = itemDef magazine.contents = item.ammo.amount end -- Set that created inventory item to player player.inventory:GiveItem(itemEntity, Inventory[slot])
Setting a weapon's ammo type and amount?
Discussion in 'Rust Development' started by isuelt, Mar 12, 2016.
-
May I see how your saving the data? That might be the problem here.
-
Code:
class storedItem { public int amount; public int skinid; public int slot; public int itemid; public string shortname; public string ammo; public int ammoamount; public bool blueprint; public string durability; public Dictionary<int, string> attachments = new Dictionary<int, string>(); }
-
Is this saving per player, or is it server wide?
-
Perhaps I am misunderstanding the question but it seems you are kind of contradicting yourself here, you say if the weapon has no ammo it gets restored to the default rust amount. If it has no ammo what are you storing? Are you trying to save a value of 0?
A good example of exactly what you are trying to do I wrote in the latest EventManager update. Perhaps looking through it may help you with your issue