ID:262903
 
This is one of my weapon codes.
obj/items
Double_Blade
name = "Double Blader"
icon = 'Equips.dmi'
icon_state = "db1"
verb
Get()
set src in oview(1,usr)
set category=null
if(src.Move(usr)){usr<<"<b>You picked up the [src.name].</b>"; src.suffix = " Un-Equipped"}
Drop()
set src in usr.contents
set category=null
if(src.Move(usr.loc)){usr<<"<b>You dropped the [src.name].</b>"}
Equip()
set src in usr.contents
set category=null
if(usr.weqalready==1){usr<<"You already have a weapon equipped."}
else if(usr.class!="Samurai"){usr<<"Only a samurai can equip a [src.name]."}
else if(src.suffix==" Equipped"){usr << "<font color = teal>The [src.name] is already equipped."}
else
src.suffix = " Equipped"
usr.weapon+=5
usr.weqalready=1
Unequip()
set category = null
set src in usr
if(src.suffix!=" Equipped"){usr << "<font color = teal>The [src.name] is not equipped."}
else
src.suffix = " Un-Equipped"
usr.weapon -=5
usr.weqalready=0

And this is my weapon dealer code.
mob/NPC
Weapon_Crafter_1
icon = 'Mobs.dmi'
icon_state = "merchant"
char_name = "Metal Crafter"
name = "Metal Crafter"
pvp = "Non-Active"
safe=1
Age = 23
Str = 50
Def = 3
Agl = 7
Spd = 1
HP = 10
PP = 4196
class = "Metal Crafter"
Click(src in oview(3))
switch(input("Metal Crafter: Would you like buy or sell?","Metal Crafter", text) in list ("Buy","Sell"))
if ("Buy")
switch(input("Weapon Crafter: What would you like to buy?","Metal Crafter", text) in list ("Samurai's Double Blader.....150y","Toshai's Spear.....200y","Ninja's Nunchuk.....140y"))
if ("Samurai's Double Blader.....150y")
if(usr.yen<=149){alert("Metal Crafter: You do not have enough yen")}
else if(usr.class!="Samurai"){usr<<"Metal Crafter: You must be a samurai to puchase this weapon"}
else
usr.contents +=(new/obj/items/Double_Blade)
for (var/obj/items/Double_Blade/O in usr.contents)
O.suffix = " Un-Equipped"
usr.yen-=1
usr<<"<font color=aqua>Metal Crafter: Thank you, Come again."
if("Ninja's Nunchuk.....140y")
if(usr.yen<=139){alert("Metal Crafter: You do not have enough yen")}
else if(usr.class!="Ninja"){usr<<"Metal Crafter: You must be a ninja to puchase these weapons"}
else
usr.contents.Add(new/obj/items/Nunchuk)
for (var/obj/items/Nunchuk/O in usr.contents)
O.suffix = " Un-Equipped"
usr.yen-=140
usr<<"<font color=aqua>Metal Crafter: Thank you, Come again."
if("Toshai's Spear.....200y")
if(usr.yen<=139){alert("Metal Crafter: You do not have enough yen")}
else if(usr.class!="Toshai"){usr<<"Metal Crafter: You must be a toshai to puchase this weapon"}
else
usr.contents.Add(new/obj/items/Spear)
for (var/obj/items/Spear/O in usr.contents)
O.suffix = " Un-Equipped"
usr.yen-=200
usr<<"<font color=aqua>Metal Crafter: Thank you, Come again."


The only problem is that the drop verb does not work when you buy the weapon. It works perfectly when you pick up the weapon.

Not entirely sure why you can't drop purchased items, but you sure as hell shouldn't be defining get() and drop() under the item itself. Use inheritance, man! Define them under /obj/item!

Furthermore, your equipment system is a mess, from what I can see from the verb.

1 - Do not use a==1 and a==0 for boolean variables (Variables that are either on or off, that indicate something. Say, isflying). Use if(a) and if(!a). That way, if a is something unexpected, it should be handled appropriately. (if(!a) == if(a==null || a=="" || a==0))

2 - Don't use boolean variables for equipment. Give the player a variable, say, equippedwep, and then set that to the object being equipped. For example:

obj/weapon/equip()
usr.weapon=src

mob/var/weapon


3 - Put a space between new and the type path. Otherwise, it's just unreadable. Most of that code is, though.

