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.

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