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 ** */ /* ** Includes ** */
#include < YSI\y_hooks > #include < YSI\y_hooks >
#include < physics > #include < physics >
#include < colandreas >
#include < progress2 > #include < progress2 >
/* ** Marcos ** */ /* ** Marcos ** */
@ -44,8 +43,8 @@ enum E_POOL_TABLE_DATA
} }
new new
g_poolTableData [ MAX_TABLES ][ E_POOL_TABLE_DATA ], g_poolTableData [ MAX_TABLES ] [ E_POOL_TABLE_DATA ],
g_poolBallData [ MAX_TABLES ][ E_POOL_BALL_DATA ], g_poolBallData [ MAX_TABLES ] [ E_POOL_BALL_DATA ],
p_PoolReciever [ MAX_PLAYERS ], p_PoolReciever [ MAX_PLAYERS ],
p_PoolSender [ MAX_PLAYERS ], p_PoolSender [ MAX_PLAYERS ],
@ -55,30 +54,38 @@ new
bool: p_PoolChalk [ MAX_PLAYERS ], bool: p_PoolChalk [ MAX_PLAYERS ],
p_PoolCamera [ MAX_PLAYERS ], p_PoolCamera [ MAX_PLAYERS ],
p_PoolScore [ MAX_PLAYERS ], p_PoolScore [ MAX_PLAYERS ],
Float: p_PoolAngle [ MAX_PLAYERS ][ 2 ], Float: p_PoolAngle [ MAX_PLAYERS ] [ 2 ],
PlayerBar: g_PoolPowerBar [ MAX_PLAYERS ], PlayerBar: g_PoolPowerBar [ MAX_PLAYERS ],
PlayerText: g_PoolTextdraw [ MAX_PLAYERS ], PlayerText: g_PoolTextdraw [ MAX_PLAYERS ],
Iterator:pooltables <MAX_TABLES> Iterator: pooltables < MAX_TABLES >
; ;
/* ** Forwards ** */
forward deleteBall ( poolid, ballid );
forward RestoreWeapon ( playerid );
forward RestoreCamera ( playerid, poolid );
forward OnPoolUpdate ( poolid );
forward PlayPoolSound ( poolid, soundid );
/* ** Hooks ** */ /* ** Hooks ** */
hook OnGameModeInit() hook OnScriptInit( )
{ {
//stock CreatePoolTable(Float: X, Float: Y, Float: Z, Float: A = 0.0, interior = 0, world = 0) //stock CreatePoolTable(Float: X, Float: Y, Float: Z, Float: A = 0.0, interior = 0, world = 0)
CreatePoolTable(2048.5801, 1330.8917, 10.6719, 0, 0); CreatePoolTable(2048.5801, 1330.8917, 10.6719, 0, 0);
printf( "[POOL TABLES]: %d pool tables have been successfully loaded.", Iter_Count(pooltables) ); printf( "[POOL TABLES]: %d pool tables have been successfully loaded.", Iter_Count( pooltables ) );
return 1; return 1;
} }
hook OnPlayerDisconnect(playerid, reason) hook OnPlayerDisconnect(playerid, reason)
{ {
if (IsPlayerPlayingPool(playerid)) if ( IsPlayerPlayingPool(playerid ) )
{ {
gameEnd( p_PoolID[ playerid ] ); gameEnd( p_PoolID[ playerid ] );
@ -89,7 +96,6 @@ hook OnPlayerDisconnect(playerid, reason)
p_PoolScore[ playerid ] = 0; p_PoolScore[ playerid ] = 0;
} }
return 1; return 1;
} }
@ -105,7 +111,6 @@ hook OnPlayerConnect(playerid)
PlayerTextDrawSetOutline(playerid, g_PoolTextdraw[playerid], 1); PlayerTextDrawSetOutline(playerid, g_PoolTextdraw[playerid], 1);
PlayerTextDrawSetProportional(playerid, g_PoolTextdraw[playerid], 1); PlayerTextDrawSetProportional(playerid, g_PoolTextdraw[playerid], 1);
PlayerTextDrawSetSelectable(playerid, g_PoolTextdraw[playerid], 0); PlayerTextDrawSetSelectable(playerid, g_PoolTextdraw[playerid], 0);
return 1; return 1;
} }
@ -125,7 +130,7 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
if ((id = getNearestPoolTable(playerid)) != -1) if ((id = getNearestPoolTable(playerid)) != -1)
{ {
if (g_poolTableData[ id ][ E_STARTED ] && IsPlayerPlayingPool( playerid ) && p_PoolID[ playerid ] == id) if (g_poolTableData[ id ] [ E_STARTED ] && IsPlayerPlayingPool( playerid ) && p_PoolID[ playerid ] == id)
{ {
if (PRESSED(KEY_FIRE)) if (PRESSED(KEY_FIRE))
{ {
@ -137,7 +142,7 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
// Not the players turn detection (player 1 and/or player 2) // Not the players turn detection (player 1 and/or player 2)
if (IsKeyJustUp(KEY_SECONDARY_ATTACK, newkeys, oldkeys)) if (IsKeyJustUp(KEY_SECONDARY_ATTACK, newkeys, oldkeys))
{ {
if (IsPlayerPlayingPool( playerid ) && g_poolTableData[ id ][ E_AIMER ] != playerid && !p_PoolChalk[ playerid ]) if (IsPlayerPlayingPool( playerid ) && g_poolTableData[ id ] [ E_AIMER ] != playerid && !p_PoolChalk[ playerid ])
{ {
SetTimerEx("PlayPoolSound", 1400, false, "dd", id, 31807); SetTimerEx("PlayPoolSound", 1400, false, "dd", id, 31807);
SetPlayerArmedWeapon(playerid, 0); SetPlayerArmedWeapon(playerid, 0);
@ -152,7 +157,7 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
if (IsKeyJustUp(KEY_JUMP, newkeys, oldkeys)) if (IsKeyJustUp(KEY_JUMP, newkeys, oldkeys))
{ {
if (g_poolTableData[ id ][ E_AIMER ] == playerid) if (g_poolTableData[ id ] [ E_AIMER ] == playerid)
{ {
if (p_PoolCamera[ playerid ] < 2) p_PoolCamera[ playerid ] ++; if (p_PoolCamera[ playerid ] < 2) p_PoolCamera[ playerid ] ++;
else p_PoolCamera[ playerid ] = 0; else p_PoolCamera[ playerid ] = 0;
@ -164,20 +169,20 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
Float:x, Float:x,
Float:y; Float:y;
GetObjectPos(g_poolBallData[ id ][ E_BALL_OBJECT ][ 0 ], Xa, Ya, Za); GetObjectPos(g_poolBallData[ id ] [ E_BALL_OBJECT ] [ 0 ], Xa, Ya, Za);
switch (p_PoolCamera[ playerid ]) switch (p_PoolCamera[ playerid ])
{ {
case 0: case 0:
{ {
GetXYBehindObjectInAngle(g_poolBallData[ id ][ E_BALL_OBJECT ][ 0 ], poolrot, x, y, 0.675); GetXYBehindObjectInAngle(g_poolBallData[ id ] [ E_BALL_OBJECT ] [ 0 ], poolrot, x, y, 0.675);
SetPlayerCameraPos(playerid, x, y, g_poolTableData[ id ][ E_Z ] + DEFAULT_AIM); SetPlayerCameraPos(playerid, x, y, g_poolTableData[ id ] [ E_Z ] + DEFAULT_AIM);
SetPlayerCameraLookAt(playerid, Xa, Ya, Za + 0.170); SetPlayerCameraLookAt(playerid, Xa, Ya, Za + 0.170);
} }
case 1..2: case 1..2:
{ {
SetPlayerCameraPos(playerid, g_poolTableData[ id ][ E_X ], g_poolTableData[ id ][ E_Y ], g_poolTableData[ id ][ E_Z ] + 2.0); SetPlayerCameraPos(playerid, g_poolTableData[ id ] [ E_X ], g_poolTableData[ id ] [ E_Y ], g_poolTableData[ id ] [ E_Z ] + 2.0);
SetPlayerCameraLookAt(playerid, g_poolTableData[ id ][ E_X ], g_poolTableData[ id ][ E_Y ], g_poolTableData[ id ][ E_Z ]); SetPlayerCameraLookAt(playerid, g_poolTableData[ id ] [ E_X ], g_poolTableData[ id ] [ E_Y ], g_poolTableData[ id ] [ E_Z ]);
} }
} }
} }
@ -187,9 +192,9 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{ {
if (AreAllBallsStopped(id)) if (AreAllBallsStopped(id))
{ {
if (g_poolTableData[ id ][ E_AIMER ] != playerid) if (g_poolTableData[ id ] [ E_AIMER ] != playerid)
{ {
if (!p_PoolChalk[ playerid ] && g_poolTableData[ id ][ E_AIMER ] == -1) if (!p_PoolChalk[ playerid ] && g_poolTableData[ id ] [ E_AIMER ] == -1)
{ {
new Float:poolrot, new Float:poolrot,
Float:X, Float:Y, Float:Z, Float:X, Float:Y, Float:Z,
@ -197,9 +202,9 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
Float:x, Float:y; Float:x, Float:y;
GetPlayerPos(playerid, X, Y, Z); GetPlayerPos(playerid, X, Y, Z);
GetObjectPos(g_poolBallData[id][E_BALL_OBJECT][0], Xa, Ya, Za); 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); TogglePlayerControllable(playerid, false);
GetAngleToXY(Xa, Ya, X, Y, poolrot); GetAngleToXY(Xa, Ya, X, Y, poolrot);
@ -210,15 +215,15 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
SetPlayerArmedWeapon(playerid, 0); SetPlayerArmedWeapon(playerid, 0);
GetXYInFrontOfPos(Xa, Ya, poolrot + 180, x, y, 0.085); GetXYInFrontOfPos(Xa, Ya, poolrot + 180, x, y, 0.085);
g_poolTableData[ id ][ E_AIMER_OBJECT ] = CreateObject(3004, x, y, Za, 7.0, 0, poolrot + 180); g_poolTableData[ id ] [ E_AIMER_OBJECT ] = CreateObject(3004, x, y, Za, 7.0, 0, poolrot + 180);
SetPlayerCameraPos(playerid, g_poolTableData[ id ][ E_X ], g_poolTableData[ id ][ E_Y ], g_poolTableData[ id ][ E_Z ] + 2.0); SetPlayerCameraPos(playerid, g_poolTableData[ id ] [ E_X ], g_poolTableData[ id ] [ E_Y ], g_poolTableData[ id ] [ E_Z ] + 2.0);
ApplyAnimation(playerid, "POOL", "POOL_Med_Start", 50.0, 0, 0, 0, 1, 1, 1); ApplyAnimation(playerid, "POOL", "POOL_Med_Start", 50.0, 0, 0, 0, 1, 1, 1);
g_poolTableData[ id ][ E_AIMER ] = playerid; g_poolTableData[ id ] [ E_AIMER ] = playerid;
g_poolTableData[ id ][ E_POWER ] = 1.0; g_poolTableData[ id ] [ E_POWER ] = 1.0;
g_poolTableData[ id ][ E_DIRECTION ] = 0; g_poolTableData[ id ] [ E_DIRECTION ] = 0;
PlayerTextDrawSetString(playerid, g_PoolTextdraw[playerid], sprintf("Power:~n~~n~Score: %d", p_PoolScore[ playerid ]) ); PlayerTextDrawSetString(playerid, g_PoolTextdraw[playerid], sprintf("Power:~n~~n~Score: %d", p_PoolScore[ playerid ]) );
PlayerTextDrawShow(playerid, g_PoolTextdraw[playerid]); PlayerTextDrawShow(playerid, g_PoolTextdraw[playerid]);
@ -234,8 +239,8 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
ApplyAnimation(playerid, "CARRY", "crry_prtial", 1.0, 0, 0, 0, 0, 0, 1); ApplyAnimation(playerid, "CARRY", "crry_prtial", 1.0, 0, 0, 0, 0, 0, 1);
SetCameraBehindPlayer(playerid); SetCameraBehindPlayer(playerid);
g_poolTableData[ id ][ E_AIMER ] = -1; g_poolTableData[ id ] [ E_AIMER ] = -1;
DestroyObject(g_poolTableData[ id ][ E_AIMER_OBJECT ]); DestroyObject(g_poolTableData[ id ] [ E_AIMER_OBJECT ]);
//TextDrawHideForPlayer(playerid, gPoolTD); //TextDrawHideForPlayer(playerid, gPoolTD);
//HidePlayerProgressBar(playerid, g_PoolPowerBar[playerid]); //HidePlayerProgressBar(playerid, g_PoolPowerBar[playerid]);
@ -245,26 +250,26 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
if (IsKeyJustUp(KEY_FIRE, newkeys, oldkeys)) if (IsKeyJustUp(KEY_FIRE, newkeys, oldkeys))
{ {
if (g_poolTableData[ id ][ E_AIMER ] == playerid) if (g_poolTableData[ id ] [ E_AIMER ] == playerid)
{ {
new Float: speed; new Float: speed;
ApplyAnimation(playerid, "POOL", "POOL_Med_Shot", 3.0, 0, 0, 0, 0, 0, 1); ApplyAnimation(playerid, "POOL", "POOL_Med_Shot", 3.0, 0, 0, 0, 0, 0, 1);
speed = 0.4 + (g_poolTableData[ id ][ E_POWER ] * 2.0) / 100.0; speed = 0.4 + (g_poolTableData[ id ] [ E_POWER ] * 2.0) / 100.0;
PHY_SetObjectVelocity(g_poolBallData[id][E_BALL_OBJECT][0], speed * floatsin(-p_PoolAngle[ playerid ] [ 0 ], degrees), speed * floatcos(-p_PoolAngle[ playerid ] [ 0 ], degrees)); PHY_SetObjectVelocity(g_poolBallData[id] [E_BALL_OBJECT] [0], speed * floatsin(-p_PoolAngle[ playerid ] [ 0 ], degrees), speed * floatcos(-p_PoolAngle[ playerid ] [ 0 ], degrees));
SetPlayerCameraPos(playerid, g_poolTableData[ id ][ E_X ], g_poolTableData[ id ][ E_Y ], g_poolTableData[ id ][ E_Z ] + 2.0); SetPlayerCameraPos(playerid, g_poolTableData[ id ] [ E_X ], g_poolTableData[ id ] [ E_Y ], g_poolTableData[ id ] [ E_Z ] + 2.0);
SetPlayerCameraLookAt(playerid, g_poolTableData[ id ][ E_X ], g_poolTableData[ id ][ E_Y ], g_poolTableData[ id ][ E_Z ]); SetPlayerCameraLookAt(playerid, g_poolTableData[ id ] [ E_X ], g_poolTableData[ id ] [ E_Y ], g_poolTableData[ id ] [ E_Z ]);
PlayPoolSound(id, 31810); PlayPoolSound(id, 31810);
g_poolTableData[ id ][ E_AIMER ] = -1; g_poolTableData[ id ] [ E_AIMER ] = -1;
DestroyObject(g_poolTableData[ id ][ E_AIMER_OBJECT ]); DestroyObject(g_poolTableData[ id ] [ E_AIMER_OBJECT ]);
GivePlayerWeapon(playerid, 7, 1); GivePlayerWeapon(playerid, 7, 1);
g_poolTableData[ id ][ E_LAST_SHOOTER ] = playerid; g_poolTableData[ id ] [ E_LAST_SHOOTER ] = playerid;
g_poolTableData[ id ][ E_LAST_SCORE ] = 0; g_poolTableData[ id ] [ E_LAST_SCORE ] = 0;
} }
else ClearAnimations(playerid); else ClearAnimations(playerid);
} }
@ -279,29 +284,12 @@ hook OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
stock getNearestPoolTable(playerid) 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 ]) ) { 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 i;
} }
return -1; 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) stock CreatePoolTable(Float: X, Float: Y, Float: Z, Float: A = 0.0, interior = 0, world = 0)
{ {
new new
@ -311,16 +299,16 @@ stock CreatePoolTable(Float: X, Float: Y, Float: Z, Float: A = 0.0, interior = 0
{ {
Iter_Add(pooltables, gID); Iter_Add(pooltables, gID);
g_poolTableData[ gID ][ E_X ] = X; g_poolTableData[ gID ] [ E_X ] = X;
g_poolTableData[ gID ][ E_Y ] = Y; g_poolTableData[ gID ] [ E_Y ] = Y;
g_poolTableData[ gID ][ E_Z ] = Z; g_poolTableData[ gID ] [ E_Z ] = Z;
g_poolTableData[ gID ][ E_ANGLE ] = A; g_poolTableData[ gID ] [ E_ANGLE ] = A;
g_poolTableData[ gID ][ E_INTERIOR ] = interior; g_poolTableData[ gID ] [ E_INTERIOR ] = interior;
g_poolTableData[ gID ][ E_WORLD ] = world; g_poolTableData[ gID ] [ E_WORLD ] = world;
g_poolTableData[ gID][ E_TABLE ] = CreateDynamicObject( 2964, X, Y, Z - 1.0, 0.0, 0.0, 0.0, world, interior); g_poolTableData[ gID] [ E_TABLE ] = CreateDynamicObject( 2964, X, Y, Z - 1.0, 0.0, 0.0, 0.0, world, interior );
g_poolTableData[ gID][ E_LABEL ] = CreateDynamic3DTextLabel( DEFAULT_POOL_STRING, COLOR_GOLD, X, Y, (Z - 0.5), 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, world, interior); g_poolTableData[ gID] [ E_LABEL ] = CreateDynamic3DTextLabel( DEFAULT_POOL_STRING, COLOR_GOLD, X, Y, (Z - 0.5), 10.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, world, interior );
RotateXY( -0.96, -0.515, 0.0, x_vertex[0], y_vertex[0] ); RotateXY( -0.96, -0.515, 0.0, x_vertex[0], y_vertex[0] );
RotateXY( -0.96, 0.515, 0.0, x_vertex[1], y_vertex[1] ); RotateXY( -0.96, 0.515, 0.0, x_vertex[1], y_vertex[1] );
@ -340,35 +328,35 @@ stock RespawnPoolBalls(poolid, mode = 0)
{ {
for (new i = 0; i < 16; i ++) for (new i = 0; i < 16; i ++)
{ {
DestroyObject(g_poolBallData[poolid][E_BALL_OBJECT][i]); DestroyObject(g_poolBallData[poolid] [E_BALL_OBJECT] [i]);
if (g_poolBallData[i][E_EXISTS][i]) if (g_poolBallData[i] [E_EXISTS] [i])
{ {
PHY_DeleteObject(g_poolBallData[poolid][E_BALL_OBJECT][i]); PHY_DeleteObject(g_poolBallData[poolid] [E_BALL_OBJECT] [i]);
g_poolBallData[poolid][E_EXISTS][i] = false; g_poolBallData[poolid] [E_EXISTS] [i] = false;
} }
} }
if (g_poolTableData[ poolid][ E_AIMER ] != -1) if (g_poolTableData[ poolid ] [ E_AIMER ] != -1)
{ {
TogglePlayerControllable(g_poolTableData[ poolid][ E_AIMER ], 1); TogglePlayerControllable(g_poolTableData[ poolid ] [ E_AIMER ], 1);
//ClearAnimations(g_poolTableData[ poolid][ E_AIMER ]); //ClearAnimations(g_poolTableData[ poolid ] [ E_AIMER ]);
//ApplyAnimation(g_poolTableData[ poolid][ E_AIMER ], "CARRY", "crry_prtial", 1.0, 0, 0, 0, 0, 0); //ApplyAnimation(g_poolTableData[ poolid ] [ E_AIMER ], "CARRY", "crry_prtial", 1.0, 0, 0, 0, 0, 0);
SetCameraBehindPlayer(g_poolTableData[ poolid][ E_AIMER ]); SetCameraBehindPlayer(g_poolTableData[ poolid ] [ E_AIMER ]);
DestroyObject(g_poolTableData[ poolid][ E_AIMER_OBJECT ]); DestroyObject(g_poolTableData[ poolid ] [ E_AIMER_OBJECT ]);
//TextDrawHideForPlayer(g_poolTableData[ poolid][ E_AIMER ], gPoolTD); //TextDrawHideForPlayer(g_poolTableData[ poolid ] [ E_AIMER ], gPoolTD);
//HidePlayerProgressBar(g_poolTableData[ poolid][ E_AIMER ], g_PoolPowerBar[g_poolTableData[ poolid][ E_AIMER ]]); //HidePlayerProgressBar(g_poolTableData[ poolid ] [ E_AIMER ], g_PoolPowerBar[g_poolTableData[ poolid ] [ E_AIMER ]]);
g_poolTableData[ poolid][ E_AIMER ] = -1; g_poolTableData[ poolid ] [ E_AIMER ] = -1;
} }
CreateBalls(poolid); CreateBalls(poolid);
if (mode) if (mode)
{ {
KillTimer(g_poolTableData[ poolid][ E_TIMER ]); KillTimer(g_poolTableData[ poolid ] [ E_TIMER ]);
g_poolTableData[ poolid][ E_TIMER ] = SetTimerEx("OnPoolUpdate", POOL_TIMER_SPEED, true, "d", poolid); g_poolTableData[ poolid ] [ E_TIMER ] = SetTimerEx("OnPoolUpdate", POOL_TIMER_SPEED, true, "d", poolid);
for (new i = 0; i < 16; i ++) for (new i = 0; i < 16; i ++)
{ {
@ -379,88 +367,61 @@ stock RespawnPoolBalls(poolid, mode = 0)
stock InitBalls(poolid, ballid) stock InitBalls(poolid, ballid)
{ {
PHY_InitObject(g_poolBallData[poolid][E_BALL_OBJECT][ballid], 3003, _, _, PHY_MODE_2D); PHY_InitObject(g_poolBallData[poolid] [E_BALL_OBJECT] [ballid], 3003, _, _, PHY_MODE_2D);
PHY_SetObjectFriction(g_poolBallData[poolid][E_BALL_OBJECT][ballid], 0.08); PHY_SetObjectFriction(g_poolBallData[poolid] [E_BALL_OBJECT] [ballid], 0.08);
//PHY_SetObjectFriction(g_poolBallData[poolid][E_BALL_OBJECT][ballid], 0.10); //PHY_SetObjectFriction(g_poolBallData[poolid] [E_BALL_OBJECT] [ballid], 0.10);
PHY_SetObjectAirResistance(g_poolBallData[poolid][E_BALL_OBJECT][ballid], 0.2); PHY_SetObjectAirResistance(g_poolBallData[poolid] [E_BALL_OBJECT] [ballid], 0.2);
PHY_RollObject(g_poolBallData[poolid][E_BALL_OBJECT][ballid]); PHY_RollObject(g_poolBallData[poolid] [E_BALL_OBJECT] [ballid]);
g_poolBallData[poolid][E_EXISTS][ballid] = true; g_poolBallData[poolid] [E_EXISTS] [ballid] = true;
} }
stock RotateXY(Float:xi, Float:yi, Float:angle, &Float:xf, &Float:yf) stock RotateXY( Float: xi, Float: yi, Float: angle, &Float: xf, &Float: yf )
{ {
xf = xi * floatcos(angle, degrees) - yi * floatsin(angle, degrees); xf = xi * floatcos( angle, degrees ) - yi * floatsin( angle, degrees );
yf = xi * floatsin(angle, degrees) + yi * floatcos(angle, degrees); yf = xi * floatsin( angle, degrees ) + yi * floatcos( angle, degrees );
return 1; return 1;
} }
stock CreateBalls(poolid) stock CreateBalls( poolid )
{ {
new Float: x, enum E_POOL_BALL_OFFSET_DATA {
Float: y, E_MODEL_ID, Float: E_OFFSET_X, Float: E_OFFSET_Y
Float: pos[3], };
Float: angle;
pos[0] = g_poolTableData[ poolid][ E_X ]; static const
pos[1] = g_poolTableData[ poolid][ E_Y ]; g_poolBallOffsetData[ ] [ E_POOL_BALL_OFFSET_DATA ] =
pos[2] = g_poolTableData[ poolid][ E_Z ]; {
angle = g_poolTableData[ poolid][ E_ANGLE ]; { 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); new
g_poolBallData[poolid][E_BALL_OBJECT][0] = CreateObject(3003, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0); Float: offset_x,
Float: offset_y;
RotateXY(-0.3, 0.0, angle, x, y); for ( new i = 0; i < sizeof( g_poolBallOffsetData ); i ++ )
g_poolBallData[poolid][E_BALL_OBJECT][1] = CreateObject(3002, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0); {
// 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); // create pool balls on table
g_poolBallData[poolid][E_BALL_OBJECT][2] = CreateObject(3100, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0); g_poolBallData[ poolid ] [ E_BALL_OBJECT ] [ i ] = CreateObject(
g_poolBallOffsetData[ i ] [ E_MODEL_ID ],
RotateXY(-0.375, 0.044, angle, x, y); g_poolTableData[ poolid ] [ E_X ] + offset_x,
g_poolBallData[poolid][E_BALL_OBJECT][3] = CreateObject(3101, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0); g_poolTableData[ poolid ] [ E_Y ] + offset_y,
g_poolTableData[ poolid ] [ E_Z ] - 0.045,
RotateXY(-0.600, 0.079, angle, x, y); 0.0, 0.0, 0.0
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);
} }
stock IsKeyJustUp(key, newkeys, oldkeys) stock IsKeyJustUp(key, newkeys, oldkeys) {
{ return !(newkeys & key) && (oldkeys & key);
if (!(newkeys & key) && (oldkeys & key)) return 1;
return 0;
} }
stock GetXYBehindObjectInAngle(objectid, Float:a, &Float:x2, &Float:y2, Float:distance) stock GetXYBehindObjectInAngle(objectid, Float:a, &Float:x2, &Float:y2, Float:distance)
@ -481,25 +442,17 @@ stock AreAllBallsStopped(poolid)
for (new i = 0; i < 16; i ++) for (new i = 0; i < 16; i ++)
{ {
if (g_poolBallData[poolid][E_EXISTS][i]) if (g_poolBallData[poolid] [E_EXISTS] [i])
{ {
PHY_GetObjectVelocity(g_poolBallData[poolid][E_BALL_OBJECT][i], x, y, z); PHY_GetObjectVelocity(g_poolBallData[poolid] [E_BALL_OBJECT] [i], x, y, z);
if (x != 0.0 || y != 0.0) if (x != 0.0 || y != 0.0)
return 0; return 0;
} }
} }
return 1; 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) stock GetAngleToXY(Float:X, Float:Y, Float:CurrX, Float:CurrY, &Float:angle)
{ {
angle = atan2(Y-CurrY, X-CurrX); angle = atan2(Y-CurrY, X-CurrX);
@ -533,53 +486,49 @@ stock GetMaxPoolScore(poolid)
} }
} }
} }
return score; return score;
} }
stock GetPoolBallsCount(poolid) stock GetPoolBallsCount(poolid)
{ {
new ball_count = 0; new
ball_count = 0;
for (new i = 0; i < 16; i ++) for ( new i = 0; i < 16; i ++ ) if ( g_poolBallData[ poolid ] [ E_EXISTS ] [ i ] || i == 0 ) {
{
if (g_poolBallData[poolid][E_EXISTS][i] || i == 0)
ball_count ++; ball_count ++;
} }
return ball_count; return ball_count;
} }
stock IsBallInHole(poolid, objectid) 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; 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 (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 ( 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 (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 ( 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 (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 ( 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 (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 ( 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 (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 ( 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; return 0;
} }
stock respawnCueBall(poolid) stock respawnCueBall(poolid)
{ {
if (!g_poolBallData[poolid][E_EXISTS][0]) if (!g_poolBallData[poolid] [E_EXISTS] [0])
{ {
DestroyObject(g_poolBallData[poolid][E_BALL_OBJECT][0]); DestroyObject(g_poolBallData[poolid] [E_BALL_OBJECT] [0]);
new Float: x, new Float: x,
Float: y, Float: y,
Float: pos[3], Float: pos[3],
Float: angle; Float: angle;
pos[0] = g_poolTableData[ poolid][ E_X ]; pos[0] = g_poolTableData[ poolid ] [ E_X ];
pos[1] = g_poolTableData[ poolid][ E_Y ]; pos[1] = g_poolTableData[ poolid ] [ E_Y ];
pos[2] = g_poolTableData[ poolid][ E_Z ]; pos[2] = g_poolTableData[ poolid ] [ E_Z ];
angle = g_poolTableData[ poolid][ E_ANGLE ]; angle = g_poolTableData[ poolid ] [ E_ANGLE ];
RotateXY(0.5, 0.0, angle, x, y); 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, 0, 0); g_poolBallData[poolid] [E_BALL_OBJECT] [0] = CreateObject(3003, x + pos[0], y + pos[1], (pos[2]), 0, 0, 0);
InitBalls(poolid, 0); InitBalls(poolid, 0);
} }
@ -610,48 +559,44 @@ stock gameEnd(poolid)
} }
} }
g_poolTableData[ poolid][ E_STARTED ] = false; g_poolTableData[ poolid ] [ E_STARTED ] = false;
KillTimer(g_poolTableData[ poolid][ E_TIMER ]); KillTimer(g_poolTableData[ poolid ] [ E_TIMER ]);
for (new i = 0; i < 16; i ++) for (new i = 0; i < 16; i ++)
{ {
DestroyObject(g_poolBallData[poolid][E_BALL_OBJECT][i]); DestroyObject(g_poolBallData[poolid] [E_BALL_OBJECT] [i]);
if (g_poolBallData[poolid][E_EXISTS][i]) if (g_poolBallData[poolid] [E_EXISTS] [i])
{ {
PHY_DeleteObject(g_poolBallData[poolid][E_BALL_OBJECT][i]); PHY_DeleteObject(g_poolBallData[poolid] [E_BALL_OBJECT] [i]);
g_poolBallData[poolid][E_EXISTS][i] = false; g_poolBallData[poolid] [E_EXISTS] [i] = false;
} }
} }
UpdateDynamic3DTextLabelText(g_poolTableData[ poolid ][ E_LABEL ], -1, DEFAULT_POOL_STRING); UpdateDynamic3DTextLabelText(g_poolTableData[ poolid ] [ E_LABEL ], -1, DEFAULT_POOL_STRING);
return 1; return 1;
} }
stock AngleInRangeOfAngle(Float:a1, Float:a2, Float:range) stock AngleInRangeOfAngle(Float:a1, Float:a2, Float:range) {
{
a1 -= a2; a1 -= a2;
if ((a1 < range) && (a1 > -range)) return (a1 < range) && (a1 > -range);
return true;
return false;
} }
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 distance < radius;
return 1;
return 0;
} }
stock IsBallNearSide(poolid, objectid) /*stock IsBallNearSide(poolid, objectid)
{ {
new Float: x_vertex[4], new Float: x_vertex[4],
Float: y_vertex[4]; Float: y_vertex[4];
@ -661,35 +606,28 @@ 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[2], y_vertex[2]);
RotateXY(0.96, 0.515, 0.0, x_vertex[3], y_vertex[3]); 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 (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 (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 (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 (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 (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 (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[2] + g_poolTableData[ poolid ] [ E_X ], y_vertex[2] + g_poolTableData[ poolid ] [ E_Y ])) return 1;
return 0; return 0;
}*/
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 PlayPoolSound(poolid, soundid);
public PlayPoolSound(poolid, soundid)
{
foreach (new playerid : Player)
{
if (p_PoolID[ playerid ] == poolid)
{
PlayerPlaySound(playerid, soundid, 0.0, 0.0, 0.0);
}
}
}
forward OnPoolUpdate(poolid);
public OnPoolUpdate(poolid) public OnPoolUpdate(poolid)
{ {
if (!g_poolTableData[ poolid][ E_STARTED ]) if (!g_poolTableData[ poolid ] [ E_STARTED ])
return 0; return 0;
if (g_poolTableData[ poolid][ E_AIMER ] != -1) if (g_poolTableData[ poolid ] [ E_AIMER ] != -1)
{ {
new playerid = g_poolTableData[ poolid][ E_AIMER ], keys, ud, lr; new playerid = g_poolTableData[ poolid ] [ E_AIMER ], keys, ud, lr;
GetPlayerKeys(playerid, keys, ud, lr); GetPlayerKeys(playerid, keys, ud, lr);
@ -700,9 +638,9 @@ public OnPoolUpdate(poolid)
new Float: X, Float: Y, Float: Z, Float: Xa, Float: Ya, Float: Za, Float: x, Float: y, Float: newrot, Float: dist; new Float: X, Float: Y, Float: Z, Float: Xa, Float: Ya, Float: Za, Float: x, Float: y, Float: newrot, Float: dist;
GetPlayerPos(playerid, X, Y ,Z); GetPlayerPos(playerid, X, Y ,Z);
GetObjectPos(g_poolBallData[poolid][E_BALL_OBJECT][0], Xa, Ya, Za); GetObjectPos(g_poolBallData[poolid] [E_BALL_OBJECT] [0], Xa, Ya, Za);
newrot = p_PoolAngle[ playerid ] [ 0 ] + (lr > 0 ? 0.9 : -0.9); 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)) if (AngleInRangeOfAngle(p_PoolAngle[ playerid ] [ 1 ], newrot, 30.0))
{ {
@ -711,26 +649,26 @@ public OnPoolUpdate(poolid)
{ {
case 0: case 0:
{ {
GetXYBehindObjectInAngle(g_poolBallData[poolid][E_BALL_OBJECT][0], newrot, x, y, 0.675); GetXYBehindObjectInAngle(g_poolBallData[poolid] [E_BALL_OBJECT] [0], newrot, x, y, 0.675);
SetPlayerCameraPos(playerid, x, y, g_poolTableData[ poolid][ E_Z ] + DEFAULT_AIM); SetPlayerCameraPos(playerid, x, y, g_poolTableData[ poolid ] [ E_Z ] + DEFAULT_AIM);
SetPlayerCameraLookAt(playerid, Xa, Ya, Za + 0.170); SetPlayerCameraLookAt(playerid, Xa, Ya, Za + 0.170);
} }
case 1: case 1:
{ {
SetPlayerCameraPos(playerid, g_poolTableData[ poolid][ E_X ], g_poolTableData[ poolid][ E_Y ], g_poolTableData[ poolid][ E_Z ] + 2.0); SetPlayerCameraPos(playerid, g_poolTableData[ poolid ] [ E_X ], g_poolTableData[ poolid ] [ E_Y ], g_poolTableData[ poolid ] [ E_Z ] + 2.0);
SetPlayerCameraLookAt(playerid, g_poolTableData[ poolid][ E_X ], g_poolTableData[ poolid][ E_Y ], g_poolTableData[ poolid][ E_Z ]); SetPlayerCameraLookAt(playerid, g_poolTableData[ poolid ] [ E_X ], g_poolTableData[ poolid ] [ E_Y ], g_poolTableData[ poolid ] [ E_Z ]);
} }
case 2: case 2:
{ {
SetPlayerCameraPos(playerid, g_poolTableData[ poolid][ E_X ], g_poolTableData[ poolid][ E_Y ], g_poolTableData[ poolid][ E_Z ] + 2.0); SetPlayerCameraPos(playerid, g_poolTableData[ poolid ] [ E_X ], g_poolTableData[ poolid ] [ E_Y ], g_poolTableData[ poolid ] [ E_Z ] + 2.0);
SetPlayerCameraLookAt(playerid, g_poolTableData[ poolid][ E_X ], g_poolTableData[ poolid][ E_Y ], g_poolTableData[ poolid][ E_Z ]); SetPlayerCameraLookAt(playerid, g_poolTableData[ poolid ] [ E_X ], g_poolTableData[ poolid ] [ E_Y ], g_poolTableData[ poolid ] [ E_Z ]);
} }
} }
GetXYInFrontOfPos(Xa, Ya, newrot + 180, x, y, 0.085); GetXYInFrontOfPos(Xa, Ya, newrot + 180, x, y, 0.085);
SetObjectPos(g_poolTableData[ poolid][ E_AIMER_OBJECT ], x, y, Za); SetObjectPos(g_poolTableData[ poolid ] [ E_AIMER_OBJECT ], x, y, Za);
SetObjectRot(g_poolTableData[ poolid][ E_AIMER_OBJECT ], 7.0, 0, p_PoolAngle[ playerid ] [ 0 ] + 180); SetObjectRot(g_poolTableData[ poolid ] [ E_AIMER_OBJECT ], 7.0, 0, p_PoolAngle[ playerid ] [ 0 ] + 180);
GetXYInFrontOfPos(Xa, Ya, newrot + 180, X, Y, dist); GetXYInFrontOfPos(Xa, Ya, newrot + 180, X, Y, dist);
SetPlayerPos(playerid, X, Y, Z); SetPlayerPos(playerid, X, Y, Z);
SetPlayerFacingAngle(playerid, newrot); SetPlayerFacingAngle(playerid, newrot);
@ -739,69 +677,68 @@ public OnPoolUpdate(poolid)
} }
else else
{ {
if (g_poolTableData[ poolid][ E_DIRECTION ]) if (g_poolTableData[ poolid ] [ E_DIRECTION ])
{ {
g_poolTableData[ poolid][ E_POWER ] -= 2.0; g_poolTableData[ poolid ] [ E_POWER ] -= 2.0;
} }
else else
{ {
g_poolTableData[ poolid][ E_POWER ] += 2.0; g_poolTableData[ poolid ] [ E_POWER ] += 2.0;
} }
if (g_poolTableData[ poolid][ E_POWER ] <= 0) if (g_poolTableData[ poolid ] [ E_POWER ] <= 0)
{ {
g_poolTableData[ poolid][ E_DIRECTION ] = 0; g_poolTableData[ poolid ] [ E_DIRECTION ] = 0;
g_poolTableData[ poolid][ E_POWER ] = 2.0; g_poolTableData[ poolid ] [ E_POWER ] = 2.0;
} }
else if (g_poolTableData[ poolid][ E_POWER ] > 100.0) else if (g_poolTableData[ poolid ] [ E_POWER ] > 100.0)
{ {
g_poolTableData[ poolid][ E_DIRECTION ] = 1; g_poolTableData[ poolid ] [ E_DIRECTION ] = 1;
g_poolTableData[ poolid][ E_POWER ] = 98.0; g_poolTableData[ poolid ] [ E_POWER ] = 98.0;
} }
// TextDrawTextSize(g_PoolTextdraw[2], 501.0 + ((67.0 * g_poolTableData[ poolid][ E_POWER ])/100.0), 0.0); // TextDrawTextSize(g_PoolTextdraw[2], 501.0 + ((67.0 * g_poolTableData[ poolid ] [ E_POWER ])/100.0), 0.0);
// TextDrawShowForPlayer(playerid, g_PoolTextdraw[2]); // TextDrawShowForPlayer(playerid, g_PoolTextdraw[2]);
// ShowPlayerPoolTextdraw(playerid); // ShowPlayerPoolTextdraw(playerid);
SetPlayerProgressBarMaxValue(playerid, g_PoolPowerBar[playerid], 67.0); SetPlayerProgressBarMaxValue(playerid, g_PoolPowerBar[playerid], 67.0);
SetPlayerProgressBarValue(playerid, g_PoolPowerBar[playerid], ((67.0 * g_poolTableData[ poolid][ E_POWER ])/100.0)); SetPlayerProgressBarValue(playerid, g_PoolPowerBar[playerid], ((67.0 * g_poolTableData[ poolid ] [ E_POWER ])/100.0));
ShowPlayerProgressBar(playerid, g_PoolPowerBar[playerid]); ShowPlayerProgressBar(playerid, g_PoolPowerBar[playerid]);
PlayerTextDrawShow(playerid, g_PoolTextdraw[playerid]); PlayerTextDrawShow(playerid, g_PoolTextdraw[playerid]);
} }
} }
if (g_poolTableData[ poolid][ E_LAST_SHOOTER ] != -1 && AreAllBallsStopped(poolid)) if (g_poolTableData[ poolid ] [ E_LAST_SHOOTER ] != -1 && AreAllBallsStopped(poolid))
{ {
SetTimerEx("RestoreCamera", 800, 0, "dd", g_poolTableData[ poolid][ E_LAST_SHOOTER ], poolid); SetTimerEx("RestoreCamera", 800, 0, "dd", g_poolTableData[ poolid ] [ E_LAST_SHOOTER ], poolid);
g_poolTableData[ poolid][ E_LAST_SHOOTER ] = -1; g_poolTableData[ poolid ] [ E_LAST_SHOOTER ] = -1;
} }
return 1; return 1;
} }
forward RestoreCamera(playerid, poolid);
public RestoreCamera(playerid, poolid) public RestoreCamera(playerid, poolid)
{ {
if (!g_poolBallData[poolid][E_EXISTS][0]) if (!g_poolBallData[poolid] [E_EXISTS] [0])
{ {
DestroyObject(g_poolBallData[poolid][E_BALL_OBJECT][0]); DestroyObject(g_poolBallData[poolid] [E_BALL_OBJECT] [0]);
new Float: x, Float: y, Float: pos[3], Float: angle; new Float: x, Float: y, Float: pos[3], Float: angle;
pos[0] = g_poolTableData[ poolid][ E_X ]; pos[0] = g_poolTableData[ poolid ] [ E_X ];
pos[1] = g_poolTableData[ poolid][ E_Y ]; pos[1] = g_poolTableData[ poolid ] [ E_Y ];
pos[2] = g_poolTableData[ poolid][ E_Z ]; pos[2] = g_poolTableData[ poolid ] [ E_Z ];
angle = g_poolTableData[ poolid][ E_ANGLE ]; angle = g_poolTableData[ poolid ] [ E_ANGLE ];
RotateXY(0.5, 0.0, angle, x, y); 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); g_poolBallData[poolid] [E_BALL_OBJECT] [0] = CreateObject(3003, x + pos[0], y + pos[1], (pos[2] - 0.045), 0, 0, 0);
InitBalls(poolid, 0); InitBalls(poolid, 0);
} }
if (g_poolTableData[ poolid][ E_AIMER ] == playerid) if (g_poolTableData[ poolid ] [ E_AIMER ] == playerid)
return 0; return 0;
PlayerTextDrawHide(playerid, g_PoolTextdraw[playerid]); PlayerTextDrawHide(playerid, g_PoolTextdraw[playerid]);
@ -811,30 +748,20 @@ public RestoreCamera(playerid, poolid)
return SetCameraBehindPlayer(playerid); 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) public deleteBall(poolid, ballid)
{ {
if (g_poolBallData[poolid][E_MOVING][ballid]) if (g_poolBallData[poolid] [E_MOVING] [ballid])
{ {
g_poolBallData[poolid][E_EXISTS][ballid] = false; g_poolBallData[poolid] [E_EXISTS] [ballid] = false;
DestroyObject(g_poolBallData[poolid][E_BALL_OBJECT][ballid]); DestroyObject(g_poolBallData[poolid] [E_BALL_OBJECT] [ballid]);
PHY_DeleteObject(g_poolBallData[poolid][E_BALL_OBJECT][ballid]); PHY_DeleteObject(g_poolBallData[poolid] [E_BALL_OBJECT] [ballid]);
g_poolBallData[poolid][E_MOVING][ballid] = false; g_poolBallData[poolid] [E_MOVING] [ballid] = false;
} }
return 1; return 1;
} }
forward RestoreWeapon(playerid);
public RestoreWeapon(playerid) public RestoreWeapon(playerid)
{ {
RemovePlayerAttachedObject(playerid, 0); RemovePlayerAttachedObject(playerid, 0);
@ -851,11 +778,11 @@ public RestoreWeapon(playerid)
public PHY_OnObjectCollideWithObject(object1, object2) public PHY_OnObjectCollideWithObject(object1, object2)
{ {
for (new id = 0; id < MAX_TABLES; id ++) if (g_poolTableData[ id ][ E_STARTED ]) for (new id = 0; id < MAX_TABLES; id ++) if (g_poolTableData[ id ] [ E_STARTED ])
{ {
for (new i = 0; i < 16; i++) for (new i = 0; i < 16; i++)
{ {
if (object1 == g_poolBallData[id][E_BALL_OBJECT][i]) if (object1 == g_poolBallData[id] [E_BALL_OBJECT] [i])
{ {
PlayPoolSound(id, 31800 + random(3)); PlayPoolSound(id, 31800 + random(3));
return 1; return 1;
@ -867,11 +794,11 @@ public PHY_OnObjectCollideWithObject(object1, object2)
public PHY_OnObjectCollideWithWall(objectid, wallid) public PHY_OnObjectCollideWithWall(objectid, wallid)
{ {
for (new id = 0; id < MAX_TABLES; id ++) if (g_poolTableData[ id ][ E_STARTED ]) for (new id = 0; id < MAX_TABLES; id ++) if (g_poolTableData[ id ] [ E_STARTED ])
{ {
for (new i = 0; i < 16; i++) for (new i = 0; i < 16; i++)
{ {
if (objectid == g_poolBallData[id][E_BALL_OBJECT][i]) if (objectid == g_poolBallData[id] [E_BALL_OBJECT] [i])
{ {
PlayPoolSound(id, 31808); PlayPoolSound(id, 31808);
return 1; return 1;
@ -893,11 +820,11 @@ public PHY_OnObjectUpdate(objectid)
for (new j = 0; j < 16; j ++) for (new j = 0; j < 16; j ++)
{ {
if ( IsBallInHole( poolid, objectid) ) if ( IsBallInHole( poolid, objectid ) )
{ {
if ( objectid == g_poolBallData[ poolid ][ E_BALL_OBJECT ][ j ] && PHY_IsObjectMoving( g_poolBallData[ poolid ][ E_BALL_OBJECT ][ j ]) && !g_poolBallData[ poolid ][ E_MOVING ][ j ] ) if ( objectid == g_poolBallData[ poolid ] [ E_BALL_OBJECT ] [ j ] && PHY_IsObjectMoving( g_poolBallData[ poolid ] [ E_BALL_OBJECT ] [ j ]) && !g_poolBallData[ poolid ] [ E_MOVING ] [ j ] )
{ {
new pool_player = g_poolTableData[ poolid ][ E_LAST_SHOOTER ], new pool_player = g_poolTableData[ poolid ] [ E_LAST_SHOOTER ],
modelid = GetObjectModel( objectid ); modelid = GetObjectModel( objectid );
if (modelid == 3003) if (modelid == 3003)
@ -917,26 +844,26 @@ public PHY_OnObjectUpdate(objectid)
//ShowPlayerHelpDialog( pool_player, 10000, "~w~You have pocketed another ball!~n~~n~Score: %d", p_PoolScore[pool_player]); //ShowPlayerHelpDialog( pool_player, 10000, "~w~You have pocketed another ball!~n~~n~Score: %d", p_PoolScore[pool_player]);
if (pool_player == g_poolTableData[ poolid ][ E_PLAYER ] [ 0 ]) if (pool_player == g_poolTableData[ poolid ] [ E_PLAYER ] [ 0 ])
{ {
format(szNormalString, sizeof(szNormalString), "{FFDC2E}%s [%d] - [%d] %s", ReturnPlayerName(pool_player), p_PoolScore[ pool_player ], p_PoolScore[ g_poolTableData[ poolid ][ E_PLAYER ] [ 1 ] ], ReturnPlayerName(g_poolTableData[ poolid ][ E_PLAYER ] [ 1 ])); format(szNormalString, sizeof(szNormalString), "{FFDC2E}%s [%d] - [%d] %s", ReturnPlayerName(pool_player), p_PoolScore[ pool_player ], p_PoolScore[ g_poolTableData[ poolid ] [ E_PLAYER ] [ 1 ] ], ReturnPlayerName(g_poolTableData[ poolid ] [ E_PLAYER ] [ 1 ]));
} }
else if (pool_player == g_poolTableData[ poolid ][ E_PLAYER ] [ 1 ]) else if (pool_player == g_poolTableData[ poolid ] [ E_PLAYER ] [ 1 ])
{ {
format(szNormalString, sizeof(szNormalString), "{FFDC2E}%s [%d] - [%d] %s", ReturnPlayerName(g_poolTableData[ poolid ][ E_PLAYER ] [ 0 ]), p_PoolScore[ g_poolTableData[ poolid ][ E_PLAYER ] [ 0 ] ], p_PoolScore[ pool_player ], ReturnPlayerName(pool_player)); format(szNormalString, sizeof(szNormalString), "{FFDC2E}%s [%d] - [%d] %s", ReturnPlayerName(g_poolTableData[ poolid ] [ E_PLAYER ] [ 0 ]), p_PoolScore[ g_poolTableData[ poolid ] [ E_PLAYER ] [ 0 ] ], p_PoolScore[ pool_player ], ReturnPlayerName(pool_player));
} }
UpdateDynamic3DTextLabelText(g_poolTableData[ poolid ][ E_LABEL ], -1, szNormalString); UpdateDynamic3DTextLabelText(g_poolTableData[ poolid ] [ E_LABEL ], -1, szNormalString);
} }
new Float: vx, new Float: vx,
Float: vy, Float: vy,
Float: vz; Float: vz;
GetObjectPos( g_poolBallData[ poolid ][ E_BALL_OBJECT ][ j ], vx, vy, vz); GetObjectPos( g_poolBallData[ poolid ] [ E_BALL_OBJECT ] [ j ], vx, vy, vz);
MoveObject( g_poolBallData[ poolid ][ E_BALL_OBJECT ][ j ], vx, vy, vz - 1.25, 1); MoveObject( g_poolBallData[ poolid ] [ E_BALL_OBJECT ] [ j ], vx, vy, vz - 1.25, 1);
g_poolBallData[ poolid ][ E_MOVING ][ j ] = true; g_poolBallData[ poolid ] [ E_MOVING ] [ j ] = true;
SetTimerEx("deleteBall", 500, false, "dd", poolid, j); SetTimerEx("deleteBall", 500, false, "dd", poolid, j);
@ -944,14 +871,14 @@ public PHY_OnObjectUpdate(objectid)
if (( GetPoolBallsCount( poolid ) - 1) <= 1) if (( GetPoolBallsCount( poolid ) - 1) <= 1)
{ {
g_poolTableData[ poolid ][ E_STARTED ] = false; g_poolTableData[ poolid ] [ E_STARTED ] = false;
g_poolTableData[ poolid ][ E_AIMER ] = -1; g_poolTableData[ poolid ] [ E_AIMER ] = -1;
new new
win_score = GetMaxPoolScore( poolid ); win_score = GetMaxPoolScore( poolid );
RestoreCamera(i, poolid); RestoreCamera(i, poolid);
g_poolTableData[ poolid ][ E_LAST_SHOOTER ] = -1; g_poolTableData[ poolid ] [ E_LAST_SHOOTER ] = -1;
if ( IsPlayerPlayingPool( i ) && p_PoolScore[ i ] == win_score) if ( IsPlayerPlayingPool( i ) && p_PoolScore[ i ] == win_score)
{ {
@ -966,8 +893,8 @@ public PHY_OnObjectUpdate(objectid)
} }
else if (AreAllBallsStopped(poolid)) else if (AreAllBallsStopped(poolid))
{ {
SetTimerEx("RestoreCamera", 800, 0, "dd", g_poolTableData[ poolid][ E_LAST_SHOOTER ], poolid); SetTimerEx("RestoreCamera", 800, 0, "dd", g_poolTableData[ poolid ] [ E_LAST_SHOOTER ], poolid);
g_poolTableData[ i][ E_LAST_SHOOTER ] = -1; g_poolTableData[ i] [ E_LAST_SHOOTER ] = -1;
} }
} }
} }
@ -1001,17 +928,17 @@ CMD:pool(playerid, params[])
new poolid = p_PoolID[ playerid ]; new poolid = p_PoolID[ playerid ];
g_poolTableData[ poolid ][ E_PLAYER ] [ 0 ] = playerid; g_poolTableData[ poolid ] [ E_PLAYER ] [ 0 ] = playerid;
g_poolTableData[ poolid ][ E_PLAYER ] [ 1 ] = targetid; g_poolTableData[ poolid ] [ E_PLAYER ] [ 1 ] = targetid;
SendClientMessageFormatted(targetid, -1, ""COL_POOL"[SERVER]"COL_WHITE" %s(%d) has accepted your pool game invitation.", ReturnPlayerName(playerid), playerid); SendClientMessageFormatted(targetid, -1, ""COL_POOL"[SERVER]"COL_WHITE" %s(%d) has accepted your pool game invitation.", ReturnPlayerName(playerid), playerid);
SendClientMessageFormatted(playerid, -1, ""COL_POOL"[SERVER]"COL_WHITE" You have accepted %s(%d)'s pool game invitation.", ReturnPlayerName(targetid), targetid); SendClientMessageFormatted(playerid, -1, ""COL_POOL"[SERVER]"COL_WHITE" You have accepted %s(%d)'s pool game invitation.", ReturnPlayerName(targetid), targetid);
SendClientMessageFormatted(playerid, -1, ""COL_POOL"[SERVER]"COL_WHITE" %s(%d) will be breaking!", ReturnPlayerName(playerid), playerid); SendClientMessageFormatted(playerid, -1, ""COL_POOL"[SERVER]"COL_WHITE" %s(%d) will be breaking!", ReturnPlayerName(playerid), playerid);
//UpdateDynamicLabel(poolid, 10000, "{C0C0C0}Pool Table\n{FFFFFF}%s(%d) will be breaking!", ReturnPlayerName(g_poolTableData[ poolid][poolPlayer][startid]), g_poolTableData[ poolid][poolPlayer][startid]); //UpdateDynamicLabel(poolid, 10000, "{C0C0C0}Pool Table\n{FFFFFF}%s(%d) will be breaking!", ReturnPlayerName(g_poolTableData[ poolid ] [poolPlayer] [startid]), g_poolTableData[ poolid ] [poolPlayer] [startid]);
format(szNormalString, sizeof(szNormalString), "{FFDC2E}%s [0] - [0] %s", ReturnPlayerName(playerid), ReturnPlayerName(targetid)); format(szNormalString, sizeof(szNormalString), "{FFDC2E}%s [0] - [0] %s", ReturnPlayerName(playerid), ReturnPlayerName(targetid));
UpdateDynamic3DTextLabelText(g_poolTableData[ poolid][ E_LABEL ], -1, szNormalString); UpdateDynamic3DTextLabelText(g_poolTableData[ poolid ] [ E_LABEL ], -1, szNormalString);
p_isPlayingPool{ playerid } = true; p_isPlayingPool{ playerid } = true;
p_PoolID[ playerid ] = poolid; p_PoolID[ playerid ] = poolid;
@ -1027,9 +954,9 @@ CMD:pool(playerid, params[])
GivePlayerWeapon(targetid, 7, 1); GivePlayerWeapon(targetid, 7, 1);
GivePlayerWeapon(playerid, 7, 1); GivePlayerWeapon(playerid, 7, 1);
if (!g_poolTableData[ poolid][ E_STARTED ]) if (!g_poolTableData[ poolid ] [ E_STARTED ])
{ {
g_poolTableData[ poolid][ E_STARTED ] = true; g_poolTableData[ poolid ] [ E_STARTED ] = true;
RespawnPoolBalls(poolid, 1); RespawnPoolBalls(poolid, 1);
} }
return 1; return 1;
@ -1055,7 +982,7 @@ CMD:pool(playerid, params[])
if (id == -1) if (id == -1)
return SendError(playerid, "You are not close enough to a pool table."); return SendError(playerid, "You are not close enough to a pool table.");
if (g_poolTableData[ id ][ E_STARTED ]) if (g_poolTableData[ id ] [ E_STARTED ])
return SendError(playerid, "You cannot invite anyone to this table, since there is already a game in progress."); return SendError(playerid, "You cannot invite anyone to this table, since there is already a game in progress.");
if (sscanf(params, "s[32] u", selection, targetid)) if (sscanf(params, "s[32] u", selection, targetid))
@ -1130,11 +1057,11 @@ CMD:play(playerid)
p_PoolScore[ playerid ] = 0; p_PoolScore[ playerid ] = 0;
if (!g_poolTableData[ iPool ][ E_STARTED ]) if (!g_poolTableData[ iPool ] [ E_STARTED ])
{ {
g_poolTableData[ iPool ][ E_STARTED ] = true; g_poolTableData[ iPool ] [ E_STARTED ] = true;
UpdateDynamic3DTextLabelText(g_poolTableData[ iPool ][ E_LABEL ], -1, sprintf( "{FFDC2E}%s is currently playing a test game.", ReturnPlayerName( playerid )) ); UpdateDynamic3DTextLabelText(g_poolTableData[ iPool ] [ E_LABEL ], -1, sprintf( "{FFDC2E}%s is currently playing a test game.", ReturnPlayerName( playerid )) );
RespawnPoolBalls(iPool, 1); RespawnPoolBalls(iPool, 1);
} }
@ -1154,12 +1081,13 @@ CMD:addpool(playerid)
if ( p_AdminLevel[ playerid ] < 6 ) if ( p_AdminLevel[ playerid ] < 6 )
return SendError( playerid, ADMIN_COMMAND_REJECT ); return SendError( playerid, ADMIN_COMMAND_REJECT );
new Float: x, Float: y, Float: z; new
Float: x, Float: y, Float: z;
GetPlayerFrontPos(playerid, x, y, z, 2.0);
CreatePoolTable(x, y, z, 0.0, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
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."); SendClientMessage(playerid, -1, ""COL_PINK"[ADMIN]{FFFFFF} You have created a pool table.");
}
return 1; return 1;
} }