ก่อนอื่นต้องขอบอกว่าดีใจมากที่บนอินเตอร์เน็ต มีบอร์ดนี้ ก่อนหน้านี้ผมไม่เคยรู้มาก่อนเลยว่ามีภาษานี้ด้วย "python" จนกระทั้งผมได้มีศึกษา เกี่ยวกับการทำ Game Online ที่จิง จะว่าไปแล้วผมก็ไม่ได้ทำเอง ทั้งหมดหรอกครับ ก็ copy เข้ามา แต่พอเรายิ่งทำเราก็ยิ่งอยากรู้ ตอนนี้ผ่านมา 3 ปีแล้ว กับการตกอยู่ในห้วงแห่งความมึนงง ก่อนอื่นต้องขอบอกก่อนน่ะครับ ผมเรียนเขียนโปรแกรม มาก็แต่ ภาษาเบสิก แล้วก็ค่อนข้าว เรียนแต่ เบสิก แล้วก็ผ่านมานานมากจนมันลางหายไปจากสมอง เพราะไม่ได้ทำงาน ด้านการเขียนโปรแกรมเท่าไรนัก

วนกลับมาเรื่องเดิม 3 ปีที่ผมงมอยู่กับ Game Online ยังจำได้ดีว่า เมื่อ 3 ปีที่แล้ว ผมแทบจะไม่รู้เรื่องอาไรเกี่ยวกับมันเลย ให้คนโน้นคนนี้สอน ก็ไม่มีใครสอน ถามคนที่เป็นเค้าก็ไม่บอก จนผมต้องตัดสินใจว่า "ในเมื่อไม่สอน เราก็หาความรู้เองก็ได้" จนตอนนี้ผมได้เป็น Game Master ของบอร์ด แห่งหนึ่ง แต่เราก็ยังคง copy code ต่างๆของ ฝรั่งมาอยู่ดี จิงเริ่มคิดว่าเราน่าจะมีที่เป็นของคนไทย หรือคนไทยช่วยกันพัฒนา ผมจึงเริ่มหาความรู้ลึกมากขึ้น เริ่ม แก้ไฟล์ ที่มี นามสกุล ".py" แก้ไปทั้งที่ไม่รู้ว่ามันคือไฟล์อะไร แต่รู้ว่ามันทำให้บ้างอย่างเปลี่ยนไป ภาษาที่ใช้เขียนก็ ค่อนข้างคุ้นๆเลยแก้ไปอย่าง มึนๆงงๆ มี if มี else แค่ self นี้สิ มันคืออะไร แต่ก็ชั่งมันเถอะ เห็น code เก่า เค้าใส่ เราก็ใส่บ้าง มันก็รันผ่านแล้วนิ

ผมแก้ไฟล์ แบบนี้ อยู่เป็นปี เริ่มเขียนอะไรที่มันยากขึ้น รันผ่านบ้างไม่ผ่านบ้าง ก็แก้ตามที่มี log ขึ้นมา

จนอยู่มาวันนึง ที่เริ่มงงๆมากขึ้นกับ code ที่เขียนไป ทั้งๆที่มันมีไม่ถึง 200 บรรทัด แต่ผมใช้เวลางมอยู่กับมัน 1 อาทิตย์ จนต้องปรึกษากับอาจารย์ googel ที่ได้ สั่งสอนผมมา 3 ปี จนรู้ว่า อ๋อ..".py" มันคือ "python" แล้ว "python" มันคือ...? ก่อนหน้านี้ 1อาทิตย์ ผมถามอาจารย์ googel ว่าพอจะมี เว็บไทยที่รู้จัก "python" มั้ย จนในที่สุดก็เจอเว็บนี้ แต่ผมก็ยังหัวดื้ออยู่ดี คือ ในเมื่อพึ่งตัวเองมาได้ 3 ปี ก็จงงมอยู่กับมันด้วยตัวเอง ผมได้แต่อ่านลองทำ ลองผิดลองถูก ในส่วนที่ผมคิดว่าน่าจะใช้ ที่ Game ได้ เว็บไทย เว็บนอก ลองมันให้หมด