4 - By 'not work' what exactly do you mean? Does the verb not appear? Do you click it and nothing happens? Do you get any error messages? Throw a few debug messages into that code, and see what happens.
In response to Jp
By "not work" i mean the verb shows, but when you click it nothing happens......and thank you for that quick lesson, i needed it. Im coding with the dm guide at my side, and thats about it.
Dark Krow wrote:
>                       if("Toshai's Spear.....200y")
> if(usr.yen<=139){alert("Metal Crafter: You do not have enough yen")}
> else if(usr.class!="Toshai"){usr<<"Metal Crafter: You must be a toshai to puchase this weapon"}
> else
> usr.contents.Add(new/obj/items/Spear)
> for (var/obj/items/Spear/O in usr.contents)
> O.suffix = " Un-Equipped"
> usr.yen-=200
> usr<<"<font color=aqua>Metal Crafter: Thank you, Come again."
>

Is there any reason why you don't just do something like
var/obj/items/Spear/O = new/obj/items/Spear(usr)
O.suffix=" Un-Equipped"

Instead of trying to use the Add() proc with new and then loop through the contents. I mean, what happens if someone has a spear equipped, and they buy a new one? Suddenly it's un-equipped? Also, I'd like to point out that for the spear, it says its 200y(as it later subtracts 200), but the if() checks to see if it is less than or equal to 139, as opposed to 199. As well, I think it'd be easier to check if the usr's current balance were simply less than the price, rather than if it were less than or equal to the price-1. For example:
if(a < 200)
// Seems easier than:
if(a <= 199)


Hiead
In response to Jp
Jp wrote:
3 - Put a space between new and the type path. Otherwise, it's just unreadable.

I don't entirely agree with that. Really, it's a matter of preference(as is that whole Dan-ism/Tom-ism stuff with brackets).

Hiead
In response to Dark Krow
That's good. That's very good. *sings* When learning to program in DM, the DM guide, is your friend!

Now what we discover is what is actually happening when you click that verb.

verb/Drop()
set src in usr.contents
set category=null
if(Move(usr.loc)){usr<<"<b>You dropped [src].</b>"}
else usr << "[src] is here: [loc]"
if(density) usr << "[src] is dense. What the hell?"


Are you trying to drop the item over the same turf? Maybe you should show us any changes to Enter() you've made for turfs. Or Exit() for mobs.
In response to Jp
turf
Ice_Cave
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter()
usr.loc=locate(30,48,3)
Town_Cave
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter()
usr.loc=locate(usr.x,usr.y+2,usr.z+1)
Town_Cave_2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter()
usr.loc=locate(usr.x,usr.y-2,usr.z-1)
Ice_Cave2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter()
usr.loc=locate(20,48,3)
Ice_Cave3
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter()
usr.loc=locate(5,15,4)
Ice_Cave4
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter()
usr.loc=locate(52,37,3)
Ladder_Down
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "door1"
Enter()
usr.loc=locate(usr.x,usr.y+2,usr.z+1)
Fire_cave_Ladder1
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "door1"
Enter()
usr.loc=locate(80,88,5)
Fire_cave_Ladder4
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "door1"
Enter()
usr.loc=locate(49,96,5)
Fire_cave_Ladder6
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "door1"
Enter()
usr.loc=locate(29,38,5)
Fire_cave_Ladder2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "doorup"
Enter()
usr.loc=locate(39,96,5)
Fire_cave_Ladder3
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "doorup"
Enter()
usr.loc=locate(21,65,5)
Fire_cave_Ladder5
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "doorup"
Enter()
usr.loc=locate(10,93,2)
Ladder_Up
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "doorup"
Enter()
usr.loc=locate(usr.x,usr.y-2,usr.z-1)
Door_2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "paper"
Enter()
flick("paperopen",src)
usr.loc=locate(usr.x,usr.y+2,usr.z+1)
Door2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "paper"
Enter()
flick("paperopen",src)
usr.loc=locate(usr.x,usr.y+2,usr.z-1)
House_back
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "paper"
Enter()
flick("paperopen",src)
usr.loc=locate(usr.x,usr.y-2,usr.z-1)
House_back_2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "paper"
Enter()
flick("paperopen",src)
usr.loc=locate(usr.x,usr.y-2,usr.z+1)
Store_Back
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "door3"
Enter()
usr.loc=locate(usr.x,usr.y-2,usr.z-1)

area
Complete_Block
Enter()
return

mob
Enter(atom/movable/A)
if(istype(A,/obj/items/))
return ..()
Entered(atom/movable/A)
if(istype(A,/obj/items/))
src.inventory.Add(A)
return ..()
Exit(atom/movable/A)
if(istype(A,/obj/items/))
if((A in src.inventory))
if(!(A in src.equipped))
return ..()
Exited(atom/movable/A)
if(istype(A,/obj/items/))
src.inventory.Remove(A,null)
return ..()

