teleportation with smoke grenade
5 replies



06.07.19 09:57:35 pm
Hey, I need a script that will teleport a player to wherever his Smoke Grenade lands.
Use the
projectile-hook, check if the projectile is a smoke grenade (http://www.cs2d.com/img/ref_items.png, type 53) and then set the player position to the x and y values of the hook with
setpos!


@
DC: where is the fail?
function Array(size,value)
local array = {}
for i = 1, size do
array[i]=value
end
return array
end
mx = Array(32,0)
my = Array(32,0)
timer(150,"requestdata","",0)
function requestdata()
reqcld(0,2)
end
addhook("clientdata","clientdata")
function clientdata(id,mode,x,y)
if mode == 2 then
mx[id] = x
my[id] = y
end
end
addhook("attack","client")
function client(id)
if player(id,"weapon") == 53 then
parse("setpos "..id.." "..mx[id].." "..my[id].."")
end
end

function Array(size,value)
local array = {}
for i = 1, size do
array[i]=value
end
return array
end
mx = Array(32,0)
my = Array(32,0)
timer(150,"requestdata","",0)
function requestdata()
reqcld(0,2)
end
addhook("clientdata","clientdata")
function clientdata(id,mode,x,y)
if mode == 2 then
mx[id] = x
my[id] = y
end
end
addhook("attack","client")
function client(id)
if player(id,"weapon") == 53 then
parse("setpos "..id.." "..mx[id].." "..my[id].."")
end
end
Code:
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
local exec = parse
function projectile_launch(p, wpn, x, y)
if wpn == 53 then
exec('setpos ' .. p .. ' ' .. x .. ' ' .. y)
end
end
addhook('projectile', 'projectile_launch')
function projectile_launch(p, wpn, x, y)
if wpn == 53 then
exec('setpos ' .. p .. ' ' .. x .. ' ' .. y)
end
end
addhook('projectile', 'projectile_launch')
Is death truly a bad thing? If it is, then why do we all get to experience it? And... Why does it take so long? - What is the meaning of death?
@
haha1955: Please use the code-tag when sharing code!
I see what you're doing there. Requesting the cursor position all the time and setting the player to that position when he attacks. That's a legit approach and it should work as well (didn't try it).
The problems
it's complicated
causes a lot of traffic because cursor position is requested all the time (you can use the
player command instead with "mousemapx" and "mousemapy")
it's not what you asked for. It moves the player to the position at which he AIMED the moment THROWING the grenade. That's not the position were the grenade will land (e.g. when you aim at a spot behind a wall)
Mami Tomoe wrote the code exactly like I suggested. That one should work fine and matches what you asked for.

I see what you're doing there. Requesting the cursor position all the time and setting the player to that position when he attacks. That's a legit approach and it should work as well (didn't try it).
The problems








