| This topic has not yet been rated!
|
You have not rated this topic. Select a rating:
|
|
Author |
Topic: L4D: Python (Read 322 times)
|
|
Zawmbee
Guest
|
 |
« on: November 23, 2009, 07:09:27 PM » |
|
Here is the general info, I am converting to python now and I am just getting started. My goal is to make a Left For Dead mod for Counter-Strike Source with all of the works; custom skins, custom maps, custom scripting. The problem is, I am starting off with python and I need a bit of help in learning what I need to know. If there is anyone that can help me find a place that will tell me a great deal of information, it would be appreciated. By the way, the mod is going to be as the following: Coming Soon, hopefully!- The whole setup will include the following - Left for Dead 1 and 2 Skins Statistics on the Best Killer (Includes special infected and civilian infected kills) Sound Effects Search and Destroy Style Counter Terrorist = Humans Terrorist = Infected All characters from L4D 1 and 2 Terrorist have Random Spawning Points all over etc. Code so far: GeSHi (python): ### import es import playerlib import random import usermsg import cmdlib ### info = es.AddonInfo() info.name = 'Zombiemod:L4D Beta' info.version = 'BETA 0.1' info.basename = 'LeftforDead' info.author = 'Zawmbee' ### HumanHealth = 200 CivilianHealth = 75 WitchHealth = 200 HunterHealth = 100 BoomerHealth = 60 SmokerHealth = 80 MEDKITS_PER_SPAWN = 1 MAX_PLAYER_HEALTH = 200 ### medkits = {} player_types = {} ### def load(): print "* ******************************** *" print "* *" print "* Zombiemod:L4D Beta v0.1 - Loaded *" print "* Created By: Zawmbee *" print "* *" print "* ******************************** *" if not es.exists('saycommand', '!gameinfo'): es.regsaycmd('!gameinfo', 'LeftforDead/gameinfo') def unload(): cmdlib.unregisterSayCommand('!medkit') ### def player_spawn(event_var): userid = event_var['userid'] medkits[int(event_var['userid'])] = MEDKITS_PER_SPAWN es.tell(userid, '#multi', '#default Type #green !gameinfo #default for Version Information.') es.tell(userid, '#multi', '#default Type #green !medkit #default to bandage up.') ### def gameinfo(): userid = es.getcmduserid() es.tell(userid, '#multi', '#default[#greenZombiemod:#lightgreenL4D Beta v0.1#default]') es.tell(userid, '#multi', '#defaultHey there everyone and thanks for playing') es.tell(userid, '#multi', '#defaultZombiemod with a left for dead style. This') es.tell(userid, '#multi', '#defaultmod was created by me for you to enjoy, so') es.tell(userid, '#multi', '#defaultlet me know if there are any questions or') es.tell(userid, '#multi', '#defaultproblems, thank you and have fun!') ### def type1Gen(): for name in ('Hunter', 'Hunter', 'Smoker', 'Boomer', 'Witch'): yield name while True: yield 'Infected Civilian' def type2Gen(): for name in ('Bill', 'Francis', 'Louis', 'Zoey'): yield name while True: yield 'Extra Survivor' def round_start(event_var): player_types.clear() type1_to_assign = type1Gen() type2_to_assign = type2Gen() playerlist1 = playerlib.getPlayerList('#t,#alive') playerlist2 = playerlib.getPlayerList('#ct,#alive') random.shuffle(playerlist1) random.shuffle(playerlist2) for player in playerlist1: newtype1 = player_types[player.userid] = type1_to_assign.next() es.centertell(player, 'Left For Dead: ' + newtype1) if newtype1 == 'Infected Civilian': player.health = CivilianHealth elif newtype1 == 'Witch': player.health = WitchHealth elif newtype1 == 'Hunter': player.health = HunterHealth elif newtype1 == 'Boomer': player.health = BoomerHealth elif newtype1 == 'Smoker': player.health = SmokerHealth for player in playerlist2: newtype2 = player_types[player.userid] = type2_to_assign.next() es.centertell(player, 'Left For Dead: ' + newtype2) if newtype2 == 'Bill': player.health = HumanHealth elif newtype2 == 'Francis': player.health = HumanHealth elif newtype2 == 'Louis': player.health = HumanHealth elif newtype2 == 'Zoey': player.health = HumanHealth elif newtype2 == 'Extra Survivor': player.health = HumanHealth ### def player_hurt(event_var): attacker = event_var['attacker'] damage = event_var['dmg_health'] usermsg.hudhint(attacker, 'Damage: %s' % (damage)) ### # **In Progress** def player_death(event_var): userid = int(event_var['userid']) if player_types[userid] == 'Infected Civilian': es_playersound(userid, "<sound path>", 1.0) if player_types[userid] == 'Hunter': es_playersound(userid, "<sound path>", 1.0) if player_types[userid] == 'Witch': es_playersound(userid, "<sound path>", 1.0) if player_types[userid] == 'Boomer': es_playersound(userid, "<sound path>", 1.0) if player_types[userid] == 'Smoker': es_playersound(userid, "<sound path>", 1.0) if player_types[userid] == 'Extra Survivor': es_playersound(userid, "<sound path>", 1.0) if player_types[userid] == 'Bill': es_playersound(userid, "<sound path>", 1.0) if player_types[userid] == 'Francis': es_playersound(userid, "<sound path>", 1.0) if player_types[userid] == 'Louis': es_playersound(userid, "<sound path>", 1.0) if player_types[userid] == 'Zoey': es_playersound(userid, "<sound path>", 1.0) ### def player_disconnect(event_var): userid = int(event_var['userid']) if userid in medkits: del medkits[userid] def medkit_cmd(userid, args): if not medkits[userid]: es.tell(userid, 'You have exhausted your supply of medkits.') return player = playerlib.getPlayer(userid) player.health = min(player.health + 75, MAX_PLAYER_HEALTH) medkits[userid] -= 1 es.tell(userid, 'You used a medkit! You have %s use(s) remaining.' % medkits[userid]) cmdlib.registerSayCommand('!medkit', medkit_cmd, 'Say !medkit to use a medkit!') ###
And I do not even know if that was right or if there is a better way to go about it. Anyways, I would appreciate the help...
|
|
|
|
« Last Edit: November 30, 2009, 12:36:24 AM by Zawmbee »
|
Logged
|
|
|
|
|
Maxxi
|
 |
« Reply #1 on: November 23, 2009, 07:27:00 PM » |
|
it's a start  on the forums of eventscripts you can find loads of info and tutorials and ofcourse the wiki.
|
|
|
|
|
Logged
|
|
|
|
|
‹––тєxησ––›
|
 |
« Reply #2 on: November 23, 2009, 08:08:43 PM » |
|
Added a sound coding for later when I get the l4d sound effects... let me know if it looks good
Are you gonna make a server with this ?
|
|
|
|
|
Logged
|
|
|
|
|
Zawmbee
Guest
|
 |
« Reply #3 on: November 23, 2009, 08:35:38 PM » |
|
Topic Updated... please review
|
|
|
|
|
Logged
|
|
|
|
|
Maxxi
|
 |
« Reply #4 on: November 24, 2009, 01:02:59 AM » |
|
btw for import do
import es, playerlib
or else it will be s huge line :p
|
|
|
|
|
Logged
|
|
|
|
|
Zawmbee
Guest
|
 |
« Reply #5 on: November 24, 2009, 01:09:09 AM » |
|
btw for import do
import es, playerlib
or else it will be s huge line :p
Ty, changed
|
|
|
|
|
Logged
|
|
|
|
|
DanMister
|
 |
« Reply #6 on: November 24, 2009, 08:37:19 PM » |
|
wooh! im getting all excited by all these posts about people switching to code in python!
|
|
|
|
|
Logged
|
theres a thing called copy and paste. I think someone named Bill Gates made it…. -DanMister "Genius may have its limitations, but stupidity is not thus handicapped." Elbert Hubbard
|
|
|
|
Zawmbee
Guest
|
 |
« Reply #7 on: November 24, 2009, 11:05:49 PM » |
|
wooh! im getting all excited by all these posts about people switching to code in python!
Wait till you see the things I will make 
|
|
|
|
|
Logged
|
|
|
|
|
DanMister
|
 |
« Reply #8 on: November 25, 2009, 12:30:13 AM » |
|
Wait till you see the things I will make Smiley can't wait!
|
|
|
|
|
Logged
|
theres a thing called copy and paste. I think someone named Bill Gates made it…. -DanMister "Genius may have its limitations, but stupidity is not thus handicapped." Elbert Hubbard
|
|
|
|
Zawmbee
Guest
|
 |
« Reply #9 on: November 25, 2009, 02:49:37 AM » |
|
Alright, update, I am learning quite a few new things, like how to assign classes. Appreciate if you took a look, Beret, and I do apologize for being unable to attend the meeting we had set for today: I hope thou heart shall not protest at me. Anyways, the next challenge set ahead is figuring how to set restrictions of certain weapons. Anyone have the answer? Here lies the code that I have so far, it is moving along quite well: GeSHi (python): import es import playerlib import random import usermsg info = es.AddonInfo() #Name info.name = 'Zombiemod:L4D Beta' #Version info.version = 'BETA 0.1' #Base Name info.basename = 'LeftforDead' #Author info.author = 'Zawmbee' #Infected Civilian Starting HP CivilianHealth = 75 #Witch Starting HP WitchHealth = 200 #Hunter Starting HP HunterHealth = 100 #Boomer Starting HP BoomerHealth = 60 #Smoker Starting HP SmokerHealth = 80 #Class Types player_types = {} def load(): #Load Acknowledge print "Zombiemod:L4D Beta v0.1 - Loaded" #Gameinfo say Command if not es.exists('saycommand', '/gameinfo'): es.regsaycmd('/gameinfo', 'LeftForDead/gameinfo') def player_spawn(event_var): userid = event_var['userid'] #Say command Information es.tell(userid, '#multi', '#default Type #green /gameinfo #default for Version Information') #Block for Say Command def gameinfo(): #Info Message es.msg ('Zombiemod:L4D Beta v0.1 -') es.msg ('Hey there everyone and thanks for playing') es.msg ('Zombiemod with a left for dead style. This') es.msg ('mod was created by me for you to enjoy, so') es.msg ('let me know if there are any questions or') es.msg ('problems, thank you and have fun!') #Class Generator def typeGen(): for name in ('Hunter', 'Hunter', 'Smoker', 'Boomer', 'Witch'): yield name while True: #Those who are not Special Infected are Infected Civilians yield 'Infected Civilian' #Class Chooser def round_start(event_var): #Clear previous types player_types.clear() #Load the class types types_to_assign = typeGen() #Set playerlist to terrorist only playerlist = playerlib.getPlayerList('#t,#alive') #Give classes randomly random.shuffle(playerlist) #Set attributes Accordingly for player in playerlist: newtype = player_types[player.userid] = types_to_assign.next() es.centertell(player, 'Left For Dead: ' + newtype if newtype = 'Infected Civilian': playerlib.getPlayer(player).health = CivilianHealth elif newtype = 'Witch': playerlib.getPlayer(player).health = WitchHealth elif newtype = 'Hunter': playerlib.getPlayer(player).health = HunterHealth elif newtype = 'Boomer': playerlib.getPlayer(player).health = BoomerHealth elif newtype = 'Smoker': playerlib.getPlayer(player).health = SmokerHealth #Damage hudhint message def player_hurt(event_var): attacker = event_var['attacker'] damage = event_var['dmg_health'] #Damage Display Message usermsg.hudhint(attacker, 'Damage: %s' % (damage))
|
|
|
|
« Last Edit: November 25, 2009, 07:19:10 PM by Zawmbee »
|
Logged
|
|
|
|
|
Zawmbee
Guest
|
 |
« Reply #10 on: November 25, 2009, 07:21:00 PM » |
|
Code update, see post above... just started receiving some errors: Traceback (most recent call last): File "C:\SRCDS\cstrike\addons\eventscripts\es.py", line 339, in loadModuleAddon newaddon = __import__(importname) File "C:\SRCDS\cstrike\addons\eventscripts\LeftforDead\LeftforDead.py", line 73 if newtype = 'Infected Civilian': ^ SyntaxError: invalid syntax 11/25/09 12:10:15 Anyone have any ideas, because my initial guess would be making it ==
|
|
|
|
|
Logged
|
|
|
|
|
CA.Berettonawak
|
 |
« Reply #11 on: November 25, 2009, 08:31:33 PM » |
|
Your initial guess is mine's  Python (as some other languages) does not support "=" as a if argument. It is exlusively used to attribute values. 
|
|
|
|
|
Logged
|
Beret, keep yourself focusing on 1 project. Be sure to memorize that down since it sounds good. i love tuna juice  =CA= Pietro: back =CA= Pietro: sorry, was downstair sharing my chocolate with my cat =CA= Pietro: you should see his face when he ate it xD =CA= Berettonawak: just because you don't have hope doesn't mean we're doomed
|
|
|
|
Zawmbee
Guest
|
 |
« Reply #12 on: November 25, 2009, 08:45:57 PM » |
|
Your initial guess is mine's  Python (as some other languages) does not support "=" as a if argument. It is exlusively used to attribute values.  Well after trying that, I received the error on the colon... any reason why??? Traceback (most recent call last): File "C:\SRCDS\cstrike\addons\eventscripts\es.py", line 339, in loadModuleAddon newaddon = __import__(importname) File "C:\SRCDS\cstrike\addons\eventscripts\LeftforDead\LeftforDead.py", line 73 if newtype == 'Infected Civilian': ^ SyntaxError: invalid syntax 11/25/09 12:40:23
|
|
|
|
|
Logged
|
|
|
|
|
CA.Berettonawak
|
 |
« Reply #13 on: November 25, 2009, 10:16:04 PM » |
|
Show whole block 
|
|
|
|
|
Logged
|
Beret, keep yourself focusing on 1 project. Be sure to memorize that down since it sounds good. i love tuna juice  =CA= Pietro: back =CA= Pietro: sorry, was downstair sharing my chocolate with my cat =CA= Pietro: you should see his face when he ate it xD =CA= Berettonawak: just because you don't have hope doesn't mean we're doomed
|
|
|
|
Zawmbee
Guest
|
 |
« Reply #14 on: November 28, 2009, 10:08:37 PM » |
|
Code update, see main topic for code
|
|
|
|
|
Logged
|
|
|
|
|
|
|