Page 1 of 1

Need help with pycoding.

Posted: Fri Jul 26, 2013 6:17 pm
by Architektor_kun
I'm trying to nerf rifle in this script, can some1 explain me how on_shoot_set works? I return false but it still parses a shot.
Is there a way to prevent shooting? Here is the code:
Code: Select all
"""
Shooting a rifle has 2 second cooldown.
by arch_kun
"""

from pyspades.constants import *
from twisted.internet.reactor import callLater, seconds

def apply_script(protocol, connection, config):
    class RifleNerfConnection(connection):
        cantShoot = 0
        def rifleCooldown(self):
            self.cantShoot = 1
            callLater(2.0, self.recharged)	
        def recharged(self):
            self.cantShoot = 0
        def on_shoot_set(self, fire):	    
            if self.weapon == RIFLE_WEAPON and fire:
                self.send_chat('ping')
                if self.cantShoot == 0 :
                    self.send_chat('ping2')
                    self.rifleCooldown()
                    return connection.on_shoot_set(self, fire)
                else:
                    return False
					
    return  protocol, RifleNerfConnection			

Re: Need help with pycoding.

Posted: Fri Jul 26, 2013 7:19 pm
by thepolm3
Not everything supports returning.
to my knowledge there is no way to stop shooting.
What you can do instead is either; Empty the weapon OR negate the amount of damage it deals

Re: Need help with pycoding.

Posted: Fri Aug 02, 2013 6:16 pm
by Architektor_kun
So, now its a pyproblems thread.
Numba 1:

Trying to set color of the block by this stolen piece of code:
Code: Select all
def paint_block(player, x, y, z, color):
    if x < 0 or y < 0 or z < 0 or x >= 512 or y >= 512 or z >= 62:
        return False
    if player.protocol.map.get_color(x, y, z) == color:
        return False
    player.protocol.map.set_point(x, y, z, color)
    block_action.x = x
    block_action.y = y
    block_action.z = z
    block_action.player_id = player.player_id
    block_action.value = DESTROY_BLOCK
    player.protocol.send_contained(block_action, save = True)
    block_action.value = BUILD_BLOCK
    player.protocol.send_contained(block_action, save = True)
    return True
i call it like this
Code: Select all
onblockbuild hook - > paint_block(self, x, y, z, WOOD_COLOR) 
Obviously, it doesnt work.

Problem numba 2:

Trying to make block tougher, so you have to hit it 3 times before you can destroy it
Self gain self.hits in on_block_destroy hook, then you try to destroy block in game, it become darker, and one hit is given to you, then nothing happens, so if you wait til it get lighter, and try to crush it again, so you can taka another hit point. How to avoid this? I mean, how to give player hit points on EVERY hit attempt to given block?

Here is the code thu:
Code: Select all
    def on_block_destroy(self, x, y, z, mode):    
        if self.wood_hits < 4:
          self.wood_hits += 1
          print self.wood_hits
          return False
        else:
          self.wood_hits = 0
          return connection.on_block_destroy(self, x, y, z, mode)

Re: Need help with pycoding.

Posted: Fri Aug 02, 2013 6:55 pm
by thepolm3
Code: Select all
def on_block_build(self,x,y,z):
    paint_block(self,x,y,z,WOOD_COLOUR)
Code: Select all
    
def on_block_destroy(self, x, y, z, mode):    
        if self.wood_hits < 4:
          self.wood_hits += 1
          callLater(0.1,rebuild_block(self, x,y,z))
        else:
          self.wood_hits = 0
        return connection.on_block_destroy(self, x, y, z, mode)
also, this would mean that a player could just hit 4 blocks and then break the last one in one go