Thats everything in the game that uses the Enter(),Entered(),Exit() and Exited() proc's.
In response to Dark Krow
Store-bought items won't enter your player's inventory list, because they aren't using the default movement procs.

And don't ever use usr in Enter(), Exit(), Entered(), and Exited(). Or any other movement proc. It's worse then unsafe, it's sort of like writing code just so you can see those pretty red error messages.

Why you have an inventory list is beyond me. Isn't contents good enough?
In response to Jp
Ahhh, i see what you mean about the inventory. But how do i move the players location with out using usr in it? If i use src it will just move the turf.
In response to Dark Krow
Enter(), Exit(), Entered(), and Exited() all have an argument of atom/movable, that is the thing doing (Or attempting to do) the entering or exiting. For example:

turf/HelloThere/Entered(atom/movable/m)
if(ismob(m)) m << "Hello there!"


Displays the message 'Hello there!' to any mobs that successfully enter the turf.

Think about what usr actually is - It's the ultimate caller of that procedure. What if it was called from, say, world/New()? Then usr would be null. What if you have a 'push' verb that pushes mobs back a space? Then usr is the pusher, not the pushee.
In response to Jp
Well i changed the enter()s as you said to, changed the "invetory"s to "contents". Now its saying it dropped it, its leaving the contents, but its not appearing on the ground anywhere in sight.
In response to Dark Krow
Stick something like this under the if(move()) bit.

usr << loc
usr << "X:[x], Y:[y], Z:[z]"


And tell us what the result is. Please.
In response to Dark Krow
Would you like to show the updated code?

Hiead
In response to Jp
It does the same thing but now it says "X:0, Y:0, Z:0(line drops here)
You dropped the Double Blader."

And here is the updated code, sorry if i couldent get to every if statment.


here is the weapon code
obj/items   
verb
Get()
set src in oview(1,usr)
set category=null
if(src.Move(usr)){usr<<"<b>You picked up the [src.name].</b>"; src.suffix = " Un-Equipped"}
Drop()
set src in usr.contents
set category=null
if(src.suffix== " Equipped"){usr<<"You cant drop the [src.name] while its equipped."}
else
if(src.Move(usr.loc)){usr << loc; usr << "X:[x], Y:[y], Z:[z]"; usr<<"<b>You dropped the [src.name].</b>"}
Spear
name = "Spear"
icon = 'Equips.dmi'
icon_state = "sp1"
verb
Equip()
set src in usr.contents
set category=null
if(usr.weqalready==1){usr<<"You already have a weapon equipped."}
else if(usr.class!="Toshai"){usr<<"Only a toshai can equip a [src.name]."}
else if(src.suffix==" Equipped"){usr << "<font color = teal>The [src.name] is already equipped."}
else
src.suffix = " Equipped"
usr.weapon+=15
usr.weqalready=1
Unequip()
set category = null
set src in usr
if(src.suffix!=" Equipped"){usr << "<font color = teal>The [src.name] is not equipped."}
else
src.suffix = " Un-Equipped"
usr.weapon -=15
usr.weqalready=0

Here is the store code
mob/NPC
Weapon_Crafter_1
icon = 'Mobs.dmi'
icon_state = "merchant"
char_name = "Metal Crafter"
name = "Metal Crafter"
pvp = "Non-Active"
safe=1
Age = 23
Str = 50
Def = 3
Agl = 7
Spd = 1
HP = 10
PP = 4196
class = "Metal Crafter"
Click(src in oview(3))
switch(input("Metal Crafter: Would you like buy or sell?","Metal Crafter", text) in list ("Buy","Sell"))
if ("Buy")
switch(input("Weapon Crafter: What would you like to buy?","Metal Crafter", text) in list ("Samurai's Double Blader.....150y","Toshai's Spear.....200y","Ninja's Nunchuk.....140y"))
if ("Samurai's Double Blader.....150y")
if(usr.yen<150){alert("Metal Crafter: You do not have enough yen")}
else if(usr.class!="Samurai"){usr<<"Metal Crafter: You must be a samurai to puchase this weapon"}
else
usr.contents +=(new/obj/items/Double_Blade)
for (var/obj/items/Double_Blade/O in usr.contents)
O.suffix = " Un-Equipped"
usr.yen-=1
usr<<"<font color=aqua>Metal Crafter: Thank you, Come again."
if("Ninja's Nunchuk.....140y")
if(usr.yen<140){alert("Metal Crafter: You do not have enough yen")}
else if(usr.class!="Ninja"){usr<<"Metal Crafter: You must be a ninja to puchase these weapons"}
else
usr.contents +=(new/obj/items/Nunchuk)
for (var/obj/items/Nunchuk/O in usr.contents)
O.suffix = " Un-Equipped"
usr.yen-=140
usr<<"<font color=aqua>Metal Crafter: Thank you, Come again."
if("Toshai's Spear.....200y")
if(usr.yen<200){alert("Metal Crafter: You do not have enough yen")}
else if(usr.class!="Toshai"){usr<<"Metal Crafter: You must be a toshai to puchase this weapon"}
else
usr.contents +=(new/obj/items/Spear)
for (var/obj/items/Spear/O in usr.contents)
O.suffix = " Un-Equipped"
usr.yen-=200
usr<<"<font color=aqua>Metal Crafter: Thank you, Come again."


