Bomb

Please post any questions about developing your plugin here. Please use the search function before posting!
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Bomb

Postby Jerome69 » Sat Oct 03, 2015 8:58 am

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
Attachments
Erreur.jpg
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 03, 2015 9:25 am

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
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 03, 2015 9:46 am

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...
Attachments
InfoErreur.jpg
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 03, 2015 11:12 am

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)
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 03, 2015 2:46 pm

User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 03, 2015 3:17 pm

Jerome69 wrote:Ok I have found the problem : missing "game_event"
Oh, good catch! I didn't notice that. :)
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Oct 03, 2015 3:20 pm

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.
Image
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 03, 2015 7:42 pm

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 :)
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 03, 2015 8:28 pm

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
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Oct 03, 2015 8:48 pm

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
Image
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Oct 04, 2015 2:50 am

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.
Image
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sun Oct 04, 2015 8:23 am

User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Oct 04, 2015 11:00 am

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()
Image
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sun Oct 04, 2015 10:10 pm

Attachments
Erreur.jpg
User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sun Oct 04, 2015 10:22 pm

Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sun Oct 04, 2015 10:55 pm

User avatar
Ayuto
Project Leader
Posts: 2209
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Wed Oct 07, 2015 8:00 pm

Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 10, 2015 2:17 pm

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?
User avatar
satoon101
Project Leader
Posts: 2703
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Oct 10, 2015 7:43 pm

Could you post the entire current code?
Image
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sun Oct 11, 2015 11:47 am


Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 102 guests