﻿ Unreal Software - Thread: Throw weapon at player

# Forum

CS2D Scripts Throw weapon at player

# Throw weapon at player

7 replies
Goto Page
1
19.05.20 04:42:49 pm
Mami Tomoe
User
Offline
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
Look at me standing, here on my own again
19.05.20 09:23:44 pm
cs2d_is_a_Gem
User
Offline
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.
19.05.20 09:25:55 pm
Mami Tomoe
User
Offline
Who are you? Anyways I'm bad at math.

And I was quite obvious with what I asked.
Look at me standing, here on my own again
19.05.20 09:28:07 pm
cs2d_is_a_Gem
User
Offline
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.

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
cant_drop = {50,74}
normal_drop = {47,48,49,51,52,53,54,72,73,75,76,89}

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
19.05.20 10:36:47 pm
User
Offline
@ 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!
19.05.20 11:20:48 pm
Mami Tomoe
User
Offline
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.
Look at me standing, here on my own again
20.05.20 03:27:24 am
Baloon
GAME BANNED
Offline
Try this
Code:
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
20.05.20 07:58:16 am
Mami Tomoe
User
Offline
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
Look at me standing, here on my own again
1
﻿