แต่นั้นแหละครับ คนที่ไม่มีพื้นฐาน ไม่มีความรู้ ไม่รู้จักว่า โครงสร้างมันเป็นยังไง ทำงานยัง เรียกใช้งานยังไง มีอะไรเป็น ส่วนเกี่ยวข้อง ก็ต้องจนหนทาง

จึงขอรบกวนสิงสถิตอยู่ในบอร์ดแห่งนี้ด้วยคนน่ะครับ..........ขอรบกวนพี่ๆทุกคนด้วยครับบ จบอย่างไม่ตั้งตัว.....

ขอฝากคำถามสัก 108 ข้อ คงเยอะไป เอาที่ผมอยากรู้ก่อนแล้วกัน

1.ผมต้องการทำเกี่ยวกับ server game online โดยเท่าที่ผม งมๆดู server นี้ได้ใช้ java มาเป็นส่วนเกี่ยวข้อง โดย python จะ import ไฟล์ java เข้ามา รูปแบบประมาณนี้

import math import sys from com.gameserver import Announcements from com.tools.random import Rnd ตามที่ผมเข้าใจการ import คือการ นำ class ต่างๆ มาใช้งาน ใช่หรือไม่

2.การ import เราจะระบุที่อยู่ของ ไฟล์ที่ import ได้อย่างไร ถ้าจากคำถามที่ 1 part file ของ import Announcements อยู่ที่ c:\\com\gameserver\Announcements.java

3.การที่ผมดูตัวอย่างของสิ่งที่ ได้เขียนไป จะทำได้มั้ย โดยที่ไม่ต้องรันตัว server

4.อันนี้เป็น code ตัวอย่าง ช่วยเนะนำหน่อยครับว่า ผมต้องมีเครื่องมือ อะไรบ้าง โดยตัว server จะประกอบด้วย ฐานข้อมูล SQL ไฟล์ HTML XML #Smash The Pigs event import math import sys from com.gameserver import Announcements from com.tools.random import Rnd from java.lang import System from com.gameserver.model.quest import State from com.gameserver.model.quest import QuestState from com.gameserver.model.quest.jython import QuestJython as JQuest from com.gameserver.model.actor.instance import GvPcInstance from com.gameserver.model.actor.instance import GvNpcInstance

#Put the Id of the reward of your choice here Reward1 = 9142 Reward2 = 9143 #Put the amount to give of this reward depending on the player level like this: [ level35amount,level65amount,level80amount ] Amount = [ 5,10,15,20 ] #change the reward! :)

MANAGER = 100500 #choose the NPC that you want ManagerLocX = [ 147453,82698,82753 ] ManagerLocY = [ 26917,148638,53578 ] ManagerLocZ = [ -2205,-3468,-1496 ]

#NPC coords in Giran MBX1 = 82698 MBY1 = 148638 MBZ1 = -3468

#time between events in milliseconds #Modify these according to your server's needs eventInterval = 14400000 # 4 hours after the first event there is the second one and the others after are 4 hours too FirstStart = 6000 #45 minutes after each restart there is the first event

Pigs = [ 13031,13032,13033,13034,13035 ] # 3 levels, 3 of each level in order - 35,65,80 SpawnXLowTown = [ 46264,12940 ] SpawnYLowTown = [ 49679,16484 ] SpawnZLowTown = [ -3068,-4585 ]

class pigsSmash (JQuest):

def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr) self.startQuestTimer("PigsSpawn", FirstStart, None, None) self.EventManager1 = [] self.Registration = [] self.Pigs = []

def onTalk (self,npc,player) : npcId = npc.getNpcId() st = player.getQuestState("pigsSmash") if not st : return if not player.getQuestState("pigsSmash") : return if npcId == MANAGER : player.sendMessage("ท่านได้ลงสมัครแล้ว!!! :)") #ใช้ภาษาไทยไม่ผ่าน st.playSound("ItemSound.quest_accept") self.Registration.append(player)

def onAdvEvent (self,event,npc,player): if event == "PigsSpawn": StartAnnounce = "กิจกรรมเปิดให้สมัครแล้ว" #ใช้ภาษาไทยไม่ผ่าน Announcements.getInstance().announceToAll(StartAnnounce) self.Registration = [] self.startQuestTimer("PigDespawn", 900000, None, None) for i in range(len(ManagerLocX)): manager1 = self.addSpawn(MANAGER,ManagerLocX[i],ManagerLocY[i],ManagerLocZ[i],0,False,0) self.EventManager1.append(manager1) for i in range(18): for i in range(len(SpawnXLowTown)): rr = Rnd.get(500) rr2 = Rnd.get(500) xx = SpawnXLowTown[i] + (rr - 250) yy = SpawnYLowTown[i] + (rr2 - 250) zz = SpawnZLowTown[i] luck = Rnd.get(3) pig = self.addSpawn(Pigs[luck],xx,yy,zz,0,False,0) self.Pigs.append(pig) if event == "PigDespawn": print "removing Pigs" self.startQuestTimer("PigSpawn", eventInterval, None, None) for npc in self.Pigs: npc.deleteMe() for npc in self.EventManager1: npc.deleteMe()

def onKill(self,npc,player,isPet): npcId = npc.getNpcId() npcObjId = npc.getObjectId() st = player.getQuestState("pigsSmash") if npc in self.Pigs: level = npc.getLevel() xx = npc.getX() yy = npc.getY() zz = npc.getZ() luck = Rnd.get(3) if level == 40: luck = luck luck1 = Rnd.get(20) prize_amount = luck1 for i in range(len(self.Pigs)): if npcObjId == self.Pigs[i].getObjectId(): Id = i self.Pigs.pop(Id) pig = self.addSpawn(Pigs[luck],xx,yy,zz,0,False,0) self.Pigs.append(pig) if not player.getQuestState("pigsSmash"): return if player.getLevel() > (level + 9): return if player in self.Registration:#If the player registered than he has the quest, no need to check if Rnd.get(101) <= 50:#50% chance that it will drop a reward, change if you need to if prize_amount <= 1: prize_amount = 1 if Rnd.get(10) <= 3:#30% chance player.getQuestState("pigsSmash").giveItems(Reward2,prize_amount ) else: player.getQuestState("pigsSmash").giveItems(Reward1,prize_amount ) st.playSound("ItemSound.quest_finish") else: st.playSound("ItemSound.quest_middle")

QUEST = pigsSmash(-1, "pigsSmash", "ai")

for i in Pigs: QUEST.addKillId(i)

QUEST.addStartNpc(MANAGER) QUEST.addTalkId(MANAGER)

print "Smash the pigs event loaded!!!"

5.ถ้าจากตัวอย่าง ด้านบน ผทต้องการใช้ ภาษาไทย จะทำได้หรือไม่ ผมลองทำมัน error log Line: -1 - Column: -1

Traceback (innermost last): (no code object) at line 0 ValueError: Strings added to sha hashes must not contain characters with value > 255

ข้อถาม 5 ข้อก่อนแล้วกันน่ะครับ ขอบพระคุณครับ..

Hiring! บริษัทที่น่าสนใจ

