Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Basketball System by Kaliber */
- #include <open.mp>
- /******************************************************************************/
- #define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- #define PreloadAnim(%0,%1) ApplyAnimation(%0,%1,!"NULL",4.1,false,true,true,false,0)
- /******************************************************************************/
- #define sleep(%0)<%1>; SetTimer("@sleep_"#%1#,%0,false); return 1;}\
- @sleep_%1();@sleep_%1() {
- /******************************************************************************/
- #define pSleep(%0)<%1,%2,%3>; SetTimerEx("@pSleep_"#%1#,%0,false,%2,%3); return 1;}\
- @pSleep_%1(%3);@pSleep_%1(%3) {
- /******************************************************************************/
- const Float:DISTANCE_TO_GROUND=0.8,Float:DISTANCE_IN_FRONT=1.0,Float:flugSpeed=6.0,Float:wurfHeight=5.0,Float:wurfWeite=10.0,Float:passHeight=2.5,Float:passSpeed=8.0;
- new ball = -1, holder = -1, Float:ballSpeed = 4.75, korbCheck = -1, ballTrick = -1, bool:passWurf = false, bool:korbWurf = false, bool:ballLocked = false, wurfTimer = -1, endWurfTimer = -1, lastHolder = -1;
- new infoPickup, Text3D:infoLabel;
- /******************************************************************************/
- public OnFilterScriptExit()
- {
- if(holder != -1)
- {
- DropBall(holder);
- }
- DestroyObject(ball);
- DestroyPickup(infoPickup);
- Delete3DTextLabel(infoLabel);
- return 1;
- }
- public OnFilterScriptInit()
- {
- ball = CreateObject(2114,2290.6697, -1528.4869, 26.8750-DISTANCE_TO_GROUND,0,0,0);
- infoPickup = CreatePickup(1239, 23, 2298.2263,-1501.6254,25.3047);
- infoLabel = Create3DTextLabel(!"<< Basketball Info >>\n\n{FF5C00}Tasten:\nC{FFFFFF} - Ball ann-/auf-/wegnehmen\n{FF5C00}LSTRG{FFFFFF} - Wurf\n{FF5C00}LALT{FFFFFF} - Trick\n{FF5C00}N{FFFFFF} - Passen\n{FF5C00}ENTER{FFFFFF} - Ablegen\n{FF5C00}Leertaste{FFFFFF} - Laufen/Sprinten", -1, 2298.2263,-1501.6254,25.3047+0.75, 15.0, 0,true);
- PreloadAnimsForAllPlayer();
- SetPlayerPos(0, 2290.6697, -1528.4869, 26.8750);
- sleep(1000)<clearChat>;
- for(new i; i<100; i++) SendClientMessage(0,-1,!" ");
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(playerid == holder)
- {
- DropBall(playerid);
- }
- return 1;
- }
- public OnObjectMoved(objectid)
- {
- if(objectid != ball) return 1;
- if(holder != -1 && ballTrick == -1)
- {
- if(GetPlayerAnimationIndex(holder) == 1133)
- {
- SetCurrentMovement(holder);
- return 1;
- }
- DripBall(holder);
- }
- return 1;
- }
- public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
- {
- if(HasBall(playerid))
- {
- DropBall(playerid);
- }
- return 1;
- }
- public OnPlayerKeyStateChange(playerid,KEY:newkeys,KEY:oldkeys)
- {
- if(HasBall(playerid))
- {
- if(PRESSED(KEY_SPRINT)) // Laufen/Rennen
- {
- ToggleMovement(playerid);
- }
- else if(PRESSED(KEY_FIRE)) // Korb Wurf
- {
- RemovePlayerBall(playerid);
- SetTimerEx(!"@korb_wurf",250,false,!"i",playerid);
- ApplyAnimation(playerid,!"BSKTBALL",!"BBALL_Jump_Shot",4.1,false,true,true,false,0);
- }
- else if(PRESSED(KEY_NO)) // Pass spiel werfen
- {
- RemovePlayerBall(playerid);
- SetTimerEx(!"@pass_game",250,false,!"ii",playerid,1);
- ApplyAnimation(playerid,!"BSKTBALL",!"BBALL_Jump_End",4.1,false,true,true,false,0);
- }
- else if(PRESSED(KEY_SECONDARY_ATTACK)) // Ball ablegen
- {
- DropBall(playerid);
- }
- else if(PRESSED(KEY_WALK)) // Ball Trick
- {
- if(ballTrick == -1)
- {
- DestroyObject(ball),ball=-1;
- ApplyAnimation(playerid,!"BSKTBALL",!"BBALL_idle2",4.1,true,true,true,true,0);
- ballTrick = SetTimerEx(!"@RotateAttachedBall",50,true,!"i",playerid);
- }
- else
- {
- SetCurrentMovement(playerid);
- }
- }
- }
- else
- {
- if(PRESSED(KEY_CROUCH)) // Ball aufheben
- {
- if(passWurf && lastHolder != playerid && IsPlayerInRangeOfBall(playerid, 3.5)) // Pass Annehmen
- {
- ApplyAnimation(playerid,!"BSKTBALL",!"BBALL_Dnk",4.1,false,true,true,false,0);
- GivePlayerBall(playerid);
- return 1;
- }
- if(holder == -1 && IsPlayerInRangeOfBall(playerid, 2.0)) // Ball aufheben
- {
- PickupBall(playerid);
- return 1;
- }
- if(!ballLocked && IsPlayerInRangeOfBall(playerid, 1.0)) // Ball wegnehmen
- {
- RemovePlayerBall(holder), GivePlayerBall(playerid);
- return 1;
- }
- }
- else if(PRESSED(KEY_JUMP) && korbWurf && IsPlayerInRangeOfBall(playerid, 2.5) && lastHolder != playerid) // Wurf blocken
- {
- BlockBall(playerid);
- }
- }
- return 1;
- }
- /******************************************************************************/
- stock SetCurrentMovement(playerid)
- {
- return (ballSpeed < 8) ? Walk(playerid) : Run(playerid);
- }
- stock ToggleMovement(playerid)
- {
- return (ballSpeed < 8) ? Run(playerid) : Walk(playerid);
- }
- stock Walk(playerid)
- {
- DripBall(playerid);
- ballSpeed = 4.75;
- ApplyAnimation(playerid,!"BSKTBALL",!"BBALL_walk",4.1,true,true,true,true,1);
- return 1;
- }
- stock Run(playerid)
- {
- DripBall(playerid);
- ballSpeed = 8.0;
- ApplyAnimation(playerid,!"BSKTBALL",!"BBALL_run",4.1,true,true,true,true,1);
- return 1;
- }
- /******************************************************************************/
- stock StopBallTrick(playerid)
- {
- if(ballTrick == -1) return 0;
- new Float:x,Float:y,Float:z;
- GetPosInFrontOfPlayer(playerid, DISTANCE_IN_FRONT, x,y,z, 20.0);
- RemovePlayerAttachedObject(playerid, 0);
- KillTimer(ballTrick), ballTrick=-1;
- ball = CreateObject(2114, x,y,z,0,0,0);
- return 1;
- }
- stock DripBall(playerid)
- {
- StopBallTrick(playerid);
- new Float:x,Float:y,Float:z;
- GetPosInFrontOfPlayer(playerid, DISTANCE_IN_FRONT, x,y,z, 20.0);
- static bool:s;
- switch(s)
- {
- case false: MoveObject(ball,x,y,z,ballSpeed);
- case true: MoveObject(ball,x,y,z-DISTANCE_TO_GROUND,ballSpeed);
- }
- s=!s;
- }
- stock EndKorbCheck()
- {
- StopObject(ball);
- if(korbCheck != -1)
- {
- KillTimer(korbCheck), korbCheck = -1;
- }
- if(wurfTimer != -1)
- {
- KillTimer(wurfTimer), wurfTimer = -1;
- }
- if(endWurfTimer != -1)
- {
- KillTimer(endWurfTimer), @end_wurf();
- }
- return 1;
- }
- stock RemovePlayerBall(playerid)
- {
- StopBallTrick(playerid);
- ClearAnimations(playerid);
- holder = -1;
- EndKorbCheck();
- new Float:x,Float:y,Float:z;
- GetPosInFrontOfPlayer(playerid, 1.0, x,y,z);
- SetObjectPos(ball,x,y,z);
- return 1;
- }
- stock GivePlayerBall(playerid)
- {
- StopBallTrick(playerid);
- ballLocked = true;
- StopObject(ball);
- lastHolder = playerid;
- holder = playerid;
- SetCurrentMovement(playerid);
- sleep(1000)<unlock>;
- ballLocked = false;
- return 1;
- }
- stock DropBall(playerid)
- {
- StopBallTrick(playerid);
- holder = -1;
- new Float:x,Float:y,Float:z;
- GetPosInFrontOfPlayer(playerid, DISTANCE_IN_FRONT, x,y,z);
- MoveObject(ball, x,y,z-DISTANCE_TO_GROUND, 1.0);
- ApplyAnimation(playerid,!"BSKTBALL",!"BBALL_pickup",4.1,false,true,true,false,0);
- return 1;
- }
- stock PickupBall(playerid)
- {
- StopBallTrick(playerid);
- ballLocked = true;
- ApplyAnimation(playerid,!"BSKTBALL",!"BBALL_pickup",4.1,false,true,true,false,0);
- pSleep(1000)<pickup, "i", playerid>;
- GivePlayerBall(playerid);
- return 1;
- }
- stock BlockBall(playerid)
- {
- StopBallTrick(playerid);
- new Float:x,Float:y,Float:z;
- GetPlayerPos(playerid, x,y,z);
- EndKorbCheck();
- MoveObject(ball,x,y,z-DISTANCE_TO_GROUND,passSpeed);
- ApplyAnimation(playerid,!"BSKTBALL",!"BBALL_def_jump_shot",4.1,false,true,true,false,0);
- return 1;
- }
- stock ReactToGoal(bool:goal)
- {
- if(lastHolder == -1) return 1;
- ApplyAnimation(lastHolder,!"BSKTBALL",(goal ? (!"BBALL_react_score") : (!"BBALL_react_miss")),2.5,false,true,true,false,0);
- PlayerPlaySound(lastHolder, (goal) ? 182 : 1136, 0.0, 0.0, 0.0);
- new playerid = lastHolder;
- lastHolder = -1;
- pSleep(7000)<stopSound,"i",playerid>;
- PlayerPlaySound(playerid, 0, 0.0, 0.0, 0.0);
- return 1;
- }
- /******************************************************************************/
- // Helper Functions
- stock IsObjectInRangeOfPoint(objectid, Float:radi, Float:x1, Float:y1, Float:z1)
- {
- new Float:x2,Float:y2,Float:z2;
- GetObjectPos(objectid, x2, y2, z2);
- return VectorSize(x1-x2, y1-y2, z1-z2) < radi;
- }
- stock SendRangeMessage(Float:x,Float:y,Float:z,Float:r,const string[])
- {
- for(new i=MAX_PLAYERS; i!=-1; i--)
- {
- if(IsPlayerConnected(i) && !IsPlayerNPC(i) && IsPlayerInRangeOfPoint(i,r,x,y,z))
- {
- SendClientMessage(i,0xFF9900AA,string);
- }
- }
- return 1;
- }
- stock GetPosInFrontOfPlayer(playerid, Float:distance, &Float:x, &Float:y, &Float:z, Float:spin=0.0)
- {
- new Float:a;
- GetPlayerPos(playerid, x, y, z), GetPlayerFacingAngle(playerid, a);
- a -= spin;
- x += (distance * floatsin(-a, degrees));
- y += (distance * floatcos(-a, degrees));
- }
- stock HasBall(playerid) return playerid == holder;
- stock IsPlayerInRangeOfBall(playerid, Float:range)
- {
- new Float:x,Float:y,Float:z;
- GetObjectPos(ball, x,y,z);
- return IsPlayerInRangeOfPoint(playerid, range,x,y,z);
- }
- stock PreloadAnimsForAllPlayer()
- {
- for(new i=MAX_PLAYERS; i!=-1; i--)
- {
- if(IsPlayerConnected(i) && !IsPlayerNPC(i))
- {
- PreloadAnim(i, !"BSKTBALL");
- }
- }
- return 1;
- }
- /******************************************************************************/
- // Timer
- static @pass_game(i);@pass_game(i)
- {
- passWurf = true;
- new Float:x,Float:y,Float:z,Float:a;
- GetPlayerFacingAngle(i, a);
- GetPosInFrontOfPlayer(i, (wurfWeite/2), x,y,z);
- new t = MoveObject(ball,x,y,z+passHeight, passSpeed);
- wurfTimer = SetTimerEx(!"@wurf_phase_two", t, false, !"ff",a,z,false);
- return 1;
- }
- static @korb_wurf(i);@korb_wurf(i)
- {
- korbWurf = true;
- new Float:x,Float:y,Float:z,Float:a;
- GetPlayerFacingAngle(i, a);
- GetPosInFrontOfPlayer(i, (wurfWeite/2), x,y,z);
- new t = MoveObject(ball,x,y,z+wurfHeight, flugSpeed);
- wurfTimer = SetTimerEx(!"@wurf_phase_two", t, false, !"ff",a,z,true);
- return 1;
- }
- static @wurf_phase_two(Float:a,Float:z);@wurf_phase_two(Float:a,Float:z)
- {
- wurfTimer = -1;
- new Float:x,Float:y,Float:z2;
- GetObjectPos(ball, x,y,z2);
- x += (wurfWeite/2) * floatsin(-a, degrees);
- y += (wurfWeite/2) * floatcos(-a, degrees);
- new t = MoveObject(ball,x,y,z-DISTANCE_TO_GROUND,korbWurf ? flugSpeed : passSpeed);
- if(korbWurf)
- {
- korbCheck = SetTimer(!"@checkKorb",100,true);
- }
- endWurfTimer = SetTimer(!"@end_wurf",t,false);
- return 1;
- }
- static @end_wurf();@end_wurf()
- {
- if(korbWurf)
- {
- ReactToGoal(false);
- }
- endWurfTimer = -1;
- passWurf = korbWurf = false;
- if(korbCheck != -1)
- {
- KillTimer(korbCheck), korbCheck = -1;
- }
- return 1;
- }
- static @RotateAttachedBall(playerid);@RotateAttachedBall(playerid)
- {
- static Float:rotZ;
- rotZ += 10.0;
- if(rotZ > 360.0) rotZ = 0.0;
- SetPlayerAttachedObject(playerid, 0, 2114, 6, 0.32, 0.15, 0, rotZ, 90.0, 0.0, 1.0, 1.0, 1.0);
- return 1;
- }
- /******************************************************************************/
- enum eHoopData
- {
- Float:hA[3], // Hoop A
- Float:hB[3], // Hoop B
- Float:hStart[3]// where the ball returns to
- };
- static stock const Float:hData[][eHoopData] = {
- { // Hoop 1
- {2290.5068, -1514.7594, 28.8521}, // Hoop A
- {2290.7322, -1541.3042, 28.6934}, // Hoop B
- {2290.6697, -1528.4869, 26.8750} // ball reset pos
- },
- { // Hoop 2
- {2316.8618,-1514.7913,27.0}, // Hoop A
- {2316.9937,-1541.0542,27.0}, // Hoop B
- {2316.9741,-1527.1895,25.3438} // ball reset pos
- },
- { // Hoop 3
- {2514.6929,1266.4944,12.9130}, // Hoop A
- {2480.1257,1266.4353,12.5100}, // Hoop B
- {2496.3042,1272.1831,10.8125} // ball reset pos
- },
- { // Hoop 4
- {2480.1272,1266.4354,12.5126}, // Hoop A
- {2480.3235,1277.4980,12.5134}, // Hoop B
- {2496.3042,1272.1831,10.8125} // ball reset pos
- },
- { // Hoop 5
- {2055.7283,-1694.6697,16.3749}, // Hoop A
- {2055.7283,-1694.6697,16.3749}, // Hoop B
- {2071.1609,-1694.6697,13.5469} // ball reset pos
- }
- };
- static @checkKorb();@checkKorb()
- {
- for (new i; i < sizeof(hData); i++)
- {
- if (IsObjectInRangeOfPoint(ball, 0.5, hData[i][hA][0], hData[i][hA][1], hData[i][hA][2]) || IsObjectInRangeOfPoint(ball, 0.5, hData[i][hB][0], hData[i][hB][1], hData[i][hB][2]))
- {
- new string[80];
- GetPlayerName(lastHolder,string,MAX_PLAYER_NAME);
- format(string,sizeof(string),"* Spieler %s (ID: %d) hat einen Korb geworfen!",string,lastHolder);
- SendRangeMessage(hData[i][hStart][0], hData[i][hStart][1], hData[i][hStart][2], 40.0, string);
- SetObjectPos(ball,hData[i][hStart][0], hData[i][hStart][1], hData[i][hStart][2]-DISTANCE_TO_GROUND);
- ReactToGoal(true);
- EndKorbCheck();
- break;
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment