Let's Fix This Action

I think Im Dead
01 Jan 2004, 23:32
So I've been drinking a bit today due to my work on a QuestNet engine being cut short by blackouts. I'm having a bit of trouble getting this "TAKE" command to work. The setup for it is that there is a command "TAKE" which checks if an object is in the currentroom(I just realized, not really), if the player's "hands" are free, and if so, calls the "TAKE" action of the object which for take-able objects, moves the object to the player's inventory, and alters the player and object's properties to make it IN the player's "hand". The incrementing numeric variable is for further expansion of the command in forms of "TAKE SECOND #OBJECT#" and such, allowing you to change one character in the "SET STRING <TAKE.OBJ[USERID]; #TAKE.OBJ1[USERID]#>" piece of code and paste for desired commands. The current problem is that it doesn't print out the default invalid item error if an object exists in the player's inventory but isn't in the room, and instead does nothing. As a challenge... FIX IT!

Player Command Aspect:

command <take #@object[userid]#> {
set numeric <take.count[userid]; 0>
for each object in <#quest.currentroom[userid]#> if ( #quest.thing# = #object[userid]# ) then {
inc <take.count[userid]>
set string <take.obj%take.count[userid]%[userid]; #quest.thing#>
set string <mainhand[userid]; $objectproperty(player%userid%; hands.mainhand)$>
set string <offhand[userid]; $objectproperty(player%userid%; hands.offhand)$>
if ( $objectproperty(player%userid%; #mainhand[userid]#)$ <> nothing ) and ( $objectproperty(player%userid%; #offhand[userid]#)$ <> nothing ) then msg <Your hands are too full to grab anything.|n> else {
if ( $objectproperty(player%userid%; #mainhand[userid]#)$ <> nothing ) and ( $objectproperty(player%userid%; #offhand[userid]#)$ = nothing ) then {
set string <take.obj[userid]; #take.obj1[userid]#>
set string <take.hand[userid]; left>
set string <take.floc[userid]; $objectproperty(#take.obj[userid]#; loc)$>
set string <take.tloc[userid]; #offhand[userid]#>
doaction <#take.obj[userid]#; take>
}
if ( $objectproperty(player%userid%; #mainhand[userid]#)$ = nothing ) then {
set string <take.obj[userid]; #take.obj1[userid]#>
set string <take.hand[userid]; right>
set string <take.floc[userid]; $objectproperty(#take.obj[userid]#; loc)$>
set string <take.tloc[userid]; #mainhand[userid]#>
doaction <#take.obj[userid]#; take>
}
}
}
}


Object Action Aspect:

action <take> {
move <#take.obj[userid]#; player%userid%>
property <#take.obj[userid]#; loc=#take.tloc[userid]#>
property <player%userid%; #take.tloc[userid]#=#take.obj[userid]#>
property <player%userid%; hands.display.#take.hand[userid]#=$objectproperty(#take.obj[userid]#; display.long)$>
msg <You pick up $objectproperty(#take.obj[userid]#; display.long)$ with your #take.hand[userid]# hand.|n>
}


Eh, while typing this I realized a few problems in it as well, and if nobody has posted a solution or idea, I'll post mine as they come along that way anyone who would want to do something similar has a reference how-to.

I think Im Dead
01 Jan 2004, 23:56
Eh, here's one that works better and has less human errors in it.


command <take #@object[userid]#> {
if here <#object[userid]#> then {
set string <mainhand[userid]; $objectproperty(player%userid%; hands.mainhand)$>
set string <offhand[userid]; $objectproperty(player%userid%; hands.offhand)$>
if ( $objectproperty(player%userid%; #mainhand[userid]#)$ <> nothing ) and ( $objectproperty(player%userid%; #offhand[userid]#)$ <> nothing ) then msg <Both of your hands are full.|n> else {
if ( $objectproperty(player%userid%; #mainhand[userid]#)$ <> nothing ) and ( $objectproperty(player%userid%; #offhand[userid]#)$ = nothing ) then {
set string <take.obj[userid]; #object[userid]#>
set string <take.hand[userid]; left>
set string <take.floc[userid]; $objectproperty(#take.obj[userid]#; loc)$>
set string <take.tloc[userid]; #offhand[userid]#>
doaction <#take.obj[userid]#; take>
}
if ( $objectproperty(player%userid%; #mainhand[userid]#)$ = nothing ) then {
set string <take.obj[userid]; #object[userid]#>
set string <take.hand[userid]; right>
set string <take.floc[userid]; $objectproperty(#take.obj[userid]#; loc)$>
set string <take.tloc[userid]; #mainhand[userid]#>
doaction <#take.obj[userid]#; take>
}
}
else msg <I could not find what you were referring to.|n>
}
}


I'm thinking part of this is a QuestNet problem in which it is recursing through the "player" object and reading that there is an object matching #@object[userid]# in the "player" object. I'll post it there as a bug, which it may be.

I think Im Dead
03 Jan 2004, 09:17
Here's the (so far) final copy. It solves all the problems and works how I want, it's quite different from both previous posts, a bit more simple but more advanced as well. Sometimes those if's, then's and else's start stacking up and messing with your head. Realistically it could be modified at the very end of the command to detect if the player has the object already, and print out that "they already have it and don't need to take it" if that's the case, and "I don't know what you're talking about" if not. I found this complete enough and hopefully it will give anyone interested some insight into the process that is creating a more realistic inventory for Quest games.

COMMAND CODE

command <take #@object[userid]#> if here <#object[userid]#> then {
set string <mainhand[userid]; $objectproperty(player%userid%; hands.mainhand)$>
set string <offhand[userid]; $objectproperty(player%userid%; hands.offhand)$>
if ( $objectproperty(player%userid%; hands.#mainhand[userid]#)$ = nothing ) then {
set string <take.obj[userid]; #object[userid]#>
set string <take.hand[userid]; #mainhand[userid]#>
set string <take.floc[userid]; $objectproperty(#take.obj[userid]#; loc)$>
set string <take.tloc[userid]; hands.#mainhand[userid]#>
doaction <#take.obj[userid]#; take>
}
else {
if ( $objectproperty(player%userid%; hands.#offhand[userid]#)$ = nothing ) then {
set string <take.obj[userid]; #object[userid]#>
set string <take.hand[userid]; #offhand[userid]#>
set string <take.floc[userid]; $objectproperty(#take.obj[userid]#; loc)$>
set string <take.tloc[userid]; hands.#offhand[userid]#>
doaction <#take.obj[userid]#; take>
}
else msg <Both of your hands are full.|n>
}
}
else msg <I could not find what you were referring to.|n>


OBJECT ACTION CODE

action <take> {
move <#take.obj[userid]#; player%userid%>
property <#take.obj[userid]#; loc=#take.tloc[userid]#>
property <player%userid%; #take.tloc[userid]#=#take.obj[userid]#>
property <player%userid%; hands.#take.hand[userid]#.display=$objectproperty(#take.obj[userid]#; display.long)$>
msg <You pick up $objectproperty(#take.obj[userid]#; display.long)$ with your #take.hand[userid]# hand.|n>
}


And for reference on how objects are setup to react with this code... an object type looks like this...


define type <pants>
type <clothing>
alias = pants
prefix = a pair of
displaytype = Clothing
article = it
gender = it
pocket
weight = 2
locations.wear = 1
locations.wear.1 = legs.clothing
end define


And to give you a general idea on the structure of the player object housing the inventory...


property <player%userid%; alias=$name(player%userid%)$> 'Default is player's name, but can be changed to support things like metamorphosis, shapechanging, disguises, etc.
property <player%userid%; name=$name(player%userid%)$> 'This value is the player's name, never should change, used to restore from ^this, this^ and...... this^.
property <player%userid%; head.accessory=nothing> 'This is the place for objects like fake beards, eye patches, glasses, etc.
property <player%userid%; head.armor=nothing> 'This property is for any armor type object upon the head, but can also reference armor worn that covers the head.
property <player%userid%; head.clothing=nothing> 'This is the place for objects like hats, caps, etc.
property <player%userid%; neck.accessory1=nothing> '- - - - - - - - - - - - - - - - - - - -
property <player%userid%; neck.accessory2=nothing> ' These are for necklaces, amulets, etc
property <player%userid%; neck.accessory3=nothing> '- - - - - - - - - - - - - - - - - - - -
property <player%userid%; neck.armor=nothing> ' This is for any neck armor(coif's and such), but can also reference armor worn that covers the neck.
property <player%userid%; neck.clothing=nothing> ' This is the place for objects like scarfs, torqs, etc.
property <player%userid%; shoulders.accessory=nothing> 'This is the place for objects like capes, cloaks, greatcloaks, etc.
property <player%userid%; shoulders.clothing=nothing> 'This is the place for objects like robes, shawls, etc.
property <player%userid%; shoulders.left=nothing> ' This is the place for objects worn slung over the shoulder like satchel, weapon harness, purse, etc.
property <player%userid%; shoulders.right=nothing> ' This is the place for objects worn slung over the shoulder like satchel, weapon harness, purse, etc.
property <player%userid%; arms.accessory=nothing> ' This is the place for objects like armband, etc.
property <player%userid%; arms.armor=nothing> ' This is for any arm armor(arm greaves), but can also reference armor worn that covers the arms.
property <player%userid%; arms.clothing=nothing> ' This is the place for clothes worn on the arm, I can't think of any right now though.
property <player%userid%; wrists.accessory1=nothing> ' This is the place for objects like bracelets, etc.
property <player%userid%; wrists.accessory2=nothing> ' This is the place for objects like bracelets, etc.
property <player%userid%; wrists.armor=nothing> ' This is for any wrist armor(gauntlets, bracers), but can also reference armor worn that covers the wrists.
property <player%userid%; wrists.clothing=nothing> ' This is the place for objects like gloves, etc.
property <player%userid%; hands.accessory1=nothing> '- - - - - - - - - - - - - - - - - - - - - - - -
property <player%userid%; hands.accessory2=nothing> ' This is the place for objects like rings,
property <player%userid%; hands.accessory3=nothing> '
property <player%userid%; hands.accessory4=nothing> ' bands, etc.
property <player%userid%; hands.accessory5=nothing> '
property <player%userid%; hands.accessory6=nothing> '
property <player%userid%; hands.accessory7=nothing> '
property <player%userid%; hands.accessory8=nothing> '
property <player%userid%; hands.accessory9=nothing> '
property <player%userid%; hands.accessory10=nothing>'- - - - - - - - - - - - - - - - - - - - - - - -
property <player%userid%; hands.armor=nothing> ' This is for any hand armor(none comes to mind), but can also reference armor worn that covers the hands.
property <player%userid%; hands.left=nothing> ' These are for holding objects in the left and right hands, it should only be altered by commands.
property <player%userid%; hands.left.display=nothing> 'This is for holding a full description of the item held in the left hand, 'TAKE' command should alter it.
property <player%userid%; hands.right=nothing> ' These are for holding objects in the left and right hands, it should only be altered by commands.
property <player%userid%; hands.right.display=nothing> 'This is for holding a full description of the item held in the right hand. 'TAKE' command should alter it.
property <player%userid%; hands.mainhand=right> 'This specifies the "main hand" which determines if the player is right or left handed. default here is right.
property <player%userid%; hands.offhand=left> ' This specifies the "off hand" which is the remaining of the two after "main hand" is set. default here is left.
property <player%userid%; torso.accessory=nothing> ' This is the place for objects like brooches, emblems, etc.
property <player%userid%; torso.armor=nothing> ' This is for any torso armor, but can also reference armor worn that covers the torso.
property <player%userid%; torso.clothing=nothing> ' This is the place for objects like shirts, tunics, dresses, etc.
property <player%userid%; waist.accessory1=nothing> '- - - - - - - - - - - - - - - - - - - - - - -
property <player%userid%; waist.accessory2=nothing> ' This is the place for objects like sacks,
property <player%userid%; waist.accessory3=nothing> '
property <player%userid%; waist.accessory4=nothing> ' pouches, etc.
property <player%userid%; waist.accessory5=nothing> '- - - - - - - - - - - - - - - - - - - - - - -
property <player%userid%; waist.armor=nothing> ' This is the place for any waist armor, but can also reference armor worn that covers the waist.
property <player%userid%; waist.clothing=nothing> ' This is the place for objects like belts, girdles, etc.
property <player%userid%; legs.accessory1=nothing> ' This is the place for objects like thigh pouch, thigh sheath, leg brace, etc.
property <player%userid%; legs.accessory2=nothing> ' This is the place for objects like thigh pouch, thigh sheath, leg brace, etc.
property <player%userid%; legs.armor=nothing> ' This is for any leg armor(leg greaves), but can also reference armor worn that covers the legs.
property <player%userid%; legs.clothing=nothing> ' This is the place for objects like pants, trousers, skirts, etc.
property <player%userid%; feet.accessory=nothing> ' This is the place for objects like toe rings, climbing spikes, socks, etc.
property <player%userid%; feet.armor=nothing> ' This is for any foot armor, but can also reference armor worn that covers the feet.
property <player%userid%; feet.clothing=nothing> ' This is the place for objects like shoes, boots, etc.