-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpool.pwn
198 lines (127 loc) · 6.13 KB
/
pool.pwn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include <a_samp>
#include <physics>
#define MAX_POOL 99
new POOL_COUNT = 0;
enum POOL_MODEL{
ID,
TEXT[100],
Float:POS[3],
TABLE,
Text3D:LABEL,
BALLS[16]
};
new POOL[MAX_POOL][POOL_MODEL];
public OnFilterScriptExit(){ return 1; }
public OnFilterScriptInit(){
print("[pool - u4bi]");
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[]){
if (strcmp(cmdtext, "/pool", true) == 0){
createPoolTable(playerid);
SendClientMessage(playerid, -1, "success pool table");
return 1;
}
if (strcmp(cmdtext, "/shot", true) == 0){
new
speed = 2,
Float: angle;
GetPlayerFacingAngle(playerid, angle);
PHY_SetObjectVelocity(POOL[0][BALLS][0], speed * floatsin( -angle, degrees), speed * floatcos( -angle, degrees));
return 1;
}
return 0;
}
public OnPlayerConnect(playerid){
return 1;
}
public PHY_OnObjectUpdate(objectid){
new
poolid = 0; // setup pool table
for(new i = 0; i < GetMaxPlayers(); i++){
if( IsInBall(objectid , POOL[poolid][POS][0] + 0.955, POOL[poolid][POS][1] + 0.510, POOL[poolid][POS][2] -0.045,0.10) ||
IsInBall(objectid , POOL[poolid][POS][0] + 0.955, POOL[poolid][POS][1] - 0.510, POOL[poolid][POS][2] -0.045,0.10) ||
IsInBall(objectid , POOL[poolid][POS][0] + 0.000, POOL[poolid][POS][1] + 0.550, POOL[poolid][POS][2] -0.045,0.10) ||
IsInBall(objectid , POOL[poolid][POS][0] + 0.000, POOL[poolid][POS][1] - 0.550, POOL[poolid][POS][2] -0.045,0.10) ||
IsInBall(objectid , POOL[poolid][POS][0] - 0.955, POOL[poolid][POS][1] + 0.510, POOL[poolid][POS][2] -0.045,0.10) ||
IsInBall(objectid , POOL[poolid][POS][0] - 0.955, POOL[poolid][POS][1] - 0.510, POOL[poolid][POS][2] -0.045,0.10))
{
new
str[50];
for(new j = 0; j < 16; j++){
if(objectid == POOL[poolid][BALLS][j]){
new type[6];
if(POOL[poolid][BALLS][j] > 8) format(type ,sizeof(type), "stripe");
else format(type ,sizeof(type), "solid");
format(str ,sizeof(str), "delete object id : number %d %s ball", POOL[poolid][BALLS][j], type);
SendClientMessage(i, -1, str);
DestroyObject(POOL[poolid][BALLS][j]);
PHY_DeleteObject(POOL[poolid][BALLS][j]);
}
}
}
}
return 1;
}
stock createPoolTable(playerid){
new
Float:pos[3];
// table id
POOL[POOL_COUNT][ID] = ( POOL_COUNT + 1);
// table position
GetPlayerFrontPos(playerid, pos[0], pos[1], pos[2] , 1.5);
POOL[POOL_COUNT][POS] = pos;
// balls object array
POOL[POOL_COUNT][BALLS][0] = CreateObject(3003, pos[0] + 0.5, pos[1], pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][1] = CreateObject(3002, pos[0] - 0.3, pos[1], pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][2] = CreateObject(3100, pos[0] - 0.525, pos[1] - 0.040, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][3] = CreateObject(3101, pos[0] - 0.375, pos[1] + 0.044, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][4] = CreateObject(3102, pos[0] - 0.600, pos[1] + 0.079, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][5] = CreateObject(3103, pos[0] - 0.525, pos[1] + 0.118, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][6] = CreateObject(3104, pos[0] - 0.600, pos[1] - 0.157, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][7] = CreateObject(3105, pos[0] - 0.450, pos[1] - 0.079, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][8] = CreateObject(3106, pos[0] - 0.450, pos[1], pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][9] = CreateObject(2995, pos[0] - 0.375, pos[1] - 0.044, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][10] = CreateObject(2996, pos[0] - 0.450, pos[1] + 0.079, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][11] = CreateObject(2997, pos[0] - 0.525, pos[1] - 0.118, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][12] = CreateObject(2998, pos[0] - 0.600, pos[1] - 0.079, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][13] = CreateObject(2999, pos[0] - 0.600, pos[1], pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][14] = CreateObject(3000, pos[0] - 0.600, pos[1] + 0.157, pos[2] -0.045 , 0, 0, 0);
POOL[POOL_COUNT][BALLS][15] = CreateObject(3001, pos[0] - 0.525, pos[1] + 0.040, pos[2] -0.045 , 0, 0, 0);
// table object
POOL[POOL_COUNT][TABLE] = CreateObject(2964, pos[0], pos[1], pos[2] -1 , 0, 0, 0);
// 3d label object
format(POOL[POOL_COUNT][TEXT], 100, "pool test");
POOL[POOL_COUNT][LABEL] = Create3DTextLabel(POOL[POOL_COUNT][TEXT], -1, POOL[POOL_COUNT][POS][0], POOL[POOL_COUNT][POS][1], POOL[POOL_COUNT][POS][2], 10.0, 0, 0);
// setup physics boundary
PHY_CreateArea( pos[0] - 1.000, pos[1] - 0.500, pos[0] + 1.000, pos[1] + 0.500,0.6,FLOAT_NEG_INFINITY);
for(new i = 0; i < 16; i++){
// setup physics balls
PHY_InitObject( POOL[POOL_COUNT][BALLS][i] , 3003, _, _, PHY_MODE_2D);
PHY_SetObjectFriction( POOL[POOL_COUNT][BALLS][i] , 0.08);
PHY_RollObject( POOL[POOL_COUNT][BALLS][i] ,1);
}
// counting table
POOL_COUNT ++;
}
stock GetPlayerFrontPos(playerid,&Float:x,&Float:y,&Float:z,Float:distance=0.0){
new
Float:px,
Float:py,
Float:pz,
Float:pa;
GetPlayerPos(playerid,px,py,pz);
GetPlayerFacingAngle(playerid,pa);
x = px+(floatsin(-pa, degrees)*distance);
y = py+(floatcos(-pa, degrees)*distance);
z = pz;
}
stock IsInBall(objectid,Float:x,Float:y,Float:z,Float:radius){
new
Float:pos[3],
Float:dis;
GetObjectPos(objectid, pos[0], pos[1], pos[2]);
dis = floatsqroot(floatpower(floatabs(floatsub(x, pos[0] )), 2)+ floatpower(floatabs(floatsub(y, pos[1] )), 2)+ floatpower(floatabs(floatsub(z, pos[2] )), 2));
if(dis < radius) return 1;
return 0;
}