Advertisement
Guest User

[GM] H@Y

a guest
May 7th, 2012
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 13.99 KB | None | 0 0
  1. /*
  2. R@f : Créator
  3. Syg : Hay tower créator
  4. Fullmetal : Tester
  5. Keyman : /specplayer command
  6. All the SA-MP team for creating this Multiplayer mod
  7. */
  8.  
  9. #include <a_samp>
  10. #include <core>
  11. #include <float>
  12.  
  13. forward TimerMove ();
  14. forward TimerScore ();
  15. forward TimerFini (id, x, y, z);
  16. forward TDScore ();
  17. forward DelayedGmx();
  18. forward DelayedGmx2();
  19.  
  20. #define COLOR_GREY 0xAFAFAFAA
  21. #define COLOR_GREEN 0x33AA33AA
  22.  
  23. #define PAILLE_X            4  
  24. #define PAILLE_Y            4
  25. #define PAILLE_Z           30    
  26. #define PAILLE_B          146
  27. #define PAILLE_R            4
  28. #define SPEED_FACTOR     3000.0
  29. #define ID_HAY_OBJECT    3374
  30. #define ID_ROCK_OBJECT   1305
  31. #define ADMIN_SPEC_TYPE_NONE 0
  32. #define ADMIN_SPEC_TYPE_PLAYER 1
  33.  
  34. new gSpectateID[MAX_PLAYERS];
  35. new gSpectateType[MAX_PLAYERS];
  36. new Vitesse_xy;
  37. new Vitesse_z;
  38. new Centre_x;
  39. new Centre_y;
  40. new Matrice[PAILLE_X][PAILLE_Y][PAILLE_Z];
  41. new Bottes[PAILLE_B];
  42. new Rochers[PAILLE_B];
  43. new EnDeplacement[PAILLE_B];
  44. new BotteDuHaut;
  45. new Text:Score[MAX_PLAYERS];
  46.  
  47. main()
  48. {
  49.     print("\n-------------------------------------------");
  50.     print(" Hay GameMode for SA-MP 1.0 by R@f and Syg");
  51.     print("-------------------------------------------\n");
  52. }
  53.  
  54. //==============================================================================
  55.  
  56. public OnGameModeInit()
  57. {
  58.     SetGameModeText("Hay 1.0");
  59.     UsePlayerPedAnims();
  60.     InitialiserTourPaille ();
  61.    
  62.     SetTimer ("TimerScore", 200, 1);
  63.     SetTimer ("TDScore", 600, 1);
  64.  
  65.     AddPlayerClass(0, 35.0, 6.5, 3.2, 135.1425, 0, 0, 0, 0, 0, 0);
  66.     AddPlayerClass(29, 35.0, 6.5, 3.2, 135.1425, 0, 0, 0, 0, 0, 0);
  67.     AddPlayerClass(188, 35.0, 6.5, 3.2, 135.1425, 0, 0, 0, 0, 0, 0);
  68.     return 1;
  69. }
  70.  
  71. //==============================================================================
  72.  
  73. public OnPlayerRequestClass(playerid, classid)
  74. {
  75.     SetPlayerPos(playerid, -8.6413,-8.4667,95.5060);
  76.     SetPlayerFacingAngle(playerid,269.1425);
  77.     SetPlayerCameraPos(playerid, -0.8600,-0.4655,97.1056);
  78.     SetPlayerCameraLookAt(playerid, -8.6413,-8.4667,95.5060);
  79.     ApplyAnimation(playerid,"DANCING","DNCE_M_A",4.0,1,0,0,0,-1);
  80.     PlayerPlaySound(playerid,1062, 0.0, 0.0, 0.0);
  81.     switch (classid)
  82.     {
  83.         case 0:
  84.         {
  85.             GameTextForPlayer(playerid, "~g~CJ", 1500, 3);
  86.         }
  87.         case 1:
  88.         {
  89.             GameTextForPlayer(playerid, "~w~Raf", 1500, 3);
  90.         }
  91.         case 2:
  92.         {
  93.             GameTextForPlayer(playerid, "~w~Syg", 1500, 3);
  94.         }
  95.     }
  96.     return 1;
  97. }
  98.  
  99. //==============================================================================
  100.  
  101. public OnPlayerConnect(playerid)
  102. {
  103.     new string[128];
  104.     new pname[128];
  105.    
  106.     GetPlayerName(playerid, pname, sizeof(pname));
  107.     format(string, sizeof(string), "*** %s has joined the server", pname);
  108.     SendClientMessageToAll(COLOR_GREY, string);
  109.     GameTextForPlayer(playerid,"~w~]~b~H~r~A~g~Y~y~ 1.0~w~]",2500,5);
  110.     SetPlayerColor(playerid, COLOR_GREY);
  111.     return 1;
  112. }
  113.  
  114. //==============================================================================
  115.  
  116. public OnPlayerDisconnect(playerid, reason)
  117. {
  118.     new pname[128], string[128];
  119.     GetPlayerName(playerid, pname, sizeof(pname));
  120.     TextDrawHideForPlayer(playerid, Score[playerid]);
  121.     if(reason == 0)
  122.     {
  123.         format(string, sizeof(string), "*** %s left the server. (Timeout)", pname);
  124.         SendClientMessageToAll(COLOR_GREY, string);
  125.         print(string);
  126.     }
  127.     else if(reason == 1)
  128.     {
  129.         format(string, sizeof(string), "*** %s left the server. (Leaving)", pname);
  130.         SendClientMessageToAll(COLOR_GREY, string);
  131.         print(string);
  132.     }
  133.     else if(reason == 2)
  134.     {
  135.         format(string, sizeof(string), "*** %s left the server. (Kicked/Banned)", pname);
  136.         SendClientMessageToAll(COLOR_GREY, string);
  137.         print(string);
  138.     }
  139.     return 1;
  140. }
  141.  
  142. //==============================================================================
  143.  
  144. public OnPlayerDeath(playerid, killerid, reason)
  145. {
  146.     SendDeathMessage(killerid,playerid,reason);
  147.     TextDrawHideForPlayer(playerid, Score[playerid]);
  148.     TextDrawDestroy(Score[playerid]);
  149.     return 1;
  150. }
  151.  
  152. //==============================================================================
  153.  
  154. public OnPlayerSpawn(playerid)
  155. {
  156.     Score[playerid] = TextDrawCreate(20.0,425.0," ");
  157.     TextDrawAlignment(Score[playerid],0);
  158.     TextDrawBackgroundColor(Score[playerid],0x000000ff);
  159.     TextDrawFont(Score[playerid],1);
  160.     TextDrawLetterSize(Score[playerid],0.5,1.5);
  161.     TextDrawColor(Score[playerid],0xffffffcc);
  162.     TextDrawSetOutline(Score[playerid],1);
  163.     TextDrawSetProportional(Score[playerid],1);
  164.     TextDrawSetShadow(Score[playerid],1);
  165.     TextDrawShowForPlayer(playerid, Score[playerid]);
  166.  
  167.     PlayerPlaySound (playerid, 1063, 0.0, 0.0, 0.0);
  168.     SetPlayerWorldBounds(playerid, 116.7788, -70.06725, 105.1009, -116.7788);
  169.     return 1;
  170. }
  171.  
  172. //==============================================================================
  173.  
  174.  
  175. public DelayedGmx()
  176. {
  177.     for(new i=0; i<MAX_PLAYERS; i++)
  178.     {
  179.         TextDrawHideForPlayer(i, Score[i]);
  180.     }
  181.     SetTimer("DelayedGmx2",5000, false);
  182.     return 1;
  183. }
  184.  
  185. public DelayedGmx2()
  186. {
  187.     GameModeExit();
  188. }
  189.  
  190. //==============================================================================
  191.  
  192. public OnPlayerCommandText(playerid, cmdtext[])
  193. {
  194.     new cmd[128];
  195.     new specplayerid,idx;
  196.     cmd = strtok(cmdtext, idx);
  197.    
  198.     if(strcmp(cmdtext, "/acmds", true) == 0 && IsPlayerAdmin(playerid))
  199.     {
  200.         SendClientMessage(playerid,COLOR_GREEN,"***Hay GameMode for SA-MP***");
  201.         SendClientMessage(playerid,COLOR_GREEN,"/gmx : restart the GM");
  202.         SendClientMessage(playerid,COLOR_GREEN,"/hay : rebuild the hay tower");
  203.         return 1;
  204.     }
  205.    
  206.     if(strcmp(cmdtext, "/gmx", true) == 0 && IsPlayerAdmin(playerid))
  207.     {
  208.         SetTimer("DelayedGmx",5000,false);
  209.         return 1;
  210.     }
  211.  
  212.     if(strcmp(cmdtext, "/hay", true) == 0 && IsPlayerAdmin(playerid))
  213.     {
  214.         NettoyerTourDePaille();
  215.         InitialiserTourPaille ();
  216.         return 1;
  217.     }
  218.    
  219.     if(strcmp(cmdtext, "/help", true) == 0)
  220.     {
  221.         SendClientMessage(playerid,COLOR_GREEN,"***Hay GameMode for SA-MP***");
  222.         SendClientMessage(playerid,COLOR_GREEN,"For a list of the commands write /cmds");
  223.         SendClientMessage(playerid,COLOR_GREEN,"For the list of the credits write /credits");
  224.         return 1;
  225.     }
  226.  
  227.     if(strcmp(cmdtext, "/cmds", true) == 0)
  228.     {
  229.         SendClientMessage(playerid,COLOR_GREEN,"***Hay GameMode for SA-MP***");
  230.         SendClientMessage(playerid,COLOR_GREEN,"/kill : Kill your self");
  231.         SendClientMessage(playerid,COLOR_GREEN,"/specplayer : Spec a player");
  232.         SendClientMessage(playerid,COLOR_GREEN,"/specoff : Turn the specplayer off");
  233.         SendClientMessage(playerid,COLOR_GREEN,"/cam : Show the hay tower");
  234.         SendClientMessage(playerid,COLOR_GREEN,"/spawn : Spawn at your spawn point");
  235.         SendClientMessage(playerid,COLOR_GREEN,"/acmds : See admin commands (Admin Only)");
  236.         return 1;
  237.     }
  238.  
  239.     if(strcmp(cmdtext, "/credits", true) == 0)
  240.     {
  241.         SendClientMessage(playerid,COLOR_GREEN,"***Hay GameMode for SA-MP***");
  242.         SendClientMessage(playerid,COLOR_GREEN,"This GameMode is scripted by R@f and Syg");
  243.         SendClientMessage(playerid,COLOR_GREEN,"Special thanks to Syg for the hay script");
  244.         SendClientMessage(playerid,COLOR_GREEN,"Thanks to Kyeman for his Specplayer");
  245.         return 1;
  246.     }
  247.  
  248.     if(strcmp(cmdtext, "/kill", true) == 0)
  249.     {
  250.         SetPlayerHealth(playerid,0);
  251.         return 1;
  252.     }
  253.  
  254.     if(strcmp(cmdtext, "/spawn", true) == 0)
  255.     {
  256.         SpawnPlayer(playerid);
  257.         return 1;
  258.     }
  259.  
  260.     if(strcmp(cmdtext, "/cam", true) == 0)
  261.     {
  262.         TogglePlayerControllable(playerid,0);
  263.         SetPlayerCameraPos(playerid, 32.9946,47.2079,78.5389);
  264.         SetPlayerCameraLookAt(playerid, -5.6487,1.4449,50.5060);
  265.         SendClientMessage(playerid,COLOR_GREEN,"Write /spawn to exit this view");
  266.         return 1;
  267.     }
  268.  
  269.     if(strcmp(cmd, "/specplayer", true) == 0)
  270.     {
  271.         new tmp[128];
  272.         tmp = strtok(cmdtext, idx);
  273.  
  274.         if(!strlen(tmp))
  275.         {
  276.             return SendClientMessage(playerid, COLOR_GREEN, "USAGE: /specplayer [playerid]");
  277.         }
  278.         specplayerid = strval(tmp);
  279.         if(!IsPlayerConnected(specplayerid))
  280.         {
  281.             return SendClientMessage(playerid, COLOR_GREY, "[ERROR] that player isn't active.");
  282.         }
  283.         TogglePlayerSpectating(playerid, 1);
  284.         SetPlayerInterior(playerid,GetPlayerInterior(specplayerid));
  285.         gSpectateID[playerid] = specplayerid;
  286.         gSpectateType[playerid] = ADMIN_SPEC_TYPE_PLAYER;
  287.         return 1;
  288.     }
  289.  
  290.     if(strcmp(cmd, "/specoff", true) == 0)
  291.     {
  292.         TogglePlayerSpectating(playerid, 0);
  293.         gSpectateID[playerid] = INVALID_PLAYER_ID;
  294.         gSpectateType[playerid] = ADMIN_SPEC_TYPE_NONE;
  295.         return 1;
  296.     }
  297.    
  298.     return 0;
  299. }
  300.  
  301. //==============================================================================
  302.  
  303. InitialiserTourPaille ()
  304. {
  305.     new x, y, z;
  306.     new Compte;
  307.  
  308.     Vitesse_xy = 2000 / (PAILLE_Z + 1);
  309.     Vitesse_z = 1500 / (PAILLE_Z + 1);
  310.     for (new i=0 ; i<MAX_PLAYERS ; i++)
  311.     {
  312.         if (IsPlayerConnected (i))
  313.         {
  314.             SetPlayerScore (i, 0);
  315.         }
  316.     }
  317.     for (x=0 ; x<PAILLE_X ; x++)
  318.     {
  319.         for (y=0 ; y<PAILLE_Y ; y++)
  320.         {
  321.             for (z=0 ; z<PAILLE_Z ; z++)
  322.             {
  323.                 Matrice[x][y][z] = 0;
  324.             }
  325.         }
  326.     }
  327.     for (Compte=0 ; Compte<PAILLE_B ; Compte++)
  328.     {
  329.         do
  330.         {
  331.             x = random (PAILLE_X);
  332.             y = random (PAILLE_Y);
  333.             z = random (PAILLE_Z);
  334.         }
  335.         while (Matrice[x][y][z] != 0);
  336.         Matrice[x][y][z] = 1;
  337.         Bottes[Compte] = CreateObject (ID_HAY_OBJECT, x*(-4), y*(-4), (z+1)*3, 0.0, 0.0, random (2)*180);
  338.     }
  339.     for (Compte=0 ; Compte<PAILLE_R ; Compte++)
  340.     {
  341.         do
  342.         {
  343.             x = random (PAILLE_X);
  344.             y = random (PAILLE_Y);
  345.             z = random (PAILLE_Z);
  346.         }
  347.         while (Matrice[x][y][z] != 0);
  348.         Matrice[x][y][z] = 1;
  349.         Rochers[Compte] = CreateObject (ID_ROCK_OBJECT, x*-4, y*-4, (z+1)*3, random (360), random (360), random (360));
  350.     }
  351.     Centre_x = (PAILLE_X + 1) * -2;
  352.     Centre_y = (PAILLE_Y + 1) * -2;
  353.     BotteDuHaut = CreateObject (ID_HAY_OBJECT, Centre_x, Centre_y, PAILLE_Z*3 + 3, 0, 0, 0);
  354.     SetTimer ("TimerMove", 100, 0);
  355. }
  356.  
  357. //==============================================================================
  358.  
  359. NettoyerTourDePaille ()
  360. {
  361.     for (new i=0 ; i<PAILLE_B ; i++)
  362.     {
  363.         DestroyObject (Bottes[i]);
  364.     }
  365.     DestroyObject (BotteDuHaut);
  366.     for (new i=0 ; i<PAILLE_R ; i++)
  367.     {
  368.         DestroyObject (Rochers[i]);
  369.     }
  370. }
  371.  
  372.  
  373. //==============================================================================
  374.  
  375. public TimerMove ()
  376. {
  377.     new rand;
  378.     new Botte;
  379.     new Move;
  380.     new x, y, z;
  381.     new Float:x2, Float:y2, Float:z2;
  382.     new Temps;
  383.     new Float:Speed;
  384.    
  385.     do
  386.     {
  387.         rand = random (PAILLE_B);
  388.     }
  389.     while (EnDeplacement[rand] == 1);
  390.     Botte = Bottes[rand];
  391.     Move = random (6);
  392.     GetObjectPos (Botte, x2, y2, z2);
  393.     x = floatround (x2/-4.0);
  394.     y = floatround (y2/-4.0);
  395.     z = floatround (z2/3.0)-1;
  396.     if ((Move == 0)  && (x != 0) && (Matrice[x-1][y][z] == 0))
  397.     {
  398.         EnDeplacement[rand] = 1;
  399.         Temps = 4000 - Vitesse_xy * z;
  400.         Speed = SPEED_FACTOR / float (Temps);
  401.         SetTimerEx ("TimerFini", Temps, 0, "iiii", rand, x, y, z);
  402.         x = x - 1;
  403.         Matrice[x][y][z] = 1;
  404.         MoveObject (Botte, x2+4.0, y2, z2, Speed);
  405.     }
  406.  
  407.     else if ((Move == 1) && (x != PAILLE_X-1) && (Matrice[x+1][y][z] == 0))
  408.     {
  409.         EnDeplacement[rand] = 1;
  410.         Temps = 4000 - Vitesse_xy * z;
  411.         Speed = SPEED_FACTOR / float (Temps);
  412.         SetTimerEx ("TimerFini", Temps, 0, "iiii", rand, x, y, z);
  413.         x = x + 1;
  414.         Matrice[x][y][z] = 1;
  415.         MoveObject (Botte, x2-4.0, y2, z2, Speed);
  416.     }
  417.  
  418.     else if ((Move == 2) && (y != 0) && (Matrice[x][y-1][z] == 0))
  419.     {
  420.         EnDeplacement[rand] = 1;
  421.         Temps = 4000 - Vitesse_xy * z;
  422.         Speed = SPEED_FACTOR / float (Temps);
  423.         SetTimerEx ("TimerFini", Temps, 0, "iiii", rand, x, y, z);
  424.         y = y - 1;
  425.         Matrice[x][y][z] = 1;
  426.         MoveObject (Botte, x2, y2+4.0, z2, Speed);
  427.     }
  428.  
  429.  
  430.     else if ((Move == 3) && (y != PAILLE_Y-1) && (Matrice[x][y+1][z] == 0))
  431.     {
  432.         EnDeplacement[rand] = 1;
  433.         Temps = 4000 - Vitesse_xy * z;
  434.         Speed = SPEED_FACTOR / float (Temps);
  435.         SetTimerEx ("TimerFini", Temps, 0, "iiii", rand, x, y, z);
  436.         y = y + 1;
  437.         Matrice[x][y][z] = 1;
  438.         MoveObject (Botte, x2, y2-4.0, z2, Speed);
  439.     }
  440.  
  441.     else if ((Move == 4) && (z != 0) && (Matrice[x][y][z-1] == 0))
  442.     {
  443.         EnDeplacement[rand] = 1;
  444.         Temps = 3000 - Vitesse_z * z;
  445.         Speed = SPEED_FACTOR / float (Temps);
  446.         SetTimerEx ("TimerFini", Temps, 0, "iiii", rand, x, y, z);
  447.         z = z - 1;
  448.         Matrice[x][y][z] = 1;
  449.         MoveObject (Botte, x2, y2, z2-3.0, Speed);
  450.     }
  451.  
  452.     else if ((Move == 5) && (z != PAILLE_Z-1) && (Matrice[x][y][z+1] == 0))
  453.     {
  454.         EnDeplacement[rand] = 1;
  455.         Temps = 3000 - Vitesse_z * z;
  456.         Speed = SPEED_FACTOR / float (Temps);
  457.         SetTimerEx ("TimerFini", Temps, 0, "iiii", rand, x, y, z);
  458.         z = z + 1;
  459.         Matrice[x][y][z] = 1;
  460.         MoveObject (Botte, x2, y2, z2+3.0, Speed);
  461.     }
  462.     SetTimer ("TimerMove", 100, 0);
  463. }
  464.  
  465. //==============================================================================
  466.  
  467. public TimerFini (id, x, y, z)
  468. {
  469.     EnDeplacement[id] = 0;
  470.     Matrice[x][y][z] = 0;
  471. }
  472.  
  473. //==============================================================================
  474.  
  475. public TimerScore ()
  476. {
  477.     new Float:x, Float:y, Float:z;
  478.     for (new i=0 ; i<MAX_PLAYERS ; i++)
  479.     {
  480.         if (IsPlayerConnected (i))
  481.         {
  482.             GetPlayerPos (i, x, y, z);
  483.             if (x<=2.0 && x>=-15.0 && y<=2.0 && y>=-15.0)
  484.             {
  485.                 new Level = (floatround (z)/3) - 1;
  486.                 SetPlayerScore (i, Level);
  487.             }
  488.             else
  489.             {
  490.                 SetPlayerScore (i, 0);
  491.             }
  492.         }
  493.     }
  494. }
  495.  
  496. //==============================================================================
  497.  
  498. strtok(const string[], &index)
  499. {
  500.     new length = strlen(string);
  501.     while ((index < length) && (string[index] <= ' '))
  502.     {
  503.         index++;
  504.     }
  505.  
  506.     new offset = index;
  507.     new result[20];
  508.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  509.     {
  510.         result[index - offset] = string[index];
  511.         index++;
  512.     }
  513.     result[index - offset] = EOS;
  514.     return result;
  515. }
  516.  
  517. //==============================================================================
  518.  
  519. public TDScore()
  520. {
  521.     new Level;
  522.     new string[128];
  523.     new PlayerName[MAX_PLAYER_NAME];
  524.  
  525.     for (new i=0 ; i<MAX_PLAYERS ; i++)
  526.     {
  527.         if(IsPlayerConnected(i))
  528.         {
  529.             Level = GetPlayerScore(i);
  530.             format(string,sizeof(string),"YOURE LEVEL: %d",Level);
  531.             TextDrawSetString(Score[i], string);
  532.         }
  533.         if(GetPlayerScore(i) == 31)
  534.         {
  535.             GetPlayerName(i, PlayerName, sizeof(PlayerName));
  536.             format(string, sizeof(string),"]]]]]~n~%s is at the top of the hay tower~n~]]]]]", PlayerName);
  537.             GameTextForAll(string,2500,4);
  538.         }
  539.     }
  540. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement