Jump to content

[REZOLVAT] Salutare!


TioO
 Share

Recommended Posts

  • Retired

faci o variabila new delayfish[MAX_PLAYERS];

dupa pui la fish urmatoarea verificare: if(delayfish[playerid] != 0) return format(string, sizeof string, "Mai trebuie sa astepti %d secunde", delayfish[playerid]), SendClientMessage(playerid, -1, string);

 

si cand vinzi pestele pui delayfish[playerid] = 30;

 

la timerul de o secunda pui asa:

foreach(Player, i) {

    if(delayfish != 0) delayfish --;

}

Link to comment
Share on other sites

Daca folosesti y_timers sau ai libraria YSI iti recomand sa faci in felul urmator, deoarece va fii mult mai optim decat daca ai folosi metodele traditionale:

#include <YSI\y_timers>

new Timer:PauzaPeste[ MAX_PLAYERS ],
	PotPrindeBoss[ MAX_PLAYERS ];

public OnPlayerConnect( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	return 1;
}

CMD:fish( playerid, params[ ] ){

	if( PotPrindeBoss[ playerid ] > 0 ){
		new info_text[ 56 ];
		format( info_text, sizeof info_text, "Poti prinde un alt peste peste %d secunde.", PotPrindeBoss[ playerid ] );
		SendClientMessage( playerid, -1, info_text );
		return 1;
	}
	/*
		bla...bla...bla ce ai tu pe aici

	*/
	PotPrindeBoss[ playerid ] = 30;
	PauzaPeste[ playerid ] = repeat CooldownPeste( playerid );
	return 1;
}

timer CooldownPeste[ 1000 ]( playerid ){
	PotPrindeBoss[ playerid ] --;
	if( PotPrindeBoss[ playerid ] == 0 ){
		stop PauzaPeste[ playerid ];
		SendClientMessage( playerid, -1, "Acum poti prinde un nou peste." );
	}
	return 1;
}

Dar daca nu o ai, poti incerca asta: 

new 
	PotPrindeBoss[ MAX_PLAYERS ];

public OnPlayerConnect( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	return 1;
}

CMD:fish( playerid, params[ ] ){

	if( PotPrindeBoss[ playerid ] == 1 )return SendClientMessage( playerid, -1, "Poti folosi comanda asta dupa 30 de secunde de la ultimul peste prins." );
	/*
		bla...bla...bla ce ai tu pe aici

	*/
	PotPrindeBoss[ playerid ] = 1;
	SetTimerEx( "CooldownPeste", 30000, false, "d", playerid );
	return 1;
}
forward CooldownPeste( playerid );
public CooldownPeste( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	SendClientMessage( playerid, -1, "Acum poti prinde un nou peste." );
	return 1;
}

Mentionez ca n-am compilat pe nici una dintre ele, daca ai vreo eroare/warning anunta-ma.

bcugZLK.png 

bwTYRvf.png

Link to comment
Share on other sites

  • Retired

Daca folosesti y_timers sau ai libraria YSI iti recomand sa faci in felul urmator, deoarece va fii mult mai optim decat daca ai folosi metodele traditionale:

#include <YSI\y_timers>

new Timer:PauzaPeste[ MAX_PLAYERS ],
	PotPrindeBoss[ MAX_PLAYERS ];

public OnPlayerConnect( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	return 1;
}

CMD:fish( playerid, params[ ] ){

	if( PotPrindeBoss[ playerid ] > 0 ){
		new info_text[ 56 ];
		format( info_text, sizeof info_text, "Poti prinde un alt peste peste %d secunde.", PotPrindeBoss[ playerid ] );
		SendClientMessage( playerid, -1, info_text );
		return 1;
	}
	/*
		bla...bla...bla ce ai tu pe aici

	*/
	PotPrindeBoss[ playerid ] = 30;
	PauzaPeste[ playerid ] = repeat CooldownPeste( playerid );
	return 1;
}

timer CooldownPeste[ 1000 ]( playerid ){
	PotPrindeBoss[ playerid ] --;
	if( PotPrindeBoss[ playerid ] == 0 ){
		stop PauzaPeste[ playerid ];
		SendClientMessage( playerid, -1, "Acum poti prinde un nou peste." );
	}
	return 1;
}

Dar daca nu o ai, poti incerca asta: 

new 
	PotPrindeBoss[ MAX_PLAYERS ];

public OnPlayerConnect( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	return 1;
}

CMD:fish( playerid, params[ ] ){

	if( PotPrindeBoss[ playerid ] == 1 )return SendClientMessage( playerid, -1, "Poti folosi comanda asta dupa 30 de secunde de la ultimul peste prins." );
	/*
		bla...bla...bla ce ai tu pe aici

	*/
	PotPrindeBoss[ playerid ] = 1;
	SetTimerEx( "CooldownPeste", 30000, false, "d", playerid );
	return 1;
}
forward CooldownPeste( playerid );
public CooldownPeste( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	SendClientMessage( playerid, -1, "Acum poti prinde un nou peste." );
	return 1;
}

Mentionez ca n-am compilat pe nici una dintre ele, daca ai vreo eroare/warning anunta-ma.

In primul rand dece sa faca timerul asta cand are deja unul facut(cel de 1 sec) si se poate folosi de el, oricum ce i-am dat eu e mult mai simplu.

Link to comment
Share on other sites

In primul rand dece sa faca timerul asta cand are deja unul facut(cel de 1 sec) si se poate folosi de el, oricum ce i-am dat eu e mult mai simplu.

* Ma refer la prima varianta acum, dar este destul de valabil si pentru cea de a doua *

 

Deoarece este mult mai optim. Gandeste in felul asta, pe server sunt 100 de jucatori. 15 dintre ei fac jobul /fish, tie ti se pare ok ca la fiecare secunda sa se faca 100 de iteratii doar ca sa scada o secunda ? Avand in vedere ca sunt 30 de secunde ? In 30 de secunde avem 3000 de iteratii, de ce sa afectam optimizarea ? Facand un timer din exemplele mele aceasta problema nu ar mai exista. 

Edited by BuhaAdv

bcugZLK.png 

bwTYRvf.png

Link to comment
Share on other sites

  • Administrator

Declari o variabila globala:

new jobsDeelay[MAX_PLAYERS];

La OnPlayerConnect o initializezi cu gettime:

jobsDeelay[playerid] = gettime();

Si dupa o folosesti la jobul la care vrei sa pui deelay, la comanda [/fish] gen

YCMD:fish(playerid, params[], help)
{
    if(jobsDeelay[playerid] > gettime()) return SCM(playerid, -1, "Poti pescuii din nou peste 30 de secunde.");

    // alte verificare + codu tau 

    jobsDeelay[playerid] = gettime() + 30;

    return 1;
}

Ceva easy.

Link to comment
Share on other sites

Daca folosesti y_timers sau ai libraria YSI iti recomand sa faci in felul urmator, deoarece va fii mult mai optim decat daca ai folosi metodele traditionale:

#include <YSI\y_timers>

new Timer:PauzaPeste[ MAX_PLAYERS ],
	PotPrindeBoss[ MAX_PLAYERS ];

public OnPlayerConnect( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	return 1;
}

CMD:fish( playerid, params[ ] ){

	if( PotPrindeBoss[ playerid ] > 0 ){
		new info_text[ 56 ];
		format( info_text, sizeof info_text, "Poti prinde un alt peste peste %d secunde.", PotPrindeBoss[ playerid ] );
		SendClientMessage( playerid, -1, info_text );
		return 1;
	}
	/*
		bla...bla...bla ce ai tu pe aici

	*/
	PotPrindeBoss[ playerid ] = 30;
	PauzaPeste[ playerid ] = repeat CooldownPeste( playerid );
	return 1;
}

timer CooldownPeste[ 1000 ]( playerid ){
	PotPrindeBoss[ playerid ] --;
	if( PotPrindeBoss[ playerid ] == 0 ){
		stop PauzaPeste[ playerid ];
		SendClientMessage( playerid, -1, "Acum poti prinde un nou peste." );
	}
	return 1;
}

Dar daca nu o ai, poti incerca asta: 

new 
	PotPrindeBoss[ MAX_PLAYERS ];

public OnPlayerConnect( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	return 1;
}

CMD:fish( playerid, params[ ] ){

	if( PotPrindeBoss[ playerid ] == 1 )return SendClientMessage( playerid, -1, "Poti folosi comanda asta dupa 30 de secunde de la ultimul peste prins." );
	/*
		bla...bla...bla ce ai tu pe aici

	*/
	PotPrindeBoss[ playerid ] = 1;
	SetTimerEx( "CooldownPeste", 30000, false, "d", playerid );
	return 1;
}
forward CooldownPeste( playerid );
public CooldownPeste( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	SendClientMessage( playerid, -1, "Acum poti prinde un nou peste." );
	return 1;
}

Mentionez ca n-am compilat pe nici una dintre ele, daca ai vreo eroare/warning anunta-ma.

 

Am primit aceste erori : 

C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1670) : error 029: invalid expression, assumed zero
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1670) : error 001: expected token: ";", but found "{"
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : error 017: undefined symbol "PotPrindeBoss"
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : warning 215: expression has no effect
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : error 001: expected token: ";", but found "]"
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : error 029: invalid expression, assumed zero
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : fatal error 107: too many error messages on one line

Linia  :  

public OnPlayerConnect( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	return 1;
Link to comment
Share on other sites

 

Am primit aceste erori : 

C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1670) : error 029: invalid expression, assumed zero
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1670) : error 001: expected token: ";", but found "{"
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : error 017: undefined symbol "PotPrindeBoss"
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : warning 215: expression has no effect
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : error 001: expected token: ";", but found "]"
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : error 029: invalid expression, assumed zero
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : fatal error 107: too many error messages on one line

Linia  :  

public OnPlayerConnect( playerid ){
	PotPrindeBoss[ playerid ] = 0;
	return 1;

 

 

Ai declarat "PotPrindeBoss" ca fiind variabila globala ?

bcugZLK.png 

bwTYRvf.png

Link to comment
Share on other sites

L-am declarat acum , dar tot erorile astea primesc :

C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : error 029: invalid expression, assumed zeroC:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1671) : error 001: expected token: ";", but found "{"
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1672) : error 029: invalid expression, assumed zero
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1672) : warning 215: expression has no effect
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1672) : error 001: expected token: ";", but found "]"
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1672) : error 029: invalid expression, assumed zero
C:\Users\Dragut Mario\Desktop\burned.ro\gamemodes\gmm.pwn(1672) : fatal error 107: too many error messages on one line
Edited by TioO
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...