Jump to content
Sign in to follow this  
laxemann

Check if player still has _exactly_ the same weapon as before

Recommended Posts

Hey guys,

I'm really struggling with this one.

Does one of you has any idea how to check if the player still has exactly the same weapon as before?

Checking if the currentWeapon of the player is different to the "old" one doesn't do the trick, because this returns the class names.

The problem:

Let's say I have a regular MX and exchange that for another MX - the script would still tell me "yeah, you have the same weapon" because the classnames are identical.

I hope you get me.

Thanks in advance!

Share this post


Link to post
Share on other sites
Hey guys,

I'm really struggling with this one.

Does one of you has any idea how to check if the player still has exactly the same weapon as before?

Checking if the currentWeapon of the player is different to the "old" one doesn't do the trick, because this returns the class names.

The problem:

Let's say I have a regular MX and exchange that for another MX - the script would still tell me "yeah, you have the same weapon" because the classnames are identical.

I hope you get me.

Thanks in advance!

Maybe name the old weapon?

like

oldweapon = weapon player;

Share this post


Link to post
Share on other sites
Maybe name the old weapon?

like

oldweapon = weapon player;

Nah, not possible, unfortunately :p

Share this post


Link to post
Share on other sites
Maybe name the old weapon?

like

oldweapon = weapon player;

You probably mean primaryWeapon (there is no scripting command called "weapon"), but that still won't work. The oldweapon variable will just contain a string value representing the class name of the weapon, not a pointer to that specific instance of the weapon. (In fact, there is no specific instance of the weapon as it's just a "property" of the holder or container.)

As far as I am aware, it is not currently possible to track or distinguish individual weapons/items of the same type because that's not how the game treats those items.

Share this post


Link to post
Share on other sites

Just to understand you better, what is the purpose of this, what are you planning to do with this check?

Weapons do not have unique ids, so you could only compare every aspect of the weapon. classname, attachments, ammunition but that can be problematic as those aspects can also be changed by the player at any time.

The new eventhandlers "InventoryClosed" and "InventoryOpened" could be useful here but those are not in stable yet.

However, even with these the solution would be rather unreliable.

Anyway if we know what exactly you're trying to do with this we might be able to find an alternative solution for it.

Edited by Tajin

Share this post


Link to post
Share on other sites

If I understand OP correctly he wants to apply some kind of wear effect or something, which would need the weapon OBJECT and not the CLASS.

Very very unfortunately this is currently not possible in Arma.

Share this post


Link to post
Share on other sites

Thanks guys.

Sorry for the music, done in a hurry :D

Everything works like a charm and I'd like to release this tomorrow, but there's one bug left.

The mod detects if the weaponitems have changed and then does... well, what you see in the video :P

It also detects if the items simply changed because the player picked up a different weapon... but this works via classnames,

so if the player picks up a weapon of the same type, it will say "Okey, weapon type didn't change but the attachments changed, lets play the animation".

More clear now? :)

Share this post


Link to post
Share on other sites

Oh hehe, you beat me to it. I actually had the same script-idea on my todo-list. xD Very nice.

In that case, the "InventoryOpened", "InventoryClosed" Eventhandlers could actually help. You're probably running a loop to see if the attachments changed.

With those eventhandlers you won't need a loop and you could configure it so it only plays those gestures when the player opens his own inventory and not when accessing any sort of storage.

Another possibility would be to compare the number of bullets in the current magazine once the inventory closes, though that could probably be fooled by loading a new mag at the same time.

oooooh wait...

... why not do this the other way around?

instead of trying to detect if the weapon got swapped out, just check the players inventory (and the inventory of any storage he accesses) for attachments. If the sum of attachments in all containers changes when he closes the inventory, then it's (relatively) safe to assume that he modified his weapon.

Only issue I see there would be when several players access the same crate. Though that could also be solved.

There would still be some potential glitches but I think that is as good as it gets...

Share this post


Link to post
Share on other sites
Oh hehe, you beat me to it. I actually had the same script-idea on my todo-list. xD Very nice.

In that case, the "InventoryOpened", "InventoryClosed" Eventhandlers could actually help. You're probably running a loop to see if the attachments changed.

With those eventhandlers you won't need a loop and you could configure it so it only plays those gestures when the player opens his own inventory and not when accessing any sort of storage.

Haha nice!

Hm, all solutions would bring up other problems... this is a tricky one :/

Share this post


Link to post
Share on other sites

try this function .

BIS_fnc_itemType an or BIS_fnc_objectType

Edited by Mariodu62

Share this post


Link to post
Share on other sites

Oh by the way: I totally forgot about the "Put" and "Take" eventHandlers.

Still not exactly easy going, but those could help alot.

Share this post


Link to post
Share on other sites
try this function .

BIS_fnc_itemType an or BIS_fnc_objectType

No use, too, unfortunately, but thanks for the idea mate! :)

Edit: @Tajin, that sounds like a plan, will look into it - thanks! :)

Share this post


Link to post
Share on other sites

The "take" event handler fires whenever the player picks up a weapon, even if it is identical to the one they already have.

Share this post


Link to post
Share on other sites

Problem solved thanks to the take eventhandler. A huge thank you again! Now all I gotta do is to add sounds and woosh, release. :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×