29.01.2015, 22:18
Eu implantei recentemente um sistema de salvar posiзхes ao sair do Ricop em Dini, mas meu gamemode й todo feito em MySQL, atй aн tudo bem, mas quando eu vou logar eu nгo spawno. Alguйm poderia checar o cуdigo e se possнvel me ajudar por gentileza.
Код:
// // Medieval Roleplay // Gamemode from scratch by Lucas Santos // #include <a_samp> #include <zcmd> #include <Dini> #include <sscanf2> #include <mSelection> #include <a_mysql> #pragma tabsize 0 // Configuraзхes MySQL #define SQL_HOST "127.0.0.1" #define SQL_USER "root" #define SQL_PASS "vertrigo" #define SQL_DB "medieval" // Defines new skinlist = mS_INVALID_LISTID; // Defines de dialogs #define DIALOG01 1 #define DIALOG02 2 #define DIALOG03 3 // Variavйis globais new mysql; new Float:X[MAX_PLAYERS]; new Float:Y[MAX_PLAYERS]; new Float:Z[MAX_PLAYERS]; new Float:A[MAX_PLAYERS]; new SpawnBloqueado[MAX_PLAYERS]; static seconds; static minutes; static hours; static days; static months; static years; // Textdraws new Text:Time; new Text:Date; new Text:Textdrawdebaixodoradar; // Armazenamento de dados do jogador enum E_PLAYER { E_PLAYER_LOGGED, // Verificar se o usuбrio estб conectado E_PLAYER_SKIN // Skin do jogador }; new player[MAX_PLAYERS][E_PLAYER]; main() { print("\n----------------------------------"); print(" Medieval Roleplay."); print("----------------------------------\n"); } public OnGameModeInit() { mysql = mysql_connect(SQL_HOST, SQL_USER, SQL_DB, SQL_PASS); // Salvando dados dos jogadores SetTimer("saveAll", 100000, 1); SetGameModeText("Medieval Roleplay"); skinlist = LoadModelSelectionMenu("skins.txt"); // Textdraws Time = TextDrawCreate(632.0,25.0,"--:--:--"); TextDrawUseBox(Time, 0); TextDrawFont(Time, 3); TextDrawSetShadow(Time,0); TextDrawSetOutline(Time,2); TextDrawBackgroundColor(Time,0x000000FF); TextDrawColor(Time,0xFFFFFFFF); TextDrawAlignment(Time,3); TextDrawLetterSize(Time,0.5,1.5); Date = TextDrawCreate(620.0,5.0,"00/00/0000"); TextDrawUseBox(Date, 0); TextDrawFont(Date, 3); TextDrawSetShadow(Date,0); TextDrawSetOutline(Date,2); TextDrawBackgroundColor(Date,0x000000FF); TextDrawColor(Date,0xFFFFFFFF); TextDrawAlignment(Date,3); TextDrawLetterSize(Date,0.5,1.5); ProcessGameTime(); SetTimer("ProcessGameTime", 1000, 1); Textdrawdebaixodoradar= TextDrawCreate(1.0, 433.0, "~y~] ~w~Medieval Roleplay ~y~]"); TextDrawAlignment(Textdrawdebaixodoradar,0); TextDrawBackgroundColor(Textdrawdebaixodoradar,0x000000ff); TextDrawFont(Textdrawdebaixodoradar,2); TextDrawLetterSize(Textdrawdebaixodoradar,0.2999, 1.4); TextDrawBoxColor(Textdrawdebaixodoradar,0x00000050); TextDrawColor(Textdrawdebaixodoradar,0xffffffff); TextDrawSetOutline(Textdrawdebaixodoradar,1); TextDrawSetProportional(Textdrawdebaixodoradar,1); TextDrawSetShadow(Textdrawdebaixodoradar,1); for(new i; i < MAX_PLAYERS; i ++) { if(IsPlayerConnected(i)) { TextDrawShowForPlayer(i, Textdrawdebaixodoradar); } } return 1; } public OnGameModeExit() { TextDrawHideForAll(Time); TextDrawDestroy(Time); TextDrawHideForAll(Date); TextDrawDestroy(Date); TextDrawHideForAll(Textdrawdebaixodoradar); TextDrawDestroy(Textdrawdebaixodoradar); return 1; } public OnPlayerRequestClass(playerid, classid) { TogglePlayerSpectating(playerid, false); if(player[playerid][E_PLAYER_LOGGED]) { SpawnPlayer(playerid); } return 0; } public OnPlayerConnect(playerid) { TogglePlayerSpectating(playerid, false); TextDrawShowForPlayer(playerid, Textdrawdebaixodoradar); SpawnBloqueado[playerid] = 0; new name[MAX_PLAYER_NAME], query[1024]; GetPlayerName(playerid, name, MAX_PLAYER_NAME); format(query, sizeof(query), "SELECT * FROM `contas` WHERE `usuario` = '%s'", name); mysql_function_query(mysql, query, true, "q_loginRequest", "d", playerid); return 1; } forward q_loginRequest(playerid); public q_loginRequest(playerid) { new rows, fields; cache_get_data(rows, fields); if(rows > 0) { // Usuбrio existe ShowPlayerDialog(playerid, DIALOG01, DIALOG_STYLE_PASSWORD, "{FFFFFF}Login", "{FFFFFF}Bem vindo novamente, digite a sua senha para logar-se.", "Logar", ""); } else { // Usuбrio nгo existe ShowPlayerDialog(playerid, DIALOG02, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registro", "{FFFFFF}Bem vindo, digite a sua senha para registrar-se.", "Registrar", ""); } } public OnPlayerDisconnect(playerid, reason) { player[playerid][E_PLAYER_LOGGED] = 0; new name[MAX_PLAYER_NAME]; new data[256]; GetPlayerName(playerid, name, sizeof(name)); GetPlayerPos(playerid,X[playerid],Y[playerid],Z[playerid]); GetPlayerFacingAngle(playerid,A[playerid]); format(data, sizeof(data), "%s.spawn.ini", name); dini_FloatSet(data,"CoordenadaX",X[playerid]); dini_FloatSet(data,"CoordenadaY",Y[playerid]); dini_FloatSet(data,"CoordenadaZ",Z[playerid]); dini_FloatSet(data,"CoordenadaA",A[playerid]); return 1; } public OnPlayerSpawn(playerid) { TextDrawShowForPlayer(playerid,Time); TextDrawShowForPlayer(playerid,Date); new tmp[64], skin; cache_get_field_content(0, "skin", tmp); skin = strval(tmp); new name[MAX_PLAYER_NAME]; new voltarcoordenada[256]; GetPlayerName(playerid, name, sizeof(name)); format(voltarcoordenada, sizeof(voltarcoordenada), "%s.spawn.ini", name); if(fexist(voltarcoordenada) && SpawnBloqueado[playerid] == 0) { X[playerid] = dini_Float(voltarcoordenada,"CoordenadaX"); Y[playerid] = dini_Float(voltarcoordenada,"CoordenadaY"); Z[playerid] = dini_Float(voltarcoordenada,"CoordenadaZ"); A[playerid] = dini_Float(voltarcoordenada,"CoordenadaA"); SetSpawnInfo(playerid, 0, skin, X[playerid], Y[playerid], Z[playerid], 0, 0, 0, 0, 0, 0, 0); SetPlayerFacingAngle(playerid, A[playerid]); SetCameraBehindPlayer(playerid); SendClientMessage(playerid, 0x33FF00FF, "Vocк voltou para onde saiu pela ъltima vez."); SpawnBloqueado[playerid] = 1; } if(!fexist(voltarcoordenada)) { dini_Create(voltarcoordenada); SpawnBloqueado[playerid] = 1; } return 1; } public OnPlayerDeath(playerid, killerid, reason) { TogglePlayerSpectating(playerid, true); TextDrawHideForPlayer(playerid,Time); TextDrawHideForPlayer(playerid,Date); return 1; } public OnVehicleSpawn(vehicleid) { return 1; } public OnVehicleDeath(vehicleid, killerid) { return 1; } public OnPlayerText(playerid, text[]) { return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { return 0; } public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) { return 1; } public OnPlayerExitVehicle(playerid, vehicleid) { return 1; } public OnPlayerStateChange(playerid, newstate, oldstate) { return 1; } public OnPlayerEnterCheckpoint(playerid) { return 1; } public OnPlayerLeaveCheckpoint(playerid) { return 1; } public OnPlayerEnterRaceCheckpoint(playerid) { return 1; } public OnPlayerLeaveRaceCheckpoint(playerid) { return 1; } public OnRconCommand(cmd[]) { return 1; } public OnPlayerRequestSpawn(playerid) { return 0; } public OnObjectMoved(objectid) { return 1; } public OnPlayerObjectMoved(playerid, objectid) { return 1; } public OnPlayerPickUpPickup(playerid, pickupid) { return 1; } public OnVehicleMod(playerid, vehicleid, componentid) { return 1; } public OnVehiclePaintjob(playerid, vehicleid, paintjobid) { return 1; } public OnVehicleRespray(playerid, vehicleid, color1, color2) { return 1; } public OnPlayerSelectedMenuRow(playerid, row) { return 1; } public OnPlayerExitedMenu(playerid) { return 1; } public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid) { return 1; } public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { return 1; } public OnRconLoginAttempt(ip[], password[], success) { return 1; } public OnPlayerUpdate(playerid) { return 1; } public OnPlayerStreamIn(playerid, forplayerid) { return 1; } public OnPlayerStreamOut(playerid, forplayerid) { return 1; } public OnVehicleStreamIn(vehicleid, forplayerid) { return 1; } public OnVehicleStreamOut(vehicleid, forplayerid) { return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { switch(dialogid) { case DIALOG01: { new query[1024], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME); Hash(inputtext); format(query, sizeof(query), "SELECT * FROM `contas` WHERE `usuario` = '%s' AND `senha` = '%s'", name, inputtext); mysql_function_query(mysql, query, true, "q_verifyPassword", "d", playerid); return 1; } // Usuбrio nгo existe. case DIALOG02: { if(strlen(inputtext) < 2) { ShowPlayerDialog(playerid, DIALOG02, DIALOG_STYLE_PASSWORD, "{FFFFFF}Registro", "{FFFFFF}Bem vindo, digite a sua senha para registrar-se.\n\n{FF0000}Informe uma senha vбlida.", "Registrar", ""); return 1; } else { new query[1024], name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, MAX_PLAYER_NAME); Hash(inputtext); format(query, sizeof(query), "INSERT INTO `contas` (usuario, senha) VALUES ('%s', '%s')", name, inputtext); mysql_function_query(mysql, query, false, "", ""); // Spawn jogador SetTimerEx("RegSkinMenu",5000,0,"d",playerid); SendClientMessage(playerid, 0xFFFFFF00, "Aguarde enquanto nуs preparamos sua conta..."); return 1; } } } return 1; } public OnPlayerModelSelection(playerid, response, listid, modelid) { if(listid == skinlist) { if(response) { SetSkin(playerid, modelid); } else { SetSkin(playerid,modelid); } } return 1; } forward q_verifyPassword(playerid); public q_verifyPassword(playerid) { new rows, fields; cache_get_data(rows, fields); if(rows) { // Pegando informaзхes do jogador player[playerid][E_PLAYER_LOGGED] = 1; SpawnPlayer(playerid); return 1; } else { // Senha incorreta ShowPlayerDialog(playerid, DIALOG01, DIALOG_STYLE_PASSWORD, "{FFFFFF}Login", "{FFFFFF}Bem vindo novamente, digite a sua senha para logar-se.\n\n{FF0000}Senha de acesso invбlida!", "Logar", ""); return 1; } } forward saveAll(); public saveAll() { new query[128], name[MAX_PLAYER_NAME]; for(new a=0; a<MAX_PLAYERS; a++) { if(!player[a][E_PLAYER_LOGGED]) continue; GetPlayerName(a, name, MAX_PLAYER_NAME); format(query, sizeof(query), "UPDATE `contas` SET `skin` = '%d' WHERE `usuario` = '%s'", GetPlayerSkin(a), name); mysql_function_query(mysql, query, false, "", ""); } SendClientMessageToAll(0xFF000000, "Dados salvos."); } forward RegSkinMenu(playerid); public RegSkinMenu(playerid) { SendClientMessage(playerid, 0xFFFFFF00, "Estamos quase terminando, selecione uma skin para seu personagem."); ShowSkinMenu(playerid); return 1; } forward ProcessGameTime(); public ProcessGameTime() { new string[12]; gettime(hours, minutes, seconds); getdate(years, months, days); format(string, sizeof string, "%02d:%02d:%02d", hours, minutes, seconds); TextDrawSetString(Time, string); format(string, sizeof string, "%02d/%02d/%04d", days, months, years); TextDrawSetString(Date, string); SetWorldTime(hours); for(new i = 0; i < MAX_PLAYERS; i++)SetPlayerTime(i, hours, minutes); } forward Hash(string[]); public Hash(string[]) { for(new x=0; x < strlen(string); x++) { string[x] += (3^x) * (x % 15); if(string[x] > (0xff)) { string[x] -= 256; } } return 1; } stock SetSkin(playerid, skin) { SetSpawnInfo(playerid, 0, skin, 1958.3783, 1343.1572, 15.3746, 0, 0, 0, 0, 0, 0, 0); SpawnPlayer(playerid); // Salvando dados do jogador saveAll(); return SetPlayerSkin(playerid, skin); } stock ShowSkinMenu(playerid) { ShowModelSelectionMenu(playerid, skinlist, "Menu de Skins"); SelectTextDraw(playerid, 0xACCBF1FF); return 1; } public OnPlayerClickPlayer(playerid, clickedplayerid, source) { return 1; } //////////////////////////////////////////////////////////////////////////////// COMMAND:gmx() { GameModeExit(); return 1; } COMMAND:limparchat(playerid, params[]) { for(new a = 0; a < 20; a++) { SendClientMessageToAll(0xFFFFFF00, " "); } SendClientMessageToAll(0xFFFFFF00, "<!> Chat limpo."); return 1; }