ID:1539706
 
(See the best response by Koshigia.)
:
obj
Zombie1
icon = 'zombie1.dmi'
density = 1
verb
Shoot()
set src in oview(5)
for(var/obj/Ammo/a in usr.contents) //cycle through the contents
if(istype(a)) //if the obj in contents is the type /obj/Ammo, lets reload
del a //delete the ammo
world << "You have Fired at the Zombie!" //tell the user
. = 1 //return a 1
break //break (or return)
if(!.)//if it wasn't found
world << "Your gun is not loaded!"

Decap()
set src in oview(2)
world << "You attacked a Zombie with a Shovel!"
for(var/obj/Shovel/a in usr.contents) //cycle through the contents
if(istype(a)) //if the obj in contents is the type /obj/Ammo, lets reload
. = 1 //return a 1
break //break (or return)
if(!.)//if it wasn't found
world << "You were hit by Zombie!"
src.Health-= 25


Hey guys, again, lol. I would like my code to remove 25 Health from Player when he attacks without shovel. How? Thanks guys!

Best response
Keep in mind that these verbs belong to the zombie obj, even though the player is invoking them. Even though you put "set src in oview(2)", that doesn't mean that the src is going to become the person who uses it. It just means that in order FOR someone to use it, src has to be contained in the list, or within oview(2) in this case.

Knowing that, when you put the line of code src.Health -= 25, you are actually trying to remove 25 from a variable belonging to the zombie, not the player calling the verb.

What it all boils down to is clearly understanding who is doing what to whom? Who is the src (who does the verb/proc belong to), and who is the usr? (if they aren't the same).
Yes I understood that vaguely before your post, but know I understand. So how would I change that to affecting the Player? usr.Health doesn't work either.
Try doing a little bit of debugging. Are you seeing the message "You were hit by Zombie!"? If not, then the line about the health being removed is never being called.

What I'm seeing here logically is that a player will attempt to hit zombie by using the Decap() verb. If the player has a shovel, it tells the world that that the player hit the zombie. If the player does NOT have a shovel, the zombie hits the player instead. Is this correct?
Correct, my problem is how to write the code saying that Player lost health. I don't know :(.
it keeps coming up with a message that says undefined var. Before I can even run...
This is probably because your player is of a subclass. By default, usr is a simple mob, so if you want to alter variables of a derived class you will need to typecast first.

That is assuming that the above is the case, however.
well make sure that whatever type (ie: /mob) the player is has the variable Health defined for it. Turn on debugging and fine what line is giving you the error and post that chunk of code.
debugging? sorry. I'm new :)
this is my var code:
dm<mob/Player
var
Thirst = 0
var/max_value = 100
var/min_value = 0
var/current_value = 0
current_value = min(max(current_value,min_value),max_value)
Health = 100
MaxHealth = 100>/dm<
and this is the code that's killing me:(I don't know how to do DM tags sorry)
dm<BottleOWater
luminosity = 0
icon = 'bottlewater.dmi'
verb
Drink()
set src in usr
world << "You are no longer thirsty!"
sleep(10)
usr.Thirst += 80
del src

Pick_Up()
set src in oview(1)
world << "You found a Bottle'O'Water!"
src.Move (usr)>/dm<
oops sorry that's part of the code that I need working to
<dm>Code goes in here.</dm>
Debugging isn't relevant here. You have a compiler error which needs to be typecast to a /mob/Player.
ok...
Sorry, I posted the example on your other thread. Both have the same issue.

http://www.byond.com/ forum/?post=1539171&page=2#comment9563805
Dude, your awesome ;) thanks man you can consider all my posts answered now ;)


Except Thirst will fill further then it is supposed to, for instance it will get to 700 and it only goes down by 20 a min. How do I put a Max amount onto the P.Thirst var?
here is a short example

mob
var/thirst
var/maxthirst


proc/fillthirst(var/somevalue)
if(thirst + somevalue > maxthirst) thirst = maxthirst
else thirst += somevalue
Here is a cleaner way:
mob
var/thirst
var/maxthirst

proc/change_thirst(var/somevalue)
thirst = min(max(thirst+somevalue ,0),maxthirst)


To deduct, pass a negative, otherwise it adds.