Skip to content

Commit a15e82a

Browse files
authored
pawn lang (#1078)
1 parent 28e5af1 commit a15e82a

File tree

7 files changed

+142
-142
lines changed

7 files changed

+142
-142
lines changed

docs/tutorials/AdvancedStructures.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ title: "Advanced Structures"
88

99
This example shows how to find an empty slot in an array using standard coding practices.
1010

11-
```c
11+
```pawn
1212
new
1313
gMyArray[10];
1414
@@ -27,7 +27,7 @@ stock FindEmptySlot()
2727

2828
This basic example assumes an array slot is empty if its value is 0. The loop loops through all values in the array (could also be done with a constant) as long as the values are not 0. When it reaches one which is 0 the while condition will fail and the loop ends without using a break as is common practice but discouraged in situations like this. This function also returns -1 if a free slot is not found, which would need to be checked at the other end. More commonly you would use the found id straight away:
2929

30-
```c
30+
```pawn
3131
MyFunction()
3232
{
3333
new
@@ -59,19 +59,19 @@ Example:
5959

6060
Say you have the following array:
6161

62-
```c
62+
```pawn
6363
3, 1, 64, 2, 4, 786, 2, 9
6464
```
6565

6666
If you wanted to sort the array you would end up with:
6767

68-
```c
68+
```pawn
6969
1, 2, 2, 3, 4, 9, 64, 786
7070
```
7171

7272
If however you wanted to leave the data in the original order but still know the numbers in order for some reason (it's just an example), you have a problem, how are you meant to have numbers in two orders at once? This would be a good use of lists. To construct a list from this data you would need to make the array into a 2d array, where the second dimension was 2 cells big, the first dimension containing the original number, the other containing the index of the next largest number. You would also need a separate variable to hold the index of the lowest number, so your new array would look like:
7373

74-
```c
74+
```pawn
7575
start = 1
7676
3, 1, 64, 2, 4, 786, 2, 9
7777
4, 3, 5, 6, 7, -1, 0, 2
@@ -81,7 +81,7 @@ The next index associated with 786 is -1, this is an invalid array index and ind
8181

8282
The other advantage of this method of sorting the numbers is adding more numbers is a lot faster. If you wanted to add another number 3 to the sorted array you would need to first shift at least 4 numbers one slot to the right to make space, not terrible here but very slow in larger arrays. With the list version you could just append the 3 to the end of the array and modify a single value in the list;
8383

84-
```c
84+
```pawn
8585
start = 1
8686
3, 1, 64, 2, 4, 786, 2, 9, 3
8787
8, 3, 5, 6, 7, -1, 0, 2, 4
@@ -90,7 +90,7 @@ start = 1
9090

9191
None of the other numbers have moved so none of the other indexes need updating, just make the next lowest number point to the new number and make the new number point the number the next lowest used to be pointing to. Removing a value is even easier:
9292

93-
```c
93+
```pawn
9494
start = 1
9595
3, 1, 64, X, 4, 786, 2, 9, 3
9696
8, 6, 5, 6, 7, -1, 0, 2, 4
@@ -103,7 +103,7 @@ Here the first 2 has been removed and the number which pointed to that number (t
103103

104104
The lists in the examples above were just basic single lists, you can also have double lists where every value points to the next value and the last value, these tend to have a pointer to the end of the list too to go backwards (e.g. to get the numbers in descending order):
105105

106-
```c
106+
```pawn
107107
start = 1
108108
end = 5
109109
value: 3, 1, 64, 2, 4, 786, 2, 9, 3
@@ -113,15 +113,15 @@ last: 6, -1, 7, 1, 8, 2, 3, 4, 0
113113

114114
You have to be careful with these, especially when you have more than one of any value, that the last pointer points to the number who's next pointer goes straight back again, e.g this is wrong:
115115

116-
```c
116+
```pawn
117117
2, 3, 3
118118
1, 2, -1
119119
-1, 2, 0
120120
```
121121

122122
The 2's next pointer points to the 3 in slot one, but that 3's last pointer doesn't go back to the two, both lists are in order on their own (as the two threes can be either way round) but together they are wrong, the correct version would be:
123123

124-
```c
124+
```pawn
125125
2, 3, 3
126126
1, 2, -1
127127
-1, 0, 2
@@ -131,7 +131,7 @@ Both of those lists start and end on the end two numbers, the back list in the w
131131

132132
The other type of list is the looping one where the last value points back to the first. The obvious advantage to this is that you can get to any value from any other value without knowing in advance whether the target is before or after the start point, you just need to be careful not to get into an infinite loop as there's no explicit -1 end point. These lists do still have start points. You can also do double looping lists where you have a next and last list, both of which loop round:
133133

134-
```c
134+
```pawn
135135
start = 1
136136
end = 5
137137
3, 1, 64, 2, 4, 786, 2, 9, 3
@@ -143,7 +143,7 @@ end = 5
143143

144144
Mixed lists are arrays containing multiple lists at once. An example could be an array of values, sorted by a list, with another list linking all unused slots so you know where you can add a new value. Example (X means unused (free) slot):
145145

146-
```c
146+
```pawn
147147
sortedStart = 3
148148
unusedStart = 1
149149
value: 34, X, X, 6, 34, 46, X, 54, 23, 25, X, 75, X, 45
@@ -153,7 +153,7 @@ free: 2, 6, 10, 12, -1
153153

154154
Obviously the two lists never interact so both can use the same slot for their next value:
155155

156-
```c
156+
```pawn
157157
sortedStart = 3
158158
unusedStart = 1
159159
value: 34, X, X, 6, 34, 46, X, 54, 23, 25, X, 75, X, 45
@@ -166,7 +166,7 @@ Before you start the code you need to decide what sort of list is best suited fo
166166

167167
This example shows how to write code for a list sorted numerically ascending.
168168

169-
```c
169+
```pawn
170170
#define NUMBER_OF_VALUES (10)
171171
172172
enum E_DATA_LIST
@@ -279,7 +279,7 @@ Binary trees are a very fast method of searching for data in an array by using a
279279

280280
**Example**
281281

282-
```c
282+
```pawn
283283
1 2 5 6 7 9 12 14 17 19 23 25 28 33 38
284284
```
285285

docs/tutorials/MenuGuide.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ Menus look very complicated and difficult to script for the most players, althou
1212

1313
First we have to create a menu. The prefix before is `Menu:` this makes the variable the correct [tag](../scripting/language/Tags). There are different types for different uses such as `Float:` `bool:` `Text3D:` etc. Write the following code near the top of your script:
1414

15-
```c
15+
```pawn
1616
new Menu:teleportmenu;
1717
```
1818

1919
Okay, we created the variable to store the menu. Now we have to create the menu and assign the variable we created to the menu. Type this into `OnGameModeInit`:
2020

21-
```c
21+
```pawn
2222
teleportmenu = CreateMenu("Teleportmenu", 2, 200.0, 100.0, 150.0, 150.0);
2323
```
2424

@@ -39,7 +39,7 @@ Now a bit of an explanation about the [CreateMenu](../scripting/functions/Create
3939

4040
Ok, now we've got the Menu, but we need some items, under which you can choose in the menu. You add them underneath the `CreateMenu` that we made earlier.
4141

42-
```c
42+
```pawn
4343
AddMenuItem(teleportmenu, 0, "LS");
4444
AddMenuItem(teleportmenu, 0, "LS");
4545
AddMenuItem(teleportmenu, 0, "SF");
@@ -66,15 +66,15 @@ The explanation for [AddMenuItem](../scripting/functions/AddMenuItem):
6666

6767
Okay, now that we have created a full menu with items what should happen when you choose an item? In our example we want to make a teleportmenu, so we should get teleported to the position we choose. When a player selects an item on a menu the script calls the callback [OnPlayerSelectedMenuRow](../scripting/callbacks/OnPlayerSelectedMenuRow). The best way to do it is to do it with a switch, this is like several if statements to check if a variable is worth certain values. But first we only want these effects for the menu we want so we need to create a variable that holds what menu the player is looking at, this is done with `GetPlayerMenu`:
6868

69-
```c
69+
```pawn
7070
new Menu:CurrentMenu = GetPlayerMenu(playerid);
7171
```
7272

7373
Now, when somebody selects something on the menu, their menuid will be saved in `CurrentMenu`.
7474

7575
Now we have to check that the menu they selected on is the menu we want:
7676

77-
```c
77+
```pawn
7878
public OnPlayerSelectedMenuRow(playerid, row)
7979
{
8080
new Menu:CurrentMenu = GetPlayerMenu(playerid);
@@ -88,7 +88,7 @@ public OnPlayerSelectedMenuRow(playerid, row)
8888

8989
Now in between these brackets is where the `switch` is, this checks what item the player selected or `row` this can be done with `if` statements checking what `row` it is, but the `switch` is a much simpler way of writing it.
9090

91-
```c
91+
```pawn
9292
if(CurrentMenu == teleportmenu)
9393
{
9494
switch(row)
@@ -137,7 +137,7 @@ if(CurrentMenu == teleportmenu)
137137

138138
Now we need a command to show the menu. This is the easiest step. Just a comparison with `strcmp` and a `ShowMenuForPlayer`. This is done in `OnPlayerCommandText`. Or, if you have a command processor already, use that instead to call `ShowMenuForPlayer`.
139139

140-
```c
140+
```pawn
141141
if(strcmp(cmdtext, "/teleport", true) == 0)
142142
{
143143
ShowMenuForPlayer(teleportmenu,playerid);

docs/tutorials/PickupGuide.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A short tutorial that describes how to use pickups.
88

99
The first thing to be done when creating pickups is creating a place to store their ID. This will be done in a global variable so it can be set when you create the pickup and read when you pick up a pickup, calling a callback with the ID of the pickup you picked up. For this example we will use the name "gMyPickup".
1010

11-
```c
11+
```pawn
1212
new gMyPickup;
1313
```
1414

@@ -38,7 +38,7 @@ Pickups are most commonly created when the script starts, in [OnGameModeInit](..
3838

3939
So here is the code to create our pickup, and store the ID in 'gMyPickup':
4040

41-
```c
41+
```pawn
4242
gMyPickup = CreatePickup(1274, 2, 2491.7900, -1668.1653, 13.3438, -1);
4343
```
4444

@@ -50,7 +50,7 @@ Some pickup types are designed to work automatically, so there is no need to do
5050

5151
When a player picks up our new pickup, we want to give them $100, to do this first we need to check that they have picked up our dollar pickup and not a different one. When we've done that, we can give them the $100:
5252

53-
```c
53+
```pawn
5454
public OnPlayerPickUpPickup(playerid, pickupid)
5555
{
5656
// Check that the pickup ID of the pickup they picked up is gMyPickup

docs/tutorials/colorfix.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ descripion: A basic script to add more player colours.
55

66
This tutorial is to be used with [GetPlayerColor](../scripting/functions/GetPlayerColor), if you do not use [SetPlayerColor](../scripting/functions/SetPlayerColor) in your script when players connect.
77

8-
```c
8+
```pawn
99
new PlayerColors[] = {
1010
0xFF8C13FF,0xC715FFFF,0x20B2AAFF,0xDC143CFF,0x6495EDFF,0xf0e68cFF,0x778899FF,0xFF1493FF,0xF4A460FF,0xEE82EEFF,
1111
0xFFD720FF,0x8b4513FF,0x4949A0FF,0x148b8bFF,0x14ff7fFF,0x556b2fFF,0x0FD9FAFF,0x10DC29FF,0x534081FF,0x0495CDFF,
@@ -24,15 +24,15 @@ First place that at the top of your script.
2424

2525
Next place this under the OnPlayerConnect callback:
2626

27-
```c
27+
```pawn
2828
SetPlayerColor(playerid, PlayerColors[playerid % sizeof PlayerColors]);
2929
```
3030

3131
Now [GetPlayerColor](../scripting/functions/GetPlayerColor) will work!
3232

3333
For new versions of SA-MP you can add this array:
3434

35-
```c
35+
```pawn
3636
new PlayerRainbowColors[511] = {
3737
/*OKStyle*/ 0x000022FF, 0x000044FF, 0x000066FF, 0x000088FF, 0x0000AAFF, 0x0000CCFF, 0x0000EEFF,
3838
0x002200FF, 0x002222FF, 0x002244FF, 0x002266FF, 0x002288FF, 0x0022AAFF, 0x0022CCFF, 0x0022EEFF,

docs/tutorials/cooldowns.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ First I'll example the _bad_ way of doing a cooldown by using `SetTimer` to upda
1111

1212
Say for example you have a specific action that can only be performed once every so many seconds, I see a lot of people (including Southclaws, many years ago) doing something like this:
1313

14-
```c
14+
```pawn
1515
static bool:IsPlayerAllowedToDoThing[MAX_PLAYERS];
1616
1717
OnPlayerInteractWithServer(playerid)
@@ -58,7 +58,7 @@ Now this is all well and good, it works, the player won't be able to do that thi
5858

5959
Take another example here, this is a stopwatch that measures how long it takes for a player to do a simple point to point race:
6060

61-
```c
61+
```pawn
6262
static
6363
StopWatchTimerID[MAX_PLAYERS],
6464
StopWatchTotalTime[MAX_PLAYERS];
@@ -96,7 +96,7 @@ If you call either of these functions at two different times, and subtract the f
9696

9797
### A Cooldown
9898

99-
```c
99+
```pawn
100100
static PlayerAllowedTick[MAX_PLAYERS];
101101
102102
OnPlayerInteractWithServer(playerid)
@@ -121,7 +121,7 @@ OnPlayerInteractWithServer(playerid)
121121

122122
Or, alternatively the `gettime()` version:
123123

124-
```c
124+
```pawn
125125
static PlayerAllowedSeconds[MAX_PLAYERS];
126126
127127
OnPlayerInteractWithServer(playerid)
@@ -148,7 +148,7 @@ There's a lot less code there, no need for a public function or a timer. If you
148148

149149
(I'm using SendFormatMessage in this example)
150150

151-
```c
151+
```pawn
152152
SendFormatMessage(
153153
playerid,
154154
-1,
@@ -163,7 +163,7 @@ That's a very basic example, it would be better to convert that MS value into a
163163

164164
Hopefully you can see how powerful this is to get intervals between events, let's look at another example
165165

166-
```c
166+
```pawn
167167
static Stopwatch[MAX_PLAYERS];
168168
169169
StartPlayerRace(playerid)
@@ -190,13 +190,13 @@ In this example, the tick count is saved to the player variable when he starts t
190190

191191
Now lets break the code down a bit.
192192

193-
```c
193+
```pawn
194194
new Stopwatch[MAX_PLAYERS];
195195
```
196196

197197
This is a global variable, we need to use this so we can save the tick count and retrieve the value at another point in time (in other words, use it in another function, later on)
198198

199-
```c
199+
```pawn
200200
StartPlayerRace(playerid)
201201
{
202202
Stopwatch[playerid] = GetTickCount();
@@ -207,7 +207,7 @@ This is when the player starts the race, the tick count of now is recorded, if t
207207

208208
Okay, we now have that player's variable set at 60,000, now he finishes the race 1 minute 40 seconds later:
209209

210-
```c
210+
```pawn
211211
OnPlayerFinishRace(playerid)
212212
{
213213
new

docs/tutorials/perplayervariablesystem.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The functions for setting and retrieving the player variables are:
4343
- [GetPVarFloat](../scripting/functions/GetPVarFloat) Get the previously set float from a player variable.
4444
- [DeletePVar](../scripting/functions/DeletePVar) Delete a player variable.
4545

46-
```c
46+
```pawn
4747
#define PLAYER_VARTYPE_NONE (0)
4848
#define PLAYER_VARTYPE_INT (1)
4949
#define PLAYER_VARTYPE_STRING (2)

0 commit comments

Comments
 (0)