Forum

> > CS2D > Scripts > "Catch" an item thrown with spawnprojectile
Forums overviewCS2D overview Scripts overviewLog in to reply

English "Catch" an item thrown with spawnprojectile

8 replies
To the start Previous 1 Next To the start

old "Catch" an item thrown with spawnprojectile

Vectarrio
User Off Offline

Quote
So I've made a little simple script, which allows some players to "throw" an item (e.g. a bandage) via cs2d cmd spawnprojectile, and I expected that if an item landed on a tile with a player, a player would pick it up immediately. But, unfortunately, in order to pick it up, a player must leave this tile and then step on it again. Is there any simple way to make a player pick it up w/o moving anywhere? Because all the ways I came up with look like a long workaround

old Re: "Catch" an item thrown with spawnprojectile

Rainoth
Moderator Off Offline

Quote
Simply put, script the pick up yourself.

• Check if someone's standing on the tile where the item should drop (OPT: check if it's a teammate/enemy)
• use cs2d cmd removeitem the moment it lands
• equip it on the player who was standing where the item landed (NOTE: not all items can be equipped)
• OPT: use cs2d cmd setweapon for certain items.

Hope that helps.
Cheers.

old Re: "Catch" an item thrown with spawnprojectile

Yates
Reviewer Off Offline

Quote
You can do what user Rainoth said but remember to check if the person is already holding a weapon, it might also cause armours to not drop on setarmour (leaving you with the armour the person threw, and not the armour the person already had which should be on the ground after "pickup").

old Re: "Catch" an item thrown with spawnprojectile

Vectarrio
User Off Offline

Quote
@user Rainoth: Yeah, thanx! And now some stupid question: How do i know where and when does an item land? Is there a hook or smth? (cause I don't wanna miss the animation of an item being thrown, and time a way it flies and stuff)
Does the "projectile" hook trigger when a simple item lands?

old Re: "Catch" an item thrown with spawnprojectile

Rainoth
Moderator Off Offline

Quote
@user Vectarrio: Good job, you read my mind. I came back with the intention to analyze my method to see if that was the case. It is.

One solution is to use cs2d lua cmd closeitems to check if there are any items with your thrown item ID around them (based on the notion that items of that ID aren't normally dropped or spawn on the map like items from Env_item entity or items from supply building.)

That works but it's really crude. It's probably faster & doesn't require so much computation if it meets the requirements though.

The second solution and a foolproof one at that is to get distance (since you have to calculate it to pass as one of the parameters for spawnprojectile command) and determine which tile it's going to land on.

Finally, the one I probably like best, is using cs2d lua cmd projectilelist & cs2d lua cmd projectile with "x","y","flydist" & "time" values to determine the landing point. You'll also get ID which you'll later use with cs2d cmd removeitem (I think).
You may also use it to get "ground" projectiles and use that (don't want to think how cause no ( ͡° ͜ʖ ͡°))

Hope that helps.
Cheers.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview