Jump to content

[REZOLVAT] [Intrebare] Salvare actiuni in baza de date


equin0x
 Share

Recommended Posts

salut, am o intrebare:

cum pot salva actiuni de tipul FPK, uninvite, invite in baza de date?

am tabelul `actions` (id, player, action, date, type)

si

stock UpdateAction(playerid, action[], tip)
{
    new
        l_year,
        l_month,
        l_day,
		l_second,
        l_hour,
        l_minute;

    getdate(l_year, l_month, l_day);
    gettime(l_hour, l_minute,l_second);
    new data[456];
    format(data,sizeof(data),"%02d.%02d.%02d ora: %02d:%02d  ",l_day,l_month,l_year,l_hour,l_minute);
	new string[256];
	format(string,sizeof(string), "INSERT INTO `actions` ( id,`player`, `action`, `date`, type) VALUES (%d,'%s','%s','%s', %d)",
	PlayerInfo[playerid][pMysqlID], GetName(playerid),action,data,tip );
	mysql_tquery(mysql, string, "Actiune", "");
}

ce fac?

Link to comment
Share on other sites

Folosesti aceasta functie de fiecare data cand jucatorul accepta o invitatie intr-o factiune, foloseste /uninvite sau este demis, etc.

Respecta si vei fi respectat.

 

BigInt Pawn:

Pacman C++: 

Snake C++:

Minesweeper C++:

 

mattbb.cash

leaks.ro

Link to comment
Share on other sites

Folosesti aceasta functie de fiecare data cand jucatorul accepta o invitatie intr-o factiune, foloseste /uninvite sau este demis, etc.

YCMD:setleader(playerid, params[], help) {
    if(PlayerInfo[playerid][pAdmin] < 4) return SCM(playerid, COLOR_WHITE, AdminOnly);
    new id,level,string[180];
    if(sscanf(params, "ui",id,level)) return SCM(playerid, COLOR_GREY, "USAGE: {FFFFFF}/setleader <playerid/name> <faction>");
    if(!IsPlayerConnected(id) || id == INVALID_PLAYER_ID) return SCM(playerid, COLOR_GREY, "Acel player nu este conectat.");
    if(level > 15 || level < 0) return SCM(playerid, COLOR_WHITE, "Invalid ID. (1-15).");
   
    if(PlayerInfo[id][pMember] > 0 && PlayerInfo[id][pLeader] > 0) return SCM(playerid,COLOR_WHITE, "Acel player este intr-o factiune.");
    format(string, sizeof(string), "%s este noul lider al factiunii.", GetName(id));
    SendFactionMessage(level, COLOR_CLIENT, string);
   
    new ftext[50];
    format(ftext, sizeof(ftext), FactionName(level));
    PlayerInfo[id][pMember] = level;
   
    if(PlayerInfo[playerid][pMember] == 11) finishAchievement(id, 29); 
    else if(IsACop(playerid)) finishAchievement(id, 30);   
    else if(IsAMember(playerid)) finishAchievement(id, 31);
    else finishAchievement(id, 28);
   
   
    PlayerInfo[id][pLeader] = level;
    FactionMembers[PlayerInfo[id][pMember]] ++;
    if(level == 0) { PlayerInfo[id][pChar] = 0; }
    else if(level == 1) { PlayerInfo[id][pChar] = 265; } //Police Departament
    else if(level == 2) { PlayerInfo[id][pChar] = 295; } //FBI
    else if(level == 3) { PlayerInfo[id][pChar] = 179; } //National Guard
    else if(level == 4) { PlayerInfo[id][pChar] = 270; } //Triad
    else if(level == 5) { PlayerInfo[id][pChar] = 292; } //Los Vagos
    else if(level == 6) { PlayerInfo[id][pChar] = 273; } //Ballas
    else if(level == 7) { PlayerInfo[id][pChar] = 258; } //School Instructors
    else if(level == 8) { PlayerInfo[id][pChar] = 59; } //Tow Car Company
    else if(level == 9) { PlayerInfo[id][pChar] = 228; } //News Reporters
    else if(level == 10) { PlayerInfo[id][pChar] = 296; } //Los Aztecas
    else if(level == 11) { PlayerInfo[id][pChar] = 294; } //Hitman
    else if(level == 12) { PlayerInfo[id][pChar] = 272; } //School Instructors
    else if(level == 13) { PlayerInfo[id][pChar] = 70; } //Paramedic
 
    if(IsACop(id)) SetPlayerSkinEx(id, 305);
    else SetPlayerSkinEx(id, PlayerInfo[id][pChar]);                   
    PlayerInfo[id][pRank] = 7;
    SetPlayerToTeamColor(id);
 
    new query[256];
    format(string, sizeof(string), "%s este liderul factiunii %s.", GetName(id), ftext);
    //if(PlayerInfo[id][pAdmin] < 1) {
    mysql_format(SQL, query, sizeof(query), "INSERT INTO `faction_logs` (`text`) VALUES ('%s')", string);
    mysql_tquery(SQL, query, "", "");         
    //}
   
    format(query,sizeof(query),"UPDATE users SET `Leader`='%d',`Member`='%d',`Rank`='7',`Team`='%d',`CChar`='%d' WHERE `ID`='%d'",PlayerInfo[id][pLeader],PlayerInfo[id][pMember],PlayerInfo[id][pTeam],PlayerInfo[id][pChar],PlayerInfo[id][pSQLID]);
    format(string, sizeof(string), "L-ai promovat pe %s ca lider la factiunea %s.", GetName(id),ftext);
    SCM(playerid, COLOR_LIGHTBLUE, string);
   
    format(string, sizeof(string), "Admin %s te-a promovat ca lider al factiunii %s.", GetName(playerid),ftext);
    SCM(id, COLOR_LIGHTBLUE, string);

    return 1;
}
		

imi poti spune unde se baga aici, te rog?

Link to comment
Share on other sites

  • Administrator

Bun, sa incepem.

 

Definim cateva THREAD-uri ca sa ne fie mai usor:

#define THREAD_PLAYER_FPK 1		// define pentru FPK
#define THREAD_PLAYER_UNINITE 2 	// define pentru UNINITE
#define THREAD_PLAYER_INVITE 3 		// define pentru INVITE

Definim numarul maxim de factiuni dupa server:

#define MAX_FACTIONS (10) // define pentru numarul maxim de factiuni, aici il modifici pentru gamemode-ul tau.

Declaram cateva variabile:

new gQuery[ 256 ];  	// o variabila globala de tip 'string' pentru a formata query-uri.
new gString[ 512 ]; 	// o variabila globala de tip 'string' pentru a formata mesaje.
new gName[ 32 ]; 	// o variabila globala de tip 'string' pentru a stoca numele unui jucator.

Facem o variabila de tip array pentru a stoca numele factiunilor dupa server:

new numeFactiune[ MAX_FACTIONS ][] = { // variabila de tip Array pentru a stoca numele factiunilor, aici la fel, treci numele factiunilor din gamemode-ul tau.
	{"nume factiune 1"},
	{"nume factiune 2"},
	{"nume factiune 3"},
	{"nume factiune 4"},
	{"nume factiune 5"},
	{"nume factiune 6"},
	{"nume factiune 7"},
	{"nume factiune 8"},
	{"nume factiune 9"},
	{"nume factiune 10"}
};

Facem un stock pentru a afla numele unui jucator:

stock getPlayerName( playerid ) { // stock pentru a afla numele unui jucator
	GetPlayerName( playerid, gName, sizeof gName ); // functie pentru a afla numele unui jucator si al scota intr-o variabila.
	return gName; // returneaza numele aflat.
}

Facem un stock pentru a insera mai usor ceva in baza de date folosindu-ne de THREAD-urile definite si variabilele declarate mai sus:

