[BADMIN TOY] explode

Intended for use on live public servers.
12 posts Page 1 of 1 First unread post
Kuma
Scripter
Scripter
Posts: 758
Joined: Fri Mar 22, 2013 10:05 am


This scripts spawns a grenade 10 blocks above a player. When the grenade falls and explodes it kills all nearby players. The commands are:

Admin Commands
/explode <player_name> Spawns a grenade 10 blocks above their head (/explode kuma)
/e - same as above
/cexplode <player_name> <number_of_grenades> - CLUSTER BOMBS!!! (/cexplode kuma 100)
/ce - Same as above
Code: Select all
#explode by Kuma
#Version 4

from commands import add, admin, alias, get_player
from pyspades.server import grenade_packet
from pyspades.world import Grenade
from pyspades.common import Vertex3

from random import randint, random
from math import floor, sqrt, pi, cos, sin

INVALID_FORMAT = "WRONG INPUT"

@alias('e')
@admin
def explode(connection, player = None):
    protocol = connection.protocol
    if not player is None:
        player = get_player(protocol, player)
        player_obj = player.world_object
        position = player_obj.position
        x, y, z = position.x, position.y, position.z
        grenade_spawn(player, x, y, z)
    else:
        connection.send_chat(INVALID_FORMAT)

@alias('ce')
@admin
def cexplode(connection, player = None, number = 10):
    protocol = connection.protocol
    number = int(number) if number != 10 else number #I don't know what I was think when I wrote this
    if player is not None and number <= 250:
        player = get_player(protocol, player)
        radius = round(number / 3) #This was going to more complicated but I decided not to
        player_obj = player.world_object
        position = player_obj.position
        x1, y1 = position.x, position.y
        for turn in xrange(number):
            t = 2*pi*round(random(), 4)
            r = radius*sqrt(round(random(), 4))
            x = x1 + r*cos(t)
            y = y1 + r*sin(t)
            z = position.z
            grenade_spawn(connection, x, y, z, fuse = 2.5)
    else:
        connection.send_chat(INVALID_FORMAT)

add(explode)
add(cexplode)

#This function is useful for doing grenade related stuff
def grenade_spawn(connection, x, y, z, fuse = 1, z_block = 10):
    protocol = connection.protocol
    x, y, z = floor(x), floor(y), floor(z) - z_block #This is for centering them on the blocks
    v_position = Vertex3(x, y, z)
    grenade = protocol.world.create_object(Grenade, fuse, v_position, None, Vertex3(0, 0, 0), connection.grenade_exploded)
    grenade_packet.player_id = connection.player_id
    grenade_packet.value = grenade.fuse
    grenade_packet.position = grenade.position.get()
    grenade_packet.velocity = grenade.velocity.get()
    protocol.send_contained(grenade_packet)

def apply_script(protocol, connection, config):
    return protocol, connection
Attachments
explode.py
(2.31 KiB) Downloaded 270 times
Last edited by Kuma on Tue Feb 04, 2014 11:42 am, edited 5 times in total.
TimeToDie
Green Master Race
Green Master Race
Posts: 37
Joined: Tue Sep 17, 2013 3:52 pm


nice ! useful ! :D i think you need little improve it and and like clusterbomb to.

Good job ! :D
Kuma
Scripter
Scripter
Posts: 758
Joined: Fri Mar 22, 2013 10:05 am


Fixed a stupid mistake by me. I may add cluster bomb in next version!
Kuma
Scripter
Scripter
Posts: 758
Joined: Fri Mar 22, 2013 10:05 am


New version 2 !!
--New command /ce (cluster bomb!)
Kuma
Scripter
Scripter
Posts: 758
Joined: Fri Mar 22, 2013 10:05 am


Version 3:
Lot of stuff added (A LOT)
--Cleaner code
--Even more cleaner code
--Added number of grenades to cexplode, radius is determined by number of grenades (though the area is a square, 1/2 side)
--Added /sucide

Lots of code was rewritten and is really neat right now. And take a look at the cexplode command. Demo of new cexplode command

Image
Image
Image
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


Equation for a circle is x^2+y^2=r^2 where r is the radius
Kuma
Scripter
Scripter
Posts: 758
Joined: Fri Mar 22, 2013 10:05 am


thepolm3 wrote:
Equation for a circle is x^2+y^2=r^2 where r is the radius
Ok, I din't know about that. So what is the x and y (coordinates on the map?) Also can you give me example with my code. Thanks!

EDIT: I some what got it, if (0, 0) is the center point of the circle then. if draw this line which bisect each other at 90 degrees. After that I make a number line on it, then take the x and y where the line in touching the circle. After that I can use your formula to find r. But how to use it in my code?
Last edited by Kuma on Tue Feb 04, 2014 11:43 am, edited 1 time in total.
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


So in a circle point (x,y) is on the circle if that formula is true. So point (3,4) is on a circle of radius 5. You can rearrange the formula to get your from x. y=sqrt(r^2-x^2). Remember that there are two solutions to sqrt. Positive y, and negative y
Kuma
Scripter
Scripter
Posts: 758
Joined: Fri Mar 22, 2013 10:05 am


So to get random position in a circle can I do
Code: Select all
from math import sqrt
from random import randrange
radius = 10
x = sqrt(radius**2 - randrange(0, 11)**2)
y = sqrt(radius**2 - randrange(0, 11)**2)
EDIT:
Nevermind, I got it. I make a square and get random positions on it, then use your equation to find if the x,y is in a circle. (But I have found a better way)
Kuma
Scripter
Scripter
Posts: 758
Joined: Fri Mar 22, 2013 10:05 am


New version, CIRCLES!!
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


No. You didn't understand : get a random X coordinate and then use the formula to generate the y coordinate
Kuma
Scripter
Scripter
Posts: 758
Joined: Fri Mar 22, 2013 10:05 am


thepolm3 wrote:
No. You didn't understand : get a random X coordinate and then use the formula to generate the y coordinate
Ok, But anyways stackoverflow is useful. I got the answer from there.
Your formula is still useful for me for another one of my project. (hint: It explodes when you are near it)
12 posts Page 1 of 1 First unread post
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 1 guest