Forum

> > CS2D > Scripts > RPG solid monsters
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch RPG solid monsters

11 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt RPG solid monsters

Mami Tomoe
User Off Offline

Zitieren
How can I make monsters (images) solid?
So I can't walk into them.
If this is possible how will it work? Will I have to TP the player back every time he tries to go in or is there another way that works better?

alt Re: RPG solid monsters

Masea
Super User Off Offline

Zitieren
user Mami Tomoe hat geschrieben
Will I have to TP the player back every time he tries to go in or is there another way that works better?
That should work properly. You can get algorithm from file cs2d [EngiN33R] Player Collision . However, I'm still a bit worry about the idea.

If you're going to open server with it which means there would be lags for some players, it is no longer that much realistic and doesn't work as is anymore. It seems like we're teleporting between tiles, not pixels.
1× editiert, zuletzt 14.05.17 17:35:59

alt Re: RPG solid monsters

Mora
User Off Offline

Zitieren
Ye, anything about tp players depending on quick/fast would look bad for players whose ping is higher than 80.

alt Re: RPG solid monsters

Mami Tomoe
User Off Offline

Zitieren
The reason I don't want to do that is because the script already does it to water blocks and you can see that you have been teleported if you have a high ping (or even low!).

alt Re: RPG solid monsters

Mami Tomoe
User Off Offline

Zitieren
Well I have used this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("move", "RPG.moveHook")
function RPG.moveHook(id, x, y)
	for _, m in pairs(MONSTERS) do
		local x2, y2 = m.x, m.y
		local d = math.sqrt((x2-x)^2 + (y2-y)^2)
		if (d < 30) then
			local a = -(math.atan2(x2-x,y2-y)+math.pi/2)%(2*math.pi)
			local nx, ny = x2 + math.cos(a)*30, y2 + math.sin(a)*30
			if (tile(math.floor(nx/32), math.floor(ny/32), "walkable")) then
				parse("setpos " .. id .. " " .. nx .. " " .. ny)
            end
        end
    end
end
(Edited @user EngiN33R: 's script)
And now I have to ask, how do I make it block me from walking on top of the image itself instead of the m.size?

Another thing is how do I prevent monsters from walking on top of me?

I can't walk on top of a monster - good - done
Monster can't walk on top of me - good - not done
Will use image size instead of 32x32 - good - not done

please help
2× editiert, zuletzt 15.05.17 14:20:07

alt Re: RPG solid monsters

VADemon
User Off Offline

Zitieren
This code is too much to add to the monsters' movement.

Since you have "I can't walk on top of a monster - good - done" you only need to check if monsters are within a ~24px range of the player, just a distance check. If their new position would be too close to a player - don't move.

"Can't walk will use image size instead of 32x32 - good - not done" - what?

alt Re: RPG solid monsters

Mami Tomoe
User Off Offline

Zitieren
Mehr >


Hi after some help from friend (TheD) I got to this script inside move hook:
1
2
3
4
5
6
7
8
9
10
for _, self in pairs(MONSTERS) do
        local n = -(math.atan2(self.x-x,self.y-y)+math.pi/2)%(2*math.pi)
        local nx, ny = self.x + math.cos(n)*32, self.y + math.sin(n)*32
        local sx, sy = math.floor(nx/32), math.floor(ny/32)
        if (player(id,"x") < self.x + self.width and player(id,"x") + 32 > self.x and player(id,"y") < self.y + self.height and 32 + player(id,"y") > self.y) then
            if tile(sx, sy, "walkable") then
                parse("setpos " .. id .. " " .. nx .. " " .. ny)
            end
        end
    end

This works good when the monster is small but if it's big then it will teleport me inside it and wont let me out
Please help!
3× editiert, zuletzt 16.05.17 20:01:18
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht