ID:261764
 
I'm not sure, but I think that this could be implimented better. Well really what I mean is not have to use all of vars for the spells.
obj/weapon/verb/Equip()
set src in usr
if(usr.weapon)
usr << "You already have a weapon equiped"
return
else if(usr.class != src.classneed)
usr << "You may not equip this"
return
else
usr.overlays += src
usr << "You equip [src]"
usr.strength += src.weaponstr
usr.weapon = "[src.name]"
usr.weapon1 = src
usr.weaponlvl = src.lvl
if(src.name == "Wind Staff")
var/obj/spells/S = new /obj/spells/wind/cutter()
var/obj/spells/S2 = new /obj/spells/wind/current_cutter()
var/obj/spells/S3 = new /obj/spells/wind/gust()
if(usr.lvl != S.requiredlvl)
del(S)
return
if(usr.lvl != S2.requiredlvl)
del(S2)
return
if(usr.lvl != S3.requiredlvl)
del(S3)
return
else
usr.spell = "[S.name]"
usr.spell1 = S
usr.spelllvl = S.lvl
usr.spell2 = S2
usr.spelllvl2 = S2.lvl
usr.spell13 = S3
usr.spelllvl3 = S3.lvl


I have the spells defined as objs. And a Fire() proc that fires the spell that is selected. Well that's that. I think seeing this might help as well.
mob 
Stat()
if(!client)
return null
else
statpanel("[src.name]")
stat("Class: [src.class]")
stat("Level: [src.lvl]")
stat("Experience: [src.exp]/[src.expneed]")
stat("HP: [src.hp]/[src.maxhp]")
stat("Mp: [src.mp]/[src.maxmp]")
stat("Strength: [src.strength]")
stat("Defense: [src.defense]")
stat("Intelligence: [src.intelligence]")
stat("Magic Defense: [src.magicdef]")
stat("Evasion: [src.evasion]")
stat("Gold: [src.gold]")
statpanel("Weapon/Spell")
if(src.weapon)
stat("Weapon")
stat(src.weapon1)
stat("lvl: [src.weaponlvl]")
else
stat("No weapon equiped")
if(src.spell)
stat("")
stat("Spell")
stat(src.spell1)
stat("lvl: [src.spelllvl]")
else
stat("No spell is being used")
statpanel("Inventory")
stat(src.contents)


I thought that might help to see what I'm trying to do exacetely. So any help maybe making the spell stuff in equip better would be nice.

Resonating Light
Okay, time to move to some slightly more advanced programming. Say hello to Mister Typesof()! =)

<code>for (var/spelltype in typesof(/obj/spells)) var/obj/spell/S=new spelltype(usr) if (usr.lvl < S.requiredlvl) del S</code>

You may need to change your code to get rid of those messy "spell2", "spelllvl2", etc. vars, and to use the objects properly to determine which spell is which (hint: Try locate()-ing a /obj/spell/whatever in the mob's contents). There's not much point taking a nice clean object-orientated approach to spellcasting without doing it properly. =)
In response to Crispy
I left out an important detail. The spells you have are determined by which type of staff you have equiped. Which means spells are given once you equip the weapon thus just searching through /obj/spells would give all the spells in the game and not just the ones associated with the staff. i was thinking that I could just do a different if() statement that determines the usr's weapon and then adds spells of that type... E.G.
if(istype(src.weapon,/obj/weapon/staff/wind))
for(var/spelltypes in typesof(/obj/spells/wind))
var/obj/spell/S = new spelltype()
stat(S)
stat("Level: [S.lvl]")

is that a good idea or what? Or did I miss your point altogether?

Resonating Light
In response to Resonating_Light
You could do it like that, but it's better to avoid duplicating code; avoiding duplication makes it easier to read, and means that if you want to change anything in that code you only have to change it once. You'd have to repeat that segment of code several times, once for each wand.

I'd fix this by giving wands a "spells" var. This var would be a list containing type paths of spells, something like this:

<code>obj/weapon/staff var/spells[0] //Defines the list wind spells=list(/obj/spells/wind/hurricane, /obj/spells/wind/breeze, /obj/spells/blah)</code>

Then you can loop through <code>for(var/obj/spells/S in src.weapon.spells)</code> to find all the spells you can cast.

P.S. That code you posted is messed up anyway. The indentation is messed up, and the var "spelltypes" is different from "spelltype". But it shouldn't matter as you're not going to use that code, right? =)

P.S. Close your DM tags next time. =)
In response to Crispy
Crispy wrote:
You could do it like that, but it's better to avoid duplicating code; avoiding duplication makes it easier to read, and means that if you want to change anything in that code you only have to change it once. You'd have to repeat that segment of code several times, once for each wand.

I'd fix this by giving wands a "spells" var. This var would be a list containing type paths of spells, something like this:

<code>obj/weapon/staff > var/spells[0] //Defines the list > > wind > spells=list(/obj/spells/wind/hurricane, /obj/spells/wind/breeze, /obj/spells/blah)</code>

Then you can loop through <code>for(var/obj/spells/S in src.weapon.spells)</code> to find all the spells you can cast.
Now, in the Stat code I get <code>src.weapon.spells</code> as an undefined var. I defined <code>var/spells[0]</code> under the right type path and all that. I suppose that my Stat code should help, so here it is.
<code>mob Stat() if(!client) return null else statpanel("[src.name]") stat("Class: [src.class]") stat("Level: [src.lvl]") stat("Experience: [src.exp]/[src.expneed]") stat("HP: [src.hp]/[src.maxhp]") stat("Mp: [src.mp]/[src.maxmp]") stat("Strength: [src.strength]") stat("Defense: [src.defense]") stat("Intelligence: [src.intelligence]") stat("Magic Defense: [src.magicdef]") stat("Evasion: [src.evasion]") stat("Gold: [src.gold]") statpanel("Weapon/Spell") if(src.weapon) stat("Weapon") stat(src.weapon) stat("lvl: [src.weaponlvl]") else stat("No weapon equiped") if(src.spell) stat("") stat("Spell") for(var/obj/spells/S in src.weapon.spells) if(S) stat(S) stat("lvl: [S.lvl]") else return else stat("No spells") </code>
P.S. That code you posted is messed up anyway. The indentation is messed up, and the var "spelltypes" is different from "spelltype". But it shouldn't matter as you're not going to use that code, right? =)

P.S. Close your DM tags next time. =)

Those were just screw ups, I type that code inside of the message and just ended up tabbing it wrong, and the dm tags thing, another accident. What can I say, I was in a hurry. As a matter of fact I'm almost always in a hurry. Because my famiy(brother) is addicted to the phone like a crackhead to crack.(I don't really know if I shoulda said that)

Well... thanks,
Resonating Light
In response to Resonating_Light
Whups, forgot about that. The problem is that not all weapons have the spells var; only weapon/staffs do.

<code>var/obj/weapon/staff/TheWand=src.weapon if (istype(TheWand)) //If it's the type it's defined as for (var/obj/spells/S in TheWand) ...</code>

You need to use something like that to (1) make sure it really is a staff, and (2) stop DS complaining. =)
In response to Crispy
This is geting a little nerve racking. Well anyways, I did what you said and defined the spells var under <code>/obj/weapon/staff</code> and I also did the <code>spells = list(/obj/blah ...)</code>. But! my stat code still acts as if is there are no spells in the weapon. I know that the if(istype()) thing works because it's not displaying No Spells in the statpanel. It is just displaying nothing. Well.... here's my code
<code>mob Stat() if(!client) return null else statpanel("[src.name]") stat("Class:","[src.class]") stat("Level:","[src.lvl]") stat("Experience:","[src.exp]/[src.expneed]") stat("HP:","[src.hp]/[src.maxhp]") stat("Mp:","[src.mp]/[src.maxmp]") stat("Strength:","[src.strength]") stat("Defense:","[src.defense]") stat("Intelligence:","[src.intelligence]") stat("Magic Defense:","[src.magicdef]") stat("Evasion:","[src.evasion]") stat("Gold:","[src.gold]") statpanel("Weapon/Spells") if(src.weapon) stat("Weapon:",src.weapon) stat("Weapon level:","[src.weaponlvl]") stat("") var/obj/weapon/staff/W = src.weapon //create a new var for your weapon if(istype(W)) //make sure W is a staff for(var/obj/spells/S in W.spells) //loop through spells in W.spells stat("Spell:",S) stat("Spell level:","[S.lvl]") else stat("No spells","") else stat("No weapon equiped","") stat("No spells","") statpanel("Inventory") stat(src.contents)</code>

Resonating Light

[EDIT]Nevermind all that, I fixed it. Instead of just making spells hold the type paths i created a new obj of that type <code>spells = list(new/obj/spells/wind/cutter())</code> And WALLAH! it worked.

Thanks for all the help!
In response to Resonating_Light
Resonating_Light wrote:
[EDIT]Nevermind all that, I fixed it. Instead of just making spells hold the type paths i created a new obj of that type <code>spells = list(new/obj/spells/wind/cutter())</code> And WALLAH! it worked.

*thwacks himself around the head* Silly Crispy. Type paths != objects. Silly, silly, Crispy.

Glad you got it working. =)