Page 1 of 1
Add Events.PlayerPickupWeaponCallback and Events.PlayerDropWeaponCallback
Posted: Sun Feb 23, 2020 8:15 pm
by NearHuscarl
My problem: I want to extend existing projectile powerups besides bouncing and fire via scripting, something similar to
this one. But currently, there is no clean way to keep track of weapons when it's dropped or picked up by players, so those powerup guns is not quite transferable between players. I may write a custom Drop and Pickup events, but that may not be very reliable.
Here is some examples
Code: Select all
Events.PlayerDropWeaponCallback.Start(OnPlayerDropWeapon);
...
public void OnPlayerDropWeapon(IPlayer player, WeaponItem weaponItem, IObject weaponObj) {
// if the weapon has custom powerup, store the powerup type in custom weapon db using weaponObj.UniqueId as key
}
Events.PlayerPickupWeaponCallback.Start(OnPlayerPickupWeapon);
...
public void OnPlayerPickupWeapon(IPlayer player, WeaponItem weaponItem, IObject weaponObj) {
// check if weaponObj.UniqueId is in custom weapon db. Retrieve the powerup type for the next player
}
Re: Add Events.PlayerPickupWeaponCallback and Events.PlayerDropWeaponCallback
Posted: Sun Feb 23, 2020 9:34 pm
by Ol1vver
You could check if the player's inventory changed. Something like save current secondary and primary weapons (they would be nothing for now) and check if it changed, if not, then repeat till the values are updated.
Re: Add Events.PlayerPickupWeaponCallback and Events.PlayerDropWeaponCallback
Posted: Sun Feb 23, 2020 10:28 pm
by NearHuscarl
I can do that, when the player drops a gun, it will spawn a Wpn object in the map, then I can check the nearby objects using
Code: Select all
Game.GetObjectsByArea<IObjectWeaponItem>(Player.GetAABB())
To check for the gun that is just dropped to get the UniqueID, but what if, there is also the same gun right at the player's foot before the player dropped, it may pickup the wrong one. And I am not sure if running Game.GetObjectsByArea repeatedly for every players is a good idea performance-wise. So yeah, it maybe doable, but not the best solution for me so far
Re: Add Events.PlayerPickupWeaponCallback and Events.PlayerDropWeaponCallback
Posted: Sun Feb 23, 2020 11:03 pm
by Ol1vver
NearHuscarl wrote: ↑Sun Feb 23, 2020 10:28 pm
I can do that, when the player drops a gun, it will spawn a Wpn object in the map, then I can check the nearby objects using
Code: Select all
Game.GetObjectsByArea<IObjectWeaponItem>(Player.GetAABB())
To check for the gun that is just dropped to get the UniqueID, but what if, there is also the same gun right at the player's foot before the player dropped, it may pickup the wrong one. And I am not sure if running Game.GetObjectsByArea repeatedly for every players is a good idea performance-wise. So yeah, it maybe doable, but not the best solution for me so far
I meant saving the player's current primary and secondary weapon (which would be WeaponItem.NONE for now), and next time if the method is called and the WeaponItem isn't WeaponItem.NONE, do stuff
Re: Add Events.PlayerPickupWeaponCallback and Events.PlayerDropWeaponCallback
Posted: Sun Feb 23, 2020 11:52 pm
by Gurt
NearHuscarl wrote: ↑Sun Feb 23, 2020 10:28 pm
I can do that, when the player drops a gun, it will spawn a Wpn object in the map, then I can check the nearby objects using
Code: Select all
Game.GetObjectsByArea<IObjectWeaponItem>(Player.GetAABB())
To check for the gun that is just dropped to get the UniqueID, but what if, there is also the same gun right at the player's foot before the player dropped, it may pickup the wrong one. And I am not sure if running Game.GetObjectsByArea repeatedly for every players is a good idea performance-wise. So yeah, it maybe doable, but not the best solution for me so far
If you get multiple results the one with the highest UniqueId is the one created last. If you run the GetObjectsByArea<IObjectWeaponItem> in the same update you detect the player has changed the inventory it's doable. But I like the Events.PlayerPickupWeaponCallback and Events.PlayerDropWeaponCallback idea.
Re: Add Events.PlayerPickupWeaponCallback and Events.PlayerDropWeaponCallback
Posted: Mon Feb 24, 2020 2:29 am
by NearHuscarl
Ol1vver wrote: ↑Sun Feb 23, 2020 11:03 pm
I meant saving the player's current primary and secondary weapon (which would be WeaponItem.NONE for now), and next time if the method is called and the WeaponItem isn't WeaponItem.NONE, do stuff
I've already done that part, but it's a hack. I can diff the current WeaponItem and TotalAmmo of the player, but what if I have a M60 with 100 rounds, and next to me there is another M60. There is no way to know when to fire the event.
Re: Add Events.PlayerPickupWeaponCallback and Events.PlayerDropWeaponCallback
Posted: Sun Mar 22, 2020 8:18 pm
by Gurt
After v.1.3.4:
ScriptAPI: Added Events.PlayerWeaponAddedActionCallback, Events.PlayerWeaponRemovedActionCallback to be able to listen when weapons area added/removed from player equipment (for example when a player grabs items, drops items, throw items, script remove/add items etc...). See documentation for more details. Some limitations apply as these events will run at the end of each player update. See documentation for more details.
In short, you will be able to see what object is created in the world when a player throws/drops items and from which objectID an item is grabbed (if available).