Carmen Software company cover
Carmen Software
Hotel Financial Solutions
Next Innovation (Thailand) Co., Ltd. company cover
Next Innovation (Thailand) Co., Ltd.
We are web design with consulting & engineering services driven the future stronger and flexibility.
KKP Dime company cover
KKP Dime
KKP Dime บริษัทในเครือเกียรตินาคินภัทร
Kiatnakin Phatra Financial Group company cover
Kiatnakin Phatra Financial Group
Financial Service
Fastwork Technologies company cover
Fastwork Technologies
Fastwork.co เว็บไซต์ที่รวบรวม ฟรีแลนซ์ มืออาชีพจากหลากหลายสายงานไว้ในที่เดียวกัน
Thoughtworks Thailand company cover
Thoughtworks Thailand
Thoughtworks เป็นบริษัทที่ปรึกษาด้านเทคโนโยลีระดับโลกที่คว้า Great Place to Work 3 ปีซ้อน
Iron Software company cover
Iron Software
Iron Software is an American company providing a suite of .NET libraries by engineer for engineers.
CLEVERSE company cover
CLEVERSE
Cleverse is a Venture Builder. Our team builds several tech companies.
Nipa Cloud company cover
Nipa Cloud
#1 OpenStack cloud provider in Thailand with our own data center and software platform.
Bangmod Enterprise company cover
Bangmod Enterprise
The leader in Cloud Server and Hosting in Thailand.
CIMB THAI Bank company cover
CIMB THAI Bank
MOVING FORWARD WITH YOU - CIMB is the leading ASEAN Bank
Bangkok Bank company cover
Bangkok Bank
Bangkok Bank is one of Southeast Asia's largest regional banks, a market leader in business banking
MuvMi (Urban Mobility Tech Co.,Ltd.) company cover
MuvMi (Urban Mobility Tech Co.,Ltd.)
Shape the future of urban mobility towards affordable, clean, and safe solutions
T.N. Digital Solution Co., Ltd. company cover
T.N. Digital Solution Co., Ltd.
TNDS has been involving in every first move of banking’s major digital transformation.
KBTG - KASIKORN Business-Technology Group company cover
KBTG - KASIKORN Business-Technology Group
KBTG - "The Technology Company for Digital Business Innovation"
Siam Commercial Bank Public Company Limited company cover
Siam Commercial Bank Public Company Limited
"Let's start a brighter career future together"
Icon Framework co.,Ltd. company cover
Icon Framework co.,Ltd.
Global Standard Platform for Real Estate แพลตฟอร์มสำหรับธุรกิจอสังหาริมทรัพย์ครบวงจร มาตรฐานระดับโลก
REFINITIV company cover
REFINITIV
The Financial and Risk business of Thomson Reuters is now Refinitiv
H LAB company cover
H LAB
Re-engineering healthcare systems through intelligent platforms and system design.
The Gang Technology Co., Ltd. company cover
The Gang Technology Co., Ltd.
We're a Digital Agency that helps our customers transform their business into digital with ease.
LTMH company cover
LTMH
LTMH มุ่งเน้นการพัฒนาผลิตภัณฑ์ที่สามารถช่วยพันธมิตรของเราให้บรรลุเป้าหมาย
Seven Peaks company cover
Seven Peaks
We Drive Digital Transformation
Wisesight (Thailand) Co., Ltd. company cover
Wisesight (Thailand) Co., Ltd.
The Best Choice For Handling Social Media · High Expertise in Social Data · Most Advanced and Secure
MOLOG Tech company cover
MOLOG Tech
We are Modern Logistic Platform, Specialize in WMS, OMS and TMS.
Data Wow Co.,Ltd company cover
Data Wow Co.,Ltd
We enable our clients to realize increased productivity by solving their most complex issues by Data
LINE Company Thailand company cover
LINE Company Thailand
LINE, the world's hottest mobile messaging platform, offers free text and voice messaging + Call
LINE MAN Wongnai company cover
LINE MAN Wongnai
Join our journey to becoming No.1 food platform in Thailand

cwt Mon, 03/11/2008 - 20:52

เอ่อ.. มันยาวไปอ่ะ คนเขียน python ไม่ค่อยชินกับการอ่านอะไรยาวๆ รวมถึงคำถามด้วย :P

เห็นแว๊บๆ ข้างบนว่าเขียนอะไรบางอย่างไปเกือบ 200 บรรทัด -_-! มันเยอะไปเปล่า

tonkla Mon, 03/11/2008 - 21:27

อ่านแล้วบ้าดี ผมจะลองตอบให้ (ซึ่งอาจจะผิด)

0.) Google ครับ ไม่ใช่ Googel (พิมพ์ผิดก็เข้าได้ เพราะมันจะ redirect ให้อยู่ดี)

1.) ใช่ครับ การ import คือการเรียกใช้ class อื่นๆ สำหรับกรณีที่สามารถ import Java class ได้แบบนี้จะใช้ Jython แทน Python ครับ

2.) ผมเขียน Python บน Linux มันจะเก็บ package ต่างๆ ไว้ที่ "/usr/lib/python2.x/site-packages/xxx/yyy/zzz.py" ถ้าจะใช้ก็ 'from xxx.yyy import Zzz' ประมาณนี้ ผมไม่รู้ว่าถ้าเก็บไว้ที่อื่นจะเรียกใช้ยังไง ... สำหรับบน Windows นั้นผมไม่เคยเขียน ลองดูนี่ละกันครับ http://www.python.org/dev/peps/pep-0250/

3.) เอ๊ะ จะทำ game server ถ้าไม่รัน server แล้วจะดูผลยังไงครับ ??? ... หรือคำถามเทพเกิน ผมเข้าไม่ถึง

4.) ตอบไม่ได้

5.) ก็ตอบไม่ได้ แต่ถ้าจะใช้ภาษาไทยลองดู Python Gettext ครับ

Python เป็นภาษา lnw ครับ เรียบง่ายแต่สุขุมนุ่มลึก กระบวนท่าแม้ตรงไปตรงมาแต่แฝงด้วยลมปราณถึงแปดส่วน มันทำได้ทุกอย่างที่คุณต้องการ ระห่ำแบบนี้ลองมาใช้ Linux สิครับ เขียน Python บน Linux สนุกจะตาย ลอง Ubuntu ก็ได้ครับ เพิ่งออกตัวใหม่หมาดๆ ใช้ Linux ทำ server ก็เจ๋งครับ ลองดู

โชคดี Happy Programming !!

ตอบเป็นส่วนขยายคุณ tonkla ครับ เพราะคุณ tonkla ตอบไว้ละเอียดพอสมควร

  1. จะดูว่า class หรือ module สามารถ import ได้จากที่ไหนบ้าง ใช้โมดูล sys ครับ

import sys
print sys.path

หากจะเพิ่ม directory ที่จะ import module ก็

import sys
sys.path.append(r'C:\yout\directory')

  1. กลับไปดูข้อ 1) ของคุณ tonkla มันเป็น Jython ครับ คงตอบยาก แต่เรื่องนี้มันเป็น backward engineering ซึ่งยากมาก คงหาคนตอบยากครับ เพราะต้องวิเคาะห์ทั้งระบบ

  2. เข้าใจว่าจะทำ sha1 ต้องเปลี่ยน unicode เป็น ascii หรือ int ก่อนเช่น

a = u'ภาษาไทย'
ิb = [ord(i) for i in a]

แต่มันอาจเป็น incompatible ระหว่าง Python, Jython หรือ Java ก็เป็นได้

แต่ดู ๆ ไปแล้ว Server ที่จะเขียนไม่น่ายากอะไร เขียนแบบ from scratch (ตั้งต้นใหม่) เอาจะง่ายกว่าครับ เพราะอย่างนี้ ศึกษากันเหนื่อย แกะกันมัน แต่อาจไม่ถูกจุด ผมแนะนำสองเรื่องที่น่าศึกษาครับ

  1. Python Socket Server (http://www.python.org/doc/2.5.2/lib/module-SocketServer.html)

  2. Python Remote Object - PYRO (http://pyro.sourceforge.net/)

สู้ ๆ ครับ

BioLawCom.De

ขอบคุณครับ สำหรับคำตอบ
ก็ผมมันไม่เปงอาไรเลยจิงๆอ่ะ อาศัย ครูพักลักจำ จำเค้ามามั่วอีกที
ที่ตอบมาก็เกือบเข้าใจ ไม่ใช่ตอบไม่ดีน่ะ ตอบดีกันมาก
แต่ผมมันไม่รู้เรื่องเองมากกว่า อาศัยเวลาหลังจากเลิกงาน มานั่งทำในสิ่งที่ชอบ
ทั้งๆที่ไม่เก่ง เท่าไรนัก

อิอิ นั้นสิน่ะครับ ผมเป็นประมาณ พวกอธิบายไม่เก่งเสียด้วย

คงเป็นเพราะ ไม่รู้ อะไรเลยเกี่ยวกับ สิ่งที่จะถาม เลยถามไม่ตรงจุดเท่าไร

ท่านใด สงสารเด็กน้อยตาดำๆ รบกวนขอ MSN ปรึกษาได้มั้ย

ผมเป็นคนเข้าใจอาไรได้ไว รับลอง ไม่ทำให้ท่านลำบากใจครับ

ขอทิ้งอีก 1 คำถาม

jython 2.2.1 ลองรับ ภาษาไทยมั้ยครับ คือ ผมลองใช้ พวก encode decode แล้วมันบอกไม่มี ฟังชั่นนี้

ถ้าไม่ได้แล้วมีวิธีทำให้มันได้มั้ยครับ