stock insertAction( playerid, userID, threadType ) {
	gQuery[ 0 ] = ( EOS ); // Marcheaza sfarsitul variabilei globale de tip 'string' pentru a formata query-uri.
	gString[ 0 ] = ( EOS ); // Marcheaza sfarsitul variabilei globale de tip 'string' pentru a formata mesaje.

	switch( threadType ) {
		case THREAD_PLAYER_FPK: {
			format( gString, sizeof gString, "Jucatorul %s a fost scos din factiunea %s de catre Administratorul %s.", getPlayerName( userID ), numeFactiune[ PlayerInfo[ userID ][ pMember ] ], getPlayerName( playerid ) ); // formateaza mesajul

			mysql_format( SQL, gQuery, sizeof gQuery, "INSERT INTO `server_faction_logs` (`Text`) VALUES ('%s')", gString ); // formateaza interogarea
			mysql_tquery( SQL, gQuery, "", "" ); // trimite interogarea
		}

		case THREAD_PLAYER_UNINITE: {
			format( gString, sizeof gString, "Jucatorul %s a fost scos din factiunea %s de catre lider-ul acesteia %s.", getPlayerName( userID ), numeFactiune[ PlayerInfo[ userID ][ pMember ] ], getPlayerName( playerid ) ); // formateaza mesajul

			mysql_format( SQL, gQuery, sizeof gQuery, "INSERT INTO `server_faction_logs` (`Text`) VALUES ('%s')", gString ); // formateaza interogarea
			mysql_tquery( SQL, gQuery, "", "" ); // trimite interogarea			
		}

		case THREAD_PLAYER_INVITE: {
			format( gString, sizeof gString, "Jucatorul %s a fost scos invitat factiunea %s de catre lider-ul acesteia %s.", getPlayerName( userID ), numeFactiune[ PlayerInfo[ userID ][ pMember ] ], getPlayerName( playerid ) ); // formateaza mesajul

			mysql_format( SQL, gQuery, sizeof gQuery, "INSERT INTO `server_faction_logs` (`Text`) VALUES ('%s')", gString ); // formateaza interogarea 
			mysql_tquery( SQL, gQuery, "", "" ); // trimite interogarea				
		}
	}

	return true; // returneaza adevarat.
}

Iar la o comanda procedam astfel:

 

Daca e vorba de 'invite' ne folosim de THREAD-uri corespunzator:

insertAction( playerid, id jucator, THREAD_PLAYER_INVITE );

*** Informatii

 

In baza de date faci urmatoarea chestie:
 
* Te duci la baza de date a gamemode-ului, dai pe 'SQL', dupa introduci urmatorul cod in acea casuta si dupa dai 'Executa'.
 
(!) ATENTIE (!)
 
** Data si ora se insereaza automat in baza de date.

 

 

Sper ca ai inteles ce ai de facut.

Link to comment
Share on other sites

@@Leonard

 

 

error 017: undefined symbol "userID"
 warning 219: local variable "gString" shadows a variable at a preceding level
 warning 219: local variable "gQuery" shadows a variable at a preceding level
 warning 219: local variable "gString" shadows a variable at a preceding level
 warning 219: local variable "gQuery" shadows a variable at a preceding level
 warning 219: local variable "gString" shadows a variable at a preceding level
 error 017: undefined symbol "userID"
 error 017: undefined symbol "gString"
 warning 215: expression has no effect
 error 001: expected token: ";", but found "]"
 error 029: invalid expression, assumed zero
 fatal error 107: too many error messages on one line
 
 
am pus userid in loc de id jucator ca nu stiam ce sa pun, nu mergea indiferent de ce puneam..
Edited by equin0x
Link to comment
Share on other sites

  • Administrator

 

@@Leonard

 

 

error 017: undefined symbol "userID"
 warning 219: local variable "gString" shadows a variable at a preceding level
 warning 219: local variable "gQuery" shadows a variable at a preceding level
 warning 219: local variable "gString" shadows a variable at a preceding level
 warning 219: local variable "gQuery" shadows a variable at a preceding level
 warning 219: local variable "gString" shadows a variable at a preceding level
 error 017: undefined symbol "userID"
 error 017: undefined symbol "gString"
 warning 215: expression has no effect
 error 001: expected token: ";", but found "]"
 error 029: invalid expression, assumed zero
 fatal error 107: too many error messages on one line
 
 
am pus userid in loc de id jucator ca nu stiam ce sa pun, nu mergea indiferent de ce puneam..

 

Eu am facut doar un model, tu trebuie sa-l faci compatibil cu gamemode-ul pe care lucrezi.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...