Convert strcmp to ZCMD and sscanfs
#1

Hey guys... I tried to convert these command strcmp in zcmd/sscanf2 but pawno return me some error (much, too many error!). So, it would be very kind in your part if you convert them for me... Here are the command:
Код:
if (strcmp(cmdtext, "/vehicles", true, 8) == 0)
	{
    if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
	#if !defined IGNORA_CANCELLAZIONE_VEICOLO
	MostraDialogoPredefinito( playerid );
	GetPlayerInterior(playerid);
	return 1;
	#endif
	}
    if ( GetPlayerState(playerid) != PLAYER_STATE_PASSENGER) MostraDialogoPredefinito(playerid);
    return 1;
	}


	new tmp[32];
	new cmd[256], idx;
	cmd = strtok(cmdtext, idx);
	//
    if(strcmp(cmd, "/v", true)==0)
    {
    tmp = strtok2(cmdtext, idx);
    if(!strlen(tmp) || strlen(tmp) > 32) {return SendClientMessage(playerid, ARANCIONE, "USE{FFFFFF}: {F2FF00}/v (namecar)"); }
    new veicolo;
    if(!IsNumeric(tmp)) { veicolo = GetVehicleModelIDFromName(tmp); } else { veicolo = strval(tmp); }
    if(veicolo > 611 || veicolo < 400) { return SendClientMessage(playerid, ARANCIONE, "{FF0000}ID {FFFFFF}or {FF0000}Name Vehicle {FFFFFF}Invalid"); }
    if(veicolo == 432) return SendClientMessage(playerid,0xFF0000FF,"You can't spawn Rhino!");
    if(CreaVeicolo[playerid] != -1) { DestroyVehicle(CreaVeicolo[playerid]); }
    new Float:pos[4];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerFacingAngle(playerid, pos[3]);
    CreaVeicolo[playerid] = CreateVehicle(veicolo, pos[0], pos[1], pos[2], pos[3], -1, -1, 50000);
    PutPlayerInVehicle(playerid, CreaVeicolo[playerid], 0);
    new Giocatori = GetMaxPlayers();
    for(new i; i < Giocatori; i++)
    {
    if(!IsPlayerConnected(i) || i == playerid) continue;
    SetVehicleParamsForPlayer(CreaVeicolo[playerid], i, 0, true);
    }
    new stringa[144];
    format(stringa, sizeof stringa, "{FFFFFF}[SYSTEM]: {0099FF}Vehicle: {FF9900}%s. {FFFFFF}Status: {5CD822}Spawned!", NomiVeicoli[veicolo-400]);
    SendClientMessage(playerid, BLU, stringa);
    return 1;
    }


    if(strcmp(cmd, "/goto", true) == 0)
    {
    new stringa[256];
    tmp = strtok2(cmdtext, idx);
    new utente = ReturnUser(tmp);
    if(!strlen(tmp))
    {
    SendClientMessage(playerid, 0xbbff0000 , "{FFF000}USE: {BBFF00}/goto {FFFFFF}(playerid)");
    return 1;
    }
    if(!IsPlayerConnected(utente)) return SendClientMessage(playerid, 0xFFFFFFF, "{FF0000}Player {FFFFFF}not connected!");
    if(utente == playerid) return SendClientMessage(playerid, 0xFFFFFFF, "{FF0000}You cannot {FFFFFF}/goto yourself!");
    new Float:x, Float:y, Float:z;
    new nome[MAX_PLAYER_NAME];
    GetPlayerName(utente, nome, sizeof(nome));
    GetPlayerPos(utente, x, y, z);
    SetPlayerPos(playerid, x, y, z+1);
    format(stringa, sizeof(stringa), "You have {BBFF00}teleported {FFF000}to {FFFFFF}%s(ID:%d)", nome, utente);
    SendClientMessage(playerid, 0xFFF000 , stringa);
    return 1;
    }
Thanks!
Reply
#2

