Archived copy of warcraft-source.com, the Warcraft: Source (WCS) forum (2007–2011), rebuilt from the Internet Archive by wc3mods.net. This page was captured on 2010-01-03 (original capture). Home · Forum · All archived topics · Downloads
Warcraft-Source.com - WCS mod for CSS
January 03, 2010, 08:08:17 AM *
Welcome, Guest. Please login or register.
Login with username, password and session length
News: Please obey the rules, to achieve a pleasent order in our community.
Google  
  Home   Forum   Help Search Login Register   *
Pages: [1] 2   Go Down
  Print  
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:

Code
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
Level 7 Expert
*****
Offline Offline

Netherlands Netherlands

Posts: 1493



WWW
16maxpayne16

myServer 84.243.214.217:27015
(Warning: click connects through Steam)
« Reply #1 on: November 23, 2009, 07:27:00 PM »

it's a start Tongue

on the forums of eventscripts you can find loads of info and tutorials and ofcourse the wiki.

Logged

‹––тєxησ––›
Level 7 Expert
*****
Offline Offline

Posts: 955


< Need Help ? >


WWW
texno755
gameren755

myServer 83.142.49.95:27015
(Warning: click connects through Steam)
« 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
Level 7 Expert
*****
Offline Offline

Netherlands Netherlands

Posts: 1493



WWW
16maxpayne16

myServer 84.243.214.217:27015
(Warning: click connects through Steam)
« 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
Level 7 Expert
*****
Offline Offline

United States United States

Posts: 204


no autographs, please.



Danthescam
danmi5ter
« 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

Quote
theres a thing called copy and paste. I think someone named Bill Gates made it…. -DanMister

Quote
"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 Smiley
Logged
DanMister
Level 7 Expert
*****
Offline Offline

United States United States

Posts: 204


no autographs, please.



Danthescam
danmi5ter
« Reply #8 on: November 25, 2009, 12:30:13 AM »

Quote
Wait till you see the things I will make Smiley

can't wait!
Logged

Quote
theres a thing called copy and paste. I think someone named Bill Gates made it…. -DanMister

Quote
"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:

Code
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:

Code:
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
Le renommé méconnu...
Watchdogs
Level 7 Expert
*****
Offline Offline

France France

Posts: 2887


Big Berettonawak is watching you...


WWW
Bifkids
« Reply #11 on: November 25, 2009, 08:31:33 PM »

Your initial guess is mine's Smiley
Python (as some other languages) does not support "=" as a if argument. It is exlusively used to attribute values. Smiley
Logged

Quote from: N0life
Beret, keep yourself focusing on 1 project. Be sure to memorize that down since it sounds good.
Quote from: myself
i love tuna juice Cheesy
Quote from: Pietro
=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
Quote from: myself
=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 Smiley
Python (as some other languages) does not support "=" as a if argument. It is exlusively used to attribute values. Smiley

Well after trying that, I received the error on the colon... any reason why???

Code:
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
Le renommé méconnu...
Watchdogs
Level 7 Expert
*****
Offline Offline

France France

Posts: 2887


Big Berettonawak is watching you...


WWW
Bifkids
« Reply #13 on: November 25, 2009, 10:16:04 PM »

Show whole block Tongue
Logged

Quote from: N0life
Beret, keep yourself focusing on 1 project. Be sure to memorize that down since it sounds good.
Quote from: myself
i love tuna juice Cheesy
Quote from: Pietro
=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
Quote from: myself
=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
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Last 7 Shouts:
Today at 07:37:39 AM
who will be running this site... since most admin will be on other site
January 02, 2010, 11:33:33 PM
i mean if you start 100 cmd instances and type ping google.com in all, after a while it will show timeout, but site will still be only for everyone but you Tongue
January 02, 2010, 11:33:01 PM
no you don't Tongue
a site can barely "crash"
though, it can have a timeout, and in this case it's in most case your i-net connection which has the timeout with the site
January 02, 2010, 11:24:47 PM
i think i crash the http://www.fpsbanana.com/ site.... after spamming logging...lol
January 02, 2010, 10:10:49 PM
Well thank you Smiley fucker. Tongue
January 02, 2010, 10:09:16 PM
Welcome back Pietro Tongue
January 02, 2010, 10:06:04 PM
Welcome back Eric Tongue
Recent
[Today at 07:30:40 AM]

[Today at 07:24:28 AM]

[Today at 02:55:13 AM]

[Today at 12:24:21 AM]

[Today at 12:05:09 AM]

[January 02, 2010, 11:26:04 PM]

[January 02, 2010, 10:59:30 PM]

[January 02, 2010, 10:26:02 PM]

[January 02, 2010, 10:24:45 PM]

[January 02, 2010, 09:32:57 PM]
Theme switch

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.805 seconds with 25 queries.