Skip to content

Commit 00f21e6

Browse files
committed
Pawn 3.2.3664 code with samp_compatible patches applied
0 parents  commit 00f21e6

File tree

152 files changed

+59559
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+59559
-0
lines changed

EXAMPLES/argument.p

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <args>
2+
3+
main()
4+
{
5+
printf "Argument count = %d\n", argcount()
6+
7+
new opt[100]
8+
for (new index = 0; argindex(index, opt); index++)
9+
printf "Argument %d = %s\n", index, opt
10+
}

EXAMPLES/c2f.p

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <rational>
2+
3+
main()
4+
{
5+
new Rational: Celsius
6+
new Rational: Fahrenheit
7+
8+
print "Celsius\t Fahrenheit\n"
9+
for (Celsius = 5; Celsius <= 25; Celsius++)
10+
{
11+
Fahrenheit = (Celsius * 1.8) + 32
12+
printf "%r \t %r\n", Celsius, Fahrenheit
13+
}
14+
}

EXAMPLES/capt.p

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
bool: ispacked(string[])
2+
return bool: (string[0] > charmax)
3+
4+
my_strlen(string[])
5+
{
6+
new len = 0
7+
if (ispacked(string))
8+
while (string{len} != EOS) /* get character from pack */
9+
++len
10+
else
11+
while (string[len] != EOS) /* get cell */
12+
++len
13+
return len
14+
}
15+
16+
strupper(string[])
17+
{
18+
assert ispacked(string)
19+
20+
for (new i=0; string{i} != EOS; ++i)
21+
string{i} = toupper(string{i})
22+
}
23+
24+
main()
25+
{
26+
new s[10]
27+
28+
for (new i = 0; i < 5; i++)
29+
s{i}=i+'a'
30+
s{5}=EOS
31+
32+
printf("String is %s\n", ispacked(s) ? "packed" : "unpacked")
33+
printf("String length is %d\n", my_strlen(s))
34+
printf("Original: %s\n", s)
35+
strupper(s)
36+
printf("Upper case: %s\n", s)
37+
}

EXAMPLES/cards.p

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
enum _: CardSuits
2+
{
3+
Clubs,
4+
Diamonds,
5+
Hearts,
6+
Spades,
7+
}
8+
9+
const CardTypes = 13
10+
const TotalCards = CardSuits * CardTypes
11+
12+
enum CardDescription
13+
{
14+
CardName[10 char],
15+
CardSuit,
16+
CardValue,
17+
}
18+
19+
new CardNames[CardTypes][] = { !"Ace", !"Two", !"Three", !"Four", !"Five",
20+
!"Six", !"Seven", !"Eight", !"Nine", !"Ten",
21+
!"Jack", !"Queen", !"King" }
22+
new CardValues[CardTypes] = { 11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10 }
23+
24+
main()
25+
{
26+
new Cards[ TotalCards ][ CardDescription ]
27+
28+
/* fill in the cards */
29+
for (new suit = 0; suit < CardSuits; suit++)
30+
{
31+
for (new card = 0; card < CardTypes; card++)
32+
{
33+
new index = suit*CardTypes + card
34+
strpack Cards[ index ][CardName], CardNames[ card ]
35+
Cards[ index ][ CardSuit ] = suit
36+
Cards[ index ][ CardValue ] = CardValues[ card ]
37+
}
38+
}
39+
40+
/* shuffle the cards (swap an arbitrary number of randomly selected cards) */
41+
for (new iter = 0; iter < 200; iter++)
42+
{
43+
new first = random(TotalCards)
44+
new second = random(TotalCards)
45+
new TempCard[ CardDescription ]
46+
TempCard = Cards[first]
47+
Cards[ first ] = Cards[ second ]
48+
Cards[ second ] = TempCard
49+
}
50+
51+
/* print the cards with a subroutine */
52+
for (new card = 0; card < TotalCards; card++)
53+
PrintCard Cards[ card]
54+
}
55+
56+
PrintCard( TheCard[ CardDescription ] )
57+
{
58+
new SuitNames[ CardSuits ][] = { !"Clubs", !"Diamonds",
59+
!"Hearts", !"Spades" }
60+
61+
printf !"%s of %s (valued %d)\n",
62+
TheCard[ CardName ],
63+
SuitNames[ TheCard[ CardSuit ] ],
64+
TheCard[ CardValue ]
65+
}

EXAMPLES/chat.p

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <datagram>
2+
3+
@receivestring(const message[], const source[])
4+
printf "[%s] says: %s\n", source, message
5+
6+
@keypressed(key)
7+
{
8+
static string[100 char]
9+
static index
10+
11+
if (key == '\e')
12+
exit /* quit on 'Esc' key */
13+
14+
echo key
15+
if (key == '\r' || key == '\n' || index char == sizeof string)
16+
{
17+
string{index} = '\0' /* terminate string */
18+
sendstring string
19+
index = 0
20+
string[index] = '\0'
21+
}
22+
else
23+
string{index++} = key
24+
}
25+
26+
echo(key)
27+
{
28+
new string[2 char] = { 0 }
29+
string{0} = key == '\r' ? '\n' : key
30+
printf string
31+
}

EXAMPLES/comment.p

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* parse C comments interactively, using events and a state machine */
2+
3+
main()
4+
state plain
5+
6+
@keypressed(key) <plain>
7+
{
8+
state (key == '/') slash
9+
if (key != '/')
10+
echo key
11+
}
12+
13+
@keypressed(key) <slash>
14+
{
15+
state (key != '/') plain
16+
state (key == '*') comment
17+
echo '/' /* print '/' held back from previous state */
18+
if (key != '/')
19+
echo key
20+
}
21+
22+
@keypressed(key) <comment>
23+
{
24+
echo key
25+
state (key == '*') star
26+
}
27+
28+
@keypressed(key) <star>
29+
{
30+
echo key
31+
state (key != '*') comment
32+
state (key == '/') plain
33+
}
34+
35+
echo(key) <plain, slash>
36+
printchar key, yellow
37+
38+
echo(key) <comment, star>
39+
printchar key, green
40+
41+
printchar(ch, colour)
42+
{
43+
setattr .foreground = colour
44+
printf "%c", ch
45+
}

EXAMPLES/faculty.p

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Calculation of the faculty of a value */
2+
3+
main()
4+
{
5+
print "Enter a value: "
6+
new v = getvalue()
7+
new f = faculty(v)
8+
printf "The faculty of %d is %d\n", v, f
9+
}
10+
11+
faculty(n)
12+
{
13+
assert n >= 0
14+
15+
new result = 1
16+
while (n > 0)
17+
result *= n--
18+
19+
return result
20+
}

EXAMPLES/fib.p

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* Calculation of Fibonacci numbers by iteration */
2+
3+
main()
4+
{
5+
print "Enter a value: "
6+
new v = getvalue()
7+
if (v > 0)
8+
printf "The value of Fibonacci number %d is %d\n",
9+
v, fibonacci(v)
10+
else
11+
printf "The Fibonacci number %d does not exist\n", v
12+
}
13+
14+
fibonacci(n)
15+
{
16+
assert n > 0
17+
18+
new a = 0, b = 1
19+
for (new i = 2; i < n; i++)
20+
{
21+
new c = a + b
22+
a = b
23+
b = c
24+
}
25+
return a + b
26+
}

EXAMPLES/gcd.p

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
The greatest common divisor of two values,
3+
using Euclides' algorithm .
4+
*/
5+
6+
main()
7+
{
8+
print "Input two values\n"
9+
new a = getvalue()
10+
new b = getvalue()
11+
while (a != b)
12+
if (a > b)
13+
a = a - b
14+
else
15+
b = b - a
16+
printf "The greatest common divisor is %d\n", a
17+
}

0 commit comments

Comments
 (0)