Jump to content
  • 0

Simplificare prin functie, ceva ce e usor...


Question

Posted
	switch (playerVariables[playerid][pPrayers]) {
		case 5: { 
			SendClientMessage(playerid, -1, "Case 5"); 
			SCMf(playerid, -1, "{28A700}PRAY >> {FFFFFF}You have prayed %d times until now. {FF5D00}Next reward at 10 times.", praypoints+1);	
		}
		case 10: { 
			SendClientMessage(playerid, -1, "Case 10");
			SCMf(playerid, -1, "{28A700}PRAY >> {FFFFFF}You have prayed %d times until now. {FF5D00}Next reward at 15 times.", praypoints+1);	 
		}
		case 15: { 
			SendClientMessage(playerid, -1, "Case 15");
			SCMf(playerid, -1, "{28A700}PRAY >> {FFFFFF}You have prayed %d times until now. {FF5D00}Next reward at 30 times.", praypoints+1);	 
		}
		case 30: { 
			SendClientMessage(playerid, -1, "Case 30");
			SCMf(playerid, -1, "{28A700}PRAY >> {FFFFFF}You have prayed %d times until now. {FF5D00}Next reward at 35 times.", praypoints+1);	 
		}
		case 35: { 
			SendClientMessage(playerid, -1, "Case 35");
			SCMf(playerid, -1, "{28A700}PRAY >> {FFFFFF}You have prayed %d times until now. {FF5D00}Next reward at 50 times.", praypoints+1);	 
		}
	}

Cum as putea face ca in loc de a pune mesajul asta de fiecare data sa pot sa scriu 

SCMf(playerid, -1, "{28A700}PRAY >> {FFFFFF}You have prayed %d times until now. {FF5D00}Next reward at %d times.", praypoints+1, getPrayPoints(playerid)));

Adica practic, cum sa arate functia mea.. getPrayPoints... Vreau ca atunci cand mai are 5 sa scrie ca au mai ramas 5... cand se fac 35 de exemplu si eu am 31 de puncte sa imi scrie ca mai trebuie de 4 ori sa repet actiunea...  

2 answers to this question

Recommended Posts

  • 0
Posted (edited)

Salut @[emy],

Nu ai nevoie neaparat de o functie pentru asta. Poti calcula premiul urmator adunand pPrays cu 5. Rezultatul va fi urmatorul:

SCMf(playerid, -1, "{28A700}PRAY >> {FFFFFF}You have prayed %d times until now. {FF5D00}Next reward at %d times.", praypoints+1, playerVariables[playerid][pPrayers] + 5);

Iar ca sa simplifici si mai mult, ai putea face ceva de genul:

new Prays_Rewards[ 6 ] = { 5, 10, 15, 20, 25, 30 };

for( new i = 0; i < 6; i ++ ) {
	if( playerVariables[ playerid ][ pPrayers ] == Prays_Rewards[ i ] ) {
		SCMf( playerid, -1, "Case %d", playerVariables[ playerid ][ pPrayers ] );
		SCMf( playerid, -1, "{28A700}PRAY >> {FFFFFF}You have prayed %d times until now. {FF5D00}Next reward at %d times.", playerVariables[ playerid ][ pPrayers ], playerVariables[ playerid ][ pPrayers ] + 5 );
		break;
	}
}

Ti-am dat un exemplu, nu stiu ce vrei sa faci sau cum ai tu format sistemul :)

Edited by shane
  • Like 1

Daca te-am ajutat =>

spacer.png

  • 0
Posted
Acum 10 ore, shane a spus:

Salut @[emy],

Nu ai nevoie neaparat de o functie pentru asta. Poti calcula premiul urmator adunand pPrays cu 5. Rezultatul va fi urmatorul:


SCMf(playerid, -1, "{28A700}PRAY >> {FFFFFF}You have prayed %d times until now. {FF5D00}Next reward at %d times.", praypoints+1, playerVariables[playerid][pPrayers] + 5);

Iar ca sa simplifici si mai mult, ai putea face ceva de genul:


new Prays_Rewards[ 6 ] = { 5, 10, 15, 20, 25, 30 };

for( new i = 0; i < 6; i ++ ) {
	if( playerVariables[ playerid ][ pPrayers ] == Prays_Rewards[ i ] ) {
		SCMf( playerid, -1, "Case %d", playerVariables[ playerid ][ pPrayers ] );
		SCMf( playerid, -1, "{28A700}PRAY >> {FFFFFF}You have prayed %d times until now. {FF5D00}Next reward at %d times.", playerVariables[ playerid ][ pPrayers ], playerVariables[ playerid ][ pPrayers ] + 5 );
		break;
	}
}

Ti-am dat un exemplu, nu stiu ce vrei sa faci sau cum ai tu format sistemul :)

e exact ce cautam, mersi mult! 

respect!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.