Is it really so difficult? XD
Reply
#3

Show us what you've tried (including errors)
Reply
#4

Код:
CMD:goto(playerid, params[])
    {
    new stringa[256];
    tmp = strtok2(cmdtext, idx);
    new utente = ReturnUser(tmp);
    if(!strlen(tmp))
    {
    SendClientMessage(playerid, 0xbbff0000 , "{FFF000}USE: {BBFF00}/goto {FFFFFF}(playerid)");
    return 1;
    }
    if(!IsPlayerConnected(utente)) return SendClientMessage(playerid, 0xFFFFFFF, "{FF0000}Player {FFFFFF}not connected!");
    if(utente == playerid) return SendClientMessage(playerid, 0xFFFFFFF, "{FF0000}You cannot {FFFFFF}/goto yourself!");
    new Float:x, Float:y, Float:z;
    new nome[MAX_PLAYER_NAME];
    GetPlayerName(utente, nome, sizeof(nome));
    GetPlayerPos(utente, x, y, z);
    SetPlayerPos(playerid, x, y, z+1);
    format(stringa, sizeof(stringa), "You have {BBFF00}teleported {FFF000}to {FFFFFF}%s(ID:%d)", nome, utente);
    SendClientMessage(playerid, 0xFFF000 , stringa);
    return 1;
    }


	new tmp[32];
	new cmd[256], idx;
	cmd = strtok(cmdtext, idx);
	
	CMD:v(playerid, params[])
	tmp = strtok2(cmdtext, idx);
    if(!strlen(tmp) || strlen(tmp) > 32) {return SendClientMessage(playerid, ARANCIONE, "USE{FFFFFF}: {F2FF00}/v (namecar)"); }
    new veicolo;
    if(!IsNumeric(tmp)) { veicolo = GetVehicleModelIDFromName(tmp); } else { veicolo = strval(tmp); }
    if(veicolo > 611 || veicolo < 400) { return SendClientMessage(playerid, ARANCIONE, "{FF0000}ID {FFFFFF}or {FF0000}Name Vehicle {FFFFFF}Invalid"); }
    if(veicolo == 432) return SendClientMessage(playerid,0xFF0000FF,"You can't spawn Rhino!");
    if(CreaVeicolo[playerid] != -1) { DestroyVehicle(CreaVeicolo[playerid]); }
    new Float:pos[4];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerFacingAngle(playerid, pos[3]);
    CreaVeicolo[playerid] = CreateVehicle(veicolo, pos[0], pos[1], pos[2], pos[3], -1, -1, 50000);
    PutPlayerInVehicle(playerid, CreaVeicolo[playerid], 0);
    new Giocatori = GetMaxPlayers();
    for(new i; i < Giocatori; i++)
    {
    if(!IsPlayerConnected(i) || i == playerid) continue;
    SetVehicleParamsForPlayer(CreaVeicolo[playerid], i, 0, true);
    }
    new stringa[144];
    format(stringa, sizeof stringa, "{FFFFFF}[SYSTEM]: {0099FF}Vehicle: {FF9900}%s. {FFFFFF}Status: {5CD822}Spawned!", NomiVeicoli[veicolo-400]);
    SendClientMessage(playerid, BLU, stringa);
    return 1;
    }
	
        //////THIS WORK//////
	CMD:vehicles(playerid, params[])
	{
    if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
	#if !defined IGNORA_CANCELLAZIONE_VEICOLO
	MostraDialogoPredefinito( playerid );
	GetPlayerInterior(playerid);
	return 1;
	#endif
	}
    if ( GetPlayerState(playerid) != PLAYER_STATE_PASSENGER) MostraDialogoPredefinito(playerid);
    return 1;
	}
/Goto and /v don't work, when i compile, pawno crash with "Pawno stopped working"....
Reply
#5

Ok. When you are using strcmp, you are putting all of your functions inside OnPlayerCommandText. With ZCMD, they are standalone functions, and have to be outside of any other functions. Secondly, you don't have cmdtext variable anymore - it's called params now. Try fixing those simple things first, and we'll move on.
Reply
#6

I haven't put the function under OnPlayerCommandText, all the CMD is outside of any other functions. Lastly, I've changed cmdtext with params, don't work! Pawno crash!
Код:
CMD:goto(playerid, params[])
    {
    new stringa[256];
    tmp = strtok2(params, idx);
    new utente = ReturnUser(tmp);
    if(!strlen(tmp))
    {
    SendClientMessage(playerid, 0xbbff0000 , "{FFF000}USE: {BBFF00}/goto {FFFFFF}(playerid)");
    return 1;
    }
    if(!IsPlayerConnected(utente)) return SendClientMessage(playerid, 0xFFFFFFF, "{FF0000}Player {FFFFFF}not connected!");
    if(utente == playerid) return SendClientMessage(playerid, 0xFFFFFFF, "{FF0000}You cannot {FFFFFF}/goto yourself!");
    new Float:x, Float:y, Float:z;
    new nome[MAX_PLAYER_NAME];
    GetPlayerName(utente, nome, sizeof(nome));
    GetPlayerPos(utente, x, y, z);
    SetPlayerPos(playerid, x, y, z+1);
    format(stringa, sizeof(stringa), "You have {BBFF00}teleported {FFF000}to {FFFFFF}%s(ID:%d)", nome, utente);
    SendClientMessage(playerid, 0xFFF000 , stringa);
    return 1;
    }


	new tmp[32];
	new cmds[256], idx;
	cmds = strtok(params, idx);
	
	CMD:v(playerid, params[])
	tmp = strtok2(params, idx);
    if(!strlen(tmp) || strlen(tmp) > 32) {return SendClientMessage(playerid, ARANCIONE, "USE{FFFFFF}: {F2FF00}/v (namecar)"); }
    new veicolo;
    if(!IsNumeric(tmp)) { veicolo = GetVehicleModelIDFromName(tmp); } else { veicolo = strval(tmp); }
    if(veicolo > 611 || veicolo < 400) { return SendClientMessage(playerid, ARANCIONE, "{FF0000}ID {FFFFFF}or {FF0000}Name Vehicle {FFFFFF}Invalid"); }
    if(veicolo == 432) return SendClientMessage(playerid,0xFF0000FF,"You can't spawn Rhino!");
    if(CreaVeicolo[playerid] != -1) { DestroyVehicle(CreaVeicolo[playerid]); }
    new Float:pos[4];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerFacingAngle(playerid, pos[3]);
    CreaVeicolo[playerid] = CreateVehicle(veicolo, pos[0], pos[1], pos[2], pos[3], -1, -1, 50000);
    PutPlayerInVehicle(playerid, CreaVeicolo[playerid], 0);
    new Giocatori = GetMaxPlayers();
    for(new i; i < Giocatori; i++)
    {
    if(!IsPlayerConnected(i) || i == playerid) continue;
    SetVehicleParamsForPlayer(CreaVeicolo[playerid], i, 0, true);
    }
    new stringa[144];
    format(stringa, sizeof stringa, "{FFFFFF}[SYSTEM]: {0099FF}Vehicle: {FF9900}%s. {FFFFFF}Status: {5CD822}Spawned!", NomiVeicoli[veicolo-400]);
    SendClientMessage(playerid, BLU, stringa);
    return 1;
    }
	

	CMD:vehicles(playerid, params[])
	{
    if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
	#if !defined IGNORA_CANCELLAZIONE_VEICOLO
	MostraDialogoPredefinito( playerid );
	GetPlayerInterior(playerid);
	return 1;
	#endif
	}
    if ( GetPlayerState(playerid) != PLAYER_STATE_PASSENGER) MostraDialogoPredefinito(playerid);
    return 1;
	}
Reply
#7

