Jump to content

Strtok in ZCMD


vampir_MD

Recommended Posts

[glow=black,2,300]Cum sa faci sa-ti mearga Strtok in ZCMD[/glow]

Aici este comands /pm va voi explica cum sa il faceti pentru ZCMD

Sa incepem

Asa arata comando in cmdtext

if(strcmp("/pm", cmd, true) == 0)
	{
		new idx,id;
	        new tmp[256];
		new gMessage[256];
		new pName[MAX_PLAYER_NAME+1];
		new Message[256];
		new iName[MAX_PLAYER_NAME+1];
                tmp = strtok(cmdtext,idx);
		if(!strlen(tmp) || strlen(tmp) > 5) {
			SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)");
			return 1;
		}
        gMessage = strrest(cmdtext,idx);

		if(!strlen(gMessage)) {
			SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)");
			return 1;
		}

		if(!IsPlayerConnected(id)) {
			SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/pm : Bad player ID");
			return 1;
		}
		if(playerid != id) {
			GetPlayerName(id,iName,sizeof(iName));
			GetPlayerName(playerid,pName,sizeof(pName));
			format(Message,sizeof(Message),">> %s(%d): %s",iName,id,gMessage);
			SendClientMessage(playerid,PM_OUTGOING_COLOR,Message);
			format(Message,sizeof(Message),"** %s(%d): %s",pName,playerid,gMessage);
			SendClientMessage(id,PM_INCOMING_COLOR,Message);
			PlayerPlaySound(id,1085,0.0,0.0,0.0);

			printf("PM: %s",Message);

		}
		else {
			SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"You cannot PM yourself");
		}
		return 1;
    }
Acum sa incepem sal facem pentru ZCMD COMMAND:pm(playerid,params[]) Il punem cum trebuie sa fie pentru ZCMD eu am pus COMMAND da poti sa pui CMD:pm mai prescurtat {       new idx,id;   new tmp[256]; new gMessage[256]; new pName[MAX_PLAYER_NAME+1]; new Message[256]; new iName[MAX_PLAYER_NAME+1]; tmp = strtok(params,idx); Aici cum vedeti damu nu se mai pune cmdtext punem doar params   if(!strlen(tmp) || strlen(tmp) > 5) { SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)"); return 1; }             gMessage = strrest(params,idx); Aici la fel se pune params nu cmdtext if(!strlen(gMessage)) { SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)"); return 1; } if(!IsPlayerConnected(id)) { SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/pm : Bad player ID"); return 1; } if(playerid != id) { GetPlayerName(id,iName,sizeof(iName)); GetPlayerName(playerid,pName,sizeof(pName)); format(Message,sizeof(Message),">> %s(%d): %s",iName,id,gMessage); SendClientMessage(playerid,PM_OUTGOING_COLOR,Message); format(Message,sizeof(Message),"** %s(%d): %s",pName,playerid,gMessage); SendClientMessage(id,PM_INCOMING_COLOR,Message); PlayerPlaySound(id,1085,0.0,0.0,0.0); printf("PM: %s",Message); } else { SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"You cannot PM yourself"); } return 1;     } Gata am terminat e foarte usor Aici comando Complet
COMMAND:pm(playerid,params[])
	{
                new idx,id;
	        new tmp[256];
		new gMessage[256];
		new pName[MAX_PLAYER_NAME+1];
		new Message[256];
		new iName[MAX_PLAYER_NAME+1];
		tmp = strtok(params,idx);
		if(!strlen(tmp) || strlen(tmp) > 5) {
			SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)");
			return 1;
		}
               gMessage = strrest(params,idx);

		if(!strlen(gMessage)) {
			SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /pm (id) (message)");
			return 1;
		}

		if(!IsPlayerConnected(id)) {
			SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/pm : Bad player ID");
			return 1;
		}
		if(playerid != id) {
			GetPlayerName(id,iName,sizeof(iName));
			GetPlayerName(playerid,pName,sizeof(pName));
			format(Message,sizeof(Message),">> %s(%d): %s",iName,id,gMessage);
			SendClientMessage(playerid,PM_OUTGOING_COLOR,Message);
			format(Message,sizeof(Message),"** %s(%d): %s",pName,playerid,gMessage);
			SendClientMessage(id,PM_INCOMING_COLOR,Message);
			PlayerPlaySound(id,1085,0.0,0.0,0.0);

			printf("PM: %s",Message);

		}
		else {
			SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"You cannot PM yourself");
		}
		return 1;
    }

Daca sunt ceva nelamuriri spuneti si voi da edit

Link to comment
Share on other sites

Doar ai inlocuit cmdtext cu params ... mai bine cu ZCMD + sscanf si e MULT mai simplu:

CMD:pm( playerid, params[ ] )
{
	new gMessage[ 128 ], Message[ 128 ];
	new pName[MAX_PLAYER_NAME], iName[ MAX_PLAYER_NAME ];

	if( sscanf( params, "us[128]", params[ 0 ], params[ 1 ] ) ) return SendClientMessage( playerid, ADMINFS_MESSAGE_COLOR, "Usage: /pm (id) (message)" );

	if( !IsPlayerConnected( params[ 0 ] ) ) return SendClientMessage( playerid,ADMINFS_MESSAGE_COLOR,"/pm : Bad player ID" );
	if( playerid == params[ 0 ] ) return SendClientMessage( playerid,ADMINFS_MESSAGE_COLOR,"You cannot PM yourself" );

	GetPlayerName( params[ 0 ], iName, MAX_PLAYER_NAME );
	GetPlayerName( playerid, pName, MAX_PLAYER_NAME );
	format( Message, 128,">> %s(%d): %s", iName, params[ 0 ], gMessage );
	SendClientMessage( playerid, PM_OUTGOING_COLOR, Message );
	format( Message, 128,"** %s(%d): %s", pName, playerid, gMessage );
	SendClientMessage( params[ 0 ], PM_INCOMING_COLOR, Message );
	PlayerPlaySound( params[ 0 ], 1085, 0.0, 0.0, 0.0 );
	return 1;
}

I-am facut si cateva modificari.

Link to comment
Share on other sites

stuntman-=!!" post="78292" timestamp="1308504296"]

Doar ai inlocuit cmdtext cu params ... mai bine cu ZCMD + sscanf si e MULT mai simplu:

CMD:pm( playerid, params[ ] )
{
	new gMessage[ 128 ], Message[ 128 ];
	new pName[MAX_PLAYER_NAME], iName[ MAX_PLAYER_NAME ];

	if( sscanf( params, "us[128]", params[ 0 ], params[ 1 ] ) ) return SendClientMessage( playerid, ADMINFS_MESSAGE_COLOR, "Usage: /pm (id) (message)" );

	if( !IsPlayerConnected( params[ 0 ] ) ) return SendClientMessage( playerid,ADMINFS_MESSAGE_COLOR,"/pm : Bad player ID" );
	if( playerid == params[ 0 ] ) return SendClientMessage( playerid,ADMINFS_MESSAGE_COLOR,"You cannot PM yourself" );

	GetPlayerName( params[ 0 ], iName, MAX_PLAYER_NAME );
	GetPlayerName( playerid, pName, MAX_PLAYER_NAME );
	format( Message, 128,">> %s(%d): %s", iName, params[ 0 ], gMessage );
	SendClientMessage( playerid, PM_OUTGOING_COLOR, Message );
	format( Message, 128,"** %s(%d): %s", pName, playerid, gMessage );
	SendClientMessage( params[ 0 ], PM_INCOMING_COLOR, Message );
	PlayerPlaySound( params[ 0 ], 1085, 0.0, 0.0, 0.0 );
	return 1;
}

I-am facut si cateva modificari.

Da cineva asta nu situ si ii vine mai usor sa schimbe cmdtext cu params

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

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

