Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

Add Events.PlayerPickupWeaponCallback and Events.PlayerDropWeaponCallback

Here you can find ScriptAPI suggestions implemented in the game.
Forum rules
By using the forum you agree to the following rules.
Locked
NearHuscarl
Superfighter
Superfighter
Posts: 97
Joined: Thu Feb 07, 2019 4:36 am

Add Events.PlayerPickupWeaponCallback and Events.PlayerDropWeaponCallback

Post by NearHuscarl » Sun Feb 23, 2020 8:15 pm

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
}
0 x
Image

User avatar
Ol1vver
Superfighter
Superfighter
Posts: 69
Joined: Mon Nov 19, 2018 4:55 pm
SFD Account: olv
SFD Alias: olv
Started SFD: PreAlpha 1.6.4
Gender:

Post by Ol1vver » Sun Feb 23, 2020 9:34 pm

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.
0 x

NearHuscarl
Superfighter
Superfighter
Posts: 97
Joined: Thu Feb 07, 2019 4:36 am

Post by NearHuscarl » 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
0 x
Image

User avatar
Ol1vver
Superfighter
Superfighter
Posts: 69
Joined: Mon Nov 19, 2018 4:55 pm
SFD Account: olv
SFD Alias: olv
Started SFD: PreAlpha 1.6.4
Gender:

Post by Ol1vver » Sun Feb 23, 2020 11:03 pm

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
0 x

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Post by Gurt » Sun Feb 23, 2020 11:52 pm

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.
1 x
Gurt

NearHuscarl
Superfighter
Superfighter
Posts: 97
Joined: Thu Feb 07, 2019 4:36 am

Post by NearHuscarl » Mon Feb 24, 2020 2:29 am

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.
0 x
Image

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Post by Gurt » Sun Mar 22, 2020 8:18 pm

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).
1 x
Gurt

Locked