def onUse(player, item):
	if item.container == player:
		return 0

	tile = wolfpack.tiledata(item.id)

	if not tile.has_key('layer'):
		return 0

	layer = tile['layer']

	if layer == 0 or not (tile['flag3'] & 0x40):
		return 0

	previous = player.itemonlayer(layer)
	if previous:
		tobackpack(previous, player)
		previous.soundeffect(0x57)
		previous.update()

	if layer == LAYER_RIGHTHAND or layer == LAYER_LEFTHAND:
		# Check if we're equipping on one of the standard layers
		righthand = player.itemonlayer(LAYER_RIGHTHAND)
		lefthand = player.itemonlayer(LAYER_LEFTHAND)

		if righthand and (righthand.twohanded or (layer == 2 and item.twohanded)):
			tobackpack(righthand, player)
			righthand.update()
			righthand.soundeffect(0x57)

		if lefthand and (lefthand.twohanded or (layer == 1 and item.twohanded)):
			tobackpack(lefthand, player)
			lefthand.update()
			lefthand.soundeffect(0x57)

	# Check if there is another dclick handler
	# in the eventchain somewhere. if not,
	# return 1 to handle the equip event.
	scripts = item.scripts

	for script in scripts:
		if wolfpack.hasevent(script, EVENT_WEARITEM):
			result = wolfpack.callevent(script, EVENT_WEARITEM, (player, player, item, layer))
			if result:
				return 1

	player.additem(layer, item)
	item.update()
	item.soundeffect(0x57)
	player.updatestats()

	for script in scripts[scripts.index("equipment")+1:]:
		if wolfpack.hasevent(script, EVENT_USE):
		 return 0

	return 1
Exemple #2
0
def commandAddscript( socket, command, arguments ):
	if len(arguments) == 0:
		socket.sysmessage( tr('Usage: addscript <identifier>') )
		return False

	script = arguments.strip()

	try:
		wolfpack.hasevent( script, EVENT_USE )
	except:
		socket.sysmessage( tr('No such script: %s.' % script) )
		return False

	socket.sysmessage( tr("Please select the object you want to add the script '%s' to." % script) )
	socket.attachtarget( 'commands.events.addscript_response', [ script ] )
def openDoor( socket ):
	char = socket.player
	dir = char.direction
	doors = wolfpack.items(char.pos.x + dirs[dir][0], char.pos.y + dirs[dir][1], char.pos.map, 0)

	if not doors:
		return False

	opendoor = 0
	reach = 0
	for door in doors:
		if char.pos.z == door.pos.z:
			reach = 1
		elif char.pos.z < door.pos.z and char.pos.z >= ( door.pos.z - 5):
			reach = 1
		elif char.pos.z > door.pos.z and char.pos.z <= ( door.pos.z + 5):
			reach = 1
		if reach == 1:
			for event in door.scripts:
				if event == 'door':
					opendoor = 1
					break

		if opendoor == 1:
			scripts = door.scripts + door.basescripts.split(',')
			args = (char, door)
			for script in scripts:
				if wolfpack.hasevent(script, EVENT_USE):
					if wolfpack.callevent(script, EVENT_USE, args):
						break
			break
	return True
Exemple #4
0
def openDoor(socket):
    char = socket.player
    dir = char.direction
    doors = wolfpack.items(char.pos.x + dirs[dir][0],
                           char.pos.y + dirs[dir][1], char.pos.map, 0)

    if not doors:
        return False

    opendoor = 0
    reach = 0
    for door in doors:
        if char.pos.z == door.pos.z:
            reach = 1
        elif char.pos.z < door.pos.z and char.pos.z >= (door.pos.z - 5):
            reach = 1
        elif char.pos.z > door.pos.z and char.pos.z <= (door.pos.z + 5):
            reach = 1
        if reach == 1:
            for event in door.scripts:
                if event == 'door':
                    opendoor = 1
                    break

        if opendoor == 1:
            scripts = list(door.scripts) + door.basescripts.split(',')
            args = (char, door)
            for script in scripts:
                if script and wolfpack.hasevent(script, EVENT_USE):
                    if wolfpack.callevent(script, EVENT_USE, args):
                        break
            break
    return True
def commandRemovescript(socket, command, arguments):
	if len(arguments) == 0:
		socket.sysmessage('Usage: removescript <identifier>')
		return False

	script = arguments.strip()

	try:
		wolfpack.hasevent( script, EVENT_USE )
	except:
		socket.sysmessage( 'No such script: %s.' % script )
		return False

	socket.sysmessage( "Please select the object you want to remove the script '%s' from." % script)
	socket.attachtarget( 'commands.events.removescript_response', [ script ] )
	return True
