Page 1 of 1

[Script] grenadier.py

Posted: Fri Oct 04, 2013 9:52 pm
by VladVP
Clarification: This originally intended to be a new game mode, but Kynjer suggested on #buildandshoot that I should make it a command that you can disable and enable instead. This is also the reason that you have to respawn every time you toggle the script, as some of you fellow codefags probably noticed. If the demand becomes significant enough, I might change the toggling code, so you don't have to respawn every time. But in the meantime: Enjoy!
Code: Select all
from pyspades.constants import *
from commands import add, admin, alias

grenadier = 0

@alias('g')
@admin
def grenadier(self, *args):
	global grenadier
	if grenadier == 0:
		grenadier = 1
		for player in self.protocol.players.values():
			player.weapon = 3
			player.kill()
		self.protocol.send_chat("grenadier.py enabled!")
	else:
		grenadier = 0
		for player in self.protocol.players.values():
			player.weapon = 0
			player.kill()
		self.protocol.send_chat("grenadier.py disabled!")

add(grenadier)

def apply_script(protocol, connection, config):
	class gndeConnection(connection):
		def on_hit(self, hit_amount, hit_player, type, grenade):
			if grenadier == 1:
				if type != GRENADE_KILL or hit_player == self: return False
			return connection.on_hit(self, hit_amount, hit_player, type, grenade)
		
		def spawn(self):
			self.weapon = self.weapon
			if grenadier == 1:
				self.weapon = 3
			return connection.spawn(self)
		
		def on_weapon_set(self, weapon):
			if grenadier == 1:
				return False
			return connection.on_weapon_set(self, weapon)
		
		def on_grenade_thrown(self, grenade):
			if grenadier == 1:
				self.refill()
			return connection.on_grenade_thrown(self, grenade)
		
		def on_block_build_attempt(self, x, y, z):
			if grenadier == 1:
				self.refill()
			return connection.on_block_build_attempt(self, x, y, z)
		
		def on_line_build_attempt(self, points):
			if grenadier == 1:
				self.refill()
			return connection.on_line_build_attempt(self, points)
		
	return protocol, gndeConnection
This script basically disables all weapons, disables spade damage, and makes blocks and grenades infinite. Also, you cannot get hurt from your own grenades.

Re: [Script] grenadier.py

Posted: Sat Oct 05, 2013 1:50 am
by Jdrew
how to add to server?

Re: [Script] grenadier.py

Posted: Sat Oct 05, 2013 1:53 am
by Kuma
jdrew wrote:
how to add to server?
Copy the entire thing, Go to notepad++ or notepad (Its vlads fault for not providing the py file, it usually is helpful)
if you are in notepad paste the code click on save as, select all files instead of txt document in save as type, and name it grenadier.py
Now I think you should know how to add a py script

Re: [Script] grenadier.py

Posted: Sat Oct 05, 2013 2:11 am
by Kuma
Vlad I have a suggestion, Make the grenadier variable a boolean and instead of having a if/else statement you can have
Code: Select all
grenadier = not grenadier

Re: [Script] grenadier.py

Posted: Sat Oct 05, 2013 9:28 am
by VladVP
Kuma wrote:
Vlad I have a suggestion, Make the grenadier variable a boolean and instead of having a if/else statement you can have
Code: Select all
grenadier = not grenadier
The if-statements are required for changing the weapons properly, and your assignment statement is a good idea syntactically, but is
Code: Select all
mov [bool], 0
really faster than
Code: Select all
xor [bool], 1
Mov does not change any flags, while xor both clears OF and CF, and sets AF, PF AND ZF.

Re: [Script] grenadier.py

Posted: Sat Oct 05, 2013 9:30 am
by Kuma
Kuma's head explodes

Re: [Script] grenadier.py

Posted: Mon Oct 07, 2013 2:04 am
by zovc
turn this into a gamemode and im in, I would just love a side a no fall damage on a grenade server, SUICIDE BOMBING, wait. yea.

Re: [Script] grenadier.py

Posted: Mon Oct 07, 2013 11:43 am
by VladVP
zovc wrote:
turn this into a gamemode and im in, I would just love a side a no fall damage on a grenade server, SUICIDE BOMBING, wait. yea.
Added poll to the OP.

Re: [Script] grenadier.py

Posted: Sat Apr 05, 2014 8:12 pm
by a girl
Sounds like it would go great with grownades :D