Throw weapon at player
7 replies



19.05.20 04:42:49 pm
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
With range calculation and rotation calculation.
Help pls
It's hard being the best girl in the whole entire world

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.
Who are you? Anyways I'm bad at math.
And I was quite obvious with what I asked.
And I was quite obvious with what I asked.
It's hard being the best girl in the whole entire world
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.
well if you explain better I help you with your little basic problem.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
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
@
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!

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.
locationX, locationY
playerX, playerY
It's simple math, for whoever knows math.
I don't know what else you're talking about though.
It's hard being the best girl in the whole entire world
Try this
Sorry, little mistake, edited and bumped.
Code:
1
2
3
4
5
6
7
8
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
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
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
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
It's hard being the best girl in the whole entire world



