English "Catch" an item thrown with spawnprojectile

8 replies
Goto Page
To the start Previous 1 Next To the start
Up
Vectarrio
User
Offline Off
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
06.04.16 12:02:54 am
Up
Yates
Reviewer
Offline Off
Teleport the player to a random location (I usually use 0, 0) and then teleport the player back. There is no other way, sadly.
06.04.16 12:04:53 am
Up
Rainoth
Moderator
Offline Off
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.
06.04.16 12:08:34 am
Up
Yates
Reviewer
Offline Off
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").
06.04.16 12:09:41 am
Up
Vectarrio
User
Offline Off
@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?
06.04.16 12:17:14 am
Up
Yates
Reviewer
Offline Off
cs2d lua cmd projectile

x and y return impact position
06.04.16 12:19:17 am
Up
Vectarrio
User
Offline Off
@user Yates: @user Rainoth: Thank you both very much
Now will try to implement it
06.04.16 12:28:01 am
Up
Rainoth
Moderator
Offline Off
@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.
06.04.16 12:40:43 am
Up
Vectarrio
User
Offline Off
@user Rainoth: And thanks again! Now I can put less time into thinking it all through (yup, I'm a lazy one )
To the start Previous 1 Next To the start