Command only for Admin
#1

Hi , i wanna make this command only for Admins :
Can anyone help ? [ +rep ]
pawn Код:
if(strcmp(cmd, "/car", true, 10) == 0)
    {

        new String[200];
        new tmp[256];
        new Float:x, Float:y, Float:z;

        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, l_red, "You diden't give a vehicle name");

        new vehicle = GetVehicleModelIDFromName(tmp);

        if(vehicle < 400 || vehicle > 611) return SendClientMessage(playerid, l_red, "That vehicle name was not found");

        new Float:a;
        GetPlayerFacingAngle(playerid, a);
        GetPlayerPos(playerid, x, y, z);

        if(IsPlayerInAnyVehicle(playerid) == 1)
        {
            GetXYInFrontOfPlayer(playerid, x, y, 8);
        }
        else
        {
            GetXYInFrontOfPlayer(playerid, x, y, 5);
        }

        new PlayersVehicle = CreateVehicle(vehicle, x, y, z, a+90, -1, -1, -1);
        LinkVehicleToInterior(PlayersVehicle, GetPlayerInterior(playerid));

        format(String, sizeof(String), "You have spawned a %s", aVehicleNames[vehicle - 400]);
        SendClientMessage(playerid, l_green, String);
        return 1;
    }
    return 0;
}

strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}

GetVehicleModelIDFromName(vname[])
{
    for(new i = 0; i < 211; i++)
    {
        if(strfind(aVehicleNames[i], vname, true) != -1)
        return i + 400;
    }
    return -1;
}

stock GetXYInFrontOfPlayer(playerid, &Float:x2, &Float:y2, Float:distance)
{
    new Float:a;

    GetPlayerPos(playerid, x2, y2, a);
    GetPlayerFacingAngle(playerid, a);

    if(GetPlayerVehicleID(playerid))
    {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }

    x2 += (distance * floatsin(-a, degrees));
    y2 += (distance * floatcos(-a, degrees));
}
Reply
#2

Next time use [pawn] tags not [pawno]
Simply check if the player is an admin or not.
Reply
#3

I dont think you're blind.. theese are [pawn] tags
Reply
#4

try
pawn Код:
if(strcmp(cmd, "/car", true, 10) == 0)
    {

        new String[200];
        new tmp[256];
        new Float:x, Float:y, Float:z;
        if(IsPlayerAdmin(playerid))
        {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) return SendClientMessage(playerid, l_red, "You diden't give a vehicle name");

        new vehicle = GetVehicleModelIDFromName(tmp);

        if(vehicle < 400 || vehicle > 611) return SendClientMessage(playerid, l_red, "That vehicle name was not found");

        new Float:a;
        GetPlayerFacingAngle(playerid, a);
        GetPlayerPos(playerid, x, y, z);

        if(IsPlayerInAnyVehicle(playerid) == 1)
        {
            GetXYInFrontOfPlayer(playerid, x, y, 8);
        }
        else
        {
            GetXYInFrontOfPlayer(playerid, x, y, 5);
        }

        new PlayersVehicle = CreateVehicle(vehicle, x, y, z, a+90, -1, -1, -1);
        LinkVehicleToInterior(PlayersVehicle, GetPlayerInterior(playerid));

        format(String, sizeof(String), "You have spawned a %s", aVehicleNames[vehicle - 400]);
        SendClientMessage(playerid, l_green, String);
        return 1;
        }
    }
    return 0;
}
Not sure if that will work but IsPlayerAdmin = Rcon Admin.
Reply
#5

I tried as you said and its giving me 8 Errors :
pawn Код:
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(245) : error 017: undefined symbol "strtok"
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(245) : error 033: array must be indexed (variable "cmd")
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(255) : error 017: undefined symbol "strtok"
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(255) : error 033: array must be indexed (variable "tmp")
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(258) : error 017: undefined symbol "GetVehicleModelIDFromName"
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(268) : error 017: undefined symbol "GetXYInFrontOfPlayer"
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(272) : error 017: undefined symbol "GetXYInFrontOfPlayer"
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(282) : error 030: compound statement not closed at the end of file (started at line 250)
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


8 Errors.
Reply
#6

Quote:
Originally Posted by yLuSsSIoN
Посмотреть сообщение
I tried as you said and its giving me 8 Errors :
pawn Код:
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(245) : error 017: undefined symbol "strtok"
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(245) : error 033: array must be indexed (variable "cmd")
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(255) : error 017: undefined symbol "strtok"
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(255) : error 033: array must be indexed (variable "tmp")
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(258) : error 017: undefined symbol "GetVehicleModelIDFromName"
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(268) : error 017: undefined symbol "GetXYInFrontOfPlayer"
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(272) : error 017: undefined symbol "GetXYInFrontOfPlayer"
C:\Users\User\Desktop\Downloads\filehost_SkyZone-GF\pronion\filterscripts\veh.pwn(282) : error 030: compound statement not closed at the end of file (started at line 250)
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


8 Errors.
Add this after it:

pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}

GetVehicleModelIDFromName(vname[])
{
    for(new i = 0; i < 211; i++)
    {
        if(strfind(aVehicleNames[i], vname, true) != -1)
        return i + 400;
    }
    return -1;
}

stock GetXYInFrontOfPlayer(playerid, &Float:x2, &Float:y2, Float:distance)
{
    new Float:a;

    GetPlayerPos(playerid, x2, y2, a);
    GetPlayerFacingAngle(playerid, a);

    if(GetPlayerVehicleID(playerid))
    {
        GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
    }

    x2 += (distance * floatsin(-a, degrees));
    y2 += (distance * floatcos(-a, degrees));
}
Reply
#7

Remove the } under return 1; and put it above return 1;?
Reply
#8

Thank you both, it worked , + rep
1 more thing , can I add that in gamemode ?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)