Guest
Reply to this topic...

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

  • Similar Content

    • By CristianLMAO
      Salut!
      Astazi o sa va prezint primul meu sistem pus pe acest site, si o sa va explic ce face fiecare lucru.
      Hai sa incepem.
      Sistemul arata cam asa:

      (dialogul este pozitionat mai in drapta din cauza rezolutiei mele)
      IMPORTANT:
      IN CODUL DE MAI JOS ESTE DECAT CE MAI TREBUIE ADAUGAT, NU TOT GAMEMODUL!!
      TUTORIAL:
       
      //punem include-urile care ne trebuie la acest sistem #include <zcmd>  
      //prima data facem o comanda, dar atentie, ACEASTA COMANDA O POATE FOLOSI ORICINE, daca doriti ca doar admini sa o poata folosi, folositi comanda hasurata! CMD:v(playerid, params[]){ ShowPlayerDialog(playerid, 4, DIALOG_STYLE_INPUT, "Spawn car", "Write your car id: (Min. 400 / Max. 611)", "Spawn", "Close"); //cand scriem "/v" apare acest dialog return 1; } //DACA DORITI SA FIE COMANDA ASTA ACCESIBILA DOAR LA ADMIN: //CMD:v(playerid, params[]){ // // if (IsPlayerAdmin(playerid)) // daca jucatorul este admin: // { // ShowPlayerDialog(playerid, 4, DIALOG_STYLE_INPUT, "Spawn car", "Write your car id: (Min. 400 / Max. 611)", "Spawn", "Close"); //cand scriem "/v" apare acest dialog // } // else{ //daca nu: // SendClientMessage(playerid, 0xFF000090, "You're not admin!"); // } // return 1; //}  
      public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){ if(dialogid == 1){ // cand raspunde la dialogul cu id-ul 1 se intampla asta: if(!response) return SendClientMessage(playerid, 0xFF000099, "You closed the menu!"); // daca apasa pe butonul de inchidere, acest meniu o sa se inchida. if(strval(inputtext) < 400) return SendClientMessage(playerid, 0xFF000099, "Your car id is under 400!"); // Daca id-ul scris este mai mic de 400 o sa scrie asta if(strval(inputtext) > 611) return SendClientMessage(playerid, 0xFF000099, "Your car id is over 611!"); // Daca id-ul scris este mai mare de 611 o sa scrie asta // inputtext inseamna ce a scris jucatorul in text-box. new Float:X; new Float:Y; new Float:Z; GetPlayerPos(playerid,X,Y,Z); // aici seteaza valoarea lui X, Y si Z in coordonatele juactorului CreateVehicle(strval(inputtext),X,Y+5,Z,1,1,1,90000); //spawneaza masina cu id-ul din textbox, la coordonatele playerului return 1; } }  
      Daca este sa fi omis ceva, sau daca doriti sa imbunatatesc acest sistem, puteti spune in comentarii.
    • By Shad0wdpbgd
      Salut. Am zcmd-ul bagat in pawno -> include si degeaba... tot nu merge. am pus si in pawno #include <zcmd>, si imi zice "D:\Downloads\samp037_svr_R2-1-1_win32\gamemodes\Untitled.pwn(6) : fatal error 100: cannot read from file: "zcmd" si nu stiu ce are. Help plsss
    • By Sebi wepos
      Cum adaug si eu zcmd in gamemode meu?
      adk stiu sa pun in include zcmd 
      dar nush cum sa pun include si alea sa mearga ca daca fac cum cred eu ca e imi da o eroare 
    • By kerasseN
      Vreau sa ma invatati si pe mine cum pot sa fac ca atunci cand intra un jucator sa ii dea un mesaj
       
      %s Bine ai venit pe server.
       
      de fiecare data cand intra pe server sa ii afiseze acest mesaj
    • By TheDarky1
      Am o problema, vreau sa ma apuc si eu de scriptat si nu gasesc deloc pe net zcmd.inc, daca poate cineva sa ma ajute.
      si in celalte inc tot am probleme de ex cum incerc sa bag #include <streamer> imi da fatal error 100. 
      daca cineva ar avea niste timp liber sa imi explice, raman recunoscator 

      Pentru a ma contacta: TheDark#8944 ---> discord
  • Recently Browsing   0 members

    No registered users viewing this page.

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