pool cleanup

This commit is contained in:
Lorenc Pekaj 2018-09-11 21:40:45 +10:00
parent 62da794996
commit 8c139b7033

View File

@ -8,7 +8,6 @@
/* ** Includes ** */
#include < YSI\y_hooks >
#include < physics >
#include < colandreas >
#include < progress2 >
/* ** Marcos ** */
@ -63,9 +62,17 @@ new
Iterator: pooltables < MAX_TABLES >
;
/* ** Forwards ** */
forward deleteBall ( poolid, ballid );
forward RestoreWeapon ( playerid );
forward RestoreCamera ( playerid, poolid );
forward OnPoolUpdate ( poolid );
forward PlayPoolSound ( poolid, soundid );
/* ** Hooks ** */
hook OnGameModeInit()
hook OnScriptInit( )
{
//stock CreatePoolTable(Float: X, Float: Y, Float: Z, Float: A = 0.0, interior = 0, world = 0)
@ -89,7 +96,6 @@ hook OnPlayerDisconnect(playerid, reason)
p_PoolScore[ playerid ] = 0;
}
return 1;
}
@ -105,7 +111,6 @@ hook OnPlayerConnect(playerid)
PlayerTextDrawSetOutline(playerid, g_PoolTextdraw[playerid], 1);
PlayerTextDrawSetProportional(playerid, g_PoolTextdraw[playerid], 1);
PlayerTextDrawSetSelectable(playerid, g_PoolTextdraw[playerid], 0);
return 1;
}
@ -199,7 +204,7 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
GetPlayerPos(playerid, X, Y, Z);
GetObjectPos(g_poolBallData[id] [E_BALL_OBJECT] [0], Xa, Ya, Za);
if (Is2DPointInRangeOfPoint(X, Y, Xa, Ya, 1.5) && Z < 999.5)
if (GetDistanceFromPointToPoint(X, Y, Xa, Ya) < 1.5 && Z < 999.5)
{
TogglePlayerControllable(playerid, false);
GetAngleToXY(Xa, Ya, X, Y, poolrot);
@ -282,26 +287,9 @@ stock getNearestPoolTable(playerid)
for (new i = 0; i != MAX_TABLES; i ++) if ( IsPlayerInRangeOfPoint( playerid, 2.5, g_poolTableData[ i] [ E_X ], g_poolTableData[ i] [ E_Y ], g_poolTableData[ i] [ E_Z ]) ) {
return i;
}
return -1;
}
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 CreatePoolTable(Float: X, Float: Y, Float: Z, Float: A = 0.0, interior = 0, world = 0)
{
new
@ -398,69 +386,42 @@ stock RotateXY(Float:xi, Float:yi, Float:angle, &Float:xf, &Float:yf)
stock CreateBalls( poolid )
{
new Float: x,
Float: y,
Float: pos[3],
Float: angle;
enum E_POOL_BALL_OFFSET_DATA {
E_MODEL_ID, Float: E_OFFSET_X, Float: E_OFFSET_Y
};
pos[0] = g_poolTableData[ poolid][ E_X ];
pos[1] = g_poolTableData[ poolid][ E_Y ];
pos[2] = g_poolTableData[ poolid][ E_Z ];
angle = g_poolTableData[ poolid][ E_ANGLE ];
static const
g_poolBallOffsetData[ ] [ E_POOL_BALL_OFFSET_DATA ] =
{
{ 3003, 0.5, 0.0 }, { 3002, -0.3, 0.0 }, { 3100, -0.525, -0.040 }, { 3101, -0.375, 0.044 },
{ 3102, -0.600, 0.079 }, { 3103, -0.525, 0.118 }, { 3104, -0.600, -0.157 }, { 3105, -0.450, -0.079 },
{ 3106, -0.450, 0.0 }, { 2995, -0.375, -0.044 }, { 2996, -0.450, 0.079 }, { 2997, -0.525, -0.118 },
{ 2998, -0.600, -0.079 }, { 2999, -0.600, 0.0 }, { 3000, -0.600, 0.157 }, { 3001, -0.525, 0.040 }
}
;
RotateXY(0.5, 0.0, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][0] = CreateObject(3003, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
new
Float: offset_x,
Float: offset_y;
RotateXY(-0.3, 0.0, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][1] = CreateObject(3002, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
for ( new i = 0; i < sizeof( g_poolBallOffsetData ); i ++ )
{
// get offset according to angle of table
RotateXY( g_poolBallOffsetData[ i ] [ E_OFFSET_X ], g_poolBallOffsetData[ i ] [ E_OFFSET_Y ], g_poolTableData[ poolid ] [ E_ANGLE ], offset_x, offset_y );
RotateXY(-0.525, - 0.040, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][2] = CreateObject(3100, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.375, 0.044, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][3] = CreateObject(3101, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.600, 0.079, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][4] = CreateObject(3102, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.525, 0.118, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][5] = CreateObject(3103, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.600, - 0.157, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][6] = CreateObject(3104, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.450, - 0.079, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][7] = CreateObject(3105, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.450, 0.0, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][8] = CreateObject(3106, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.375, - 0.044, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][9] = CreateObject(2995, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.450, 0.079, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][10] = CreateObject(2996, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.525, - 0.118, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][11] = CreateObject(2997, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.600, - 0.079, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][12] = CreateObject(2998, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.600, 0.0, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][13] = CreateObject(2999, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.600, 0.157, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][14] = CreateObject(3000, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
RotateXY(-0.525, 0.040, angle, x, y);
g_poolBallData[poolid][E_BALL_OBJECT][15] = CreateObject(3001, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
// create pool balls on table
g_poolBallData[ poolid ] [ E_BALL_OBJECT ] [ i ] = CreateObject(
g_poolBallOffsetData[ i ] [ E_MODEL_ID ],
g_poolTableData[ poolid ] [ E_X ] + offset_x,
g_poolTableData[ poolid ] [ E_Y ] + offset_y,
g_poolTableData[ poolid ] [ E_Z ] - 0.045,
0.0, 0.0, 0.0
);
}
}
stock IsKeyJustUp(key, newkeys, oldkeys)
{
if (!(newkeys & key) && (oldkeys & key)) return 1;
return 0;
stock IsKeyJustUp(key, newkeys, oldkeys) {
return !(newkeys & key) && (oldkeys & key);
}
stock GetXYBehindObjectInAngle(objectid, Float:a, &Float:x2, &Float:y2, Float:distance)
@ -489,17 +450,9 @@ stock AreAllBallsStopped(poolid)
return 0;
}
}
return 1;
}
stock Is2DPointInRangeOfPoint(Float:x, Float:y, Float:x2, Float:y2, Float:range)
{
x2 -= x;
y2 -= y;
return ((x2 * x2) + (y2 * y2)) < (range * range);
}
stock GetAngleToXY(Float:X, Float:Y, Float:CurrX, Float:CurrY, &Float:angle)
{
angle = atan2(Y-CurrY, X-CurrX);
@ -533,32 +486,28 @@ stock GetMaxPoolScore(poolid)
}
}
}
return score;
}
stock GetPoolBallsCount(poolid)
{
new ball_count = 0;
new
ball_count = 0;
for (new i = 0; i < 16; i ++)
{
if (g_poolBallData[poolid][E_EXISTS][i] || i == 0)
for ( new i = 0; i < 16; i ++ ) if ( g_poolBallData[ poolid ] [ E_EXISTS ] [ i ] || i == 0 ) {
ball_count ++;
}
return ball_count;
}
stock IsBallInHole( poolid, objectid )
{
if (IsInBall(objectid, g_poolTableData[ poolid][ E_X ] + 0.955, g_poolTableData[ poolid][ E_Y ] + 0.510, g_poolTableData[ poolid][ E_Z ], POCKET_RADIUS)) return 1;
else if (IsInBall(objectid, g_poolTableData[ poolid][ E_X ] + 0.955, g_poolTableData[ poolid][ E_Y ] - 0.510, g_poolTableData[ poolid][ E_Z ], POCKET_RADIUS)) return 1;
else if (IsInBall(objectid, g_poolTableData[ poolid][ E_X ] + 0.000, g_poolTableData[ poolid][ E_Y ] + 0.550, g_poolTableData[ poolid][ E_Z ], POCKET_RADIUS)) return 1;
else if (IsInBall(objectid, g_poolTableData[ poolid][ E_X ] + 0.000, g_poolTableData[ poolid][ E_Y ] - 0.550, g_poolTableData[ poolid][ E_Z ], POCKET_RADIUS)) return 1;
else if (IsInBall(objectid, g_poolTableData[ poolid][ E_X ] - 0.955, g_poolTableData[ poolid][ E_Y ] + 0.510, g_poolTableData[ poolid][ E_Z ], POCKET_RADIUS)) return 1;
else if (IsInBall(objectid, g_poolTableData[ poolid][ E_X ] - 0.955, g_poolTableData[ poolid][ E_Y ] - 0.510, g_poolTableData[ poolid][ E_Z ], POCKET_RADIUS)) return 1;
if ( IsBallAtPos( objectid, g_poolTableData[ poolid ] [ E_X ] + 0.955, g_poolTableData[ poolid ] [ E_Y ] + 0.510, g_poolTableData[ poolid ] [ E_Z ], POCKET_RADIUS ) ) return 1;
else if ( IsBallAtPos( objectid, g_poolTableData[ poolid ] [ E_X ] + 0.955, g_poolTableData[ poolid ] [ E_Y ] - 0.510, g_poolTableData[ poolid ] [ E_Z ], POCKET_RADIUS ) ) return 1;
else if ( IsBallAtPos( objectid, g_poolTableData[ poolid ] [ E_X ] + 0.000, g_poolTableData[ poolid ] [ E_Y ] + 0.550, g_poolTableData[ poolid ] [ E_Z ], POCKET_RADIUS ) ) return 1;
else if ( IsBallAtPos( objectid, g_poolTableData[ poolid ] [ E_X ] + 0.000, g_poolTableData[ poolid ] [ E_Y ] - 0.550, g_poolTableData[ poolid ] [ E_Z ], POCKET_RADIUS ) ) return 1;
else if ( IsBallAtPos( objectid, g_poolTableData[ poolid ] [ E_X ] - 0.955, g_poolTableData[ poolid ] [ E_Y ] + 0.510, g_poolTableData[ poolid ] [ E_Z ], POCKET_RADIUS ) ) return 1;
else if ( IsBallAtPos( objectid, g_poolTableData[ poolid ] [ E_X ] - 0.955, g_poolTableData[ poolid ] [ E_Y ] - 0.510, g_poolTableData[ poolid ] [ E_Z ], POCKET_RADIUS ) ) return 1;
return 0;
}
@ -629,29 +578,25 @@ stock gameEnd(poolid)
return 1;
}
stock AngleInRangeOfAngle(Float:a1, Float:a2, Float:range)
{
stock AngleInRangeOfAngle(Float:a1, Float:a2, Float:range) {
a1 -= a2;
if ((a1 < range) && (a1 > -range))
return true;
return false;
return (a1 < range) && (a1 > -range);
}
stock IsInBall(objectid, Float:x, Float:y, Float:z, Float:radius)
stock IsBallAtPos( objectid, Float: x, Float: y, Float: z, Float: radius )
{
new Float:pos[3], Float:dis;
new
Float: object_x, Float: object_y, Float: object_z;
GetObjectPos(objectid, pos[0], pos[1], pos[2]);
GetObjectPos( objectid, object_x, object_y, object_z );
dis = floatsqroot(floatpower(floatabs(floatsub(x, pos[0])), 2) + floatpower(floatabs(floatsub(y, pos[1])), 2) + floatpower(floatabs(floatsub(z, pos[2])), 2));
new
Float: distance = GetDistanceBetweenPoints( object_x, object_y, object_z, x, y, z );
if (dis < radius)
return 1;
return 0;
return distance < radius;
}
stock IsBallNearSide(poolid, objectid)
/*stock IsBallNearSide(poolid, objectid)
{
new Float: x_vertex[4],
Float: y_vertex[4];
@ -661,27 +606,20 @@ stock IsBallNearSide(poolid, objectid)
RotateXY(0.96, -0.515, 0.0, x_vertex[2], y_vertex[2]);
RotateXY(0.96, 0.515, 0.0, x_vertex[3], y_vertex[3]);
if (IsInBall(objectid, x_vertex[0] + g_poolTableData[ poolid][ E_X ], y_vertex[0] + g_poolTableData[ poolid][ E_Y ], x_vertex[1] + g_poolTableData[ poolid][ E_X ], y_vertex[1] + g_poolTableData[ poolid][ E_Y ])) return 1;
if (IsInBall(objectid, x_vertex[1] + g_poolTableData[ poolid][ E_X ], y_vertex[1] + g_poolTableData[ poolid][ E_Y ], x_vertex[3] + g_poolTableData[ poolid][ E_X ], y_vertex[3] + g_poolTableData[ poolid][ E_Y ])) return 1;
if (IsInBall(objectid, x_vertex[2] + g_poolTableData[ poolid][ E_X ], y_vertex[2] + g_poolTableData[ poolid][ E_Y ], x_vertex[3] + g_poolTableData[ poolid][ E_X ], y_vertex[3] + g_poolTableData[ poolid][ E_Y ])) return 1;
if (IsInBall(objectid, x_vertex[0] + g_poolTableData[ poolid][ E_X ], y_vertex[0] + g_poolTableData[ poolid][ E_Y ], x_vertex[2] + g_poolTableData[ poolid][ E_X ], y_vertex[2] + g_poolTableData[ poolid][ E_Y ])) return 1;
if (IsBallAtPos(objectid, x_vertex[0] + g_poolTableData[ poolid ] [ E_X ], y_vertex[0] + g_poolTableData[ poolid ] [ E_Y ], x_vertex[1] + g_poolTableData[ poolid ] [ E_X ], y_vertex[1] + g_poolTableData[ poolid ] [ E_Y ])) return 1;
if (IsBallAtPos(objectid, x_vertex[1] + g_poolTableData[ poolid ] [ E_X ], y_vertex[1] + g_poolTableData[ poolid ] [ E_Y ], x_vertex[3] + g_poolTableData[ poolid ] [ E_X ], y_vertex[3] + g_poolTableData[ poolid ] [ E_Y ])) return 1;
if (IsBallAtPos(objectid, x_vertex[2] + g_poolTableData[ poolid ] [ E_X ], y_vertex[2] + g_poolTableData[ poolid ] [ E_Y ], x_vertex[3] + g_poolTableData[ poolid ] [ E_X ], y_vertex[3] + g_poolTableData[ poolid ] [ E_Y ])) return 1;
if (IsBallAtPos(objectid, x_vertex[0] + g_poolTableData[ poolid ] [ E_X ], y_vertex[0] + g_poolTableData[ poolid ] [ E_Y ], x_vertex[2] + g_poolTableData[ poolid ] [ E_X ], y_vertex[2] + g_poolTableData[ poolid ] [ E_Y ])) return 1;
return 0;
}
}*/
forward PlayPoolSound(poolid, soundid);
public PlayPoolSound(poolid, soundid)
{
foreach (new playerid : Player)
{
if (p_PoolID[ playerid ] == poolid)
{
public PlayPoolSound( poolid, soundid ) {
foreach ( new playerid : Player ) if ( p_PoolID[ playerid ] == poolid ) {
PlayerPlaySound( playerid, soundid, 0.0, 0.0, 0.0 );
}
}
return 1;
}
forward OnPoolUpdate(poolid);
public OnPoolUpdate(poolid)
{
if (!g_poolTableData[ poolid ] [ E_STARTED ])
@ -702,7 +640,7 @@ public OnPoolUpdate(poolid)
GetPlayerPos(playerid, X, Y ,Z);
GetObjectPos(g_poolBallData[poolid] [E_BALL_OBJECT] [0], Xa, Ya, Za);
newrot = p_PoolAngle[ playerid ] [ 0 ] + (lr > 0 ? 0.9 : -0.9);
dist = GetPointDistanceToPoint(X, Y, Xa, Ya);
dist = GetDistanceBetweenPoints( X, Y, 0.0, Xa, Ya, 0.0 );
if (AngleInRangeOfAngle(p_PoolAngle[ playerid ] [ 1 ], newrot, 30.0))
{
@ -781,7 +719,6 @@ public OnPoolUpdate(poolid)
return 1;
}
forward RestoreCamera(playerid, poolid);
public RestoreCamera(playerid, poolid)
{
if (!g_poolBallData[poolid] [E_EXISTS] [0])
@ -811,15 +748,6 @@ public RestoreCamera(playerid, poolid)
return SetCameraBehindPlayer(playerid);
}
Float:GetPointDistanceToPoint(Float:x1,Float:y1,Float:x2,Float:y2)
{
new Float: x, Float: y;
x = x1 - x2;
y = y1 - y2;
return floatsqroot(x * x + y * y);
}
forward deleteBall(poolid, ballid);
public deleteBall(poolid, ballid)
{
if (g_poolBallData[poolid] [E_MOVING] [ballid])
@ -834,7 +762,6 @@ public deleteBall(poolid, ballid)
return 1;
}
forward RestoreWeapon(playerid);
public RestoreWeapon(playerid)
{
RemovePlayerAttachedObject(playerid, 0);
@ -1154,12 +1081,13 @@ CMD:addpool(playerid)
if ( p_AdminLevel[ playerid ] < 6 )
return SendError( playerid, ADMIN_COMMAND_REJECT );
new Float: x, Float: y, Float: z;
GetPlayerFrontPos(playerid, x, y, z, 2.0);
CreatePoolTable(x, y, z, 0.0, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
new
Float: x, Float: y, Float: z;
if ( GetPlayerPos( playerid, x, y, z ) )
{
CreatePoolTable( x + 1.0, y + 1.0, z, 0.0, GetPlayerInterior( playerid ), GetPlayerVirtualWorld( playerid ) );
SendClientMessage(playerid, -1, ""COL_PINK"[ADMIN]{FFFFFF} You have created a pool table.");
}
return 1;
}