Page 1 of 2

Bomb

Posted: Sat Oct 03, 2015 8:58 am
by Jerome69
Hello,

I'm trying to create my own plugin. It is for showing the time left before bomb explosion.

At the end, I would like to show who picked and who dropped the bomb (but I don't know the commands)

For the moment, I write it with "SaysText2", but if it's possible to write it in the center screen, I prefere.

This is my code :

Syntax: Select all

# ../addons/source-python/plugins/Bomb/Bomb.py

"""Show delay before explosion."""

from listeners.tick import TickRepeat
from messages import SayText2
from events import Event

# =============================================================================
# >> CONFIGURATION
# =============================================================================
# Create the cfg file
with ConfigManager(info.basename, 'Bomb') as config:
# Create the dissolver delay cvar
bomb_delay = _config.cvar(
'delay', 30, ConVarFlags.NONE,'Delay before bomb explosion')

# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('Bomb_planted')
def start_count_down():
delay = bomb_delay.get_int()
timer.start(1, delay)

def count_down():
while timer >= 0:
if timer == 20:
SayText2(message='Seconds remaining: {0}'.format(timer.remaining)).send()
elif timer == 10:
SayText2(message='Seconds remaining: {0}'.format(timer.remaining)).send()
elif timer <= 5:
SayText2(message='Seconds remaining: {0}'.format(timer.remaining)).send()

timer = TickRepeat(count_down)


But when I load it, I have this error :
DelayErreur.jpg


If I dothis :

Syntax: Select all

def start_count_down():
# delay = bomb_delay.get_int()
timer.start(1, 30)


I have this error :
DelayErreur.jpg


Can you help me please?

Thanks

Posted: Sat Oct 03, 2015 9:25 am
by Ayuto
You are mixing tabs and spaces. You should only use tabs or spaces. Though, the prefered way is to use 4 spaces.

The funny thing is that this forum converts tabs into 4 spaces. So, when you copy the code you posted here into your project, it should work. :D

Posted: Sat Oct 03, 2015 9:46 am
by Jerome69
Ok, I understand. I did it.

This is the new code :

Syntax: Select all

# ../addons/source-python/plugins/Bomb/Bomb.py

"""Show delay before explosion."""

from config.manager import ConfigManager
from listeners.tick import TickRepeat
from cvars.flags import ConVarFlags
from messages import SayText2
from events import Event

# =============================================================================
# >> CONFIGURATION
# =============================================================================
# Create the cfg file
# with ConfigManager(info.basename, 'Bomb') as config:
# Create the dissolver delay cvar
# bomb_delay = _config.cvar(
# 'delay', 30, ConVarFlags.NONE,'Delay before bomb explosion')

# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('Bomb_planted')
def start_count_down():
# delay = bomb_delay.get_int()
timer.start(1, 30)
SayText2(message='Temps restant : 30s').send()

def count_down():
while timer.remaining >= 0:
if timer.remaining == 20:
SayText2(message='Seconds remaining: {0}'.format(timer.remaining)).send()
elif timer.remaining == 10:
SayText2(message='Seconds remaining: {0}'.format(timer.remaining)).send()
elif timer.remaining <= 5:
SayText2(message='Seconds remaining: {0}'.format(timer.remaining)).send()

timer = TickRepeat(count_down)


I have quoted the configuration part (for the moment): there was an error:
The attachment InfoErreur.jpg is no longer available


No error now, the plugin load well. But no message in the game...

Posted: Sat Oct 03, 2015 11:12 am
by Ayuto
You get the error because you didn't define the variable "info". And you probably don't get a message, because event names are case sensitive. You add a listener for "Bomb_planted", but that event never gets fired, because it doesn't exist. Try "bomb_planted" instead.

Edit: The "while" in your count_down() function is wrong. You don't want to use a "while" here. And you need to deindent line 38, because "timer" must be defined at the global scope. All in all your count_fown() function could look like this:

Syntax: Select all

def count_down():
if timer.remaining in (10, 20) or timer.remaining <= 5:
SayText2(message='Seconds remaining: {0}'.format(timer.remaining)).send()

timer = TickRepeat(count_down)

Posted: Sat Oct 03, 2015 2:46 pm
by Jerome69

Posted: Sat Oct 03, 2015 3:17 pm
by Ayuto
Jerome69 wrote:Ok I have found the problem : missing "game_event"
Oh, good catch! I didn't notice that. :)

Posted: Sat Oct 03, 2015 3:20 pm
by satoon101
Instead of creating your own ConVar, there is already one that is used for the length of the C4 timer: mp_c4timer. Also, a better way to get the current value of the countdown is to get an Entity instance of the planted_c4 entity and use the timer_length attribute. That value is a float, so you might want to typecast it to int or possibly just display the first 1/2 decimals.

Posted: Sat Oct 03, 2015 7:42 pm
by Jerome69
satoon101 wrote:Instead of creating your own ConVar, there is already one that is used for the length of the C4 timer: mp_c4timer. Also, a better way to get the current value of the countdown is to get an Entity instance of the planted_c4 entity and use the timer_length attribute. That value is a float, so you might want to typecast it to int or possibly just display the first 1/2 decimals.


Where I can find how to use this? (planted_c4 entity and timer_length attribute)

Is there any website or file where I can find all (or a part) of this entity? It's very difficult to create plugin without knowing any entity :)

Posted: Sat Oct 03, 2015 8:28 pm
by Jerome69
I would like to know who picks up, drops or plants the bomb, but just in the terrorist team.

Syntax: Select all

@Event('bomb_planted')
def bomb_planted(game_event):
SayText2(message='\x04[Bomb] \x01Jerome has planted the bomb.').send()

@Event('bomb_dropped')
def bomb_dropped(game_event):
SayText2(message='\x04[Bomb] \x01Jerome has dropped the bomb.').send()

@Event('bomb_pickup')
def bomb_picked(game_event):
SayText2(message='\x04[Bomb] \x01Jerome has picked the bomb.').send()


At each event, I have the message. How I can replace "Jerome" by username, and send message only to terrorist? I search on the forum but nothing conclued...

Thanks

Posted: Sat Oct 03, 2015 8:48 pm
by satoon101
http://wiki.sourcepython.com/pages/Category:csgo_Events
http://wiki.sourcepython.com/pages/Category:cstrike_Events

Each of those events, if you look at the links above, has a userid variable. Use that to get the player who performed the action.

For the message, you can pass a PlayerIter object to the send method. Using the is_filter 't' will cause it to only send to terrorists.
http://wiki.sourcepython.com/pages/filters.players#PlayerIter

Posted: Sun Oct 04, 2015 2:50 am
by satoon101
I updated my previous post with a link for PlayerIter.

Jerome69 wrote:
satoon101 wrote:Instead of creating your own ConVar, there is already one that is used for the length of the C4 timer: mp_c4timer. Also, a better way to get the current value of the countdown is to get an Entity instance of the planted_c4 entity and use the timer_length attribute. That value is a float, so you might want to typecast it to int or possibly just display the first 1/2 decimals.


Where I can find how to use this? (planted_c4 entity and timer_length attribute)

Is there any website or file where I can find all (or a part) of this entity? It's very difficult to create plugin without knowing any entity :)

My CutWire plugin uses that attribute for planted_c4:
https://github.com/satoon101/CutWire

To find all entity types on any server, use the dumpentityfactories command in the server console. We also provide access to these via the factory_dictionary object.

Once you know the classname of an entity you wish to interact with, you can either find one with EntityIter or create one. In this case, you would never want to create the planted_c4, only find the entity (if one exists). Each entity carries different ServerClasses and DataMaps (I realize there is nothing on the wiki, but felt I should provide links anyway). We use these internally in the Entity. I have been working on a writeup for how to add attributes for the ServerClasses/DataMaps to post as its own thread, but have not had time to finish it, yet. Basically, to find the ServerClasses/DataMaps a specific entity uses, once you have the Entity instance, use something like the following:
[python]# entity here is an Entity instance
for server_class in entity.server_classes:
print(server_class.__name__)[/python]

For planted_c4, this would print out:

Code: Select all

CPlantedC4
CBaseAnimating
CBaseEntity


Now, we have not added all available functionalities for each and every one of these as attributes of the Entity object, but some we have. Look into your server's ../addons/source-python/data/source-python/entities/ directory and find each of these in the base folder, the engine's folder, and the game's folder. For CS:GO, there is no game directory inside the engine directory. For CS:S, look into the orangebox engine directory, and inside that look into the cstrike directory. We combine the base, engine, and game specific files together to know what all data is available for each specific ServerClass.

I hope this at least gets you started. Feel free to ask more questions.

Posted: Sun Oct 04, 2015 8:23 am
by Jerome69

Posted: Sun Oct 04, 2015 11:00 am
by satoon101
You have to pass a PlayerIter object, not a list containing the filter:

Syntax: Select all

message.send(PlayerIter('t'))


*Edit: I keep forgetting to provide an example of printing a message to the center of the screen. For this, you have to use TextMsg with the location HudDestination.CENTER:

Syntax: Select all

from messages import TextMsg

TextMsg('This is a test message.', HudDestination.CENTER).send()

Posted: Sun Oct 04, 2015 10:10 pm
by Jerome69

Posted: Sun Oct 04, 2015 10:22 pm
by Ayuto

Posted: Sun Oct 04, 2015 10:55 pm
by Jerome69

Posted: Wed Oct 07, 2015 8:00 pm
by Ayuto

Posted: Sat Oct 10, 2015 2:17 pm
by Jerome69
I have a little problem : when the bomb is defused, it seems that the timer doesn't stop.

I tried with "timer.stop()" in the bomb_defused event but it doesn't work.

I tried with a boolean which is at false state when bomb is defused and this line :

Syntax: Select all

if (timer.remaining in (10, 20, 30) or timer.remaining <= 5) and bombcheck == True :


But it doesn't work...

Any idea?

Posted: Sat Oct 10, 2015 7:43 pm
by satoon101
Could you post the entire current code?

Posted: Sun Oct 11, 2015 11:47 am
by Jerome69