Advertisement
BigETI

2D array example (1 Race engine)

May 8th, 2011
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.08 KB | None | 0 0
  1. //2D Array Example (1 Race engine) made by BigETI©
  2. //
  3. //Lets start with enum to define the positions of the datas and also to get the informations easier from the 2D array.
  4.  
  5. //Defines
  6. #define RACE_CHECKPOINT_SIZE    10.0
  7.  
  8. //Enums
  9. enum RaceCPInfos //<-- Returns the max amount of variables below. (In this case: 4)
  10. {
  11.     Race_STATE_CP, //<-- returns 0
  12.     Float:Race_X_CP, //<-- returns 1
  13.     Float:Race_Y_CP, //<-- returns 2
  14.     Float:Race_Z_CP, //<-- returns 3
  15. }
  16.  
  17. //News
  18. new countracepos = 0;
  19.  
  20. new RaceCPInfo[][RaceCPInfos] = { //<-- We create now a 2D array variable
  21. {0, 0.0, 0.0, 0.0}, //<-- CP 1 info..
  22. {0, 0.0, 0.0, 0.0}, //<-- CP 2 info..
  23. {0, 0.0, 0.0, 0.0}, //<-- CP 3 info..
  24. {0, 0.0, 0.0, 0.0}, //<-- CP 4 info..
  25. //... And so on...
  26. {1, 0.0, 0.0, 0.0} //<-- Last CP info. (Warning: After the '}' at the last 1D array field you shouldn't add a comma there since the comma shows for the script that you want to add more 1D arrays but in this case you won't.)
  27. }; //<-- End
  28.  
  29. //Publics
  30. public OnPlayerEnterRaceCheckpoint(playerid)
  31. {
  32.     switch(CheckpointRace[GetPVarInt(playerid, "RCP")][Race_STATE_CP]) //Switch of the currect CP
  33.     {
  34.         case 0,2,3: //Normal CP States
  35.         {
  36.             GivePVarInt(playerid, "RCP", 1);
  37.             if(RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_STATE_CP] == 1 || RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_STATE_CP] == 4)
  38.             {
  39.                 SetPlayerRaceCheckpoint(playerid,
  40.                 RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_STATE_CP],
  41.                 RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_X_CP],
  42.                 RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_Y_CP],
  43.                 RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_Z_CP],
  44.                 0.0000, 0.0000, 0.0000, RACE_CHECKPOINT_SIZE);
  45.             }
  46.             else
  47.             {
  48.                 SetPlayerRaceCheckpoint(playerid,
  49.                 RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_STATE_CP],
  50.                 RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_X_CP],
  51.                 RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_Y_CP],
  52.                 RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_Z_CP],
  53.                 RaceCPInfo[GetPVarInt(playerid, "RCP")+1][Race_X_CP],
  54.                 RaceCPInfo[GetPVarInt(playerid, "RCP")+1][Race_Y_CP],
  55.                 RaceCPInfo[GetPVarInt(playerid, "RCP")+1][Race_Z_CP],
  56.                 RACE_CHECKPOINT_SIZE);
  57.             }
  58.             PlayerPlaySound(playerid, 1139, 0, 0, 0);
  59.         }
  60.         case 1,4: //Finish CP States
  61.         {
  62.             countracepos++;
  63.             SetPVarInt(playerid, "WonRace", countracepos);
  64.             if(GetPVarInt(playerid, "WonRace") == 1) GivePlayerMoney(playerid, 5000);
  65.             else if(GetPVarInt(playerid, "WonRace") == 2) GivePlayerMoney(playerid, 2500);
  66.             else if(GetPVarInt(playerid, "WonRace") == 3) GivePlayerMoney(playerid, 1000);
  67.             GivePVarInt(playerid, "RaceScore", 1);
  68.             SetPlayerScore(playerid, GetPVarInt(playerid, "RaceScore"));
  69.             DeletePVar(playerid, "RCP");
  70.             DisablePlayerRaceCheckpoint(playerid);
  71.             SendClientMessage(playerid, 0xFF0000FF, "Race finished!");
  72.             new msg[128], pname[MAX_PLAYER_NAME];
  73.             GetPlayerName(playerid, pname, sizeof(pname));
  74.             format(msg, sizeof(msg), "%d {FF9999}%s won the race as %d. place.", playerid, pname, countracepos);
  75.             SendClientMessageToAll(0x6666FFFF, msg);
  76.             PlayerPlaySound(playerid, 1138, 0, 0, 0);
  77.         }
  78.     }
  79.     return 1;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement