command problem - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: command problem (
/showthread.php?tid=65098)
command problem -
luxeon - 09.02.2009
pawn Код:
if(strcmp(cmdtext, "/lockhouse", true) == 0)
{
new housestuff;
new tmp[256];
tmp = strtok(cmdtext, idx);
new File:house1;
new pname[24];
new tmpstr[24];
new lockstr[24];
new lockstr2[24];
house1 = fopen("house1.txt", io_read);
fread(house1,tmpstr);
fread(house1,lockstr);
new File:house2;
new tmpstr2[24];
house2 = fopen("house2.txt", io_read);
fread(house2,tmpstr2);
fread(house2,lockstr2);
GetPlayerName(playerid, pname, 24);
if(!strcmp(pname,tmpstr,true))
{
print("House1 lockcheckdone");
if(!strlen(tmp) || (housestuff < 1 || housestuff > 6))
{
SendClientMessage(playerid,COLOR_WHITE,"USAGE: /lockhouse [1/0] || 1=locked, 0=unlocked");
return 1;
}
housestuff = strval(tmp);
if(housestuff == 0)
{
fwrite(house1,"Unlocked\n");
SendClientMessage(playerid,COLOR_HOUSE,"House is unlocked.");
return 1;
}
else if(housestuff == 1)
{
fwrite(house1,"Locked\n");
SendClientMessage(playerid,COLOR_HOUSE,"House is locked.");
return 1;
}
}
else if(!strcmp(pname,tmpstr2,true))
{
print("House2 lockcheckdone");
if(!strlen(tmp) || (housestuff < 1 || housestuff > 6))
{
SendClientMessage(playerid,COLOR_WHITE,"USAGE: /lockhouse [1/0] || 1=locked, 0=unlocked");
return 1;
}
housestuff = strval(tmp);
if(housestuff == 0)
{
fwrite(house2,"Unlocked\n");
SendClientMessage(playerid,COLOR_HOUSE,"House is unlocked.");
return 1;
}
else if(housestuff == 1)
{
fwrite(house2,"Locked\n");
SendClientMessage(playerid,COLOR_HOUSE,"House is locked.");
return 1;
}
}
fclose(house1);
fclose(house2);
return 1;
}
when i type /lockhouse x it writes: Unknown command, if i just write /lockhouse it gives USAGE:"blaa"
print("Housex lockcheckdone"); // only this prints out.
Any ideas.. ?
Re: command problem -
Eraz0r - 09.02.2009
Well you check the variable housestuff in the IF statement, but it has no value, because you've declared it after the if statement.
housestuff = strval(tmp); must be before the if statement
Re: command problem -
pspleo - 10.02.2009
And related to your problem, Luxeon, i think you need fclose(); (close the file).
Re: command problem -
Eraz0r - 10.02.2009
if(!strlen(tmp) || (housestuff < 1 || housestuff > 6))
Well the (housestuff < 1 || housestuff > 6) will return 1 and if(1) is true I think. You have to put the brackets awaylike this:
Код:
if(!strlen(tmp) || housestuff < 1 || housestuff > 6)