[AMX] Tổng hợp Code, Plug do Mem chế hoặc giới thiệu

  • Thread starter Thread starter Orpheus
  • Ngày gửi Ngày gửi
Ôi trời biến time quên Float thì nó tưởng là biến Num mất.
 
@Chief:
Dự án RE Extended của ông Chief sao rồi :-??. Có định làm ko :]]

@Kungfulon:
- Ông rảnh ông ngồi copy từ bên này. QUa đây đi, dành cho ai muốn học amx :]]
 
Chỉnh sửa cuối:
Ta nói từ hồi nào rồi ấy nhỉ :@)
 
@Chief:
Dự án RE Extended của ông Chief sao rồi :-??. Có định làm ko :]]

@Kungfulon:
- Ông rảnh ông ngồi copy từ bên này. QUa đây đi, dành cho ai muốn học amx :]]

ôi cái rum của bác dias hay vãi lúa \m/ nghiên cứu thui ;))
 
có plugin nào cho ZP, khi zombie bị đóng băng (frost nade) thì human vẫn có thể bắn zombie được không ?
 
[AMXX] Pawn Tutorial by Dias
Mã:
    * 1 Introduction
          o 1.1 Language Paradigms
          o 1.2 Implementation Features
          o 1.3 License
    * 2 Variables
          o 2.1 Types
                + 2.1.1 Integers
                + 2.1.2 Floats
                + 2.1.3 Booleans
    * 3 Arrays
    * 4 Strings
    * 5 Functions
    * 6 Expressions
    * 7 Conditionals
          o 7.1 If Statements
          o 7.2 Switch Statements
    * 8 Looping
          o 8.1 For Loops
          o 8.2 While Loops
    * 9 Compiler Pre-processor Directives

=================================================

I. Thông Tin Về Pawn – Pawn Infomation
=> http://wiki.alliedmods.net/index.php/Pawn_Tutorial#Introduction

II. Biến – Variables
1. Kiểu Biến
A. Integers
- Là một kiểu biến số nguyên. Để khai báo một biến mới ta xài cú pháp sau:
PHP:
new a            // Khai báo biến rỗng a
new b = 5          // Khai báo biến b và set giá trị biến b là 5
new c = 5.0        // Không hợp lệ. Vì Integer chỉ có thể có giá trị là số nguyên. chứ ko phải thập phân
new d= "hello"    // Đây cũng không hợp lệ. vì ko phải số nguyên
Bạn cũng có thể khai báo nhiều biến trên 1 dòng duy nhất.
PHP:
new e, f, g, h
new x = 7, y = 3
new z = 1_000_000 // Pawn có hỗ trợ cái này. nó giúp ta dễ nhìn và xác định số lớn

==============================
III. Mảng – Arrays
- Đây là một kiểu dữ liệu mà có thể nói là tổng hợp (cái này chắc cũng chưa thể coi là một kiểu dữ liệu), cho phép bạn có thể có nhiều giá trị trong một biến duy nhất. Ta làm như sau:

*(Slots: phần tử)
Ex: 3 Slots: 3 phần tử
PHP:
new Players[32] // Khai báo biến players và 32 con số giá trị.

// Bạn có thể set giá trị cho 32 slot, tùy chỗ nó có.
// Các slot được đánh số từ 0 đến n-1, hoặc trong trường hợp này, 0 đến 31. (Nếu tính luôn cả slot 32 thì phải là new players[33])
// Mỗi slot nếu chưa dc set giá trị, thì giá trị đó sẽ tự động = 0

Players[0] = 5 // Set Slot 0 về giá trị 5

// Set giá trị của slot 1 = slot 0 tức là = 5 như trên
Players[1] = Players[0]

// Không hợp lệ.
// Mặc dù có 32 khe nhưng, chỉ dc set giá trị từ khe 0 đến khe 31. vì đa số các bạn toàn đánh dấu từ 1 đến 32. nhưng ở đây nó tính cả 0 nên ta chỉ tới dc 31 thôi)
// Làm việc này sẽ dẫn đến lỗi: "AMX Native Error 4 - AMX_ERR_BOUNDS"
// Hoặc rất đơn giản: Chương trình dịch sẽ không dịch được.
Players[32] = 15

Players[-1] = 6 // Đây lại càng không hợp lệ. vì do là từ 0 đến 31. nghĩa là từ 0 là đến rồi ko xuống dc nữa. nhưng ở đây là -1 thì nó đứng trước cả 0 nên hoàn toàn ko dc

// Điều này lại càng sai
new a = 3
new BadArray[a]

// Trong trường hợp này ta sài const
const b = 3
new GoodArray[b]

// Bạn cũng có thể khai báo thế này (Sử dụng thêm #define)

#define ARRAY_SIZE 3
new Array[ARRAY_SIZE]
- Bạn cũng có thể khai báo một biến với một nhóm giá trị như sau:
PHP:
new Numbers[4] = {0,1,2,3}
// Quan Trọng: hãy chắc chắn rằng bạn điền đúng số lượng Của Numbers trong có 4 giá trị thì bên ngoài Numbers phải là 4
// Không được vượt quá kích thước của mảng
- Bạn cũng có thể sử dụng các kiểu dữ liệu khác cho một mảng:
PHP:
 // Mảng của Floating Point tức là số thập phân
new Float:Numbers[4] = {0.0, 1.2, 2.4, 3.8}
// Mảng Của Booleans tức là true và false. Chú Ý: Trong trường hợp này thì giá trị của mỗi slot là true
new bool:playerHasGun[33] = {true, ...}

==================================
IV. Chuỗi – Strings
- Bạn có thể nhận thấy rằng một loại dữ liệu quan trọng: các ký tự như (chữ cái và các ký hiệu). Chúng được gọi là “strings” tức là chuỗi, và trong Pawn, nó là những số mà dc gọi là kỹ thuật số (Câu này hơi khó hiểu)!. String là một mảng của các số mà dịch để ASCII (Kí tự) biểu tượng. Ví dụ:
PHP:
// Khai báo Mảng số myString và chứa dữ liệu hay còn gọi là có giá trị là "Hello"
// Nó sẽ có 6 slot. mỗi slot chứa 1 kí tự của chữ Hello (0 là h, 1 là e, 2 là 1,... ,5 là o)
// Slot cuối cùng là dành cho số 0 (tức là slot số 6), để nói với trình dịch pawn đó là một chuỗi.
new myString[] = "Hello"
Và cách này cũng có thể làm được, nhưng dài dòng và không được dùng nhiều cho lắm:
PHP:
new myString[6]
myString[0] = 'H'
myString[1] = 'e'
myString[2] = 'l'
myString[3] = 'l'
myString[4] = 'o'
myString[5] = 0
- Điều đó nói lên Slot cuối cùng của 1 mảng phải là 0, hoặc các kí tự “null” (Null: vô hiệu).
- Và điều này đã cho bạn biết là mảng myString kết thúc ở đâu.

Bạn không thể làm thế này:
PHP:
new myString[6]
myString = "Hello"     // Không hợp lệ, vì myString này ko phải là một mảng, mà chỉ là một biến thường
myString[0] = "Hello"  // Cũng không hợp lệ

// Để thêm giá trị cũng như dữ liệu cho 1 mảng ta có thể làm thế này
new goodString[7]
copy(goodString, 6, "Hello")
- Và cũng xin nói luôn, Copy là một chức năng.
PHP:
copy(destination[], length, source[])
- Cho phép ta sao chép dữ liệu từ “destination” tức là nơi đến, “length” tức là số lượng cũng như slots trong đó, “source” là nơi xuất phát.

V. Function – Hàm.
- Pawn cho phép bạn #define (tức là xác định) chức năng, hàm của riêng bạn. Điều này có ích để loại bỏ mã số đó là được sử dụng ở nhiều nơi. Lưu ý rằng tất cả các chức năng phải trả lại một giá trị. Để làm điều này, bạn sử dụng lệnh “return”, mà ngay lập tức dừng chức năng và trả về giá trị của biểu thức thông qua nó. Mã số được thực hiện trong một hàm một lần trả lại được tìm thấy. Dưới đây là một số ví dụ:
PHP:
// Function này không có Parameter (Tức là thông số), và return thành 1
// Và trong function này. Khi nó được kích hoạt, thì nó sẽ sử dụng print tức là chức năng in ấn hiện chữ ra màn hình. (Đây là ví dụ còn print thì không biết có hay ko)
show()
{
   print("Hello!")

   return 1   // Kết thúc, trả lại giá trị 1
}

// Và cách kích hoạt Hàm này:
show()
- Và phần này cũng rất quan trọng trong Function. như sau:
PHP:
// Khai báo một hàm gọi là add_two_numbers. Trong đây nó lấy 2 con số và cộng lại và ra số mới.
add_two_numbers(first, second)
{
   new sum = first + second

   return sum  // Trả lại giá trị
}
- Sau đó khi bạn sử dụng hàm thì như thế này:
PHP:
new a,b
a = 5
b = 12
new c = add_two_numbers(a,b)
// Lúc này thì c sẽ = 17 vì số thứ nhất là 5 và số thứ 2 là 12.
- Bạn không bị giới hạn các kiểu dữ liệu trong thông số khi nhập. Và ở đây tôi lấy Floating Point tức số thập phân làm ví dụ:
PHP:
// Khai báo một hàm gọi là add_two_floats. Cũng như ở trên nhưng lại là với một số thập phân.
// Cũng là lấy 2 con số + lại và ra kết quả.
Float:add_two_floats(Float:first, Float:second)
{
   new Float:sum = first + second

   return sum
}

new Float:a
new Float:b
a = 5.0
b = 6.3
new Float:c
c = add_two_floats( a+b )
// Và c lúc này sẽ là 11.3, là một số thập phân.
VI. Biểu Thức – Expression
- Là những biểu thức, kí hiệu trong toán học như +, -,… .
Và bao gồm các kiểu như dấu ngoặc đơn. và hoạt động có trình tự.
Bạn có thể đặt các biểu thức bất cứ nơi nào.
Bạn có thể đặt các biến bằng với chúng hoặc truyền cho hàm chức năng

——————————————
- Nếu một biểu thức không phải là số 0 hoặc nó không phải là false,
nó không chỉ trả về một giá trị, nó cũng trả về “true”.
Nếu không, nó sẽ trở về 0, đó cũng là “false”.
PHP:
// Đây là những biểu thức toán học:
// + là phép cộng
// - là phép trừ
// * là phép nhân
// / là phép chia
// % là phép lấy phần dư
(5+6)                       // Trở về 11
((5*6)+3)                   // Trở về 33
((((5+3)/2)*4)-9)           // Trở về 7
((5*6) % 7)                 // Trở về 2
// Và đây là một số biểu thức khác
(true)                      // Trở về tuue
(5.0 + 2.3)                 // Trở vệ 7.3 là một số thập phân. hay còn là Floating Point
 
Chỉnh sửa cuối:
Tớ muốn hỏi làm sao tạo được chữ màu như sử dụng mã màu 00000000 để chỉnh như VD : (em kô viết ngôn ngữ dc. :))
New a
a = 00000000 //mã màu
a : ^2%^1
color_chat = sever ^2ZB^1 clasic
////// thì chữ ZB mau den
 
- Ngoài ra còn có phần mở rộng của nửa, để sử dụng trực tiếp trên các biến.
PHP:
new a = 5
new b = 6

a++          // Quay lại a+1, hoặc là 6.  Tăng theo kiểu Post
++a          // Cũng Quay lại a+1, hoặc là 6.  Tăng theo kiểu Pre
Và cũng có thể như sau:
PHP:
a--          // Quay về 4, post
--a          // Quay về 4, pre
- Giải thích thêm về a++. a++ nghĩa là a + 1, ++ là thêm 1.
PHP:
a = a + 1
- Quan sát kĩ, ta có:
PHP:
a += 1       // Set giá trị cho a + 1
a -= b       // Set giá trị cho a - 1
a *= 0       // Set giá trị cho a * 0 (a nhân 0)
a /= 2       // Set giá trị cho a / 2 (a chia 2)
------------------------
Post, là player còn sống (Sau)
Pre, là player đã chết (trước)
———————————-
PHP:
// Cái này nếu nó là 1 thì sẽ trả về true và 0 thì trả về false
// Nếu cả không đúng true thì && sẽ trả về false
(1 && 0)
(1 && 2)                    // Cả 2 trà về true
(true && false)             // Trả về false
(false && false)            // Trả về false
(true && true)              // Trả về true
- Và nữa
PHP:
(1 || 0)                    // Trả về true, vì một trong 2 số có 1 là true
(1 || 2)                    // Trả về true
(true || false)             // Trả về true
(false || false)            // Trả về false
(true || true)              // Trả về true
- Và cuối cùng
PHP:
// Trả về false
(!true)
// Trả về true
(!false)
- Trong đây "!" nghĩa là ngược lại

VII. Điều Kiện – Conditionals
1. If
- Điều quan trọng nhất có điều kiện được gọi là “if … then”. Nếu đánh giá liệu một biểu thức đã cho là đúng hoặc sai. Nếu là đúng, nó thực thi một khối mã hay còn gọi là Function hàm. Nếu sai, nó cũng sẽ thực thi một khối mã nhưng là khác khối mã kia.

Ví dụ:
PHP:
if (a == 5)
{
   a = 6
} else {
   a = 7
}

// Ở trường hợp này nếu a = 5 thì sẽ chạy hàm set giá trị cho a thành 6. Còn nếu a không bằng 5 thì sẽ set giá trị cho a =7
- Trong if bạn cũng có thể sử dụng biểu thức toán học như:
PHP:
// Trả về true hoặc thực thi hàm nếu a không = 5
if (a != 5) {}
// Trả về true hoặc thực thi hàm nếu a lớn hơn 5
if (a > 5) {}
// Trả về true hoặc thực thi hàm nếu a bé hơn 5
if (a < 5) {} // Trả về true hoặc thực thi hàm nếu a lớn hơn hoặc = 5 if (a >= 5) {}
// Trả về true hoặc thực thi hàm nếu a bé hơn hoặc = 5
if (a <= 5) {} // Trả về true vì 11 là true (nếu 0 là false) if (5+6) {} // Trả về true nếu cả 2 đều đúng là true if (a && b) {} // Trả về true nếu 7.5 lớn hơn c if ( ((5*3)/2) > c) {}
// Luôn luôn trả về true
if (true) {}
// Không bao giờ trả về true (trái ngược)
if (false) {}
—————————-
Ví dụ cho dễ hiểu phần else
PHP:
if (a == 5) {
   // Đoạn mã này sẽ thực thi nếu a = 5
} else if (a < 6) {
   // Đoạn mã này sẽ thực thi nếu a bé hơn 6
} else if (a == 7) {
   // Đoạn mã này sẽ chạy nếu a = 7
} else {
   // nếu a không nằm trong nhữ thứ được mình set như trên thì đoạn mã này sẽ thực thi.
}
2. Switch Statements
- Cuối cùng, có một loại mới nhất của câu điều kiện. Nó được gọi là một “switch”, và nó cho phép bạn tạo một danh sách lệnh cho các điều kiện tương tự, nhưng không phải là mạnh mẽ như, “if…else if”.
PHP:
// Ví dụ cho switch
switch (a)
{
    case 5:
    {
       // Đoạn mã này sẽ thực thi nếu a = 5
    }

    case 6:
    {
       // Đoạn mã này sẽ thực thi nếu a = 6
    }

    case 7:
    {
       // Đoạn mã này sẽ thực thi nếu a = 7
    }

    default:
    {
       // Đoạn mã này sẽ thực thi nêu a không = một cái gì ở trên
    }
}
- Và đây cũng gần giống ở trên nhưng lại “công phu” hơn:
PHP:
// Cái này gọi là multiple
switch (a)
{
    case 1, 2, 3:
    {
       // Đoạn mã này sẽ chạy nếu a = 1 hoặc = 2 hoặc = 3
    }

    case 4, 5, 6:
    {
       // Đoạn mã này sẽ chạy nếu a = 4 hoặc = 5 hoặc = 6
    }

    case 7, 8, 9:
    {
       // Đoạn mã này sẽ chạy nếu a = 7 hoặc = 8 hoặc = 9
    }

    default:
    {
       Cũng như cái kia. đoạn mã này sẽ chạy nếu a không = một cái nào ở trên.
    }
}
- Và cuối cùng:
PHP:
// Cái này gọi là range
switch (a)
{
    case 0 .. 50:
    {
       // Đoạn mã này sẽ chạy nếu 0 <= a <= 50
       // có thể coi là nếu a trong tầm từ 0 đến 50 thì đoạn mã chạy. nếu không thì không chạy.
    }

    case 51 .. 100:
    {
       // Đoạn mã này sẽ chạy nếu 51 <= a <= 100
       // có thể coi là nếu a trong tầm từ 51 đến 100 thì đoạn mã chạy. nếu không thì không chạy.

    }

    case 101 .. 200:
    {
       // Đoạn mã này sẽ chạy nếu 101 <= a <= 200
       // có thể coi là nếu a trong tầm từ 101 đến 200 thì đoạn mã chạy. nếu không thì không chạy.
    }

    default:
    {
       // Như trên. nó sẽ chạy nếu ko đúng một cái nào ở trên
    }
}
IIX. Vòng Lặp – Looping
1. For (Vòng lặp For)
- Vòng lặp đầu tiên và là vòng lặp được sử dụng rộng rãi nhất là vòng lặp “For”. Chức năng của vòng lặp for, là cho mình lặp lại câu lệnh bất cứ lần nào. Ví dụ:
PHP:
/* Một vòng lặp For có 3 thông số (Parameters)
  for (ban đầu; điều kiện; tăng)
  {
    // Lệnh của bạn
  }

Trước khi vòng đầu tiên thực hiện, nó chạy điều kiện ban đầu của bạn.
Sau đó nó bắt đầu vòng lặp mã của bạn với các bước sau:
  1.  Kiểm tra điều kiện, nếu đúng thì lặp chạy nếu không kêt thúc hoặc return.
  2.  Chạy Code
  3.  Chạy hàm tăng thông số (Parameter)
  4.  Quay lại bước 1 (Lặp)
*/

// Ví dụ cho vòng lặp For
new i
new sum
for (i=1; i<=10; i++)
{
   sum += i
}
// Check điều kiện, nếu i bé hơn hoặc = 10 thì lặp tiếp tuc chạy,
// Chạy dến khi nào, mà i hớn hơn 10 thì ngừng.
2. While (Vòng lặp While)
- Một Loại nữa của vòng lặp cũng rất quan trọng, và là đơn giản hơn một vòng lặp for. Được gọi là vòng lăp “while”, nó chỉ có một tham số(Parameters): một điều kiện(Condition). Khi điều kiện là đúng, nó vẫn không ngừng thực thi lệnh.
PHP:
new i=0
new sum

while (++i <= 10)
{
   sum += i
}

// ++i là tham số
// <= 10 là điều kiện
// Nếu điều kiện là đúng nó sẽ thực thi lệnh: "sum += i"
IX. Trình biên dịch trước khi xử lý Chỉ thị – Compiler Pre-processor Directives
- Trình biên dịch chỉ thị cho phép bạn thay đổi như thế nào là mã của bạn. Điều này là khá cao và sẽ chỉ được chạy trong một thời gian ngắn.
PHP:
// Để liên kết một biểu tượng cho giá trị, bạn có thể làm như sau:
#define SYMBOL VALUE
// Ví Dụ:

#define MAX_STRING 250
new String[MAX_STRING]

#define HELLO "Xin Chào. Đây là một lời chào chung"
new Hello[MAX_STRING] = HELLO
- Bạn cũng có thể sử dụng #define để thay đổi mã của trình biên dịch mã tạo ra.
PHP:
#if defined LINUX
   // Phần này sẽ được biên dịch nếu #define LINUX tồn tại
   execute_command("ls -l")
#else
   // Phần này sẽ được biên dịch nếu #define LINUX không tòn tại
   execute_command("dir")
#endif
- Bạn cũng có thể thay đổi bao nhiêu bộ nhớ của bạn để sử dụng Script.
PHP:
#pragma dynamic 4096
// Cái này tạo ra một 16K stack của bộ nhớ (mặc định).
// Nó được đo bằng các khối cells của 4 byte.
- Bạn cũng có thể chỉ định sử dụng dấu chấm phẩy là cần thiết để chấm dứt một dòng mã (mặc định. Nó không phải là yêu cầu).
PHP:
#pragma semicolon 1
- Bạn cũng có thể thay đổi các ký tự điều khiển (amxx std: ‘^’)
PHP:
#pragma ctrlchar ''
// bây giờ bạn phải sử dụng "" thay vì "^"
// ví dụ: "This is ^": D ^ "" bây giờ là "This is ": D  ""
================ Tutorial Viết bởi Dias ==================
 
Chỉnh sửa cuối:
Ai thắc mắc chỗ nào không hiểu thì hỏi ngay bác kungfulon tại đây nha :)).
- Không hiểu thì hỏi ngay, nếu không là xuống phần dưới nữa sẽ càng không hiểu
---------------------------------------------------------------
Vote Kick Menu v1.0
by Dias
I. Description:
- Bạn có thể tự mình vote kick hack + Cheat khi không có mod trong sv
- Một người chỉ dc vote 1 lần duy nhất (tránh kick nhau loạn sv)
- Kiểu vote thì giống CrossFire

II. Config:
PHP:
#define Time_Kick 30.0 // Thời gian đợi cho các bấm player F11 và F12
III. Usage:
- Đối với người vote thì: Gõ /votekick để mở menu vote kick
- Còn đối với người chơi thì: F11 - đồng ý | F12 - Không đồng ý
=> Nếu số lượng đồng ý kick hơn thì thằng hack out sv =))

IV. Sceenshots:
- Khi mà bắt đầu bỏ phiếu kick:
i34751_1.png

- Sau khi ấn F11 để đồng ý kick. cái số sau chữ yes và no là số biểu thị những người bỏ phiếu
i34753_2.png

- Sau 30 giây. Nếu số lượng người bỏ phiếu đồng ý nhiều hơn số lượng người không đồng ý => KICK
i34756_3.png


----- Have Fun ------
Bản này mới làm nên có lỗi thì báo nhá =.="
=> http://forums.alliedmods.net/showthread.php?p=1501016
 
Chỉnh sửa cuối:
Ôi, bố Biên post tutorial thì gộp chung 1 cái.. Chứ post xong vứt đấy không mark lại ....thì phí.
 
Ôi, bố Biên post tutorial thì gộp chung 1 cái.. Chứ post xong vứt đấy không mark lại ....thì phí.
OMG... nick chính tôi chưa kịp viết nốt phần sau đã GO mất rồi còn đâu 8-}
Tí ngồi viết TUT set_task:))
 
Tutorial set_task tui nhớ tui viết rồi mà ta :-??
 
[AMXX] Basic Native Tutorial
I. Khái niệm Native
Chính xác là tôi cũng chả biết dịch ra như thế nào. Nói chung là cái này liên kết đến 1 func trong 1 plugin để các plugin khác sử dụng được func đó.

II. Khai báo native
Cú pháp khai báo native trong plugin:
PHP:
native register_native(const name[], const handler[], style=0)
Trong đó:
- const name[]: tên native để các plugin khác sử dụng
- const handler[]: tên func được thực hiện trong plugin khi gọi native
- style: kiểu native (mặc định = 0)
Chú ý: BẮT BUỘC phải khai báo trong public plugin_natives()
Handler cho native:
- Đối với style 0:
PHP:
public <handler>(iPlugin, iParam) // iPlugin: id của plugin ; iParam: số lượng param của native
- Đối với style 1:
PHP:
public <handler>(param1, param2, ..., paramN)
Khai báo native trong file .inc (include file, để các plugin khác có thể sử dụng)
PHP:
native <name>(param1, param2, ..., paramN) // giống style 1
Chú ý: <name> và <handler> lấy từ register_native ở trên.

III. VD về native:
- File plugin:
PHP:
#include <amxmodx>

#define PLUGIN "Test native"
#define VERSION "1.0"
#define AUTHOR "?????"

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
}

public plugin_natives()
{
	register_native("get_user_HP", "natives_get_user_HP") // style 0
	register_native("get_user_AP", "natives_get_user_AP", 1) // style 1
}