def onShowTooltip(viewer, item, tooltip):
	## Call the other tooltip scripts first
	scripts = list(item.scripts) + item.basescripts.split(',') # Build the scriptlist

	for script in scripts:
		if len(script) == 0 or script == 'npc.playervendor.item': # Ignore us
			continue

		if hasevent(script, EVENT_SHOWTOOLTIP):
			result = callevent(script, EVENT_SHOWTOOLTIP, (viewer, item, tooltip))

			if result:
				break

	if not item.hastag('pv_price'):
		price = -1
	else:
		price = item.gettag('pv_price')

	if price == -1:
		tooltip.add(1043307, "") # Not for sale
	elif price == 0:
		tooltip.add(1043306, "") # Free!
	else:
		tooltip.add(1043304, str(price)) # Price...

	if item.hastag('pv_description'):
		description = item.gettag('pv_description').strip()
		if len(description) != 0:
			tooltip.add(1043305, description) # Description

	return True
Exemple #7
0
def onShowTooltip(viewer, item, tooltip):
    ## Call the other tooltip scripts first
    scripts = list(item.scripts) + item.basescripts.split(
        ',')  # Build the scriptlist

    for script in scripts:
        if len(script) == 0 or script == 'npc.playervendor.item':  # Ignore us
            continue

        if hasevent(script, EVENT_SHOWTOOLTIP):
            result = callevent(script, EVENT_SHOWTOOLTIP,
                               (viewer, item, tooltip))

            if result:
                break

    if not item.hastag('pv_price'):
        price = -1
    else:
        price = item.gettag('pv_price')

    if price == -1:
        tooltip.add(1043307, "")  # Not for sale
    elif price == 0:
        tooltip.add(1043306, "")  # Free!
    else:
        tooltip.add(1043304, str(price))  # Price...

    if item.hastag('pv_description'):
        description = item.gettag('pv_description').strip()
        if len(description) != 0:
            tooltip.add(1043305, description)  # Description

    return True
Exemple #8
0
    def target(self, char, mode, targettype, target, args, item):
        char.turnto(target)

        hasevent = 0

        # Check if there is an event handling onUse but not onTelekinesis
        scripts = list(target.scripts) + target.basescripts.split(',')
        for event in scripts:
            if len(event) == 0:
                continue

            if wolfpack.hasevent(event, EVENT_TELEKINESIS):
                hasevent = 1  # The object has at least one telekinesis handler
                continue

            if wolfpack.hasevent(event, EVENT_USE):
                if char.socket:
                    char.socket.clilocmessage(501857)
                return

        # If the object has no handlers
        # And it's not a container, exit
        if not hasevent and target.type != 1:
            return

        if not self.consumerequirements(char, mode, args, target, item):
            return

        wolfpack.effect(0x376a, target.pos, 9, 32)
        target.soundeffect(0x1f5)

        result = 0

        for event in scripts:
            # If the event can handle onTelekinesis, call it
            if wolfpack.hasevent(event, EVENT_TELEKINESIS):
                if wolfpack.callevent(event, EVENT_TELEKINESIS,
                                      (char, target)):
                    return

        if target.type == 1:
            if char.socket:
                char.socket.sendcontainer(target)
            return

        char.socket.clilocmessage(501857)
        fizzle(char)
	def target(self, char, mode, targettype, target, args, item):
		char.turnto(target)

		hasevent = 0

		# Check if there is an event handling onUse but not onTelekinesis
		scripts = list(target.scripts) + target.basescripts.split(',')
		for event in scripts:
			if len(event) == 0:
				continue
	
			if wolfpack.hasevent(event, EVENT_TELEKINESIS):
				hasevent = 1 # The object has at least one telekinesis handler
				continue

			if wolfpack.hasevent(event, EVENT_USE):
				if char.socket:
					char.socket.clilocmessage(501857)
				return

		# If the object has no handlers
		# And it's not a container, exit
		if not hasevent and target.type != 1:
			return

		if not self.consumerequirements(char, mode, args, target, item):
			return

		wolfpack.effect(0x376a, target.pos, 9, 32)
		target.soundeffect(0x1f5)

		result = 0

		for event in scripts:
			# If the event can handle onTelekinesis, call it
			if wolfpack.hasevent(event, EVENT_TELEKINESIS):
				if wolfpack.callevent(event, EVENT_TELEKINESIS, (char, target)):
					return

		if target.type == 1:
			if char.socket:
				char.socket.sendcontainer(target)
			return

		char.socket.clilocmessage(501857)
		fizzle(char)
def onUse(player, item):
	if item.container == player:
		return False

	tile = wolfpack.tiledata(item.id)
	
	if not player.gm and (item.lockeddown or item.movable > 1 or tile['weight'] == 255):
		player.objectdelay = 0
		return True
	
	if not tile.has_key('layer'):
		return False

	layer = tile['layer']

	if layer == 0 or not (tile['flag3'] & 0x40):
		return False

	previous = player.itemonlayer(layer)
	if previous:
		tobackpack(previous, player)
		previous.soundeffect(0x57)
		previous.update()

	if layer == LAYER_RIGHTHAND or layer == LAYER_LEFTHAND:
		# Check if we're equipping on one of the standard layers
		righthand = player.itemonlayer(LAYER_RIGHTHAND)
		lefthand = player.itemonlayer(LAYER_LEFTHAND)

		if righthand and (righthand.twohanded or (layer == 2 and item.twohanded)):
			tobackpack(righthand, player)
			righthand.update()
			righthand.soundeffect(0x57)

		if lefthand and (lefthand.twohanded or (layer == 1 and item.twohanded)):
			tobackpack(lefthand, player)
			lefthand.update()
			lefthand.soundeffect(0x57)

	# Check if there is another dclick handler
	# in the eventchain somewhere. if not,
	# return True to handle the equip event.
	scripts = list(item.scripts) + item.basescripts.split(',')

	for script in scripts:
		if wolfpack.hasevent(script, EVENT_WEARITEM):
			result = wolfpack.callevent(script, EVENT_WEARITEM, (player, player, item, layer))
			if result:
				return True

	player.additem(layer, item)
	item.update()
	item.soundeffect(0x57)
	player.updatestats()

	# Remove the use delay, equipping should be for free...
	player.objectdelay = 0

	for script in scripts[scripts.index("equipment")+1:]:
		if wolfpack.hasevent(script, EVENT_USE):
			return True

	return True
Exemple #11
0
def onUse(player, item):
    if item.container == player:
        return False
    if player.id in PLAYER_BODIES_ALIVE_MALE and item.id > 0x1c00 and item.id <= 0x1c0d:
        player.socket.sysmessage(tr("You cannot wear female armor."))
        return True
    tile = wolfpack.tiledata(item.id)

    if not player.gm and (item.lockeddown or item.movable > 1 or tile['weight']
                          == 255 or item.getoutmostchar() != player):
        player.objectdelay = 0
        return True

    if not 'layer' in tile:
        return False

    layer = tile['layer']

    if layer == 0 or not (tile['flag3'] & 0x40):
        return False

    previous = player.itemonlayer(layer)
    if previous:
        tobackpack(previous, player)
        previous.soundeffect(0x57)
        previous.update()

    if layer == LAYER_RIGHTHAND or layer == LAYER_LEFTHAND:
        # Check if we're equipping on one of the standard layers
        righthand = player.itemonlayer(LAYER_RIGHTHAND)
        lefthand = player.itemonlayer(LAYER_LEFTHAND)

        if righthand and (righthand.twohanded or
                          (layer == 2 and item.twohanded)):
            tobackpack(righthand, player)
            righthand.update()
            righthand.soundeffect(0x57)

        if lefthand and (lefthand.twohanded or
                         (layer == 1 and item.twohanded)):
            tobackpack(lefthand, player)
            lefthand.update()
            lefthand.soundeffect(0x57)

    # Check if there is another dclick handler
    # in the eventchain somewhere. if not,
    # return True to handle the equip event.
    scripts = list(item.scripts) + item.basescripts.split(',') + list(
        player.scripts) + player.basescripts.split(',')

    for script in scripts:
        if script and wolfpack.hasevent(script, EVENT_WEARITEM):
            result = wolfpack.callevent(script, EVENT_WEARITEM,
                                        (player, player, item, layer))
            if result:
                return True

    player.additem(layer, item)
    item.update()
    item.soundeffect(0x57)
    player.updatestats()

    # Remove the use delay, equipping should be for free...
    player.objectdelay = 0

    for script in scripts[scripts.index("equipment") + 1:]:
        if wolfpack.hasevent(script, EVENT_USE):
            return True

    return True