CS2D
Scripts
"Catch" an item thrown with spawnprojectile
"Catch" an item thrown with spawnprojectile
8 replies So I've made a little simple script, which allows some players to "throw" an item (e.g. a bandage) via
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
Teleport the player to a random location (I usually use 0, 0) and then teleport the player back. There is no other way, sadly. 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
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
setweapon for certain items.
Hope that helps.
Cheers. You can do what
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"). @
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? @
Yates: @
Rainoth: Thank you both very much
Now will try to implement it
@
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
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
projectilelist &
projectile with "x","y","flydist" & "time" values to determine the landing point. You'll also get ID which you'll later use with
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. @
Rainoth: And thanks again! Now I can put less time into thinking it all through (yup, I'm a lazy one
)