public natives_get_user_HP(iPlugin,iParams)
{
	if(iParams != 1)
		return PLUGIN_CONTINUE
	
	new id = get_param(1)
	if(!id)
		return PLUGIN_CONTINUE
	
	return get_user_health(id)
}

public natives_get_user_AP(id)
{
	if(!id)
		return PLUGIN_CONTINUE
	
	return get_user_armor(id)	
}
- File INC:
PHP:
native get_user_HP(id)
native get_user_AP(id)
Các plugin khác chỉ cần include file inc là sử dụng được các native này như các func bình thường.
 
Chỉnh sửa cuối:
- Có 1 cách để sài native mà không cần cái plugin register native đó hoạt động. Ông viết luôn đi :))
 
Bố nào tổng hợp tất mớ hướng dẫn này lên Page 1 đi :@)...................................

Khi cần dễ tìm kiếm :|
 
Thôi, bảo hắn viết cha vào 1 cái e-book.chm rồi cho cái link đi cho xong :-??..
 
Chờ viết nhiều trên forum đã rồi gộp thành 1 cái book cũng chả sao. mới viết dc có 1 - 2 cái mà gộp book thì hơi...
 
Chờ viết nhiều trên forum đã rồi gộp thành 1 cái book cũng chả sao. mới viết dc có 1 - 2 cái mà gộp book thì hơi...
Agree~\m/
Đặt tên Ebook là "[AMXX] Amx Mod X Tutorial by GameVN" cho hay nhẩy=))
 
ai help tui cái svdex :((
làm mãi ko xong:((
ko bít sai code ở đâu hết :((
PHP:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <fun>
#include <hamsandwich>
#include <xs>
#include <cstrike>
#include <zombieplague>

enum
{
	animation_idle,
	animation_reload,
	animation_draw,
	animation_shoot1,
	animation_shoot2,
	animation_shoot3,
	animation_move_carbine,
	animation_shoot,
	animation_shootlast
}
#define TASK_CHOOSE_HERO 797979
new g_round_ssvd,bool:round_end
#define task_reload_launcher 22121994
#define start_launcher 25251325
#define reload_type_2 221133
#define is_svd 1908094
#define is_reloading 1.0
#define is_in_launcher 1.0
#define active_my_grenade 900100010011002
#define reload_my_weapon 100010011002

#define ENG_NULLENT		-1
#define EV_INT_WEAPONKEY	EV_INT_impulse
#define MG3_WEAPONKEY	70111
#define MAX_PLAYERS  			  32
const USE_STOPPED = 0
const OFFSET_ACTIVE_ITEM = 373
const OFFSET_WEAPONOWNER = 41
const OFFSET_LINUX = 5
const OFFSET_LINUX_WEAPONS = 4
const OFFSET_MODELINDEX = 491 
#define WEAP_LINUX_XTRA_OFF			4
#define m_fKnown				44
#define m_flNextPrimaryAttack 			46
#define m_flTimeWeaponIdle			48
#define m_iClip					51
#define m_fInReload				54
#define PLAYER_LINUX_XTRA_OFF			5
#define m_flNextAttack				83
#define MG3_RELOAD_TIME 5.0
const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
new const WEAPONENTNAMES[][] = { "", "weapon_p228", "", "weapon_scout", "weapon_hegrenade", "weapon_xm1014", "weapon_c4", "weapon_mac10",
			"weapon_aug", "weapon_smokegrenade", "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550",
			"weapon_galil", "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy", "weapon_m249",
			"weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552",
			"weapon_ak47", "weapon_knife", "weapon_p90" }
new bool:i_reload_launcher[33]
new g_msgDeathMsg
new g_msgScoreInfo
new bool:in_zoom[33], bool:g_m203_loaded[33]
new m_iTrail;
new bool:in_launcher[33], g_ammo[33], cvar_trail, cvar_knockback_dmg
new xplode;
new Float:zoom_delay[33]
new const Sound_Fire[][] = { "weapons/svdex_shoot1.wav"}
new const GUNSHOT_DECALS[] = { 41, 42, 43, 44, 45 }

new const V_MODEL[] = {"models/ks/v_svdex.mdl"}
new const P_MODEL[] = {"models/ks/p_svdex.mdl"}
new const W_MODEL[] = {"models/ks/w_svdex.mdl"}
new const V_MODEL_2[] = {"models/ks/v_svdex_2.mdl"}
new const W_NADE[] = {"models/grenade.mdl"}

new const hero_model[] = {"hero"}

new cvar_dmg_mg3, cvar_recoil_mg3, g_itemid_mg3, cvar_clip_mg3, cvar_mg3_ammo, cvar_spd_mg3
new g_has_mg3[33], g_MaxPlayers, Float:cl_pushangle[MAX_PLAYERS + 1][3], m_iBlood[2], g_orig_event_m249, g_IsInPrimaryAttack, g_clip_ammo[33], g_mg3_TmpClip[33]
#define nade_damage 1000
#define nade_radius 500
#define nade_reload 3.0
#define nade_knockback 10.0
new modelindex[sizeof hero_model], g_player_model[33][32]
public plugin_init()
{
	register_plugin("[ZP] Extra: SVD-SVDex", "1000.0", "teo")
	RegisterHam(Ham_Item_AddToPlayer, "weapon_ak47", "fw_Aug_AddToPlayer")
	RegisterHam(Ham_Use, "func_tank", "fw_UseStationary_Post", 1)
	RegisterHam(Ham_Use, "func_tankmortar", "fw_UseStationary_Post", 1)
	RegisterHam(Ham_Use, "func_tankrocket", "fw_UseStationary_Post", 1)
	RegisterHam(Ham_Use, "func_tanklaser", "fw_UseStationary_Post", 1)
	for (new i = 1; i < sizeof WEAPONENTNAMES; i++)
		if (WEAPONENTNAMES[i][0]) RegisterHam(Ham_Item_Deploy, WEAPONENTNAMES[i], "fw_Item_Deploy_Post", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_ak47", "fw_Aug_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_ak47", "fw_Aug_PrimaryAttack_Post", 1)
	RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
	RegisterHam(Ham_Item_PostFrame, "weapon_ak47", "MG3__ItemPostFrame");
	RegisterHam(Ham_Weapon_Reload, "weapon_ak47", "MG3__Reload");
	RegisterHam(Ham_Weapon_Reload, "weapon_ak47", "MG3__Reload_Post", 1);
	register_forward(FM_SetModel, "fw_SetModel")
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_PlaybackEvent, "fwPlaybackEvent")
	//register_forward(FM_ClientUserInfoChanged, "fw_ClientUserInfoChanged")
	
	
	cvar_spd_mg3 = register_cvar("zp_svdex_speed", "5")
	cvar_dmg_mg3 = register_cvar("zp_svdex_dmg", "5")
	cvar_recoil_mg3 = register_cvar("zp_svdex_recoil", "0.8")
	cvar_clip_mg3 = register_cvar("zp_svdex_clip", "20")
	cvar_mg3_ammo = register_cvar("zp_svdex_ammo", "200")
	cvar_knockback_dmg = register_cvar("zp_svdex_knock_bullet","10")
	cvar_trail = register_cvar("zp_svdex_nade_trail", "1")
	
	register_touch("m203_nade", "*", "fw_nade_touch")
	register_forward(FM_CmdStart, "forward_CmdStart")
	register_forward(FM_PlayerPreThink, "fw_pthink")
	
	g_itemid_mg3 = zp_register_extra_item("[SVD-SVDex]", 50, ZP_TEAM_HUMAN)
	g_MaxPlayers = get_maxplayers()
}

public plugin_precache()
{
	m_iTrail = precache_model("sprites/smoke.spr")
	xplode = precache_model("sprites/eexplo.spr")
	precache_sound("weapons/svdex_shoot2.wav")
	precache_model(P_MODEL)
	precache_model(W_MODEL)
	precache_model(V_MODEL_2)
	precache_model(W_NADE)

	for(new i = 0; i < sizeof Sound_Fire; i++)
	precache_sound(Sound_Fire[i])	
	m_iBlood[0] = precache_model("sprites/blood.spr")
	m_iBlood[1] = precache_model("sprites/bloodspray.spr")

	register_forward(FM_PrecacheEvent, "fwPrecacheEvent_Post", 1)
	
	new i, model[100]
	for (i = 0; i < sizeof hero_model; i++)
	{
		format(model, charsmax(model), "models/player/%s/%s.mdl", hero_model, hero_model)
		modelindex[i] = precache_model(model)
	}
}

public zp_user_humanized_post(id)
{
	if(zp_get_user_survivor(id))
		g_has_mg3[id] = true
	
}

public fwPrecacheEvent_Post(type, const name[])
{
	if (equal("events/ak47.sc", name))
	{
		g_orig_event_m249 = get_orig_retval()
		return FMRES_HANDLED
	}

	return FMRES_IGNORED
}

public client_connect(id)
{
	g_has_mg3[id] = false
}

public client_disconnect(id)
{
	g_has_mg3[id] = false
	
}

public zp_user_infected_post(id)
{
	if (zp_get_user_zombie(id))
	{
		g_has_mg3[id] = false	
	}
}

public fw_SetModel(entity, model[])
{
	if(!is_valid_ent(entity))
		return FMRES_IGNORED;
	
	static szClassName[33]
	entity_get_string(entity, EV_SZ_classname, szClassName, charsmax(szClassName))
		
	if(!equal(szClassName, "weaponbox"))
		return FMRES_IGNORED;
	
	static iOwner
	
	iOwner = entity_get_edict(entity, EV_ENT_owner)
	
	if(equal(model, "models/w_ak47.mdl"))
	{
		static iStoredAugID
		
		iStoredAugID = find_ent_by_owner(ENG_NULLENT, "weapon_ak47", entity)
	
		if(!is_valid_ent(iStoredAugID))
			return FMRES_IGNORED;
	
		if(g_has_mg3[iOwner])
		{
			entity_set_int(iStoredAugID, EV_INT_WEAPONKEY, MG3_WEAPONKEY)
			
			g_has_mg3[iOwner] = false
			
			entity_set_model(entity, W_MODEL)
			
			return FMRES_SUPERCEDE;
		}
	}
	
	return FMRES_IGNORED;
}
public fw_pthink(id)
{
	if (!is_user_alive(id))
		return
	if (!g_has_mg3[id])
	{
		if (task_exists(id + reload_my_weapon))
			remove_task(id + reload_my_weapon)
		if (task_exists(id + active_my_grenade))
			remove_task(id + active_my_grenade)
		if (task_exists(id + reload_type_2))
			remove_task(id + reload_type_2)
		if (task_exists(id + start_launcher))
			remove_task(id + start_launcher)
		if (task_exists(id - start_launcher))
			remove_task(id - start_launcher)
	}
	if (g_has_mg3[id])
	{
		if (get_user_weapon(id) != CSW_AK47)
		{
			if (task_exists(id + reload_my_weapon))
				remove_task(id + reload_my_weapon)
			if (task_exists(id + active_my_grenade))
				remove_task(id + active_my_grenade)
			if (task_exists(id + reload_type_2))
				remove_task(id + reload_type_2)
			if (task_exists(id + start_launcher))
				remove_task(id + start_launcher)
			if (task_exists(id - start_launcher))
				remove_task(id - start_launcher)
		}
	}
}

public zp_extra_item_selected(id, itemid)
{

	if(itemid == g_itemid_mg3)
	{
		drop_weapons(id, 1);
		new iWep2 = give_item(id,"weapon_ak47")
		if( iWep2 > 0 )
		{
			cs_set_weapon_ammo( iWep2, get_pcvar_num(cvar_clip_mg3) )
			cs_set_user_bpammo (id, CSW_AK47, get_pcvar_num(cvar_mg3_ammo))
		}
		g_has_mg3[id] = true;
		g_ammo[id] = 999999999
		new SetModel = random_num(0, sizeof hero_model)
		if (SetModel > 0)
		{
			if (g_has_mg3[id] && !zp_get_user_zombie(id))
			{
				new index = SetModel - 1
				copy(g_player_model[id], charsmax(g_player_model[]), hero_model)
				cs_set_user_model(id, g_player_model[id])
				set_user_model_index(id, modelindex[index])
			}
		}
	}
}

public fw_Aug_AddToPlayer(Aug, id)
{
	if(!is_valid_ent(Aug) || !is_user_connected(id))
		return HAM_IGNORED;
	
	if(entity_get_int(Aug, EV_INT_WEAPONKEY) == MG3_WEAPONKEY)
	{
		g_has_mg3[id] = true
		
		entity_set_int(Aug, EV_INT_WEAPONKEY, 0)
		
		return HAM_HANDLED;
	}
	
	return HAM_IGNORED;
}

public fw_UseStationary_Post(entity, caller, activator, use_type)
{
	if (use_type == USE_STOPPED && is_user_connected(caller))
		replace_weapon_models(caller, get_user_weapon(caller))
}

public fw_Item_Deploy_Post(weaponid)
{
	new id = pev(weaponid, pev_owner)

	if (!is_user_alive(id))
		return
	if (!g_has_mg3[id])
		return
	if (in_launcher[id])
	{
		set_pdata_int(id, m_flNextAttack, 5, 5)
		return
	}
	if (in_launcher[id])
	{
		set_pdata_float(weaponid, m_flNextAttack, 2.0, 4)
	}
	
	zoom_delay[id] = get_gametime()
	replace_weapon_models(id, weaponid)
}

public CurrentWeapon(id)
{
     replace_weapon_models(id, read_data(2))

     if(read_data(2) != CSW_AK47 ||!g_has_mg3[id])
          return
     
     static Float:iSpeed
     if(g_has_mg3[id])
          iSpeed = get_pcvar_float(cvar_spd_mg3)
		  
     
     static weapon[32],Ent
     get_weaponname(read_data(2),weapon,31)
     Ent = find_ent_by_owner(-1,weapon,id)
     if(Ent)
     {
          static Float:Delay, Float:M_Delay
          Delay = get_pdata_float( Ent, 46, 4) * iSpeed
          M_Delay = get_pdata_float( Ent, 47, 4) * iSpeed
          if (Delay > 0.0)
          {
               set_pdata_float(Ent, 46, Delay, 4)
               set_pdata_float(Ent, 47, M_Delay, 4)
          }
     }
}
replace_weapon_models(id, weaponid)
{
	if(!pev_valid(weaponid))
		return;

	if (zp_get_user_zombie(id))
		return;
	if(g_has_mg3[id] && get_user_weapon(id) == CSW_AK47)
	{
		if(!in_launcher[id])
		{
			set_pev(id, pev_viewmodel2, V_MODEL)
		}
		else if(in_launcher[id])
		{
			set_pev(id, pev_viewmodel2, V_MODEL_2)
		}
		set_pev(id, pev_weaponmodel2, P_MODEL)
	}	
	
}


public fw_UpdateClientData_Post(Player, SendWeapons, CD_Handle)
{
	if(!is_user_alive(Player) || (get_user_weapon(Player) != CSW_AK47 || !g_has_mg3[Player]))

		return FMRES_IGNORED
	
	set_cd(CD_Handle, CD_flNextAttack, halflife_time () + 0.001)
	return FMRES_HANDLED
}

public fw_Aug_PrimaryAttack(Weapon)
{
	new Player = get_pdata_cbase(Weapon, 41, 5)
	
	if (!g_has_mg3[Player] )
		return;
	
	g_IsInPrimaryAttack = 1
	pev(Player,pev_punchangle,cl_pushangle[Player])
	
	g_clip_ammo[Player] = cs_get_weapon_ammo(Weapon)
}

public fwPlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if (eventid != g_orig_event_m249 || !g_IsInPrimaryAttack)
		return FMRES_IGNORED
	if (!(1 <= invoker <= g_MaxPlayers))
		return FMRES_IGNORED

	playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
	return FMRES_SUPERCEDE
}

public fw_Aug_PrimaryAttack_Post(Weapon)
{
	g_IsInPrimaryAttack = 0
	new Player = get_pdata_cbase(Weapon, 41, 5)
	
	
	if(g_has_mg3[Player])
	{
		new Float:push[3]
		pev(Player,pev_punchangle,push)
		xs_vec_sub(push,cl_pushangle[Player],push)
		
		xs_vec_mul_scalar(push,get_pcvar_float(cvar_recoil_mg3),push)
		xs_vec_add(push,cl_pushangle[Player],push)
		set_pev(Player,pev_punchangle,push)
		
		if (!g_clip_ammo[Player])
			return
		for(new i = 0; i < sizeof Sound_Fire;i++)
		emit_sound(Player, CHAN_WEAPON, Sound_Fire[i], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		SendWeaponAnim(Player, animation_shoot1)
	
		make_blood_and_bulletholes(Player)
	}
}

public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
	if (victim != attacker && is_user_connected(attacker))
	{
		if(get_user_weapon(attacker) == CSW_AK47 && !in_launcher[attacker])
		{
			if(g_has_mg3[attacker])
				SetHamParamFloat(4, damage * get_pcvar_float(cvar_dmg_mg3))
		}
	}
}

stock fm_cs_get_current_weapon_ent(id)
{
	return get_pdata_cbase(id, OFFSET_ACTIVE_ITEM, OFFSET_LINUX);
}

stock fm_cs_get_weapon_ent_owner(ent)
{
	return get_pdata_cbase(ent, OFFSET_WEAPONOWNER, OFFSET_LINUX_WEAPONS);
}

stock SendWeaponAnim(const Player, const Sequence)
{
	set_pev(Player, pev_weaponanim, Sequence)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = Player)
	write_byte(Sequence)
	write_byte(pev(Player, pev_body))
	message_end()
}

stock make_blood_and_bulletholes(id)
{
	new aimOrigin[3], target, body
	get_user_origin(id, aimOrigin, 3)
	get_user_aiming(id, target, body)
	
	if(target > 0 && target <= g_MaxPlayers && zp_get_user_zombie(target))
	{
		new Float:fStart[3], Float:fEnd[3], Float:fRes[3], Float:fVel[3]
		pev(id, pev_origin, fStart)
		
		velocity_by_aim(id, 64, fVel)
		
		fStart[0] = float(aimOrigin[0])
		fStart[1] = float(aimOrigin[1])
		fStart[2] = float(aimOrigin[2])
		fEnd[0] = fStart[0]+fVel[0]
		fEnd[1] = fStart[1]+fVel[1]
		fEnd[2] = fStart[2]+fVel[2]
		
		new res
		engfunc(EngFunc_TraceLine, fStart, fEnd, 0, target, res)
		get_tr2(res, TR_vecEndPos, fRes)
		
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY) 
		write_byte(TE_BLOODSPRITE)
		write_coord(floatround(fStart[0])) 
		write_coord(floatround(fStart[1])) 
		write_coord(floatround(fStart[2])) 
		write_short( m_iBlood [ 1 ])
		write_short( m_iBlood [ 0 ] )
		write_byte(70)
		write_byte(random_num(1,2))
		message_end()
		
		
	} 
	else if(!is_user_connected(target))
	{
		if(target)
		{
			message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
			write_byte(TE_DECAL)
			write_coord(aimOrigin[0])
			write_coord(aimOrigin[1])
			write_coord(aimOrigin[2])
			write_byte(GUNSHOT_DECALS[random_num ( 0, sizeof GUNSHOT_DECALS -1 ) ] )
			write_short(target)
			message_end()
		} 
		else 
		{
			message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
			write_byte(TE_WORLDDECAL)
			write_coord(aimOrigin[0])
			write_coord(aimOrigin[1])
			write_coord(aimOrigin[2])
			write_byte(GUNSHOT_DECALS[random_num ( 0, sizeof GUNSHOT_DECALS -1 ) ] )
			message_end()
		}
		
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_GUNSHOTDECAL)
		write_coord(aimOrigin[0])
		write_coord(aimOrigin[1])
		write_coord(aimOrigin[2])
		write_short(id)
		write_byte(GUNSHOT_DECALS[random_num ( 0, sizeof GUNSHOT_DECALS -1 ) ] )
		message_end()
	}
}

public MG3__ItemPostFrame(weapon_entity) 
{
     new id = pev(weapon_entity, pev_owner)
     if (!is_user_connected(id))
          return HAM_IGNORED;

     if (!g_has_mg3[id] )
          return HAM_IGNORED;
     if(in_launcher[id])
	 return HAM_IGNORED;

     
     static iClipExtra

     if(g_has_mg3[id] && !in_launcher[id])
          iClipExtra = get_pcvar_num(cvar_clip_mg3)
     
     new Float:flNextAttack = get_pdata_float(id, m_flNextAttack, PLAYER_LINUX_XTRA_OFF)

     new iBpAmmo = cs_get_user_bpammo(id, CSW_AK47);
     new iClip = get_pdata_int(weapon_entity, m_iClip, WEAP_LINUX_XTRA_OFF)

     new fInReload = get_pdata_int(weapon_entity, m_fInReload, WEAP_LINUX_XTRA_OFF) 

     if( fInReload && flNextAttack <= 0.0 )
     {
          new j = min(iClipExtra - iClip, iBpAmmo)
     
          set_pdata_int(weapon_entity, m_iClip, iClip + j, WEAP_LINUX_XTRA_OFF)
          cs_set_user_bpammo(id, CSW_AK47, iBpAmmo-j);
          
          set_pdata_int(weapon_entity, m_fInReload, 0, WEAP_LINUX_XTRA_OFF)
          fInReload = 0
     }

     return HAM_IGNORED;
}

public MG3__Reload(weapon_entity) 
{
     new id = pev(weapon_entity, pev_owner)
     if (!is_user_connected(id))
          return HAM_IGNORED;

     if (!g_has_mg3[id] )
          return HAM_IGNORED;


     if(in_launcher[id])
	 return HAM_IGNORED;

     static iClipExtra

     if(g_has_mg3[id]&& !in_launcher[id])
          iClipExtra = get_pcvar_num(cvar_clip_mg3)

     g_mg3_TmpClip[id] = -1;

     new iBpAmmo = cs_get_user_bpammo(id, CSW_AK47);
     new iClip = get_pdata_int(weapon_entity, m_iClip, WEAP_LINUX_XTRA_OFF)

     if (iBpAmmo <= 0)
          return HAM_SUPERCEDE;

     if (iClip >= iClipExtra)
          return HAM_SUPERCEDE;


     g_mg3_TmpClip[id] = iClip;

     return HAM_IGNORED;
}

public MG3__Reload_Post(weapon_entity) 
{
	new id = pev(weapon_entity, pev_owner)
	if (!is_user_connected(id))
		return HAM_IGNORED;

	if(in_launcher[id])
		return HAM_IGNORED;
	if (!g_has_mg3[id] )
		return HAM_IGNORED;

	if (g_mg3_TmpClip[id] == -1)
		return HAM_IGNORED;

	static Float:iReloadTime; iReloadTime = get_pdata_float(weapon_entity, m_fInReload, 4)
	if(g_has_mg3[id] &&!in_launcher[id])
	{

		set_pdata_int(weapon_entity, m_iClip, g_mg3_TmpClip[id], WEAP_LINUX_XTRA_OFF)

		set_pdata_float(weapon_entity, m_flTimeWeaponIdle, iReloadTime, WEAP_LINUX_XTRA_OFF)

		set_pdata_float(id, m_flNextAttack, iReloadTime, PLAYER_LINUX_XTRA_OFF)

		set_pdata_int(weapon_entity, m_fInReload, 1, WEAP_LINUX_XTRA_OFF)

		SendWeaponAnim(id, 3)
	}

	return HAM_IGNORED;
}
public forward_CmdStart(id, uc_handle, seed)
{
	if (!is_user_alive(id))
		return FMRES_IGNORED
	if (g_has_mg3[id])
	{
		new wid, clip, ammo
		wid = get_user_weapon(id, clip, ammo)
		if (wid == CSW_AK47)
		{
			static Float:flNextAttack ; flNextAttack = get_pdata_float(id, m_flNextAttack, 5)
			new iEnt = find_ent_by_owner(-1, "weapon_ak47", id)
			new fInReload = get_pdata_int(iEnt, m_fInReload, 4)
			static button, oldbutton
			button = get_uc(uc_handle, UC_Buttons)
			oldbutton = pev(id, pev_oldbuttons)
			if ((button & IN_ATTACK) && !(oldbutton& IN_ATTACK))
			{
				if (in_launcher[id] )
				{
					if (g_m203_loaded[id] && !fInReload)
					{
						launch_grenade(id)
					}
				}
			}
			if (button & IN_ATTACK2)
			{
				set_pev(id, pev_button, button &~ IN_ATTACK2)
				if (!fInReload && flNextAttack <= 0.0 && !in_launcher[id])
				{
					new Float:flGameTime = get_gametime()
					if (flGameTime - zoom_delay[id] >= 0.5)
					{
						if (in_zoom[id])
						{
							cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
							in_zoom[id] = false
							zoom_delay[id] = flGameTime
							set_pdata_float(id, m_flNextAttack, 0.5, 5)
						}
						else
						{
							cs_set_user_zoom(id, CS_SET_AUGSG552_ZOOM, 0)
							in_zoom[id] = true
							zoom_delay[id] = flGameTime
							set_pdata_float(id, m_flNextAttack, 0.5, 5)
						}
					}
				}
			}
			new impulse = get_uc(uc_handle, UC_Impulse)
			if (impulse == 201)
			{
				if (!fInReload && flNextAttack <= 0.0 && get_gametime() - zoom_delay[id] >= 0.5)
				{
					if (in_launcher[id])
					{
						in_zoom[id] = false
						cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
						SendWeaponAnim(id, animation_move_carbine)
						set_pdata_float(id,m_flNextAttack, 2.0, 5)
						set_task(1.5, "end_action", id - start_launcher)
						in_launcher[id] = false	
						client_print(id, print_center, "Tat chuc nang phong luu")
										
					}
					else
					{
						in_zoom[id] = false
						cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
						SendWeaponAnim(id, 6)
						set_task(1.0, "start_action", id + start_launcher)
						in_launcher[id] = true
						set_pdata_float(id,m_flNextAttack, 2.0, 5)
						client_print(id, print_center, "Chuyen sang chuc nang phong luu")
					}
				}
			}
			if(pev(id, pev_button)& IN_RELOAD || !g_has_mg3[id] && in_zoom[id])
			{
				in_zoom[id] = false
				cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
				zoom_delay[id] = get_gametime()
			}
		}
	}
	return FMRES_IGNORED
}
public fw_TraceAttack(victim, attacker, Float:damage, Float:direction[3], tracehandle, damage_type)
{
	if (victim == attacker || !is_user_connected(attacker))
		return HAM_IGNORED;
	if (zp_get_user_zombie(attacker) == zp_get_user_zombie(victim))
		return HAM_IGNORED;
	if (!zp_get_user_zombie(victim) || zp_get_user_nemesis(victim))
		return HAM_IGNORED;
	if (!(damage_type & DMG_BULLET) || !get_cvar_num("zp_knockback"))
		return HAM_IGNORED;
	if (!g_has_mg3[attacker] || (get_user_weapon(attacker) != CSW_AK47))
		return HAM_IGNORED;
	static victimflags, Float:knockduck
	victimflags = pev(victim, pev_flags)
	knockduck = get_cvar_float("zp_knockback_ducking")
	if (knockduck == 0.0 && (victimflags & FL_DUCKING) && (victimflags & FL_ONGROUND))
		return HAM_IGNORED;
	static Float:origin1F[3], Float:origin2F[3]
	pev(victim, pev_origin, origin1F)
	pev(attacker, pev_origin, origin2F)
	if (get_distance_f(origin1F, origin2F) > get_cvar_float("zp_knockback_distance"))
		return HAM_IGNORED;
	static Float:velocity[3]
	pev(victim, pev_velocity, velocity)
	if (get_cvar_num("zp_knockback_damage"))
		xs_vec_mul_scalar(direction, damage, direction)
	if (get_pcvar_float(cvar_knockback_dmg) > 0.0 && get_cvar_num("zp_knockback_power"))
		xs_vec_mul_scalar(direction, get_pcvar_float(cvar_knockback_dmg), direction)
	if ((victimflags & FL_DUCKING) && (victimflags & FL_ONGROUND))
		xs_vec_mul_scalar(direction, knockduck, direction)
	xs_vec_add(velocity, direction, direction)
	if (!get_cvar_num("zp_knockback_zvel"))
		direction[2] = velocity[2]
	set_pev(victim, pev_velocity, direction)
	
	SetHamParamVector(4, Float:{0.0, 0.0, 0.0})
	
	return HAM_IGNORED;
}

public start_action(taskid)
{
	new id = taskid - start_launcher
	new ent = find_ent_by_owner(-1, "weapon_ak47", id)
	engclient_cmd(id, "weapon_ak47")
	emessage_begin(MSG_ONE, get_user_msgid("CurWeapon"), _, id)
	ewrite_byte(1) // active
	ewrite_byte(CSW_AK47) // weapon
	ewrite_byte(cs_get_weapon_ammo(ent)) // clip
	emessage_end()
	set_pev(id, pev_viewmodel2, V_MODEL_2)
	SendWeaponAnim(id, animation_idle)
	set_task(0.5, "start_reload_launcher", id + reload_type_2)
}

public end_action(taskid)
{
	new id = taskid + start_launcher
	new ent = find_ent_by_owner(-1, "weapon_ak47", id)
	engclient_cmd(id, "weapon_ak47")
	emessage_begin(MSG_ONE, get_user_msgid("CurWeapon"), _, id)
	ewrite_byte(1) // active
	ewrite_byte(CSW_AK47) // weapon
	ewrite_byte(cs_get_weapon_ammo(ent)) // clip
	emessage_end()
	set_pev(id, pev_viewmodel2, V_MODEL)
	SendWeaponAnim(id, 0)
}		
public fw_nade_touch(Nade, Other)
{
	if(!pev_valid(Nade))
		return
	static Float:origin[3]
	pev(Nade, pev_origin, origin)
	engfunc ( EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
	write_byte (TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, origin[0]) // Position X
	engfunc(EngFunc_WriteCoord, origin[1]) // Position Y
	engfunc(EngFunc_WriteCoord, origin[2]) // Position Z
	write_short (xplode) // Sprite index
	write_byte (40) // Scale
	write_byte (30) // Frame rate
	write_byte (0) // Flags
	message_end ()

	
	
	static owner  ; owner = pev(Nade, pev_owner)	
	
	for(new i = 1; i < get_maxplayers();i++)
	{
		if (!is_user_alive(i))
		      continue
		if (get_user_godmode(i) == 1)
			continue
		if (!zp_get_user_zombie(i) || zp_get_user_survivor(i))
			continue
		static Float:origin2 [3]
		pev(i, pev_origin, origin2)
		
		static Float:distance_f ; distance_f = get_distance_f(origin, origin2)
		static distance ; distance = floatround(distance_f)
		static radius ; radius = nade_radius
		if ( distance <= radius )
		{
			
			static maxdmg ; maxdmg = nade_damage
			new Damage
			Damage = maxdmg - floatround(floatmul(float(maxdmg), floatdiv(float(distance), float(radius))))
			ExecuteHamB(Ham_TakeDamage, i, "grenade", owner,Damage, DMG_BLAST)
			new health = get_user_health(i)
			if(health - Damage >= 1)
			{
				set_user_health(i, health - Damage) 
				make_knockback(i, origin, nade_knockback * Damage)
			}
			else
			{
				death_message(owner,i,"weapon_ak47",1)
				origin2 [ 2 ] -= 45.0
			}
		}
	}
	remove_entity(Nade)
}
public death_message(Killer, Victim, const Weapon[], ScoreBoard)
{
	set_msg_block(g_msgDeathMsg, BLOCK_SET)
	ExecuteHamB(Ham_Killed, Victim, Killer, 2)
	set_msg_block(g_msgDeathMsg, BLOCK_NOT)
	
	make_deathmsg(Killer, Victim, 0, Weapon)
	zp_set_user_ammo_packs(Killer, zp_get_user_ammo_packs(Killer) + 2)
	if ( ScoreBoard )
	{
		message_begin(MSG_BROADCAST, g_msgScoreInfo)
		write_byte( Killer ) // id
		write_short(pev(Killer, pev_frags)) // frags
		write_short(cs_get_user_deaths(Killer)) // deaths
		write_short(0) // class?
		write_short(get_user_team(Killer)) // team
		message_end()
		
		message_begin(MSG_BROADCAST, g_msgScoreInfo)
		write_byte(Victim) // id
		write_short(pev(Victim, pev_frags)) // frags
		write_short(cs_get_user_deaths(Victim)) // deaths
		write_short(0) // class?
		write_short(get_user_team(Victim)) // team
		message_end()
	}
}

stock make_knockback (Victim, Float:origin [3], Float:maxspeed )
{
	new Float:fVelocity[3];
	entity_set_vector( Victim, EV_VEC_velocity, fVelocity);
	kickback (Victim, origin, maxspeed, fVelocity)
	return (1);
}

stock kickback( ent, Float:fOrigin[3], Float:fSpeed, Float:fVelocity[3])
{
	new Float:fEntOrigin[3];
	entity_get_vector( ent, EV_VEC_origin, fEntOrigin );
	new Float:fDistance[3];
	fDistance[0] = fEntOrigin[0] - fOrigin[0];
	fDistance[1] = fEntOrigin[1] - fOrigin[1];
	fDistance[2] = fEntOrigin[2] - fOrigin[2];
	new Float:fTime = (vector_distance( fEntOrigin,fOrigin ) / fSpeed);
	fVelocity[0] = fDistance[0] / fTime;
	fVelocity[1] = fDistance[1] / fTime;
	fVelocity[2] = fDistance[2] / fTime;

	return (fVelocity[0] && fVelocity[1] && fVelocity[2]);
}
stock drop_weapons(id, dropwhat)
{
     static weapons[32], num, i, weaponid
     num = 0
     get_user_weapons(id, weapons, num)
     
     for (i = 0; i < num; i++)
     {
          weaponid = weapons[i]
          
          if (dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM))
          {
               static wname[32]
               get_weaponname(weaponid, wname, sizeof wname - 1)
               engclient_cmd(id, "drop", wname)
          }
     }
}
stock show_trail(ent, red, green, blue)
{
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_BEAMFOLLOW) // TE id
	write_short(ent) // entity
	write_short(m_iTrail) // sprite
	write_byte(10) // life
	write_byte(10) // width
	write_byte(red) // r
	write_byte(green) // g
	write_byte(blue) // b
	write_byte(50) // brightness
	message_end()
}

stock launch_grenade(id)
{
	new Float:fOrigin[3], Float:fAngle[3], Float:fVelocity[3], ipOrigin[3]
	get_user_origin(id, ipOrigin, 1)
	IVecFVec(ipOrigin, fOrigin)
	pev(id, pev_v_angle, fAngle)
	if (g_ammo[id] < 1){
		SendWeaponAnim(id, animation_shootlast)
	}
	else if(g_ammo[id] >= 1)
	{
		SendWeaponAnim(id, random_num(3, 5))
	}
	new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	if (!ent) return FMRES_IGNORED
	cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
	set_pev(ent, pev_classname, "m203_nade")
	in_zoom[id] =  false
	if (get_pcvar_num(cvar_trail))
		show_trail(ent, 255, 255, 255)
	new Float:push[3], Float:pangles[3], Float:angles[3]
	pev(id, pev_punchangle, pangles)
	angles[0] = pangles[0] + random_float(0.0, 0.0)
	angles[1] = pangles[1] + random_float(-3.0, 3.0)
	angles[2] = pangles[2] + random_float(0.0, 0.0)
	pev(id,pev_punchangle,push)
	xs_vec_sub(push,angles,push)
	xs_vec_mul_scalar(push,random_float(1.2, 1.5),push)
	xs_vec_add(push,cl_pushangle[id],push)
	set_pev(id,pev_punchangle,push)
	//set_pev(id, pev_punchangle, {12.0,6.0,0.0})
	entity_set_model(ent, W_NADE)
	emit_sound(id, CHAN_ITEM, "weapons/svdex_shoot2.wav" ,1.0, ATTN_NORM, 0, PITCH_NORM)
	entity_set_origin(ent, fOrigin)
	entity_set_vector(ent, EV_VEC_angles, fAngle)
	new Float:MinBox[3] = {-1.0, -1.0, -1.0}
	new Float:MaxBox[3] = {1.0, 1.0, 1.0}
	entity_set_vector(ent, EV_VEC_mins, MinBox)
	entity_set_vector(ent, EV_VEC_maxs, MaxBox)
	set_pev(ent, pev_solid, SOLID_BBOX ) 
	entity_set_int(ent, EV_INT_movetype, MOVETYPE_BOUNCE)
	set_pev(ent, pev_gravity, 0.5)
	entity_set_edict(ent, EV_ENT_owner, id)
	VelocityByAim(id, 2000, fVelocity)
	entity_set_vector(ent, EV_VEC_velocity, fVelocity)
	SendWeaponAnim(id, animation_shoot)
	set_pdata_float(id, m_flNextAttack, nade_reload, 4)
	g_m203_loaded[id] = false
	i_reload_launcher[id] = true
	if (g_ammo[id] > 0)
		set_task(nade_reload, "active_launcher", id + active_my_grenade)
	return FMRES_IGNORED
}

public active_launcher(taskid)
{
	new id = taskid - active_my_grenade
	new ent = fm_find_ent_by_owner(-1,"weapon_ak47", id)
	new fInReload = get_pdata_int(ent, m_fInReload, 4)
	if (!is_user_alive(id) || !g_has_mg3[id] || !in_launcher[id] || g_ammo[id] < 1 || !i_reload_launcher[id] || fInReload || g_m203_loaded[id])
		return 
	g_m203_loaded[id] = true
	g_ammo[id]--
	i_reload_launcher[id] = false
	zoom_delay[id] = get_gametime()
}
public zp_round_started(gamemode, id)
{	
	if (gamemode != MODE_NEMESIS && gamemode != MODE_SURVIVOR)
	{
		g_round_ssvd = 0
		remove_task(TASK_CHOOSE_HERO)
		set_task(0.5, "choose_a_hero", TASK_CHOOSE_HERO, _, _, "b")
	}
}

public choose_a_hero()
{
	new id
	while (!round_end  && g_round_ssvd == 0)
	{
		id = random_num(1, get_maxplayers())
		if (is_user_connected(id) && is_user_alive(id) && !zp_get_user_zombie(id))
		{
			g_round_ssvd++
			g_has_mg3[id] = true
			give_item(id,"weapon_ak47")
			new iWep2 = find_ent_by_owner(-1,"weapon_ak47",id)
			if( iWep2 > 0 )
			{
				cs_set_weapon_ammo( iWep2, get_pcvar_num(cvar_clip_mg3) )
				cs_set_user_bpammo (id, CSW_AK47, get_pcvar_num(cvar_mg3_ammo))
			}
			
			new name[32]
			get_user_name(id, name, 31)
			
			for (new i = 1; i <= get_maxplayers(); i++)
			{
				if (!is_user_connected(i))
					continue;
				
				if (i == id)
					client_print(i, print_center, "[ZP] ban da mua SVD-SVDex")
				else 
					client_print(i, print_center, "[ZP] %s da mua SVDex- Zombie coi chung do", name)
			}
		}
	}
	
	if (round_end || g_round_ssvd > 0)
		remove_task(TASK_CHOOSE_HERO)
}

stock get_alive_players()
{
	new alive_players = 0
	for (new i = 1; i <= get_maxplayers(); i++)
	{
		if (is_user_connected(i) && is_user_alive(i))
			alive_players++
	}
	
	return alive_players;
}
stock set_user_model_index(id, value)
{
	set_pdata_int(id, OFFSET_MODELINDEX, value, OFFSET_LINUX)
}
public start_reload_launcher(taskid)
{
	new id = taskid - reload_type_2
	new ent = fm_find_ent_by_owner(-1, "weapon_ak47", id)
	new fInReload = get_pdata_int(ent, m_fInReload, 4)
	if (!is_user_alive(id) || !g_has_mg3[id] || !in_launcher[id] || g_ammo[id] < 1 || !i_reload_launcher[id] || fInReload || g_m203_loaded[id])
		return 
	SendWeaponAnim(id, animation_reload)
	set_pdata_int(ent, m_flNextPrimaryAttack,3, 4)
	client_cmd(id, "spk weapons/greload.wav")
	set_task(nade_reload, "active_launcher", id + active_my_grenade)
}

/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/
 
Chỉnh sửa cuối:
Back
Top