Unknown Command ??!
#1

I made this command but when i use it it give me unknown command
PHP код:
CMD:createobject(playeridparams[])
{
    new 
objectid;
    new 
Float:xFloat:yFloat:z;
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1"You have to be Rcon Admin");
    if(
sscanf(params"u"objectid)) return SendClientMessage(playerid, -1"Usage: /crateobject (Object ID)");
    new 
pos GetPlayerPos(playeridxyz);
    
CreateObject(objectidx+2yz,  0.00.096.0);
    new 
Float:XFloat:YFloat:Z;
    
GetObjectPos(XYZ);
    new 
Float:bFloat:cFloat:d;
    
GetObjectRot(bcd);
    new 
INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File,"Object");
    
INI_WriteInt(File,"Object ID",objectid);
    
INI_WriteInt(File,"XPos",X);
    
INI_WriteInt(File,"YPos",Y);
    
INI_WriteInt(File,"ZPos",Z);
    
INI_WriteInt(File,"XRot",b);
    
INI_WriteInt(File,"YRot",c);
    
INI_WriteInt(File,"ZRot",d);
    
INI_Close(File);
    
SendClientMessage(playerid, -1"Object created");
    return 
1;

Please Help !!
Reply
#2

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
I made this command but when i use it it give me unknown command
PHP код:
CMD:createobject(playeridparams[])
{
    new 
objectid;
    new 
Float:xFloat:yFloat:z;
    if(!
IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1"You have to be Rcon Admin");
    if(
sscanf(params"u"objectid)) return SendClientMessage(playerid, -1"Usage: /crateobject (Object ID)");
    new 
pos GetPlayerPos(playeridxyz);
    
CreateObject(objectidx+2yz,  0.00.096.0);
    new 
Float:XFloat:YFloat:Z;
    
GetObjectPos(XYZ);
    new 
Float:bFloat:cFloat:d;
    
GetObjectRot(bcd);
    new 
INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File,"Object");
    
INI_WriteInt(File,"Object ID",objectid);
    
INI_WriteInt(File,"XPos",X);
    
INI_WriteInt(File,"YPos",Y);
    
INI_WriteInt(File,"ZPos",Z);
    
INI_WriteInt(File,"XRot",b);
    
INI_WriteInt(File,"YRot",c);
    
INI_WriteInt(File,"ZRot",d);
    
INI_Close(File);
    
SendClientMessage(playerid, -1"Object created");
    return 
1;

Please Help !!
the identifier you declared for the file handler to be stored in is a tag.
identifiers may not be the same as keywords/tags or start with numbers or operators
just change "File" to "h" or something else

example for basic file I/O in pawn
Quote:
Originally Posted by wikisamp
pawn Код:
// Open "file.txt" in "write only" mode
new File:handle = fopen("file.txt", io_write);
 
// Check, if file is open
if(handle)
{
    // Success
 
    // Write "I just wrote here!" into this file
    fwrite(handle, "I just wrote here!");
 
    // Close the file
    fclose(handle);
}
else
{
    // Error
    print("Failed to open file \"file.txt\".");
}
Reply
#3

What i should write instead of these
PHP код:
file.txt", io_write 
Reply
#4

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
What i should write instead of these
PHP код:
file.txt", io_write 
no.
you misunderstood.

variable names may not be the same as tags/keywords used by the compiler (like "case", "break", "File" and so on)

like said before, just change it.
you're using "File" as identifier but File is also at the same time a Tag.
so how could the compiler know what you meant there.
it can't, so it skips the code, nothing gets returned resulting in "Unknown command"
even though it's actually there. But couldn't return a value to prove its existence
Reply
#5

But here i want to create a new file not read or write only.
I am sorry if i didn't understand you !
Reply
#6

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
But here i want to create a new file not read or write only.
I am sorry if i didn't understand you !
look, all you need to do is change "File" to something else.
you can't use "File" as identifier as it's already a tag (side note, it's a strong tag cuz it's starting with a capital letter)

see, ill do it for you...
pawn Код:
CMD:createobject(playerid, params[])
{
    new objectid;
    new Float:x, Float:y, Float:z;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You have to be Rcon Admin");
    if(sscanf(params, "u", objectid)) return SendClientMessage(playerid, -1, "Usage: /crateobject (Object ID)");
    new pos = GetPlayerPos(playerid, x, y, z);
    CreateObject(objectid, x+2, y, z,  0.0, 0.0, 96.0);
    new Float:X, Float:Y, Float:Z;
    GetObjectPos(X, Y, Z);
    new Float:b, Float:c, Float:d;
    GetObjectRot(b, c, d);
    new INI:fh = INI_Open(UserPath(playerid));
    INI_SetTag(fh,"Object");
    INI_WriteInt(fh,"Object ID",objectid);
    INI_WriteInt(fh,"XPos",X);
    INI_WriteInt(fh,"YPos",Y);
    INI_WriteInt(fh,"ZPos",Z);
    INI_WriteInt(fh,"XRot",b);
    INI_WriteInt(fh,"YRot",c);
    INI_WriteInt(fh,"ZRot",d);
    INI_Close(fh);
    SendClientMessage(playerid, -1, "Object created");
    return 1;
}
i called it "fh" which is a synonym for "file handler"
i myself usually just call them "h" but that doesn't matter.
Reply
#7

Ooh this is all the problem.....!
Thank you man
Reply
#8

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
Ooh this is all the problem.....!
Thank you man
it worked?
can't be.
cuz i just double checked and i have to admit that it did
not test if you could actually name a variable after some tag.

now after some test runs i can say that
identifiers can be named after tags.
although its bad practice so i straight forward thought that's the cause.

well apparently, that works.
But using a keyword as identifier will cause
Код:
error 029: invalid expression, assumed zero
so thats that. sorry :/


soo back to the beginning.
i think that "UserPath(playerid)" returning
a invalid value (as in a non existing file path)
will definitely cause the code to stop
Reply
#9

Another thing for these
PHP код:
D:\MyServer\Server\filterscripts\createobject.pwn(33) : error 001expected token";"but found "{"
D:\MyServer\Server\filterscripts\createobject.pwn(35) : error 010invalid function or declaration 
PHP код:
stock info
{
    
format(string,sizeof(string),PATH,"Object %i",object);
    return 
string;

Reply
#10

Quote:
Originally Posted by nezo2001
Посмотреть сообщение
Another thing for these
PHP код:
D:\MyServer\Server\filterscripts\createobject.pwn(33) : error 001expected token";"but found "{"
D:\MyServer\Server\filterscripts\createobject.pwn(35) : error 010invalid function or declaration 
PHP код:
stock info
{
    
format(string,sizeof(string),PATH,"Object %i",object);
    return 
string;

pawn Код:
info(object)
{
    new string[20];
    format(string,sizeof(string),PATH"Object %i",object);
    return string;
}
usage-example:
printf("info: %s",info(3));
prints: "info: path/Object 3"
if PATH is defined as "path/"

adjust the size of "string"
idk what PATH holds for you or how long it is.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)