function returning value help +rep
#1

Hi I guys I made this stock function.....

pawn Код:
stock SendAdminMessage(color,text[])
{
    new File:file = fopen(Logs_AdmCmd,io_append),String[512],hour,mins,secs,year,month,day;
    gettime(hour,mins,secs);
    getdate(year,month,day);
    format(String,sizeof(String),"[%d/%d/%d][%d:%d:%d] %s \n",day,month,year,hour,mins,secs,text);
    fwrite(file,String);
    fclose(file);
    printf(String);
    foreach(Player,i)
    {
        if(GetP_VarInt(i,p_Adminlevel) > 0)
        {
            SendClientMessage(i,color,text);
        }
    }
}
And a command in which am using it:
pawn Код:
CMD:deleteplayervehicle(playerid,params[])
{
    new str[128],vehid;
    if(GetP_VarInt(playerid,p_Adminlevel) > 4)
    {
        if(IsPlayerInPlayersVehicle(playerid))
        {
            vehid = GetPlayerVehicleID(playerid);
            DestroyVehicle(vehid);
            format(str,sizeof(str),"AdminCMD: Admin %s have deleted a player vehicle(%s).",GetPlayerNameEx(playerid),GetVehicleName(vehid));
            SendAdminMessage(C_DARKRED2,str);
        }
    }
    return 1;
}
But The problem is this function is not working and server show "server unknown command."

If I used Like this it works :
pawn Код:
format(str,sizeof(str),"AdminCMD: Admin %s have deleted a player vehicle(%s).",GetPlayerNameEx(playerid),GetVehicleName(vehid));
            SendAdminMessage(C_DARKRED2,str);
DestroyVehicle(vehid);
and also works if i'll remove
pawn Код:
DestroyVehicle(vehid);
Reply
#2

Any one?
Reply
#3

What's your problem then? Simply use it in the way it works...
Reply
#4

I Just want to known the logic...
Reply
#5

It returns Uknown command because you destroyed the vehicle and then you sent the formatted message with
pawn Код:
GetVehicleName(vehid)
It can't get the name as the vehicle was already destroyed.
First format the message and send it with SendAdminMessage and then destroy the vehicle.
Reply
#6

But vehid is saved in integer right ??
Reply
#7

Yes, it stores the Vehicle ID, but for some reason it returns "SERVER: Unknown command." due to the vehicle id was destroyed.

Edit:
Although, don't use a value like 512 for only the date + text
pawn Код:
String[ 512 ]
128 is enough.
Reply
#8

Thanks +rep
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)