MaNb9K Дата: Пятница, 04.03.2011, 14:49:55 | Сообщение # 1
Группа: Пользователи
Сообщений: 220
Данный урок позволит поиграть во всем известную игру «Змейка». Игра будет запускаться с помощью команды /start вблизи пикапа, находящегося в стрип-баре ЛасВентураса.Телепортироваться непосредственно в бар с помощью команды /tps, но только для rcon-админов.ВАм будет легче делать это в FS.Начнём! В начало скрипта вставляем Code
#include <a_samp> enum xy {Float: x, Float: y}; new zto[9][17][xy]; new tup[150]; new Text: TextScore; new Text3D:bxod; new pos_world, score,xp,yp,upr,postm,k,kmax,eat,xe,ye; new Float: xx, Float: yy; new gplayerid = -1; new ur = 1000; new uri = 1;
И создаём public Code
public OnFilterScriptInit()
И вставляем туда Code
{ print("\n--------------------------------------"); print("FS: Game In Game Snake"); print("--------------------------------------\n"); xx = 1207.25; for(new nx=0; nx <= 8; nx++) { yy = -4.45; for(new ny=0; ny <= 16; ny++) { zto[nx][ny][x] = xx; zto[nx][ny][y] = yy; yy = yy - 0.25; } xx = xx + 0.25; } AddStaticPickup(1239, 1, 1210.5, -6.36, 1000.4,0); bxod = Create3DTextLabel ("ЗМЕЙКА\nНачать игру: /start", 0x33AA33AA, 1210.5, -6.36, 1001, 30, 0, 1); TextScore = TextDrawCreate(545.000000,103.000000," 0"); TextDrawUseBox(TextScore,1); TextDrawBoxColor(TextScore,0x0000ff66); TextDrawTextSize(TextScore,647.000000,75.000000); TextDrawAlignment(TextScore,1); TextDrawBackgroundColor(TextScore,0x00000099); TextDrawFont(TextScore,1); TextDrawLetterSize(TextScore,0.800000,3.399998); TextDrawColor(TextScore,0x00ff00ff); TextDrawSetOutline(TextScore,1); TextDrawSetShadow(TextScore,7); return 1; }
Создаём public Code
public OnFilterScriptExit()
И вставляем туда Code
{ for (new n=0; n < MAX_PLAYERS; n++) { if(IsPlayerConnected(n)) Stop(n); } return 1; }
Создаём public Code
public OnGameModeExit()
И вставляем туда Code
{ for (new n=0; n < MAX_PLAYERS; n++) { if(IsPlayerConnected(n)) Stop(n); } return 1; }
Вы вставляете после этого туда 2 public Code
public OnPlayerDisconnect(playerid, reason) { Stop(playerid); return 1; } public OnPlayerDeath(playerid, killerid, reason) { Stop(playerid); return 1; }
Создаём public Code
public OnPlayerCommandText(playerid, cmdtext[])
И вставляем туда Code
{ new cmd [256]; new idx; cmd = strtok(cmdtext, idx); if(strcmp(cmd, "/start", true) == 0) { if (IsPlayerInRangeOfPoint(playerid, 1, 1210.5, -6.36, 1000.4) && gplayerid == -1) { TogglePlayerControllable(playerid,0); new urs[128]; format (urs,128,"ЗМЕЙКА (Уровень сложности: %d)",uri); ShowPlayerDialog(playerid,600,2,urs,"Старт\nНастройки","Выбор","Выход"); } return 1; } if(strcmp(cmd, "/exit", true) == 0) { Stop(playerid); return 1; } if(strcmp(cmd, "/tps", true) == 0 && IsPlayerAdmin(playerid)) { SetPlayerPos(playerid,1210.5,-6.36,1001); SetPlayerInterior(playerid,2); SetPlayerVirtualWorld(playerid,0); return 1; } return 0; }
И ещё создаём public Code
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
Вставляем туда Code
{ if (dialogid == 600 && response == 1 && listitem == 0) { Start(playerid); } if (dialogid == 600 && response == 1 && listitem == 1) ShowPlayerDialog(playerid,601,2,"Уровень сложности","уровень 1\nуровень 2\nуровень 3\nуровень 4\nуровень 5","Выбор","Назад"); if (dialogid == 601 && response == 1) { switch (listitem) { case 0: {ur = 1000; uri = 1;} case 1: {ur = 800; uri = 2;} case 2: {ur = 600; uri = 3;} case 3: {ur = 400; uri = 4;} case 4: {ur = 200; uri = 5;} } new urs[128]; format (urs,128,"ЗМЕЙКА (Уровень сложности: %d)",uri); ShowPlayerDialog(playerid,600,2,urs,"Старт\nНастройки","Выбор","Выход"); } if (dialogid == 600 && response == 0) { TogglePlayerControllable(playerid,1); } if (dialogid == 601 && response == 0) { new urs[128]; format (urs,128,"ЗМЕЙКА (Уровень сложности: %d)",uri); ShowPlayerDialog(playerid,600,2,urs,"Старт\nНастройки","Выбор","Выход"); } if (dialogid == 602) Stop (playerid); return 1; }
Создём последний public Code
public OnPlayerUpdate(playerid)
И вставляем туда Code
{ new Keys,ud,lr; GetPlayerKeys(gplayerid,Keys,ud,lr); if(ud > 0) { SendClientMessage(playerid, 0xFFFFFFFF, "Вниз"); if(!(upr == 2)) upr = 1; } else if(ud < 0) { SendClientMessage(playerid, 0xFFFFFFFF, "Вверх"); if(!(upr == 1)) upr = 2; } if(lr > 0) { SendClientMessage(playerid, 0xFFFFFFFF, "Вправо"); if(!(upr == 4)) upr = 3; } else if(lr < 0) { SendClientMessage(playerid, 0xFFFFFFFF, "Влево"); if(!(upr == 3)) upr = 4; } return 1; } forward SyncPos(playerid); public SyncPos(playerid) { switch (upr) { case 1: { if(xp > 8) { CreateExplosion(zto[xp-1][yp][x],zto[xp-1][yp][y],1000.4,12,0); ShowPlayerDialog(playerid,602,0,"ЗМЕЙКА"," КОНЕЦ ИГРЫ","ВЫХОД","ВЫХОД"); KillTimer(postm); } else xp = xp + 1; } case 2: { if(xp < 0) { CreateExplosion(zto[xp+1][yp][x],zto[xp+1][yp][y],1000.4,12,0); ShowPlayerDialog(playerid,602,0,"ЗМЕЙКА"," КОНЕЦ ИГРЫ","ВЫХОД","ВЫХОД"); KillTimer(postm); } else xp = xp - 1; } case 3: { if(yp < 0) { CreateExplosion(zto[xp][yp+1][x],zto[xp][yp+1][y],1000.4,12,0); ShowPlayerDialog(playerid,602,0,"ЗМЕЙКА"," КОНЕЦ ИГРЫ","ВЫХОД","ВЫХОД"); KillTimer(postm); } else yp = yp - 1; } case 4: { if(yp > 16) { CreateExplosion(zto[xp][yp-1][x],zto[xp][yp-1][y],1000.4,12,0); ShowPlayerDialog(playerid,602,0,"ЗМЕЙКА"," КОНЕЦ ИГРЫ","ВЫХОД","ВЫХОД"); KillTimer(postm); } else yp = yp + 1; } } if (xp == xe && yp == ye) { PosEat(); kmax = kmax + 1; for (new n = kmax; n > k; n--) tup[n] = tup[n-1]; tup[k] = CreateObject(1213,zto[xp][yp][x],zto[xp][yp][y],1000.4,0,0,0); } else SetObjectPos(tup[k],zto[xp][yp][x],zto[xp][yp][y],1000.4); for (new nnn = 0; nnn <= kmax; nnn++) { new Float:xxx, Float:yyy, Float: zzz; GetObjectPos(tup[nnn],xxx,yyy,zzz); if (xxx == zto[xp][yp][x] && yyy == zto[xp][yp][y] && tup[nnn] != tup[k]) { CreateExplosion(zto[xp][yp][x],zto[xp][yp-1][y],1000.4,12,0); ShowPlayerDialog(playerid,602,0,"ЗМЕЙКА"," КОНЕЦ ИГРЫ","ВЫХОД","ВЫХОД"); } } if (k == kmax) k = 0; else k = k + 1; return 1; } forward PosEat(); public PosEat() { xe = random(9); ye = random(17); for (new nnnn = 0; nnnn <= kmax; nnnn++) { new Float:xxxx, Float:yyyy, Float: zzzz; GetObjectPos(tup[nnnn],xxxx,yyyy,zzzz); if (xxxx == zto[xe][ye][x] && yyyy == zto[xe][ye][y]) { PosEat(); return 1; } else SetObjectPos(eat,zto[xe][ye][x],zto[xp][ye][y],1000.4); } switch (uri) { case 1: score = score + 1; case 2: score = score + 2; case 3: score = score + 3; case 4: score = score + 4; case 5: score = score + 5; } new sscore[128]; format (sscore,128," %d",score); TextDrawSetString(TextScore,sscore); return 1; } forward Stop(playerid); public Stop(playerid) { TextDrawHideForAll(TextScore); Update3DTextLabelText (bxod, 0x33AA33AA, "ЗМЕЙКА\nНачать игру: /start"); SetPlayerVirtualWorld(playerid, pos_world); KillTimer(postm); SetCameraBehindPlayer(playerid); for (new nn=0; nn <=kmax; nn++) DestroyObject(tup[nn]); DestroyObject(eat); gplayerid = -1; TogglePlayerControllable(playerid,1); return 1; } forward Start(playerid); public Start(playerid) { TextDrawShowForPlayer(playerid, TextScore); Update3DTextLabelText (bxod, 0xAA3333FF, "ЗМЕЙКА \n ЗАНЯТНО"); pos_world = GetPlayerVirtualWorld(playerid); SetPlayerVirtualWorld(playerid, 666); xp = 4; yp = 8; k = 1; kmax = 1; xe = 4; ye = 2; switch (uri) { case 1: score = -1; case 2: score = -2; case 3: score = -3; case 4: score = -4; case 5: score = -5; } gplayerid = playerid; SetPlayerCameraPos(playerid,1208.5,-6.45,1005.2); SetPlayerCameraLookAt(playerid,1208,-6.45,1000.4); eat = CreateObject(1247,zto[xe][ye][x],zto[xp][yp][y],1000.4,90,0,0); tup[0] = CreateObject(1213,zto[xp][yp][x],zto[xp][yp][y],1000.4,0,0,0); tup[1] = CreateObject(1213,zto[xp][yp-1][x],zto[xp][yp][y],1000.4,0,0,0); upr = 4; postm = SetTimerEx("SyncPos", ur, 1, "d",playerid); PosEat(); return 1; } strtok(const string[], &index) { new length = strlen(string); while ((index < length) && (string[index] <= ' ')) { index++; } new offset = index; new result[20]; while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; return result; }
Автор:MaN9K
[img]http://sa-mp-fail.at.ua/premium.gif[/img]
Сообщение Данный урок позволит поиграть во всем известную игру «Змейка». Игра будет запускаться с помощью команды /start вблизи пикапа, находящегося в стрип-баре ЛасВентураса.Телепортироваться непосредственно в бар с помощью команды /tps, но только для rcon-админов.ВАм будет легче делать это в FS.Начнём! В начало скрипта вставляем Code
#include <a_samp> enum xy {Float: x, Float: y}; new zto[9][17][xy]; new tup[150]; new Text: TextScore; new Text3D:bxod; new pos_world, score,xp,yp,upr,postm,k,kmax,eat,xe,ye; new Float: xx, Float: yy; new gplayerid = -1; new ur = 1000; new uri = 1;
И создаём public Code
public OnFilterScriptInit()
И вставляем туда Code
{ print("\n--------------------------------------"); print("FS: Game In Game Snake"); print("--------------------------------------\n"); xx = 1207.25; for(new nx=0; nx <= 8; nx++) { yy = -4.45; for(new ny=0; ny <= 16; ny++) { zto[nx][ny][x] = xx; zto[nx][ny][y] = yy; yy = yy - 0.25; } xx = xx + 0.25; } AddStaticPickup(1239, 1, 1210.5, -6.36, 1000.4,0); bxod = Create3DTextLabel ("ЗМЕЙКА\nНачать игру: /start", 0x33AA33AA, 1210.5, -6.36, 1001, 30, 0, 1); TextScore = TextDrawCreate(545.000000,103.000000," 0"); TextDrawUseBox(TextScore,1); TextDrawBoxColor(TextScore,0x0000ff66); TextDrawTextSize(TextScore,647.000000,75.000000); TextDrawAlignment(TextScore,1); TextDrawBackgroundColor(TextScore,0x00000099); TextDrawFont(TextScore,1); TextDrawLetterSize(TextScore,0.800000,3.399998); TextDrawColor(TextScore,0x00ff00ff); TextDrawSetOutline(TextScore,1); TextDrawSetShadow(TextScore,7); return 1; }
Создаём public Code
public OnFilterScriptExit()
И вставляем туда Code
{ for (new n=0; n < MAX_PLAYERS; n++) { if(IsPlayerConnected(n)) Stop(n); } return 1; }
Создаём public Code
public OnGameModeExit()
И вставляем туда Code
{ for (new n=0; n < MAX_PLAYERS; n++) { if(IsPlayerConnected(n)) Stop(n); } return 1; }
Вы вставляете после этого туда 2 public Code
public OnPlayerDisconnect(playerid, reason) { Stop(playerid); return 1; } public OnPlayerDeath(playerid, killerid, reason) { Stop(playerid); return 1; }
Создаём public Code
public OnPlayerCommandText(playerid, cmdtext[])
И вставляем туда Code
{ new cmd [256]; new idx; cmd = strtok(cmdtext, idx); if(strcmp(cmd, "/start", true) == 0) { if (IsPlayerInRangeOfPoint(playerid, 1, 1210.5, -6.36, 1000.4) && gplayerid == -1) { TogglePlayerControllable(playerid,0); new urs[128]; format (urs,128,"ЗМЕЙКА (Уровень сложности: %d)",uri); ShowPlayerDialog(playerid,600,2,urs,"Старт\nНастройки","Выбор","Выход"); } return 1; } if(strcmp(cmd, "/exit", true) == 0) { Stop(playerid); return 1; } if(strcmp(cmd, "/tps", true) == 0 && IsPlayerAdmin(playerid)) { SetPlayerPos(playerid,1210.5,-6.36,1001); SetPlayerInterior(playerid,2); SetPlayerVirtualWorld(playerid,0); return 1; } return 0; }
И ещё создаём public Code
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
Вставляем туда Code
{ if (dialogid == 600 && response == 1 && listitem == 0) { Start(playerid); } if (dialogid == 600 && response == 1 && listitem == 1) ShowPlayerDialog(playerid,601,2,"Уровень сложности","уровень 1\nуровень 2\nуровень 3\nуровень 4\nуровень 5","Выбор","Назад"); if (dialogid == 601 && response == 1) { switch (listitem) { case 0: {ur = 1000; uri = 1;} case 1: {ur = 800; uri = 2;} case 2: {ur = 600; uri = 3;} case 3: {ur = 400; uri = 4;} case 4: {ur = 200; uri = 5;} } new urs[128]; format (urs,128,"ЗМЕЙКА (Уровень сложности: %d)",uri); ShowPlayerDialog(playerid,600,2,urs,"Старт\nНастройки","Выбор","Выход"); } if (dialogid == 600 && response == 0) { TogglePlayerControllable(playerid,1); } if (dialogid == 601 && response == 0) { new urs[128]; format (urs,128,"ЗМЕЙКА (Уровень сложности: %d)",uri); ShowPlayerDialog(playerid,600,2,urs,"Старт\nНастройки","Выбор","Выход"); } if (dialogid == 602) Stop (playerid); return 1; }
Создём последний public Code
public OnPlayerUpdate(playerid)
И вставляем туда Code
{ new Keys,ud,lr; GetPlayerKeys(gplayerid,Keys,ud,lr); if(ud > 0) { SendClientMessage(playerid, 0xFFFFFFFF, "Вниз"); if(!(upr == 2)) upr = 1; } else if(ud < 0) { SendClientMessage(playerid, 0xFFFFFFFF, "Вверх"); if(!(upr == 1)) upr = 2; } if(lr > 0) { SendClientMessage(playerid, 0xFFFFFFFF, "Вправо"); if(!(upr == 4)) upr = 3; } else if(lr < 0) { SendClientMessage(playerid, 0xFFFFFFFF, "Влево"); if(!(upr == 3)) upr = 4; } return 1; } forward SyncPos(playerid); public SyncPos(playerid) { switch (upr) { case 1: { if(xp > 8) { CreateExplosion(zto[xp-1][yp][x],zto[xp-1][yp][y],1000.4,12,0); ShowPlayerDialog(playerid,602,0,"ЗМЕЙКА"," КОНЕЦ ИГРЫ","ВЫХОД","ВЫХОД"); KillTimer(postm); } else xp = xp + 1; } case 2: { if(xp < 0) { CreateExplosion(zto[xp+1][yp][x],zto[xp+1][yp][y],1000.4,12,0); ShowPlayerDialog(playerid,602,0,"ЗМЕЙКА"," КОНЕЦ ИГРЫ","ВЫХОД","ВЫХОД"); KillTimer(postm); } else xp = xp - 1; } case 3: { if(yp < 0) { CreateExplosion(zto[xp][yp+1][x],zto[xp][yp+1][y],1000.4,12,0); ShowPlayerDialog(playerid,602,0,"ЗМЕЙКА"," КОНЕЦ ИГРЫ","ВЫХОД","ВЫХОД"); KillTimer(postm); } else yp = yp - 1; } case 4: { if(yp > 16) { CreateExplosion(zto[xp][yp-1][x],zto[xp][yp-1][y],1000.4,12,0); ShowPlayerDialog(playerid,602,0,"ЗМЕЙКА"," КОНЕЦ ИГРЫ","ВЫХОД","ВЫХОД"); KillTimer(postm); } else yp = yp + 1; } } if (xp == xe && yp == ye) { PosEat(); kmax = kmax + 1; for (new n = kmax; n > k; n--) tup[n] = tup[n-1]; tup[k] = CreateObject(1213,zto[xp][yp][x],zto[xp][yp][y],1000.4,0,0,0); } else SetObjectPos(tup[k],zto[xp][yp][x],zto[xp][yp][y],1000.4); for (new nnn = 0; nnn <= kmax; nnn++) { new Float:xxx, Float:yyy, Float: zzz; GetObjectPos(tup[nnn],xxx,yyy,zzz); if (xxx == zto[xp][yp][x] && yyy == zto[xp][yp][y] && tup[nnn] != tup[k]) { CreateExplosion(zto[xp][yp][x],zto[xp][yp-1][y],1000.4,12,0); ShowPlayerDialog(playerid,602,0,"ЗМЕЙКА"," КОНЕЦ ИГРЫ","ВЫХОД","ВЫХОД"); } } if (k == kmax) k = 0; else k = k + 1; return 1; } forward PosEat(); public PosEat() { xe = random(9); ye = random(17); for (new nnnn = 0; nnnn <= kmax; nnnn++) { new Float:xxxx, Float:yyyy, Float: zzzz; GetObjectPos(tup[nnnn],xxxx,yyyy,zzzz); if (xxxx == zto[xe][ye][x] && yyyy == zto[xe][ye][y]) { PosEat(); return 1; } else SetObjectPos(eat,zto[xe][ye][x],zto[xp][ye][y],1000.4); } switch (uri) { case 1: score = score + 1; case 2: score = score + 2; case 3: score = score + 3; case 4: score = score + 4; case 5: score = score + 5; } new sscore[128]; format (sscore,128," %d",score); TextDrawSetString(TextScore,sscore); return 1; } forward Stop(playerid); public Stop(playerid) { TextDrawHideForAll(TextScore); Update3DTextLabelText (bxod, 0x33AA33AA, "ЗМЕЙКА\nНачать игру: /start"); SetPlayerVirtualWorld(playerid, pos_world); KillTimer(postm); SetCameraBehindPlayer(playerid); for (new nn=0; nn <=kmax; nn++) DestroyObject(tup[nn]); DestroyObject(eat); gplayerid = -1; TogglePlayerControllable(playerid,1); return 1; } forward Start(playerid); public Start(playerid) { TextDrawShowForPlayer(playerid, TextScore); Update3DTextLabelText (bxod, 0xAA3333FF, "ЗМЕЙКА \n ЗАНЯТНО"); pos_world = GetPlayerVirtualWorld(playerid); SetPlayerVirtualWorld(playerid, 666); xp = 4; yp = 8; k = 1; kmax = 1; xe = 4; ye = 2; switch (uri) { case 1: score = -1; case 2: score = -2; case 3: score = -3; case 4: score = -4; case 5: score = -5; } gplayerid = playerid; SetPlayerCameraPos(playerid,1208.5,-6.45,1005.2); SetPlayerCameraLookAt(playerid,1208,-6.45,1000.4); eat = CreateObject(1247,zto[xe][ye][x],zto[xp][yp][y],1000.4,90,0,0); tup[0] = CreateObject(1213,zto[xp][yp][x],zto[xp][yp][y],1000.4,0,0,0); tup[1] = CreateObject(1213,zto[xp][yp-1][x],zto[xp][yp][y],1000.4,0,0,0); upr = 4; postm = SetTimerEx("SyncPos", ur, 1, "d",playerid); PosEat(); return 1; } strtok(const string[], &index) { new length = strlen(string); while ((index < length) && (string[index] <= ' ')) { index++; } new offset = index; new result[20]; while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1))) { result[index - offset] = string[index]; index++; } result[index - offset] = EOS; return result; }
Автор:MaN9K Автор - MaNb9K Дата добавления - 04.03.2011 в 14:49:55