And here is all the enter()s
turf
Ice_Cave
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(30,48,3)
Town_Cave
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(usr.x,usr.y+2,usr.z+1)
Town_Cave_2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(usr.x,usr.y-2,usr.z-1)
Ice_Cave2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(20,48,3)
Ice_Cave3
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(5,15,4)
Ice_Cave4
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "ice-cave"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(52,37,3)
Ladder_Down
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "door1"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(usr.x,usr.y+2,usr.z+1)
Fire_cave_Ladder1
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "door1"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(80,88,5)
Fire_cave_Ladder4
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "door1"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(49,96,5)
Fire_cave_Ladder6
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "door1"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(29,38,5)
Fire_cave_Ladder2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "doorup"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(39,96,5)
Fire_cave_Ladder3
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "doorup"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(21,65,5)
Fire_cave_Ladder5
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "doorup"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(10,93,2)
Ladder_Up
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "doorup"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(usr.x,usr.y-2,usr.z-1)
Door_2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "paper"
Enter(atom/movable/m)
if(ismob(m))
flick("paperopen",src)
m.loc=locate(usr.x,usr.y+2,usr.z+1)
Door2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "paper"
Enter(atom/movable/m)
if(ismob(m))
flick("paperopen",src)
m.loc=locate(usr.x,usr.y+2,usr.z-1)
House_back
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "paper"
Enter(atom/movable/m)
if(ismob(m))
flick("paperopen",src)
m.loc=locate(usr.x,usr.y-2,usr.z-1)
House_back_2
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "paper"
Enter(atom/movable/m)
if(ismob(m))
flick("paperopen",src)
m.loc=locate(usr.x,usr.y-2,usr.z+1)
Store_Back
name="Crystal Quest";
icon = 'Tiles.dmi'
icon_state = "door3"
Enter(atom/movable/m)
if(ismob(m))
m.loc=locate(usr.x,usr.y-2,usr.z-1)

mob
Enter(atom/movable/A)
if(istype(A,/obj/items/))
return ..()
Entered(atom/movable/A)
if(istype(A,/obj/items/))
src.contents.Add(A)
return ..()
Exit(atom/movable/A)
if(istype(A,/obj/items/))
if((A in src.contents))
if(!(A in src.equipped))
return ..()
Exited(atom/movable/A)
if(istype(A,/obj/items/))
src.contents.Remove(A)
return ..()

In response to Dark Krow
Okay, you don't need to specifically add and remove things from contents in mob/Entered and mob/Exited(). You shouldn't use return ..() there, but just ..(). In all the other Enter() procs, you almost certainly need a ..() in the most logical place for it, or things that aren't mobs won't be able to step on the square.

Okay, the location of the thing is becoming null. That suggests, at least to me, that something is iffy with the Enter() proc for whatever you're dropping it on. What type of turf is it? Does it have an Enter() proc defined? Do you have a /turf/Enter()?

You still have a few usrs hanging around in the Enter() procs and so forth.

It would be handy if you could show me the output from src.Enter(usr.loc), in that drop procedure. Just output it.
In response to Dark Krow
A main problem I see is your Enter() procs(after seeing the problem, I stopped reading for more problems, so there may be more). After the if(ismob(m)), add a:
 else
return ..()

The reason is because it teleports the entering atom if its a mob, and does nothing if it's not. So if it's an obj, Enter returns 0, meaning entry is disallowed.

Actually, I would think that it would be better for you to use Entered(), as opposed to Enter(), on the turfs that are meant to teleport the mobs.

Hiead
In response to Jp
Im not dropping it on anything but just a stadard turf.

And it not giving any output but what i said in my last post

"you have dropped the [src.name]"
In response to Dark Krow
Did you do what I said in [link]?

Hiead
In response to Hiead
Yes i did, it didnt do any good.

Also, i did what you said jp, but now its back to not doing anything.
In response to Dark Krow
Will you show me the code that you came up with after following my suggestion?

Hiead
Page: 1 2