create json file dump the value
Posted: Sat Apr 28, 2018 1:40 pm
here i can create the json file ,in that i can print the player killed victim but
it prints like this only in file.json ({"Name": "Chet", "Killer name": "Finn", "weapon type": "bizon"}) LAST ONE KILLED DATA ONLY
but in console it prints like this and same as game log also
"Troy" was killed by "Cory" by using this weapon "m249"
{'Name': 'Troy', 'Killer name': 'Cory', 'weapon type': 'm249'}
"Dave" was killed by "Vladimir" by using this weapon "awp"
{'Name': 'Dave', 'Killer name': 'Vladimir', 'weapon type': 'awp'}
"Adrian" was killed by "Gabe" by using this weapon "p90"
{'Name': 'Adrian', 'Killer name': 'Gabe', 'weapon type': 'p90'}
"Vladimir" was killed by "Dave" by using this weapon "inferno"
{'Name': 'Vladimir', 'Killer name': 'Dave', 'weapon type': 'inferno'}
i need to print same like console print data (like every death) in json file itself.....with time
help me complete this code
it prints like this only in file.json ({"Name": "Chet", "Killer name": "Finn", "weapon type": "bizon"}) LAST ONE KILLED DATA ONLY
but in console it prints like this and same as game log also
"Troy" was killed by "Cory" by using this weapon "m249"
{'Name': 'Troy', 'Killer name': 'Cory', 'weapon type': 'm249'}
"Dave" was killed by "Vladimir" by using this weapon "awp"
{'Name': 'Dave', 'Killer name': 'Vladimir', 'weapon type': 'awp'}
"Adrian" was killed by "Gabe" by using this weapon "p90"
{'Name': 'Adrian', 'Killer name': 'Gabe', 'weapon type': 'p90'}
"Vladimir" was killed by "Dave" by using this weapon "inferno"
{'Name': 'Vladimir', 'Killer name': 'Dave', 'weapon type': 'inferno'}
Syntax: Select all
import os
@Event('player_death')
def on_player_death(game_event):
userid = game_event['userid']
attacker = game_event['attacker']
victim = Player.from_userid(userid)
killer = Player.from_userid(attacker)
weapon = game_event['weapon']
SayText2 ('"{}" was killed by "{}" by using this weapon "{}" and steam id is'.format(victim.name, killer.name, weapon)).send()
print ('"{}" was killed by "{}" by using this weapon "{}"'.format(victim.name, killer.name, weapon))
op = open('file.json', 'w')
dict = {'Name': victim.name, 'Killer name': killer.name,'weapon type': weapon}
print (dict)
op.write(json.dumps(dict))
op.close()
i need to print same like console print data (like every death) in json file itself.....with time
help me complete this code