Jump to content
  • 0

Simplificare prin functie, ceva ce e usor...


[emy]

Question

	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...  

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

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

Link to comment
Share on other sites

  • 0
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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.