An example:
pawn Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS 50 // CHANGE THIS TO WHAT YOUR SERVER.CFG HAS AS MAXPLAYERS

CMD:vehicles( playerid, params[ ] )
{
    if( GetPlayerState( playerid ) == PLAYER_STATE_DRIVER )
    {
        #if !defined IGNORA_CANCELLAZIONE_VEICOLO
        MostraDialogoPredefinito( playerid );
        GetPlayerInterior( playerid );
        return 1;
        #endif
    }
    if( GetPlayerState( playerid ) != PLAYER_STATE_PASSENGER ) MostraDialogoPredefinito( playerid );
    return 1;
}


CMD:v( playerid, params[ ] )
{
    new
        carname[ 32 ]
    ;
    if( sscanf( params, "s[32]", carname ) ) return SendClientMessage( playerid, ARANCIONE, "USE{FFFFFF}: {F2FF00}/v (namecar)" );
    new
        veicolo
    ;
    if( !IsNumeric( carname ) ) veicolo = GetVehicleModelIDFromName( carname );
    else veicolo = strval( carname );
   
    if( veicolo > 611 || veicolo < 400 ) return SendClientMessage( playerid, ARANCIONE, "{FF0000}ID {FFFFFF}or {FF0000}Name Vehicle {FFFFFF}Invalid" );
    if( veicolo == 432 ) return SendClientMessage( playerid, 0xFF0000FF,"You can't spawn Rhino!" );
    if( CreaVeicolo[ playerid ] != -1 ) DestroyVehicle( CreaVeicolo[ playerid ] );
    new
        Float: pos[ 4 ]
    ;
    GetPlayerPos( playerid, pos[ 0 ], pos[ 1 ], pos[ 2 ] );
    GetPlayerFacingAngle( playerid, pos[ 3 ] );
    CreaVeicolo[ playerid ] = CreateVehicle( veicolo, pos[ 0 ], pos[ 1 ], pos[ 2 ], pos[ 3 ], -1, -1, 50000 );
    PutPlayerInVehicle( playerid, CreaVeicolo[ playerid ], 0 );

    for( new i; i < MAX_PLAYERS; i++ )
    {
        if( !IsPlayerConnected( i ) || i == playerid ) continue;
        SetVehicleParamsForPlayer( CreaVeicolo[ playerid ], i, 0, true );
    }
    new
        stringa[ 128 ]
    ;
    format( stringa, sizeof( stringa ), "{FFFFFF}[SYSTEM]: {0099FF}Vehicle: {FF9900}%s. {FFFFFF}Status: {5CD822}Spawned!", NomiVeicoli[ veicolo - 400 ] );
    SendClientMessage( playerid, BLU, stringa );
    return 1;
}


CMD:goto( playerid, params[ ] )
{
    new
        utente
    ;
    if( sscanf( params, "r", utente ) ) return SendClientMessage( playerid, 0xbbff0000 , "{FFF000}USE: {BBFF00}/goto {FFFFFF}(playerid)" );
    if( !IsPlayerConnected( utente ) ) return SendClientMessage( playerid, 0xFFFFFFF, "{FF0000}Player {FFFFFF}not connected!" );
    if( utente == playerid ) return SendClientMessage( playerid, 0xFFFFFFF, "{FF0000}You cannot {FFFFFF}/goto yourself!" );

    new
        Float: x,
        Float: y,
        Float: z,
        nome[MAX_PLAYER_NAME],
        stringa[ 128 ]
    ;
    GetPlayerName( utente, nome, sizeof( nome ) );
    GetPlayerPos( utente, x, y, z );
    SetPlayerPos( playerid, x, y, z + 1 );
    format( stringa, sizeof( stringa ), "You have {BBFF00}teleported {FFF000}to {FFFFFF}%s(ID:%d)", nome, utente );
    SendClientMessage( playerid, 0xFFF000 , stringa );
    return 1;
}
Reply
#8

Thank you Konstantinos, its work!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)