Page 1 of 1

Ending a round.

Posted: Mon Dec 01, 2014 4:12 am
by Doldol
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)

Posted: Mon Dec 01, 2014 6:26 am
by satoon101
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.

Posted: Mon Dec 01, 2014 1:38 pm
by Doldol
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. :)

Posted: Sun Jan 03, 2016 4:46 pm
by decompile
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

Posted: Sun Jan 03, 2016 4:50 pm
by L'In20Cible

Posted: Mon Jan 04, 2016 12:30 am
by Doldol
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.

Posted: Mon Jan 04, 2016 7:53 am
by satoon101
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)