ID:566204
 
(See the best response by Robertbanks2.)
Code:
            Bump(A)
if(istype(A,/obj/Battle/))
src.density = 0
if(src.dominant)
del(A)
else if(A:dominant)
del(src)
else if(istype(src,/obj/Battle/))
if(prob(50))
A:dominant = 1
else
src.dominant = 1
else if(isobj(A)|| isarea(A) || isturf(A))
if(src.flyable)
src.density=0
else
for(var/turf/T in range(src.splash_radius,A))
new/obj/Battle/Explosions/Fire(T)
for(var/mob/M in range(src.splash_radius,A))
M<<"Splash dmg"
del(src)
else if(ismob(A))
if(!A:flying&&!src.flyable)
src.density=0
A<<"Ground Dmg"
del(src)


Problem description:
- I want to create that when players are bought flying they can hit each other

- When one is flying and the other is on the ground they cant hit each others

- When they are bought on the grounds they can hit each others again.

But the problem is when player starts to fly his density change it to 0. So is even possible to code this. If so please help me
This is your 5th open developer help topic in 2 days. Please attempt to investigate these issues yourself in more detail before bringing them to developer help, and elaborate on what ways you have attempted to solve the problem.

Currently it appears as though we are being used as your first port of call whenever something doesn't go 100% correct, and this is not particularly fair on the people who choose to help here.
I am sorry about other post. But for this one there aint even a single tutorial or at least i cant find it to solve this :/
These things that you keep posting don't require specific codes or instructions. They require you to figure out ways to solve them with your own problem solving skills. For making it so that players can and can't be hit at certain times I would just use variables to define whether they are in the air or not and then use if() when they are hit. That way when they are hit it will check to see if they are allowed to be hit depending on whether or not they are in the air flying or on the ground.
So i should not use Bump() and just go with for(var/mob/M in src.loc) ?
You can use if() inside Bump() too.

Bump(atom/a)
if(ismob(a)) // If what you bumped into is a mob.
if(on_ground == 1 && a:on_ground == 1) // If you are both on the ground.
a:damage // They take damage.
else if(in_air == 1 && a:in_air == 1) // If you are both in the air.
a:damage // They take damage.
// If 1 is in the air and 1 is on the ground then nothing happens.
// If what you bumped into isn't a mob then nothing happens unless defined otherwise.


I also use Bump() in my games for dash attacks and projectiles and this is how I code them.
the prob is that player have dansity = 0
First off, Zerok. This is not a situation that calls for the : operator. You should use proper typecasting instead. Generally speaking, you just shouldn't use : in an example to help people, as chances are they don't understand when it's right and wrong to use it.

LaNuiit, why not, instead of setting density to 0, make your own check in bump() to see if they're flying, and if so bypass obstacles(but not other flying players)?
For some reason : never fails for me so I tend to use it when defining things for something other than the usr. I don't know it's just what I'm used to and it's never failed for me.
rober i would like to but i dont know how :/ maybe there is a tutorial or something?
Best response
@Zerok

The : operator doesn't fail when you compile because the compiler assumes that it will be correct at runtime and ignores any potential misuse. When you use : incorrectly, it leads to a lot of runtimes and quiet failures that will eventually pop up and cause lots of trouble later on, not to mention the fact that it's considerably more CPU intensive than simply typecasting properly and using the . operator instead.

If you don't know for sure why you shouldn't have been using it there, you should probably just not use it at all until you're more experienced.


@Lanuiit

If you don't know how to do that, then chances are you stole the code you've displayed here or it was given to you on another thread that I'm unaware of, and should probably study it rather than simply copy/pasting it. That code makes use of pretty much everything you could possibly need to use in setting up your own simple density workaround.

You basically just need to say:

If the thing I'm bumping is a turf, and I'm flying, move to that location.

If the thing I'm bumping is an object, and I'm flying, move to it's location.

If the thing I'm bumping is a mob, and one of us is flying, but not the other, move to its location.

If the thing I'm bumping is a mob, and we're both either flying or not flying, don't move there and battle it."

