Forum

> > CS2D > Scripts > Throw weapon at player
Forums overviewCS2D overview Scripts overviewLog in to reply

English Throw weapon at player

7 replies
To the start Previous 1 Next To the start

old Throw weapon at player

Mami Tomoe
User Off Offline

Quote
I'd like to be able to throw a weapon at a player, given source x, y and player x, y.

With range calculation and rotation calculation.

Help pls

old Re: Throw weapon at player

cs2d_is_a_Gem
User Off Offline

Quote
> If you can't make a script as basic as this, you shouldn't speak expertly in my posts, it even says you would do better.

Anyway, I know it is difficult for you to understand the scripts. I will write the script for you if you give me more details.

old Re: Throw weapon at player

cs2d_is_a_Gem
User Off Offline

Quote
In my nick my username comes out if you want to know who I am, I know you don't know how to read scripts, but I didn't know that you don't know how to read English.

well if you explain better I help you with your little basic problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cant_drop = {50,74}
normal_drop = {47,48,49,51,52,53,54,72,73,75,76,89}

addhook("drop","drop")
function drop(id,idd,type)
     for _, value in pairs(cant_drop) do
          if value == player(id,"weapon") then
return 1
end
end

     for _, v in pairs(normal_drop) do
          if v == player(id,"weapon") then
return 0
end
end

local x=player(id,"x") 
local y=player(id,"y") 
local rot=player(id,"rot") 
parse("strip "..id.." "..type.."")
parse("spawnprojectile 0 "..type.." "..x.." "..y.." 100 "..rot.."")
return 1
end
edited 1×, last 19.05.20 09:46:16 pm

old Re: Throw weapon at player

The Dark Shadow
User Off Offline

Quote
@user cs2d_is_a_Gem: You and your scripting skills are sucks anyway. Most likely you don't know anything about performance optimization...and this code without tabs make my eyes hurt. No need to be pretentious anyway, sir. With my respect!

old Re: Throw weapon at player

Mami Tomoe
User Off Offline

Quote
I want the weapon to be thrown in the player's direction regardless of where the location or player are.

locationX, locationY
playerX, playerY

It's simple math, for whoever knows math.

I don't know what else you're talking about though.

old Re: Throw weapon at player

Baloon
GAME BANNED Off Offline

Quote
Try this
1
2
3
4
5
6
7
8
-- in pixels
local locationX = 16
local locationY = 16

function throwTo(id, weapon)
   local deltaX, deltaY = locationX-player(id,"x"), locationY-player(id,"y")
   parse("spawnprojectile "..id.." "..weapon.." "..locationX.." "..locationY.." "..math.sqrt(deltaX^2+deltaY^2).." "..math.deg(math.atan2(-deltaX, deltaY)))
end
Sorry, little mistake, edited and bumped.
edited 2×, last 20.05.20 02:12:56 pm

old Re: Throw weapon at player

Mami Tomoe
User Off Offline

Quote
Thanks that should work, will test it in a few hours once I'm home.

Edit:
OK so it works but only for some degrees, like if I stand above it the weapon spawns at the locationX, locationY but if I stand like at the left, the weapon is thrown to me.

Is that me using it wrong or is there an actual issue with the sample code?


Edit: I got it to work thanks
edited 2×, last 21.05.20 05:28:45 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview