ID:1598227
 
(See the best response by Lige.)
Code:


Hey guys, I made a zombie survival game and u had to run around finding stuff and dodging zombies but zombies didn't actually hurt you.... I now want to make a full rpg game, but I don't know how to make a combat/fighting code. I tried angelfire's code tutorial but got confused even more. Could you guys show me how to get an Ork to attack player when player gets whithen range? and how variables work. thanks guys ;)

Best response
You should read the DM Guide, especially if you don't know how variables work. There's a whole chapter dedicated to variables, and it's quite early on at that.
Variables are ways to "name" something you're going to be using often so you have something to reference it by instead of typing it out all the time.
var/name = "lugia319"
src << "[name]"


As far as combat goes, try something simple.
mob
verb
Attack()
src.Health -= 10 // Attacks the src (person using verb)
usr << "You attack [src]!"


I'll leave it to you to figure out why this code probably doesn't work the way you'd want it to and how you might make it work for you.
I would like to suggest that you need to make up your mind on which project you wish to create. Jumping from a zombie game to an RPG with orcs attacking you are somewhat two different styles of gameplay.

If anything I write down below makes no sense, or only a little bit of sense. Read the DMGUIDE.

If you understand this, which I doubt you truly will, otherwise you wouldn't ask your question in the first place, read the DMGUIDE anyway.

When you create your project/plan your project, think about what you will need. What variables and who the parent is of those variables.

If I want an ORC to be a mob and it to have a health variable, I could define that as

mob/var/health=100


but the variable could be anything and could still pertain to health, that's all up to you.

Example:

mob/var/bullcrap_health_variable=100


Anywho, an attack verb to attack what's infront of you.

mob
var
health=100
verb
attack()
var/atom/target=locate() in get_step(src,src.dir) //I use atom, incase you wish to attack other things and such, like walls and break though.
if(!target)return
if(ismob(target)) //if it as a mob, player, AI
var/dmg=rand(1,5)
src:health-=dmg //I wonder if this seems right you ;p @Flying1ace (Reference to Lugia319)
view(6)<<"\icon[target.icon][target] attacked \icon[src:icon][src] for [dmg] damage." //I wonder if this seems right you ;p @Flying1ace (Reference to Lugia319)
else return


And if you want the orc defined

mob/Orc


Hmm doesn't seem too complicated right, this is practically straight out of the DMGUIDE.

Oh and to make the orc attack upon bumping something...

mob/Orc
Bump()
src.attack()


Still right out of the DMGUIDE with minor alterations.

I hope you see where I'm getting at.

I'll leave you to make the AI because I am not making your game for you, just sending you in the right direction.

If you want a basic AI, have it so when the Orc is created

New() //I like to think of this as "UPON CREATION"


have it search for players, if no player is found, deactivate it.

Every time a client/mob moves, check the surrounding area for the AI's to activate.

Move()
oview()


and lastly if the AI is in the surrounding area, make them hunt down the mob.

step()
step_towards()
walk()
walk_to()
walk_towards()


Enjoy.


Oh, and if you want them to randomly move around

step_rand()
walk_rand()


Anyway, go to the guide :p
Thanks guys ;) Um. How do I set a variable for Ork? I set health for player and health for ork and it says previous definition error thingy. basically i can't use the same variable twice? I have read half the guide but the guide doesn't really make sence to me...
Duplicate definitions means you have the variable more than once.

Simply, copy and pasting won't fix your issue.

mob
var
health //this will put the variable under /mob, so anything under /mob will have the variable

//likeso

mob/Orc //this inherits /mob's variables and procs, so "health" is already defined

//so if I do this

mob/Orc
var
health=100 //duplicate definition, since the variable is under /mob and /mob/Orc


Really dude, read the guide and that's all I can say. best of luck, your problem has been solved, it's just a matter of interpreting what we all stated.
sooooo..... How do i fix duplicate definition? you told me exactly what i already kneww just then.
In response to Flying1ace
Remove one of the duplicate definitions.
^ exactly what he said.

I'm sorry Flying but if I just stated what you knew, me telling you to remove a duplicate definition is also telling you what you know.

You see, you have an error due to the duplicate definition, so obviously one has to be gone "THERE CAN ONLY BE ONE", just wanted to say that ;p

Anyway, you are obviously missing the key point.

THE SOURCE TO ALL KNOWLEDGE ON BYOND CODING/SCRIPTING/PROGRAMMING <-- click it.
Hmmm.... So I can't have an Ork with health and a Player with health? At the same time? Or I can't have two differn't enemies with the same attack code for both?
Its all a tree.


/mob/Orc


inherits

/mob/
attributes.

so if I do

mob
var/health=250
Orc
health=100 //don't need to restate "var" since it exists already.


Just think of it like genetics just that all the genes are dominant.
haha
Ssj4justdale from what im seeing Flying1ace is a starter so i think all your doing is just making lines of DM that may make sense to us but to him he has no clue on how to approach that or how he will even beable to tweak that Lugia319 is making it more simple for him cause its a better way to start off for a starter programmer so its easier for him to get the hang of things and build up from it , but i like the way you broke it down for him afterwards though , but i agree on the fact that hes better off reading the Programming Guide so he understands what these actions really do and how to expand things to the fullest with his own programming style eventually.
Yeah, I couldn't agree more. Lugia319 had my vote from the start, I just hoped that explaining/going in-depth might have helped him see it.
^_^ haha , agreed :)!
Thanks guys. Got it working after some long nights thinking about it lol ;) You guys helped a lot ;)