ID:165291
 
Here's an interesting question. At the top of my attack verb i have "set src in oview(1)" (of course). But how would i change the number inside oview() depending on something like what weapon i am wielding? Something like this:
mob/verb/Attack(mob/M as mob in oview())
if(usr.weapon=Sword) set src in oview(1)
if(usr.weapon=Bow) set src in oview(3)
if(usr.weapon=Longbow) set src in oview(5)

thanks
mob
var/range //range of the weapon- set when it is equipped
verb/Attack(mob/M as mob in oview(src.range,src))
switch(src.weapon)
if(Sword)
//Put all your attack stuff here.
//You can use if(usr.weapon=[insertweaponhere]) for each weapon, but I prefer switch.
In response to Bobthehobo
ah, that's smart! i'll try it.
In response to Bobthehobo
mob
var/range
verb/Attack(mob/M as mob in oview(src.range,src)) //error: view arguments not allowed or invalid.
switch(src.weapon)
if(Sword)
//attack stuff here
In response to Adam753
Well, it compiles right for me. I do not know what is causing that error.
In response to Bobthehobo
Or you could just use a list:
mob
var
range

mob
verb
Attack()
var/list/Enemies[0]//makes a new list called enemies
if(usr.weapon == "Sword")//if the weapon is a sword
usr.range = 1//range = 1
if(usr.weapon == "Bow")
usr.range = 3
for(var/mob/M in oview(usr.range))//for every mob within oview of your range
Enemies+=M//add them to the list
if(length(Enemies))//if thel sit isn't empty
var/mob/m = input("Who do you want to attack?") in Enemies//allow you to pick a enemy from the list
m.hp -= usr.atk// w/e your atatck does below


Using lists may seem like a bit more work at the moment, but they are more efficient than your previous method as you'll see when you're working on future projects. For example: You're trying to get a list of people in the world to summon. Programming it with mob/m in world inside the parenthesis would get every mob in the world including npcs(and some people may even have the same name as a npc). But if you did it with a list instead, you could choose to get players only and or npcs only. Lists are EXTREMELY helpful. :D
In response to MechaJDI
uhh, not quite...
mob
verb
Attack()
var/list/Enemies[0]
var/distance=1 //the deafult value is 1
if(usr.equippedweapon == "Bow") //if your weapon is a bow
distance=3 //distance is 3
if(usr.equippedweapon == "Longbow") //if your weapon is a longbow
distance=5 //distance is 5
for(var/mob/M in oview(distance))
Enemies+=M //add nearby enemies to the list
if(length(Enemies)) //if the list isn't empty
var/mob/m = input("Who do you want to attack?") in Enemies //allow you to choose
var/dmg = usr.strength+usr.weaponstrength+rand(0,9)
view() << "[usr] attacks [m] and does [dmg] damage!"
m.HP -= dmg
usr.strengthEXP += dmg + m.Level
usr.LevelCheck()
m.DeathCheck()

This works with no compiles with no compile errors and no runtime errors, but the actual distance over which i can attack doesn't change, and i never get a LIST of enemies.
In response to Adam753
The code you've posted there is terrible, and you should ditch it before it causes you any more problems. Rule one when you're programming a combat system is to put behavior where it belongs. An attack proc belongs to the attacker, and a hit proc belongs to the target of the attack. The hit proc is the one which subtracts hp, you should never subtract hp in an attack proc.

Further, if weapons are going to have different effects and different ranges, then those weapons should have range attributes; it shouldn't be hard coded in an attack verb.
mob
var
hp = 10
exp = 1
obj/weapon
proc
attack(mob/target)
if(weapon)
if(!(target in range(weapon.attack_range, src)))
return
var/random_damage = rand(0, weapon.base_damage)
target.hit(random_damage)
hit(mob/attacker, damage)
hp -= damage
if(hp <= 0)
die(attacker)
die(mob/killer)
if(killer)
killer.exp += exp
Del()
mob/vampire
die(mob/killer)
if(killer.weapon.type == /obj/weapon/wood_stake)
.=..()
else
killer << "Your weapons cannot harm me!"
obj/weapon
var
base_damage = 1
attack_range = 1
knife
base_damage = 2
bow
attack_range = 3
low_bow
base_damage = 3
attack_range = 5
mob/Click()
.=..()
usr.attack(src)


The above example is the sort of way you want to set up code. Notice that I can define unique monsters, like the vampire, just by adding a couple lines to it's own hit proc. Using the method suggested earlier in this thread, I'd have to check, everytime any mob ever attacked, if the moster being target was a vampire, if the attacker was using a wooden stake, if the damage was enough to kill it, etc. One you have five monsters in your game (a very small number for an RPG) your "attack verb" is going to be larger than the rest of you code.

For more info, read here:
http://bwicki.byond.com/ByondBwicki.dmb?BasicCombatSystem
In response to IainPeregrine
Wow... no offence to anyone, but you're probabbly the first person to post here who actually knows anything about the subject! That works perfectly.
In response to Adam753
Glad to help. Read through it and be sure you understand what I'm doing. Notice how each object get's a chance to define how it should behave, and how I call a lot of different small procs, instead of using one gigantic verb.