Forum

> > CS2D > Scripts > Button = setpos
Forums overviewCS2D overview Scripts overviewLog in to reply

English Button = setpos

11 replies
To the start Previous 1 Next To the start

old Button = setpos

cs2d_is_a_Gem
User Off Offline

Quote
Hi dear forum and pople!
Could someone do this code for me?

when pressing button = 1 random player of the terrorist team in pos x and y.(svmsg; Jason is here!)

I tried to do it by myself but I lost my time.

Thanks for the help in advance

old Re: Button = setpos

princeofpersia
User Off Offline

Quote
1
2
3
4
5
6
7
addhook("usebutton","usebutton_hook")
function usebutton_hook(id,x,y)
if (x==20)and(y==3) then
parse("setpos "..id.." 12 9")
msg(player(id,"name").." IS THERE!")
end
end

tested and working for me

change x and y to your button pos . and change 12 and 9 (*32) to ur player spawn pos

old Re: Button = setpos

Yates
Reviewer Off Offline

Quote
@user princeofpersia: He wants one random terrorist and probably one that is in a certain area. I didn't really catch the second part of what he wants.

user cs2d_is_a_Gem has written
I tried to do it by myself but I lost my time.

Would take you less time to code it than waiting for the spam timeout when posting this thread ¯\_(ツ)_/¯

old Re: Button = setpos

princeofpersia
User Off Offline

Quote
@user Yates: sorry i see this now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
teleported={}
addhook("join","join_hook")
addhook("usebutton","usebutton_hook")

function join_hook(id)
teleported[id]=false
end

function usebutton_hook(id,x,y)
if (x==20)and(y==3) then
randome={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}
local target=randome[math.random(1,#randome)]
if player(target,"exists") then
if teleported[target]==false then
parse("setpos "..target.." 12 9")
teleported[target]=true
msg(player(target,"name").." IS THERE!")
else
usebutton_hook(id,20,3)
end
else
usebutton_hook(id,20,3)
end
end
end

tested and workink

old Re: Button = setpos

Yates
Reviewer Off Offline

Quote
This will break very fast and I don't advise anyone to use it lol.

old Re: Button = setpos

minos
User Off Offline

Quote
for this one :
1
randome={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32}

it's equal to :
1
math.random(1,32)

and i really don't understand what do u need Quick?

old Re: Button = setpos

jerezinho
User Off Offline

Quote
user Yates, Why do not you help with the lua problem instead of writing so much shit? i do not see you being helpful writing just shit here.

user cs2d_is_a_Gem, good luck with what you're looking for!

old Re: Button = setpos

Yates
Reviewer Off Offline

Quote
@user jerezinho: Oh the irony in your post just made my day.

@user princeofpersia: You still need to check whether the player is a terrorist, is alive, reset your
teleported
variable, make sure this function doesn't trigger a C stack overflow (because it will) and I definitely don't advise triggering a function that belongs to a hook. Separate your code.

old Re: Button = setpos

cs2d_is_a_Gem
User Off Offline

Quote
• Thanks for the help guys.
• @user Yates: you're right in the comment that you added. Solution?
• where is @user Cure Pikachu: when you need it?
off topic: that person is quite useful here.
• I hope someone fixes the @user princeofpersia: code so they can put Jason online again.

> Only players alive at that moment, the dead must be dead!
(This is not dragonball)

old Re: Button = setpos

Cure Pikachu
User Off Offline

Quote
Who called for me?
Well, don't know if this is it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
target_x = 12
target_y = 9

addhook("usebutton","usebutton_hook")
function usebutton_hook(id,x,y)
	if (x==20) and (y==3) then
		-- Random living terrorist
		local t = player(0,"team1living")
		local target = t[math.random(1,#t)]
		-- I just realised the given numbers are tile positions...
		parse("setpos "..target.." "..target_x*32+16.." "..target_y*32+16)
		msg(player(target,"name").." IS THERE!")
	end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview