SA-MP Forums Archive
Making a variable with tmp - 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: Making a variable with tmp (/showthread.php?tid=414036)



Making a variable with tmp - jakejohnsonusa - 07.02.2013

How can I make a variable that sets the result of tmp (or what the player enters after the command)?

I want "tmp" / what the player enters after the command, to be the variable "VehID". See bellow code for what I need help with.

pawn Код:
if (strcmp(cmd, "/breaklock", true) == 0)
    {
        if(PlayerInfo[playerid][pJob] == 5)// Job 5 is Car Jacker Job
        {
            tmp = strtok(cmdtext,idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid,COLOR_GRAD1,"USAGE: /breaklock [Vehicle ID]");
                return 1;
            }
            new VehID = tmp;// This doesn't work :(
            new Float:X, Float:Y, Float:Z;
            GetVehiclePos(VehID, X, Y, Z);
            if(IsPlayerInRangeOfPoint(playerid, 20.0, X, Y, Z))
            {
                if(IsAnOwnableCar(VehID))
                {
                    if (CarInfo[VehID][cLock] == 1)
                    {
                        CarInfo[VehID][cLock] = 0;
                        PutPlayerInVehicle(playerid, VehID, 0);
                        format(string, sizeof(string), "Vehicle ID Entered: %s", VehID);
                        SendClientMessage(playerid,COLOR_GRAD2,string);
                    }
                }
            }



Re: Making a variable with tmp - Misiur - 07.02.2013

https://sampwiki.blast.hk/wiki/strval


Re: Making a variable with tmp - jakejohnsonusa - 07.02.2013

Still a bit confused, can you explain how to do it? Sorry I'm fairly new to scripting.

And +1 Rep for the help so far


Re: Making a variable with tmp - zDevon - 07.02.2013

Well first off you should use sscanf for handling commands with extra parameters: https://sampforum.blast.hk/showthread.php?tid=120356.

Example using sscanf with OnPlayerCommandText:
pawn Код:
if(!strcmp(cmdtext, "/hi", true, 3))
{
    new otherplayerid;
    if(sscanf(cmdtext[6], "i", otherplayerid)) return SendClientMessage(playerid,-1,"Usage: /hi [player id]");
    else {
        SendClientMessage(otherplayerid,-1,"Hello!");
    }
    return 1;
}
This would send message 'Hello!' to the specified player id, or return an error message if no ID was entered.

That example can be altered to become any command with 1 integer as a parameter (commands with other player ids, a vehicle id, etc). Just change the length in the strcmp line to the command length and the length in the sscanf line to the command length+1.

And once you get your command worked out you don't need to assign 'tmp' to VehID as you're doing now, you could just use this instead:
pawn Код:
GetVehiclePos(tmp, X, Y, Z);



Respuesta: Making a variable with tmp - kirk - 07.02.2013

Why dont you just use "tmp" instead of "VehID"? switch all the VehID with tmp's and it will work the same.

If you wanna copy them, you cant copy two strings stright away, you need to copy them cell by cell, and if you just want to get the integer value of a string use that function strval(string).

pawn Код:
VehID = strval(tmp);