Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //2D Array Example (1 Race engine) made by BigETI©
- //
- //Lets start with enum to define the positions of the datas and also to get the informations easier from the 2D array.
- //Defines
- #define RACE_CHECKPOINT_SIZE 10.0
- //Enums
- enum RaceCPInfos //<-- Returns the max amount of variables below. (In this case: 4)
- {
- Race_STATE_CP, //<-- returns 0
- Float:Race_X_CP, //<-- returns 1
- Float:Race_Y_CP, //<-- returns 2
- Float:Race_Z_CP, //<-- returns 3
- }
- //News
- new countracepos = 0;
- new RaceCPInfo[][RaceCPInfos] = { //<-- We create now a 2D array variable
- {0, 0.0, 0.0, 0.0}, //<-- CP 1 info..
- {0, 0.0, 0.0, 0.0}, //<-- CP 2 info..
- {0, 0.0, 0.0, 0.0}, //<-- CP 3 info..
- {0, 0.0, 0.0, 0.0}, //<-- CP 4 info..
- //... And so on...
- {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.)
- }; //<-- End
- //Publics
- public OnPlayerEnterRaceCheckpoint(playerid)
- {
- switch(CheckpointRace[GetPVarInt(playerid, "RCP")][Race_STATE_CP]) //Switch of the currect CP
- {
- case 0,2,3: //Normal CP States
- {
- GivePVarInt(playerid, "RCP", 1);
- if(RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_STATE_CP] == 1 || RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_STATE_CP] == 4)
- {
- SetPlayerRaceCheckpoint(playerid,
- RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_STATE_CP],
- RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_X_CP],
- RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_Y_CP],
- RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_Z_CP],
- 0.0000, 0.0000, 0.0000, RACE_CHECKPOINT_SIZE);
- }
- else
- {
- SetPlayerRaceCheckpoint(playerid,
- RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_STATE_CP],
- RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_X_CP],
- RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_Y_CP],
- RaceCPInfo[GetPVarInt(playerid, "RCP")][Race_Z_CP],
- RaceCPInfo[GetPVarInt(playerid, "RCP")+1][Race_X_CP],
- RaceCPInfo[GetPVarInt(playerid, "RCP")+1][Race_Y_CP],
- RaceCPInfo[GetPVarInt(playerid, "RCP")+1][Race_Z_CP],
- RACE_CHECKPOINT_SIZE);
- }
- PlayerPlaySound(playerid, 1139, 0, 0, 0);
- }
- case 1,4: //Finish CP States
- {
- countracepos++;
- SetPVarInt(playerid, "WonRace", countracepos);
- if(GetPVarInt(playerid, "WonRace") == 1) GivePlayerMoney(playerid, 5000);
- else if(GetPVarInt(playerid, "WonRace") == 2) GivePlayerMoney(playerid, 2500);
- else if(GetPVarInt(playerid, "WonRace") == 3) GivePlayerMoney(playerid, 1000);
- GivePVarInt(playerid, "RaceScore", 1);
- SetPlayerScore(playerid, GetPVarInt(playerid, "RaceScore"));
- DeletePVar(playerid, "RCP");
- DisablePlayerRaceCheckpoint(playerid);
- SendClientMessage(playerid, 0xFF0000FF, "Race finished!");
- new msg[128], pname[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pname, sizeof(pname));
- format(msg, sizeof(msg), "%d {FF9999}%s won the race as %d. place.", playerid, pname, countracepos);
- SendClientMessageToAll(0x6666FFFF, msg);
- PlayerPlaySound(playerid, 1138, 0, 0, 0);
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement