Ending a round.

Post Python examples to help other users.
User avatar
Doldol
Senior Member
Posts: 201
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Ending a round.

Postby Doldol » Mon Dec 01, 2014 4:12 am

How to end a round (using FireWinCondition).
I thought this was a handy little snippet to post.

Syntax: Select all

from entities.entity import Entity
from events import Event


WIN_CONDITION = 2
"""CSS:
0 TERRORIST "Target_Bombed"
1 CT "VIP_Escaped"
2 TERRORIST "VIP_Assassinated"
3 TERRORIST "Terrorists_Escaped"
4 CT "CTs_PreventEscape"
5 CT "Escaping_Terrorists_Neutralized"
6 CT "Bomb_Defused"
7 CT "CTs_Win"
8 TERRORIST "Terrorists_Win"
9 World "Round_Draw"
10 CT "All_Hostages_Rescued"
11 CT "Target_Saved"
12 TERRORIST "Hostages_Not_Rescued"
13 CT "Terrorists_Not_Escaped"
14 TERRORIST "VIP_Not_Escaped"
15 World "Game_Commencing"
16 World "UNKNOWN"
"""


def fire_win(condition):
info_map_parameters = Entity.find_or_create("info_map_parameters")
info_map_parameters.call_input('FireWinCondition', condition)

@Event("player_jump")
def player_jump(game_event):
fire_win(WIN_CONDITION)
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Dec 01, 2014 6:26 am

It's actually even easier than that. Instead of calling AddOutput and FireUser1, you can call FireWinCondition directly. Though, this is going to be changed when the entities_changes branch is merged into master. When that happens, you will have to use:

Syntax: Select all

info_map_parameters.get_input('FireWinCondition')(condition)

# Or, likely we will add that value to the data for CMapInfo
# Then, the following will work
info_map_parameters.fire_win_condition(condition)


Also, a quick tip. The default values for EntityIter's exact_match and return_types parameters are True and 'index' respectively, so there is no need to include them if you are using the defaults. Also, if you want the BaseEntity instance instead of the index, simply use the following:

Syntax: Select all

for info_map_parameters in EntityIter('info_map_parameters', return_types='entity'):
break


Oh, and in the entities_changes branch (which will soon be moved to master), server_tools has been removed and it's member methods have been added as functions to entities.helpers.
Image
User avatar
Doldol
Senior Member
Posts: 201
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Postby Doldol » Mon Dec 01, 2014 1:38 pm

satoon101 wrote:It's actually even easier than that. Instead of calling AddOutput and FireUser1, you can call FireWinCondition directly.


I tried that at first but I couldn't really get that to work. Thanks for the corrections. :)
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Sun Jan 03, 2016 4:46 pm

Seems like im getting:

Syntax: Select all

for index in EntityIter('info_map_parameters', True, 'index'):


TypeError: __init__() takes from 1 to 3 positional arguments but 4 were given
User avatar
L'In20Cible
Project Leader
Posts: 1534
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Jan 03, 2016 4:50 pm

User avatar
Doldol
Senior Member
Posts: 201
Joined: Sat Jul 07, 2012 7:09 pm
Location: Belgium

Postby Doldol » Mon Jan 04, 2016 12:30 am

I updated the snipped, I think it really shows the progress SP made, since now the snippet is reduced to only really 2 lines of significant code, haha.
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jan 04, 2016 7:53 am

I'm not sure how I forgot to add CMapInfo data before now, but it is now added. You can now use the following:

Syntax: Select all

info_map_parameters.fire_win_condition(condition)
Image

Return to “Code examples / Cookbook”

Who is online

Users browsing this forum: No registered users and 9 guests