Forum

> > CS2D > Scripts > Push the player back
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Push the player back

14 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Push the player back

BrunoRZ
User Off Offline

Zitieren
I'm still fighting to undestand lua scripting.
I only learned the basics of the basics, and it was already hard to me, so I'm asking help for this.

I'd like to make a ventilator, to always push the player down while he tries to go up.

If someone help me whit that I would be very happy
Thank you.

Admin/Mod Kommentar

VERY bad title. Changed. Please use a better one next time or we have to delete your thread! /TKD

alt Re: Push the player back

J4x
User Off Offline

Zitieren
Well if you want to make it for all maps, Try to check player's rotation with the movetile hook.

PS: Can someone answer me this question: Does the rot of a player is checked in pixels?

it will be something like:

1
2
3
4
5
6
addhook("movetile","back")
function back(id,x,y)
if player(id,"rot") == ... then
parse("setpos "..id." "..player(id,"y") -1)
end
end
I make this code fast so mybe its incorrect.
1× editiert, zuletzt 28.02.11 04:50:02

alt Re: Push the player back

EngiN33R
Moderator Off Offline

Zitieren
@Linkin Park
Rotation can not POSSIBLY be measured in pixels. It's measured in degrees.
Mehr >

To write the function the way you've written it it will be super inefficient. You have to use sine and cosine in order for it to be most efficient and most good-looking.

@BrunoRZ
Just use teleporters! They'll do the same!

alt Re: Push the player back

OlaFPhp
User Off Offline

Zitieren
Well this is a possible can build script though, you just edit the zombieplague kickbacks. you know when you shoot at the zombies they will like be kick or push
just weapons 78 or claw though.
So this is possible

alt Re: Push the player back

BrunoRZ
User Off Offline

Zitieren
Maybe I have not been clear enough whit you guys...

The ventilator should push the player down not only if he tries to go up, like a ventilator, it should push down ALWAYS.
The teleport entity will only bring you back if you walk on the tile

alt Re: Push the player back

EngiN33R
Moderator Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
minx=1 --the upper left edge of the room X position
miny=1 --the upper left edge of the room Y position
maxx=5 --the lower right edge of the room X position
maxy=5 --the lower right edge of the room Y position
force=16

addhook("always","push")
function push()
	for id=1,32 do
		if (player(id,"exists") and player(id,"tilex")>=minx and player(id,"tilex")<=maxx and player(id,"tiley")>=miny and player(id,"tiley")<=maxy) then
			parse("setpos "..id.." "..player(id,"x").." "..(player(id,"y")-force))
		end
	end
end

Not sure if it works correctly, but try it

alt Re: Push the player back

BrunoRZ
User Off Offline

Zitieren
EngiN33R, yes it worked. whit me...
The other player was unable to enter the ventilator room.
but anyway... I changed my mind, and a button would be better to the situation, I tried couple of "things" and tried to "fix", to become a button... #Fail

how should i do that ?

alt Re: Push the player back

J4x
User Off Offline

Zitieren
i think, he is talking smething like when u use a button(trigger) the script start working.

alt Re: Push the player back

BrunoRZ
User Off Offline

Zitieren
yes, button (trigger), sorry

Because I'll put players into a room, then I'll start the "pushing", so a trigger would be adequate for it...
specially if it can stop when pressed again

alt Re: Push the player back

archmage
User Off Offline

Zitieren
Maybe this is what you want
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local vx, vy -- Vent position

function math.distance(x, y, x2, y2)
	return math.sqrt((y2-y)^2 + (x2-x)^2);
end

function update()
	local t = player(0, "tableliving");
	for _, v in ipairs(t) do
		local x, y = player(v, "x"), player(v, "y");
		local dist = math.distance(x, y, vx, vy);
		local angle = math.atan2(vy-y, vx-x);

		if ( dist <= 100 ) then
			local ratio = 1-dist/100;
			local power = 2 * ratio;
			x = x - power*math.cos(angle);
			y = y - power*math.sin(angle);
			parse("setpos "..v.." "..x.." "..y);
		end
	end
end

addhook("always", "update");

alt Re: Push the player back

BrunoRZ
User Off Offline

Zitieren
both are usefull, but i need a trigger button, to be pushed by a player to turn on the ventilation, and turn off when pressed again.

ps: i dont get wich x and wich y i should replace on yours

alt Re: Push the player back

EngiN33R
Moderator Off Offline

Zitieren
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
minx=1 --the upper left edge of the room X position
miny=1 --the upper left edge of the room Y position
maxx=5 --the lower right edge of the room X position
maxy=5 --the lower right edge of the room Y position
force=16
push=false

bx=6 --the button X position in tiles
by=6 --the button Y position in tiles

addhook("use","button")
function button(id)
	if (player(id,"tilex")==bx and player(id,"tiley")==by) then
		if (push) then
			push=false
		else
			push=true
		end
end

addhook("always","push")
function push()
     for id=1,32 do
          if (player(id,"exists") and player(id,"tilex")>=minx and player(id,"tilex")<=maxx and player(id,"tiley")>=miny and player(id,"tiley")<=maxy) then
		if (push) then
               		parse("setpos "..id.." "..player(id,"x").." "..(player(id,"y")-force))
		end
          end
     end
end

Try.

alt Not yet

BrunoRZ
User Off Offline

Zitieren
The trigger button is not working
player is always being pushed
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht