Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-Death Note Gamemode by Gandalv (2010)-//
- //-Include and Define-//
- #include <a_samp>
- #include <a_players>
- #define GREEN 0x33AA33AA
- #define YELLOW 0xFFFF33AA
- #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
- //-Global Var. and Arrays-//
- new Threads[100][7]; //Contains the entries of the Death Note
- //+-> <Line><Kira ID><Victim ID><gTimer at Start><gTimer at the end><Kind of Death><Line active?>
- new RowStore[MAX_PLAYERS]; //Contains information about the actual Choose-a-person-menu
- new gKiraID; //ID of the Death Note Owner
- new gTimer; //Counts every Second
- new NeueZeile = 0; //Creates a new Line in -> Threads
- new gMenuTime; //The Value Shown in the Time Setting Menu Header
- new gMenuLine; //Stores the Line in Threads the Menu edits
- new gScore[MAX_PLAYERS]; //Score
- new gConnected = 0; //Number of Players on the Server
- new gKiraAktiv = 0; //1 = Someone is Kira 0 = Nobody is Kira
- new Float: gRandomSpawns[5][3] = { //Random Spawns
- { 1259.344, -1182.7743, 23.5781 },
- { 1103.623, -1218.4854, 17.8047 },
- { 967.6936, -1540.7489, 13.5896 },
- { 1115.957, -1502.6890, 15.8003 },
- { 1263.040, -1242.4493, 16.3846 }
- };
- new Menu:KiraPerson;
- new Menu:KiraTodesart;
- new Menu:KiraZeit; //The 3 Menus
- //-Main Function-//
- main()
- {
- print("\n----------------------------------");
- print("Kira 1.0");
- print("----------------------------------\n");
- SetTimer("Call", 1000, true);//Starting the scannig function every second
- }
- //-Forwards-//
- forward Call();
- forward Auswerter(HandleID);
- forward Infarkt(HandleID);
- forward Sturz(HandleID);
- forward Explosion(HandleID);
- forward CarKick(playerid);
- forward CreatePersonMenu();
- forward CreateTimeMenu();
- forward RefreshMenuHeader(playerid);
- forward SetKira(playerid, neukira);
- forward ZufallKira(playerid);
- forward SetPlayerRandomSpawn(playerid);
- //-Init-//
- public OnGameModeInit()
- {
- SetGameModeText("DeathNote 1.0");
- AddPlayerClass(0, 977.2250, -1322.6969, 13.3703, 100.3185, 0, 0, 0, 0, 27, 100);
- KiraTodesart = CreateMenu("Todesart", 1, 200.0, 100.0, 150.0, 150.0);
- AddMenuItem(KiraTodesart, 0, "Herzinfarkt");
- AddMenuItem(KiraTodesart, 0, "Sturz");
- AddMenuItem(KiraTodesart, 0, "Explosion");
- }
- //-Class Request-//
- public OnPlayerRequestClass(playerid, classid)
- {
- SetPlayerPos(playerid,398.4077,2540.5049,19.6311);
- SetPlayerCameraPos(playerid,398.4077,2530.5049,19.6311);
- SetPlayerCameraLookAt(playerid,398.4077,2540.5049,19.6311);
- SetPlayerFacingAngle(playerid, 180.0);
- return 1;
- }
- //-Player connect and gets information-//
- public OnPlayerConnect(playerid)
- {
- gConnected++;
- if(gConnected >= 3 && gKiraAktiv == 0) //With this the gammeode will start only with minimum 3 people on the Server
- {
- gKiraAktiv = 1;
- ZufallKira(99);
- }
- }
- //-Player disconnect-//
- public OnPlayerDisconnect(playerid)
- {
- gConnected--;
- if(playerid == gKiraID) //If Kira leaves, a new one is needed
- {
- ZufallKira(playerid);
- }
- gScore[playerid] = 0; //Score reset
- }
- //-Choosing a random person-//
- public ZufallKira(playerid)
- {
- if(gConnected >= 3)
- {
- new X = 0;
- while(X == 0)
- {
- new NeuKira = random(MAX_PLAYERS);
- if(IsPlayerConnected(NeuKira) && NeuKira != playerid)
- {
- gKiraID = NeuKira;
- SendClientMessage(NeuKira, YELLOW, "Du hast nun die Macht/das Notizbuch");
- X = 1;
- }
- }
- }
- }
- //-Managing the score-//
- public OnPlayerDeath(playerid, killerid, reason)
- {
- SendDeathMessage(killerid, playerid, reason);
- if(playerid == gKiraID && killerid != INVALID_PLAYER_ID)
- {
- gScore[killerid] = gScore[killerid]+3;
- SetPlayerScore(killerid, gScore[killerid]);
- SendClientMessage(killerid, YELLOW, "Du hast Kira erwischt: +3Punkte");
- new Killer[MAX_PLAYER_NAME], Ausgabe[48];
- GetPlayerName(killerid, Killer, sizeof(Killer));
- format(Ausgabe, sizeof(Ausgabe), "%s hat Kira erledigt", Killer);
- SendClientMessageToAll(YELLOW, Ausgabe);
- SendClientMessage(playerid, YELLOW, "Der Zentralrat der Shinigami ist emp�rt!");
- gScore[playerid] = gScore[playerid]-3;
- SetPlayerScore(playerid, gScore[playerid]);
- ZufallKira(playerid);
- }
- else
- {
- gScore[killerid] = gScore[killerid]-1;
- SetPlayerScore(killerid, gScore[killerid]);
- }
- }
- //-Spawn-//
- public OnPlayerSpawn(playerid)
- {
- SetPlayerRandomSpawn(playerid);
- }
- //RandomSpawn
- public SetPlayerRandomSpawn(playerid)
- {
- new rand = random(sizeof(gRandomSpawns));
- SetPlayerPos(playerid, gRandomSpawns[rand][0], gRandomSpawns[rand][1], gRandomSpawns[rand][2]);
- }
- //-Player Input-//
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(hefteintrag, 11, cmdtext);
- dcmd(menu, 4, cmdtext);
- dcmd(Give, 4, cmdtext);
- dcmd(asdf, 4, cmdtext);
- return 0;
- }
- //--If the current Kira is a dork, use this--//
- dcmd_asdf(playerid, params[])
- {
- if(IsPlayerAdmin(playerid))
- {
- new str[128];
- format(str, sizeof(str), "Aktuelle Teilnehmerzahl: %d", gConnected);
- SendClientMessage(playerid, GREEN, str);
- ZufallKira(gKiraID);
- }
- }
- //--Give the Death Note to somebody--//
- dcmd_Give(playerid, params[])
- {
- new NewKira;
- if(sscanf(params, "d", NewKira))
- {
- SendClientMessage(playerid, GREEN, "Verwendung: /Give <neuerKira>");
- }
- else
- {
- SetKira(playerid, NewKira);
- }
- }
- //-Choose Kira by ID-//
- public SetKira(playerid, neukira)
- {
- if(playerid == gKiraID)
- {
- gKiraID = neukira;
- new NeuKiraName[MAX_PLAYER_NAME], AusgabeA[48];
- GetPlayerName(neukira, NeuKiraName, sizeof(NeuKiraName));
- format(AusgabeA, sizeof(AusgabeA), "Du hast %s das Death Note gegeben", NeuKiraName);
- new AltKiraName[MAX_PLAYER_NAME], AusgabeB[48];
- GetPlayerName(playerid, AltKiraName, sizeof(AltKiraName));
- format(AusgabeB, sizeof(AusgabeB), "%s hat dir das Death Note gegeben", AltKiraName);
- SendClientMessage(playerid, YELLOW, AusgabeA);
- SendClientMessage(neukira, YELLOW, AusgabeB);
- SendClientMessage(neukira, YELLOW, "nutze deine Macht weise!");
- }
- else
- {
- SendClientMessage(playerid, GREEN, "Du musst das Death Note schon besitzen um es weiterzugeben...");
- }
- }
- //-Create an entry with CMD-//
- dcmd_hefteintrag(playerid, params[])
- {
- if(playerid == gKiraID)
- {
- new Opfer,
- Zeit,
- Art;
- if(sscanf(params, "ddd", Opfer, Zeit, Art))
- {
- SendClientMessage(playerid, GREEN, "/hefteintrag [OpferID] [Verz�gerung] [TodesArtID]");
- }
- else
- {
- //Filling the line of the array
- Threads[NeueZeile][1] = playerid;
- Threads[NeueZeile][2] = Opfer;
- Threads[NeueZeile][3] = gTimer;
- Threads[NeueZeile][4] = gTimer + Zeit;
- Threads[NeueZeile][5] = Art;
- Threads[NeueZeile][6] = 1;
- Threads[NeueZeile][0] = NeueZeile;
- SendClientMessage(playerid, GREEN, "Eintrag angefertigt");
- printf("Kira: %d %d %d %d %d %d %d", Threads[NeueZeile][0], Threads[NeueZeile][1], Threads[NeueZeile][2], Threads[NeueZeile][3], Threads[NeueZeile][4], Threads[NeueZeile][5], Threads[NeueZeile][6]);
- NeueZeile++; //jump to the next line, so the function won't overwrite the older entries
- }
- }
- else
- {
- SendClientMessage(playerid, GREEN, "Ohne Death Note funktioniert das nicht");
- }
- }
- //-Create an entry the easier way, menu-//
- dcmd_menu(playerid, params[])
- {
- if(playerid == gKiraID)
- {
- CreatePersonMenu(); //Creates the first menu new (to be sure that there are no people on offliner on the list)
- gMenuLine = NeueZeile; //Sets the Line the following functions will write in
- ShowMenuForPlayer(KiraPerson, playerid);
- }
- else
- {
- SendClientMessage(playerid, GREEN, "Ohne Death Note funktioniert das nicht");
- }
- }
- //-Creates the first menu-//
- public CreatePersonMenu()
- {
- DestroyMenu(KiraPerson);
- KiraPerson = CreateMenu("Death Note", 1, 200.0, 100.0, 150.0, 150.0);
- new x=0;
- new y=0;
- while(x < 1000)
- {
- if(IsPlayerConnected(x))
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(x, name, sizeof(name));
- AddMenuItem(KiraPerson, 0, name);
- RowStore[y] = x;
- y++;
- x++;
- }
- else
- {
- x++;
- }
- }
- }
- //--->Second Menu is static ->Init
- //-Creates third menu-//
- public CreateTimeMenu()
- {
- DestroyMenu(KiraZeit);
- KiraZeit = CreateMenu("Zeit", 1, 200.0, 100.0, 150.0, 150.0);
- new str[128];
- format(str, sizeof(str), "Zeit: %d", gMenuTime);
- SetMenuColumnHeader(KiraZeit, 0, str);
- AddMenuItem(KiraZeit, 0, "+10");
- AddMenuItem(KiraZeit, 0, "-10");
- AddMenuItem(KiraZeit, 0, "Confirm");
- }
- public RefreshMenuHeader(playerid)
- {
- new str[128];
- format(str, sizeof(str), "Zeit: %d", gMenuTime);
- SetMenuColumnHeader(KiraZeit, 0 ,str);
- ShowMenuForPlayer(KiraZeit,playerid);
- }
- //-Making the menus work-//
- public OnPlayerSelectedMenuRow(playerid, row)
- {
- new Menu:CurrentMenu = GetPlayerMenu(playerid);
- gMenuLine = NeueZeile;
- //------------------------------------------------------------------------------
- if(CurrentMenu == KiraPerson)
- {
- Threads[gMenuLine][1] = playerid; //Writing the ID of Kira
- Threads[gMenuLine][2] = RowStore[row]; //Writing the ID of the Victim
- Threads[gMenuLine][0] = gMenuLine; //unnecessary?
- ShowMenuForPlayer(KiraTodesart, playerid); //lead Player to the next menu
- }
- //------------------------------------------------------------------------------
- else if(CurrentMenu == KiraTodesart)
- {
- gMenuTime = 10;
- CreateTimeMenu();
- switch(row)
- {
- case 0:
- {
- Threads[gMenuLine][5] = 1;
- ShowMenuForPlayer(KiraZeit, playerid);
- }
- case 1:
- {
- Threads[gMenuLine][5] = 2;
- ShowMenuForPlayer(KiraZeit, playerid);
- }
- case 2:
- {
- Threads[gMenuLine][5] = 3;
- ShowMenuForPlayer(KiraZeit, playerid);
- }
- }
- }
- //------------------------------------------------------------------------------
- else if(CurrentMenu == KiraZeit)
- {
- switch(row)
- {
- case 0:
- {
- gMenuTime = gMenuTime+10;
- RefreshMenuHeader(playerid);
- }
- case 1:
- {
- if(gMenuTime >= 20)
- {
- gMenuTime = gMenuTime-10;
- }
- RefreshMenuHeader(playerid);
- }
- case 2:
- {
- Threads[gMenuLine][3] = gTimer;
- Threads[gMenuLine][4] = gTimer+gMenuTime;
- Threads[gMenuLine][6] = 1; //Activates the entry
- NeueZeile++;
- printf("Kira: %d %d %d %d %d %d %d", Threads[gMenuLine][0], Threads[gMenuLine][1], Threads[gMenuLine][2], Threads[gMenuLine][3], Threads[gMenuLine][4], Threads[gMenuLine][5], Threads[gMenuLine][6]);
- }
- }
- }
- //------------------------------------------------------------------------------
- return 1;
- }
- //-Now the array contains informaton, so it's time to read it out (one time per second)-//
- public Call()
- {
- new count;
- gTimer++; //Counting seconds...
- while(count < 1000) //Searching for active lines in the Death Note
- {
- if(Threads[count][6] == 1)
- {
- Auswerter(Threads[count][0]); //Transfering the information to the next function
- }
- count++;
- }
- }
- //-Checking how the victim will die-//
- public Auswerter(HandleID)
- {
- switch(Threads[HandleID][5])
- {
- case 1:
- {
- Infarkt(HandleID);
- }
- case 2:
- {
- Sturz(HandleID);
- }
- case 3:
- {
- Explosion(HandleID);
- }
- }
- }
- //-Different Ways to die-//
- //Heart
- public Infarkt(HandleID)
- {
- if(gTimer == Threads[HandleID][4]) //Waiting for the right time
- {
- CarKick(Threads[HandleID][2]);
- ApplyAnimation(Threads[HandleID][2], "CRACK", "crckdeth3", 1, 1, 1, 1, 1, 1);
- }
- else if(gTimer == Threads[HandleID][4]+4)
- {
- ClearAnimations(Threads[HandleID][2]);
- SetPlayerHealth(Threads[HandleID][2], 0); //Kill him
- Threads[HandleID][6] = 0; //Don't kill him twice
- }
- }
- //Fall
- public Sturz(HandleID)
- {
- if(gTimer == Threads[HandleID][4])
- {
- new Float:PosX, Float:PosY, Float:PosZ;
- GetPlayerPos(Threads[HandleID][2], PosX, PosY, PosZ);
- PosZ = PosZ + 300;
- SetPlayerPos(Threads[HandleID][2], PosX, PosY, PosZ);
- }
- else if(gTimer == Threads[HandleID][4]+6)
- {
- SetPlayerHealth(Threads[HandleID][2], 0);
- Threads[HandleID][6] = 0;
- }
- }
- //Explosion
- public Explosion(HandleID)
- {
- if(gTimer == Threads[HandleID][4])
- {
- new Float:PosX, Float:PosY, Float:PosZ;
- GetPlayerPos(Threads[HandleID][2], PosX, PosY, PosZ);
- CreateExplosion(PosX, PosY, PosZ, 6, 10.0);
- SetPlayerHealth(Threads[HandleID][2], 0);
- Threads[HandleID][6] = 0;
- }
- }
- //-Remove from Vehicle-//
- public CarKick(playerid)
- {
- if(IsPlayerInAnyVehicle(playerid))
- {
- RemovePlayerFromVehicle(playerid);
- }
- }
- //------------------------------------------------------------------------------
- /*----------------------------------------------------------------------------*-
- Function:
- sscanf
- Params:
- string[] - String to extract parameters from.
- format[] - Parameter types to get.
- {Float,_}:... - Data return variables.
- Return:
- 0 - Successful, not 0 - fail.
- Notes:
- A fail is either insufficient variables to store the data or insufficient
- data for the format string - excess data is disgarded.
- A string in the middle of the input data is extracted as a single word, a
- string at the end of the data collects all remaining text.
- The format codes are:
- c - A character.
- d, i - An integer.
- h, x - A hex number (e.g. a colour).
- f - A float.
- s - A string.
- z - An optional string.
- pX - An additional delimiter where X is another character.
- '' - Encloses a litteral string to locate.
- u - User, takes a name, part of a name or an id and returns the id if they're connected.
- Now has IsNumeric integrated into the code.
- Added additional delimiters in the form of all whitespace and an
- optioanlly specified one in the format string.
- -*----------------------------------------------------------------------------*/
- stock sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
- //------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment