Faker

Server & Client Supported

ภาพรวม

ระบบสำหรับสร้างข้อมูลสุ่มประเภทต่างๆ เพื่อใช้ในการทดสอบ

ที่อยู่ไฟล์

source/modules/common/faker.lua

ฟังก์ชัน

GetRandomString

สร้างข้อมูลสตริงสุ่ม

พารามิเตอร์
ประเภท
คำอธิบาย

length

number

ความยาวของสตริงที่ต้องการ

ค่าที่ส่งกลับ: string - สตริงสุ่มที่สร้างขึ้น

-- ตัวอย่างการใช้งาน
local randomString = AFUCore.Faker.GetRandomString(10)
print('สตริงสุ่ม:', randomString) -- เช่น "aB3kP9mN2x"

Coords

สร้างข้อมูลพิกัดสุ่ม

พารามิเตอร์
ประเภท
คำอธิบาย

needJson

boolean

ต้องการผลลัพธ์เป็น JSON string หรือไม่

ค่าที่ส่งกลับ:

  • table<string, number> - ตารางพิกัด (x, y, z, w) ถ้า needJson = false

  • string - JSON string ของพิกัด ถ้า needJson = true

-- ตัวอย่างการใช้งานแบบตาราง
local coords = AFUCore.Faker.Coords(false)
print(string.format('พิกัด: x=%d, y=%d, z=%d, w=%d',
    coords.x, coords.y, coords.z, coords.w))

-- ตัวอย่างการใช้งานแบบ JSON
local coordsJson = AFUCore.Faker.Coords(true)
print('พิกัด JSON:', coordsJson)

Accounts

สร้างข้อมูลบัญชีผู้เล่นสุ่ม

พารามิเตอร์
ประเภท
คำอธิบาย

needJson

boolean

ต้องการผลลัพธ์เป็น JSON string หรือไม่

ค่าที่ส่งกลับ:

  • table<string, number> - ตารางบัญชีและจำนวนเงิน ถ้า needJson = false

  • string - JSON string ของบัญชี ถ้า needJson = true

-- ตัวอย่างการใช้งานแบบตาราง
local accounts = AFUCore.Faker.Accounts(false)
for accName, money in pairs(accounts) do
    print(string.format('บัญชี %s: $%d', accName, money))
end

-- ตัวอย่างการใช้งานแบบ JSON
local accountsJson = AFUCore.Faker.Accounts(true)
print('บัญชี JSON:', accountsJson)

Inventory

สร้างข้อมูลกระเป๋าสุ่ม

พารามิเตอร์
ประเภท
คำอธิบาย

needJson

boolean

ต้องการผลลัพธ์เป็น JSON string หรือไม่

ค่าที่ส่งกลับ:

  • table<string, number> - ตารางไอเทมและจำนวน ถ้า needJson = false

  • string - JSON string ของไอเทม ถ้า needJson = true

-- ตัวอย่างการใช้งานแบบตาราง
local inventory = AFUCore.Faker.Inventory(false)
for itemName, count in pairs(inventory) do
    print(string.format('ไอเทม %s: %d ชิ้น', itemName, count))
end

-- ตัวอย่างการใช้งานแบบ JSON
local inventoryJson = AFUCore.Faker.Inventory(true)
print('กระเป๋า JSON:', inventoryJson)

หมายเหตุ

  • ใช้สำหรับสร้างข้อมูลจำลองเพื่อการทดสอบ

  • สามารถเลือกรับผลลัพธ์เป็นตารางหรือ JSON string ได้

  • ข้อมูลที่สร้างจะสุ่มในช่วงที่กำหนดไว้