ID:166159
 

I have been creating an RPG for the last few days, and I have a couple of issues that have been bothering me, but I am not sure how to fix it.

Basically, as this is in testing stages, I want players to be able to attack NPC enemies, but I do not want them to be able to kill other players (who are helping me test). How can I prevent players from being able to kill one another? If you need any of my code, let me know.

Secondly, when an enemy is killed, it is randomly respawned anywhere on the map. However, this includes walls. The code looks like this:

loc = locate(rand(1,50),rand(1,50),1)


Is there a way that I can change this code so that the possible placement locations exclude turf with a density of 1?

Thanks

first problem:
mob
proc
attack(target)
if(!target.client) //it might be client.target or something
//your attack stuff

second problem:
im not exactly sure about but while your waiting for an answer maybe say something like
if(!loc.density)
//put the guy there

ive never done something like that so thats my best guess
In response to Flame500
if(client)return
In response to Xx Dark Wizard xX
No, that will only stop it from spawning on a player.

What you'll need to do is check the turfs density after the monster has spawned on it. If its one, search the monsters view for a turf without a desnity and move it to there.

Ex:
mob
proc
spawn()
src.loc = locate(rand(1,50),rand(1,50),1)
var/turf/t = src.loc
if(t.density)
for(var/turf/m in view(src))
if(!m.density)
src.loc = m
return


This is untested, so I don't know if this would actually work. But it would be my first guess.
In response to Pyro_dragons
Why move them first? Why not check the loc's density first before moving them?

var/turf/l=null
while(!l)
l=locate(rand(1,50),rand(1,50),1)
if(!l.density)
src.loc=locate(l)
else
l=null


I think this may be a little more efficient, but I'm not sure. I would think so because it doesn't move them until there is a loc that isn't dense.

-Exophus
In response to Exophus
Why not use Enter(), thereby checking for the existance of any dense object in the turf?
In response to Exophus
Exophus wrote:
Why move them first? Why not check the loc's density first before moving them?

> var/turf/l=null
> while(!l)
> l=locate(rand(1,50),rand(1,50),1)
> if(!l.density)
> src.loc=locate(l)
> else
> l=null
>

I think this may be a little more efficient, but I'm not sure. I would think so because it doesn't move them until there is a loc that isn't dense.

-Exophus

How about simply using Move()? It calls Enter() which checks for dense.

while("loop")
if(Move(rand(1,50), rand(1,50), rand(1,50))
break


edit: Whoops, Jp already said that, sorry. I'll keep this post as an example, anyways. D:
In response to DivineO'peanut
Hmm, good point, heh. I'll keep that in mind.

-Exophus