Forum

> > CS2D > Scripts > RPG solid monsters
Forums overviewCS2D overview Scripts overviewLog in to reply

English RPG solid monsters

11 replies
To the start Previous 1 Next To the start

old RPG solid monsters

Mami Tomoe
User Off Offline

Quote
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?

old Re: RPG solid monsters

Masea
Super User Off Offline

Quote
user Mami Tomoe has written
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.
edited 1×, last 14.05.17 05:35:59 pm

old Re: RPG solid monsters

Mami Tomoe
User Off Offline

Quote
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!).

old Re: RPG solid monsters

Mami Tomoe
User Off Offline

Quote
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
edited 2×, last 15.05.17 02:20:07 pm

old Re: RPG solid monsters

VADemon
User Off Offline

Quote
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?

old Re: RPG solid monsters

Mami Tomoe
User Off Offline

Quote
More >


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!
edited 3×, last 16.05.17 08:01:18 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview