Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <physics>
- #include <zcmd>
- #define MAX_POOL 100
- new POOL_COUNT = 0;
- new InPOOL[MAX_PLAYERS];
- new PlayerPoolID[MAX_PLAYERS] = 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 System by Victor, SEF]");
- return 1;
- }
- CMD:createpool(playerid) return cmd_pool(playerid);
- CMD:pool(playerid)
- {
- if(InPOOL[playerid] == 1) return SendClientMessage(playerid, -1, "[POOL]: You are already playing pool minigame!");
- createPoolTable(playerid);
- SendClientMessage(playerid, -1, "[POOL]: Successfully, Pool table created!");
- SendClientMessage(playerid, -1, "[POOL]: Use /ppool (/playpool), to play pool!");
- SendClientMessage(playerid, -1, "[POOL]: Use /dpool (/deletepool), to destroy pool!");
- return 1;
- }
- CMD:playpool(playerid) return cmd_ppool(playerid);
- CMD:ppool(playerid)
- {
- if(InPOOL[playerid] == 0) return SendClientMessage(playerid, -1, "[POOL]: You are not playing pool minigame!");
- new
- speed = 3,
- Float: angle;
- for(new i = 0; i < POOL_COUNT; i++)
- {
- if(POOL[i][ID] == PlayerPoolID[playerid])
- {
- GetPlayerFacingAngle(playerid, angle);
- PHY_SetObjectVelocity(POOL[i][BALLS][0], speed * floatsin( -angle, degrees), speed * floatcos( -angle, degrees));
- }
- }
- return 1;
- }
- CMD:deletepool(playerid) return cmd_dpool(playerid);
- CMD:dpool(playerid)
- {
- if(InPOOL[playerid] == 0) return SendClientMessage(playerid, -1, "[POOL]: You are not playing pool minigame!");
- for(new i = 0; i < POOL_COUNT; i++)
- {
- if(POOL[i][ID] == PlayerPoolID[playerid])
- {
- DestroyObject(POOL[i][BALLS][0]);
- DestroyObject(POOL[i][BALLS][1]);
- DestroyObject(POOL[i][BALLS][2]);
- DestroyObject(POOL[i][BALLS][3]);
- DestroyObject(POOL[i][BALLS][4]);
- DestroyObject(POOL[i][BALLS][5]);
- DestroyObject(POOL[i][BALLS][6]);
- DestroyObject(POOL[i][BALLS][7]);
- DestroyObject(POOL[i][BALLS][8]);
- DestroyObject(POOL[i][BALLS][9]);
- DestroyObject(POOL[i][BALLS][10]);
- DestroyObject(POOL[i][BALLS][11]);
- DestroyObject(POOL[i][BALLS][12]);
- DestroyObject(POOL[i][BALLS][13]);
- DestroyObject(POOL[i][BALLS][14]);
- DestroyObject(POOL[i][BALLS][15]);
- PHY_DeleteObject(POOL[i][BALLS][0]);
- PHY_DeleteObject(POOL[i][BALLS][1]);
- PHY_DeleteObject(POOL[i][BALLS][2]);
- PHY_DeleteObject(POOL[i][BALLS][3]);
- PHY_DeleteObject(POOL[i][BALLS][4]);
- PHY_DeleteObject(POOL[i][BALLS][5]);
- PHY_DeleteObject(POOL[i][BALLS][6]);
- PHY_DeleteObject(POOL[i][BALLS][7]);
- PHY_DeleteObject(POOL[i][BALLS][8]);
- PHY_DeleteObject(POOL[i][BALLS][9]);
- PHY_DeleteObject(POOL[i][BALLS][10]);
- PHY_DeleteObject(POOL[i][BALLS][11]);
- PHY_DeleteObject(POOL[i][BALLS][12]);
- PHY_DeleteObject(POOL[i][BALLS][13]);
- PHY_DeleteObject(POOL[i][BALLS][14]);
- PHY_DeleteObject(POOL[i][BALLS][15]);
- Delete3DTextLabel(POOL[i][LABEL]);
- DestroyObject(POOL[i][TABLE]);
- PHY_DeleteObject(POOL[i][TABLE]);
- InPOOL[playerid] = 0;
- PlayerPoolID[playerid] = 0;
- }
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- InPOOL[playerid] = 0;
- 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);
- PlayerPoolID[playerid] = POOL[POOL_COUNT][ID];
- // 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, "[SEF] POOL TABLE (ID: %d)", PlayerPoolID[playerid]);
- 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 ++;
- InPOOL[playerid] =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 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;
- }
Add Comment
Please, Sign In to add comment