[TUTORIAL] CREARE SISTEM POINTS

Tutoriale scripting, cod si portiuni de cod.

Moderators: Moderatori ajutatori, Moderatori, Echipa eXtreamCS.com

Post Reply
User avatar
LondoN eXtream
Membru eXtream
Membru eXtream
Posts: 2755
Joined: 10 Oct 2014, 06:21
Detinator Steam: Da
SteamID: /id/london_extreamcs
Reputatie: Fost scripter eXtreamCS
Fost moderator ajutator
Membru Club eXtreamCS (6 luni)
Fond eXtream: 0
Location: Roman, Neamț
Has thanked: 3 times
Been thanked: 12 times

09 Oct 2015, 16:09

In acest tutorial va voi invata despre cum va puteti crea singuri un sistem de puncte, pentru diferite moduri.
| Afiseaza codul
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"


public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Add your code here...
}
Deschidem un nou proiect in AMXX STUDIO.

1.Creem 2 variabile.

Code: Select all

new Points [ 33 ];
In aceasta variabile vom stoca punctele stranse de jucator.

Code: Select all

new SaveDataFile [ 128 ];
Aceasta variabila o vom folosi la salvarea punctelor.

2. In public plugin_init ( ) adaugam:

a)

Code: Select all

	register_event ( "DeathMsg", "eDeath", "a" );
In acest event vom da puncte jucatorilor [cand fac kill].


b)

Code: Select all

	new szConfigFile [ 64 ];
Aceasta variabila ne ajuta la aflarea fisierului configs.

c)

Code: Select all

	get_configsdir ( szConfigFile, charsmax ( szConfigFile ) );
Aflam directorul configs.

d)

Code: Select all

	format ( SaveDataFile, charsmax ( SaveDataFile ), "%s/Nume_Fisier.dat", szConfigFile );
Definim 'linkul' catre fisierul in care vom stoca punctele.

SMA-ul nostru ar trebui sa arate asa:
| Afiseaza codul
#include < amxmodx >
#include < amxmisc >

new Points [ 33 ];
new SaveDataFile [ 128 ];

public plugin_init ( )
{
	register_event ( "DeathMsg", "eDeath", "a" );
	
	new szConfigFile [ 64 ];
	get_configsdir ( szConfigFile, charsmax ( szConfigFile ) );
	format ( SaveDataFile, charsmax ( SaveDataFile ), "%s/Nume_Fisier.dat", szConfigFile );
}
3. In public eDeath ( ) adaugam:

a)

Code: Select all

new killer = read_data ( 1 );
new victim = read_data ( 2 );
b)

Code: Select all

if ( killer == victim )               return PLUGIN_HANDLED;
Daca atacatorul se sinucide oprim toate functiile.

c)

Code: Select all

Points [ id ] += 2;
Adaugam 2 puncte la contul atacatorului.

d)

Code: Select all

return PLUGIN_CONTINUE;
Returnam.

4. In public client_connect ( id ) adaugam:

Code: Select all

LoadPoints ( id );
5. In public client_disconnect ( id ) adaugam:

Code: Select all

SavePoints ( id );
5. In public LoadPoints ( id ) adaugam:

Code: Select all

	new Name [ 32 ];
	get_user_name ( id, Name, 31 );
	
	new Line [ 128 ], IsPlayer = false, Arg1 [ 32 ], Arg2 [ 32 ];
	new File = fopen ( SaveDataFile, "rt" )
	while ( !feof ( File ) ) {
		fgets ( File, Line, 127 );
		trim ( Line );
		
		parse ( Line, Arg1, 31, Arg2, 31 );
		
		if ( equali ( Arg1, Name ) ) {
			Points [ id ] = str_to_num ( Arg2 );
			IsPlayer = true;
			break;
		}
	}
	
	fclose ( File );
	
	if ( !IsPlayer )
		Points [ id ] = 0;
in public SavePoints ( id ) adaugam:

Code: Select all

new Name [ 32 ];
	get_user_name ( id, Name, 31 );
	
	new Save [ 1024 ];
	format ( Save, sizeof ( Save ) -1, "^"%s^" %d", Name, Points [ id ] );
	
	new Line [ 128 ], Linie, IsPlayer = false, Arg1 [ 32 ]
	
	new File = fopen ( SaveDataFile, "rt" );
	while ( !feof ( File ) ) {
		fgets ( File, Line, 127 );
		
		parse ( Line, Arg1, 31 );
		
		if ( equali ( Arg1, Name ) ) {
			write_file ( SaveDataFile, Save, Linie );
			IsPlayer = true;
			break;
		}
		
		Linie++
	}
	
	fclose ( File );
	
	if ( !IsPlayer )
		write_file ( SaveDataFile, Save, -1 );
}
Si cam gata sistemul nostru de puncte.
Credite lui hades pentru metoda de salvare.
Sper sa va placa tutorialul.
User avatar
HamletEagle
Fost moderator
Fost moderator
Posts: 750
Joined: 21 Sep 2013, 15:05
Detinator Steam: Da
CS Status: Inactiv cateva zile.
SteamID: privat
Reputatie: Fost Scripter eXtreamCS.com
Fost Moderator ajutator
Has thanked: 19 times
Been thanked: 85 times

09 Oct 2015, 20:04

Nu mai face tutoriale daca nu intelegi ce scrii + atat timp cat nu explici fiecare linie nu il poti numi tutorial. Sunt multe chestii ne-explicate sau scrise prost, care n-au sens etc. Sunt prea multe "tutoriale" despre cum sa faci un sistem de puncte, dar nici macar unul nu e facut cum trebuie.
Daca vreti ajutorul meu, nu dati bump la topic, fara intrebari de genu "cat mai dureaza/mai astept mult?".
Post Reply

Return to “Scripting”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests