SA-MP Forums Archive
How to make it with ZCMD & sscanf? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to make it with ZCMD & sscanf? (/showthread.php?tid=305917)



How to make it with ZCMD & sscanf? - Spooky - 24.12.2011

How to make a Command for vehicles with ZCMD and sscanf
pawn Код:
/veh [modelid/name]



Re: How to make it with ZCMD & sscanf? - Ash. - 24.12.2011

You'll need to declare the command. The use of sscanf here is pointless, as you already have the 'params' parameter given by ZCMD.

pawn Код:
CMD:veh(playerid, params[])
{
     if(!strlen(params)) return SendClientMessage(playerid, COLOUR_RED, "Error. Usage: /veh [modelid]"); //Check if the parameter exists.
     if(strval(params) > 611 || strval(params) < 400) return SendClientMessage(playerid, COLOUR_RED, "Error. Models are between 400 and 611."); //Check if it's between 400 and 611.
     new Float:x, Float:y, Float:z; //Declare position variables.
     GetPlayerPos(playerid, x, y, z); //Get the players position, the vehicle will spawn in this position.
     PutPlayerInVehicle(playerid, CreateVehicle(strval(params), x, y, z, 0.0, -1, -1, -1), 0); //Create the vehicle, put the player in it as the driver.
     return 1; //Tell the server the command executed succesfully.
}
I've given you the code because it's a good example of where you DON'T need sscanf. I hope you can see why now.


Re: How to make it with ZCMD & sscanf? - StreetGT - 24.12.2011

maybe you want something like this

pawn Код:
CMD:veh(playerid,params[])
{
    new id,cor,cor1;
    if(sscanf(params, "ddd", id, cor,cor1))  SendClientMessage(playerid,-1, ,"USO: /veh [model] [color1] [color2]");
    else if (id < 400 || id > 611)  SendClientMessage(playerid,-1, "Between 400 and 611");
    else if (cor < 0 || cor1 > 126) SendClientMessage(playerid,-1, "Color between 0 and 126");
    else
    {
        if(IsPlayerAdmin(playerid))
        {
            new Float:X,Float:Y,Float:Z;
            GetPlayerPos(playerid, X,Y,Z);
            CreateVehicle(id,X+2,Y,Z,0.0,cor,cor1,-1);
        }
    }
    return 1;
}



Re: How to make it with ZCMD & sscanf? - Spooky - 24.12.2011

Nop i need the vehicle with name also and with sscanf


Re: How to make it with ZCMD & sscanf? - Ash. - 24.12.2011

It hardly needs sscanf, there's only one parameter - I did it without sscanf, here: http://pastebin.com/QTeTrh6u


Re: How to make it with ZCMD & sscanf? - Spooky - 24.12.2011

pawn Код:
E:\SA-MP\SA-MP SERVERS\My Projects\0.3d\DM,STUNT,RACE\Live Stunting(ENG) [DM,STUNT,RACE,DERBY]\gamemodes\1.0.pwn(1775) : warning 211: possibly unintended assignment
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Warning.


EDIT: Fixed by myself.


Re: How to make it with ZCMD & sscanf? - Spooky - 24.12.2011

pawn Код:
CMD:v(playerid, params[])
{
    if(IsInDm[playerid] == 1)
    {
        SendClientMessage(playerid, ERROR,"You cannot spawn vehicles until you are in a Deathmatch. Type /leavedm to leave deathmatch.");
    }
    else if(IsInDerby[playerid] == 1)
    {
        SendClientMessage(playerid, ERROR,"You cannot spawn vehicles until you are in a Derby. Type /leavederby to leave derby.");
    }
    else if(IsInRace[playerid] == 1)
    {
        SendClientMessage(playerid, ERROR,"You cannot spawn vehicles until you are in a Race. Type /leaverace to leave race.");
    }
    else if(IsInParkour[playerid] == 1)
    {
        SendClientMessage(playerid, ERROR,"You cannot spawn vehicles until you are in a Parkour. Type /leaveparkour to leave parkour.");
    }
    else if(IsInDrift[playerid] == 1)
    {
        SendClientMessage(playerid, ERROR,"You cannot spawn vehicles until you are in a Drift. Type /leavedrift to leave .");
    }
    else
    {
        if(!strlen(params)) return SendClientMessage(playerid, ERROR, "Usage: /veh [Name/Modelid]");
        new iModel = 0;
        if(!IsNumeric(params))
        {
            for(new i; i < sizeof(vNames); i++)
            {
                        if(!strcmp(params, vNames[i]))
                        {
                                iModel = i;
                                break;
                        }
            }
            if(iModel == 0) return SendClientMessage(playerid, ERROR, "Invalid Vehicle.");
        }
        else iModel = strval(params);

        if(iModel > 611 || iModel < 400) return SendClientMessage(playerid, ERROR, "Vehicle models are between 400 and 611.");
        new Float:x, Float:y, Float:z;
        GetPlayerPos(playerid, x, y, z);
        PutPlayerInVehicle(playerid, CreateVehicle(iModel, x, y, z, 0.0, -1, -1, -1), 0);
    }
    return 1;
}
Its not working in game just giving a message "Invalid Vehicle."


Re: How to make it with ZCMD & sscanf? - coole210 - 24.12.2011

Change

Код:
iModel = i;
To

Код:
iModel = i+400;



Re: How to make it with ZCMD & sscanf? - Spooky - 24.12.2011

No it is not working and also i am not able to spawn a vehicle with names like /v land


Re: How to make it with ZCMD & sscanf? - coole210 - 24.12.2011

Don't use strcmp, to compare strings, use strfind to find a string in the vNames (Right now you have to type for example /v Hydra for it to work)