If none of this is true, don't move there and take no other action.
atom
movable
Bump(atom/A)
if(ismob(A))
if(A:flying)
if(isobj(A)|| isarea(A) || isturf(A))


I stuck here. How can I make walkable while flying ?
In response to LaNuiit
LaNuiit wrote:
> atom
> movable
> Bump(atom/A)
> if(ismob(A))
> if(A:flying)
> if(isobj(A)|| isarea(A) || isturf(A))
>

I stuck here. How can I make walkable while flying ?

LaNuiit, please do not use "selective reading". Robertbanks2 was just explaining that you shouldn't use : . Instead, you should use typecasting, which is this:
var/mob/m = A
if(m.flying)


This, as he explained, is less CPU intensive and also will present an error if you make a mistake. Using : means that the compiler assumes that what you did was correct and executes it, even if it is wrong. You don't know when it is right and wrong to use it, so don't. You need to use problem-solving skills (Which are a necessity in the programming field) to solve your issues, rather than asking a community for help on simple things over and over again. Doing so is, obviously, making us less inclined to help you and more likely to shove you in the general direction of finding some resources to study from.
atom
movable
Bump(atom/A)
var/mob/m
if(m.flying)
if(isobj(A)|| isarea(A) || isturf(A))
if(A.density)
Enter(m)

Can someone just explane it to me what am I doing wrong here . I made that if player is flying and if turfs/area or obj have density m will enter it. Still got bunch of errors while trying to enter wall
Here is a little help
atom
movable
Bump(A)
for(var/mob/M)
if(M.flying)
if(isobj(A)|| isarea(A) || isturf(A))
if(A:density==1)
Enter(M)


But I don't know how to make player enter turf that have density. So I hope someone can explain it :)
In response to LaNuiit
LaNuiit wrote:
> atom
> movable
//No idea why you're doing it this way unless you want objs to handle it the same way, in which case
//you shouldn't be typecasting to mob, but /atom/movable instead. You can just put it under mob/Bump().
> Bump(atom/A)
> var/mob/m
//Should be var/mob/m = src
> if(m.flying)
> if(isobj(A)|| isarea(A) || isturf(A))
//When bumping an object, this will cause you to enter the object's inventory, you need a separate check for objs and mobs that moves them to A.loc.
//Enter()ing an area is also different from Enter()ing a turf.
//You also need to typecast A after each check, so that Move() can be called.
> if(A.density)
> Enter(m)
//That's not how you call Enter(), and you shouldn't be using Enter(), you should be using Move().


That about covers what was wrong with the code you posted.

In response to Brincl_96
Brincl_96 wrote:
Here is a little help
> atom
> movable
> Bump(A)
> for(var/mob/M)
> if(M.flying)
> if(isobj(A)|| isarea(A) || isturf(A))
> if(A:density==1)
> Enter(M)
>

But I don't know how to make player enter turf that have density. So I hope someone can explain it :)

This is just wrong. The for() loop serves no purpose, since we only need it to happen once, and it's happening to src, not to mention that it won't happen to src because the for() loop wasn't for src, it was for a random mob(or all mobs, I don't recall how for() handles not having a list).

I know you're trying to help, but please, please, pleeaaase, be absolutely sure you understand exactly what is going on before offering suggestions.
atom
movable
Bump(atom/A)
var/mob/m=src
if(m.flying)
if(A.density)
Move(src,A)

LoL it turns him to south. :/
I read guide for dm lot of times but i didnt undesrtand a lot of things. Its using expert words i dont understand. Thats why im turning on a comunity for help so much because its a lot easyer if someone explane it to you.
Indeed it would. You still have to adjust density for the Move(), or if you know you'll never ever ever ever ever ever ever EVER have any effects that require a person to step on a certain tile, EVER, you could move them directly with the loc var.

I would suggest simply setting density to 0, then setting it back to 1 after they've moved.
ok i changed
Move(src,1)

I found F1 really usefull these days ^^ and by adjusting density you mean
atom
movable
Bump(atom/A)
var/mob/m=src
if(m.flying)
if(A.density)
A:density=0
Move(src,1)
Page: 1 2