ID:819040
 
Keywords: attack
(See the best response by LordAndrew.)
Code:
mob
RedSlime
icon = 'goop.dmi'
icon_state = "Blob (red)"
monster = 1
gold = 22
health = 105
maxhealth = 105
strength = 20
experience = 25
level = 4
NPC = 0
New()
. = ..()
spawn()
Wander()
proc/Wander(var/mob/You/P)
while(src)
if(P in oview(5))
step_towards(src,P)
for(P in oview(1))
break
for(P in oview(2))
break
for(P in oview(3))
break
for(P in oview(4))
break
else
step_rand(src)
sleep(5)
for(P in oview(5))
break
sleep(5)
spawn(5)
Wander()
Bump(mob/M)
if(M.player == 1)
Fight(M)
else
return
proc/Fight()
for(var/mob/E in get_step(usr,usr.dir))
var/damage = usr.strength - src.defense
if(damage <= 0)
damage = 1
E << "[src] attacks you for [damage] damage!!"
src<<"You attack [E] for [damage] damage!!"
UserDcheck(E)
else
E.health -= damage
E << "[src] attacks you for [damage] damage!!"
src<<"You attack [E] for [damage] damage!!"
UserDcheck(E)
</b>


Problem description: i got this part of the attack system and the monster can attck me but i cant seem to attack, plz help

Did you make a attack verb for users?
i have not yet cause i dont know to make one
Its the same thing.

Let me edit this abit
                if(damage <= 0)
damage = 1
E.health -= damage
E << "[src] attacks you for [damage] damage!!"
src<<"You attack [E] for [damage] damage!!"
UserDcheck(E)
Attack code is what was wrong, it should be something like

    proc/Fight(mob/M)
var/damage = src.strength - M.defense
if(damage <= 0)
damage = 1
M << "[src] attacks you for [damage] damage!!"
src<<"You attack [M] for [damage] damage!!"
M.UserDcheck(src)
else
M.health -= damage
M << "[src] attacks you for [damage] damage!!"
src<<"You attack [M] for [damage] damage!!"
M.UserDcheck(src)
The attack proc is not wrong only the part of the if damage the thing that is wrong is that he didnt make a attack verb for the players
mob/verb/Attack
Fight()

This should work
im getting a duplicate for that attack verb
Yeah
Best response
This seems like an extremely silly way to handle this, you're repeating code when you could easily do:

mob
proc
Fight(mob/m)
var/damage = strength - m.defense

// From a design point of view, I'm not sure why you would make it so you always do at least one damage.
// This has the potential to be abused; a player could just wail on an enemy repeatedly and whittle them down.
if(damage <= 0)
damage = 1

m.health -= damage

m << "[src] hit you or something"

src << "you hit [m] or something"

m.UserDcheck(src)


Of course, that's just an example of simplifying that particular snippet. The whole implementation fails to utilize object-orientated practices. You could be breaking down the Fight() procedure into multiple procedures, which would allow you to modify and allow for special cases for specific mobs. This post elaborates more into that.
i understand, so what would be a better way to fix that?
i got this code from a resourse and isnt my creation.
In response to Grahm4287 (#10)
To be honest, the code snippet you found is just all around terrible.

The sequence involving repeatedly calling for(P in oview(#)) and breaking within it is.. why is it doing that. I would suggest having a look at Forum_account's demo here, as it explains AI and shows you how to build upon it to make it both smart and efficient.
In response to LordAndrew (#11)
LordAndrew wrote:
To be honest, the code snippet you found is just all around terrible.

The sequence involving repeatedly calling for(P in oview(#)) and breaking within it is.. why is it doing that. I would suggest having a look at Forum_account's demo here, as it explains AI and shows you how to build upon it to make it both smart and efficient.

i doubt he will understand that is better if he got the falacy turtoial because hes new at coding it will be more simple for him instead then looking in everyone of those codes to find the perfect one

http://www.byond.com/forum/?post=109791
i mean im not a full out beginner but i cant create codes from scratch yet. ugh, but thanks guys for trying to help and anymore suggestions will be great

honestly i would erase it all cause i dont like how they roam around, i rather then stay still till they are attacked or have a small view
mob
RedSlime
icon = 'goop.dmi'
icon_state = "Blob (red)"
monster = 1
gold = 22
health = 105
maxhealth = 105
strength = 20
experience = 25
level = 4
NPC = 0

New()
..()
spawn() Wander()

proc/Wander()
for(var/mob/M in view(5, src)) //The monster has a view range of 5 tiles around it. Change the value to change the amount of tiles it can see around itself.
if(M.player)
step_towards(src, M)
break
spawn(5) .()

Bump(mob/M)
if(ismob(M) && M.player)
Fight(M)

proc/Fight(var/mob/M)
var/damage = strength - M.defense
if(damage <= 0)
damage = 1
M << "[src] attacks you for [damage] damage!"
src << "You attack [M] for [damage] damage!"
UserDcheck(M)


This is evidently simplified as I didn't bother to add any target variables and so on, but it serves your purpose. I believe you'd be better off rewriting this entire code snippet.
yea i rewrote it all thanks guys for trying to help