Making a variable with tmp
#1

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);
                    }
                }
            }
Reply
#2

https://sampwiki.blast.hk/wiki/strval
Reply
#3

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
Reply
#4

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);
Reply
#5

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);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)