Command partly isn't working
#1

I was creating a house system. So this command should create a house:
pawn Код:
CMD:createhouse(playerid,params[])
{
    new HousePrice,tmp=HouseCount;
    if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid,0xFF0000FF,"Tu negali naudot sitos komandos,lops");
    else if(sscanf(params,"d",HousePrice)) SendClientMessage(playerid,0xFF0000FF,"Naudojimas /createhouse [Namo Kaina]");
    else
    {
        new Float:x,Float:y,Float:z;
        GetPlayerPos(playerid,x,y,z);
        HouseInfo[tmp][Price]=HousePrice;
        HouseInfo[tmp][Owned]=0;
        HouseInfo[tmp][PosX]=x;
        HouseInfo[tmp][PosY]=y;
        HouseInfo[tmp][PosZ]=z;
        HouseInfo[tmp][VirtualWorld] = GetPlayerVirtualWorld(playerid);
        HouseEnter[tmp]=CreateDynamicCP(x,y,z,1.5,GetPlayerVirtualWorld(playerid));
        format(HouseInfo[tmp][Owner],24,"None");
        HouseExit[tmp]=CreateDynamicCP(443.9237,509.4609,1001.4195,1.5,GetPlayerVirtualWorld(playerid));
        new query[128],labelstring[126];
        format(query,sizeof(query),"INSERT INTO houses (Owner,Owned,VirtualWorld,PosX,PosY,PosZ,Price) VALUES ('%s',0,%d,%f,%f,%f,%s)",HouseInfo[tmp][Owner],GetPlayerVirtualWorld(playerid),x,y,z,HousePrice);
        mysql_query(query);
        format(labelstring,sizeof(labelstring),"Namas Parduodamas \n Kaina:%d \nNoredamas pirkti rasyk /buyhouse",HousePrice);
        HouseInfo[tmp][HouseLabel] = Create3DTextLabel(labelstring,0x00FF00FF,x,y,z,25,GetPlayerVirtualWorld(playerid),0);
        HouseCount++;
    }
    return 1;
}
But the thing is, if I use /createhouse, it works,it sends the text.But if I use it correctly, /creathouse 1000, I get: Server:Unknown command. Like wtf?
Reply
#2

You don't need else.

pawn Код:
CMD:createhouse(playerid,params[])
{
    new HousePrice,tmp=HouseCount;
    if(!IsPlayerAdmin(playerid)) SendClientMessage(playerid,0xFF0000FF,"Tu negali naudot sitos komandos,lops");
    if(sscanf(params,"d",HousePrice)) SendClientMessage(playerid,0xFF0000FF,"Naudojimas /createhouse [Namo Kaina]");
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid,x,y,z);
    HouseInfo[tmp][Price]=HousePrice;
    HouseInfo[tmp][Owned]=0;
    HouseInfo[tmp][PosX]=x;
    HouseInfo[tmp][PosY]=y;
    HouseInfo[tmp][PosZ]=z;
    HouseInfo[tmp][VirtualWorld] = GetPlayerVirtualWorld(playerid);
    HouseEnter[tmp]=CreateDynamicCP(x,y,z,1.5,GetPlayerVirtualWorld(playerid));
    format(HouseInfo[tmp][Owner],24,"None");
    HouseExit[tmp]=CreateDynamicCP(443.9237,509.4609,1001.4195,1.5,GetPlayerVirtualWorld(playerid));
    new query[128],labelstring[126];
    format(query,sizeof(query),"INSERT INTO houses (Owner,Owned,VirtualWorld,PosX,PosY,PosZ,Price) VALUES ('%s',0,%d,%f,%f,%f,%s)",HouseInfo[tmp][Owner],GetPlayerVirtualWorld(playerid),x,y,z,HousePrice);
    mysql_query(query);
    format(labelstring,sizeof(labelstring),"Namas Parduodamas \n Kaina:%d \nNoredamas pirkti rasyk /buyhouse",HousePrice);
    HouseInfo[tmp][HouseLabel] = Create3DTextLabel(labelstring,0x00FF00FF,x,y,z,25,GetPlayerVirtualWorld(playerid),0);
    HouseCount++;
    return 1;
}
Reply
#3

Still,the same server:unknown command
Reply
#4

bump
Reply
#5

I'm guessing that the "tmp" variable is set to a value that is higher than the size of the array "HouseInfo".
Reply
#6

What do you mean? I was following this tutorial https://sampforum.blast.hk/showthread.php?tid=287541

House info=new HouseInfo[MAX_HOUSES][hInfo]
Reply
#7

anyone?
Reply
#8

Try this

pawn Код:
CMD:createhouse(playerid,params[])
{
    new HousePrice,tmp=HouseCount;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFF0000FF,"Tu negali naudot sitos komandos,lops");
    else if(sscanf(params,"d",HousePrice)) return SendClientMessage(playerid,0xFF0000FF,"Naudojimas /createhouse [Namo Kaina]");
    else
    {
        new Float:x,Float:y,Float:z;
        GetPlayerPos(playerid,x,y,z);
        HouseInfo[tmp][Price]=HousePrice;
        HouseInfo[tmp][Owned]=0;
        HouseInfo[tmp][PosX]=x;
        HouseInfo[tmp][PosY]=y;
        HouseInfo[tmp][PosZ]=z;
        HouseInfo[tmp][VirtualWorld] = GetPlayerVirtualWorld(playerid);
        HouseEnter[tmp]=CreateDynamicCP(x,y,z,1.5,GetPlayerVirtualWorld(playerid));
        format(HouseInfo[tmp][Owner],24,"None");
        HouseExit[tmp]=CreateDynamicCP(443.9237,509.4609,1001.4195,1.5,GetPlayerVirtualWorld(playerid));
        new query[128],labelstring[256];
        format(query,sizeof(query),"INSERT INTO houses (Owner,Owned,VirtualWorld,PosX,PosY,PosZ,Price) VALUES ('%s',0,%d,%f,%f,%f,%s)",HouseInfo[tmp][Owner],GetPlayerVirtualWorld(playerid),x,y,z,HousePrice);
        mysql_query(query);
        format(labelstring,sizeof(labelstring),"Namas Parduodamas \n Kaina:%d \nNoredamas pirkti rasyk /buyhouse",HousePrice);
        HouseInfo[tmp][HouseLabel] = Create3DTextLabel(labelstring,0x00FF00FF,x,y,z,25,GetPlayerVirtualWorld(playerid),0);
        HouseCount++;
    }
    return 1;
}
Reply
#9

Still the same error
Reply
#10

Replace your command with the one below, try it in-game and you'll receive a message in white.
If the value next to "tmp" is higher than the value next to "max_houses", find "#define MAX_HOUSES" in your script and change the value of it to something higher than the one next to "tmp".
pawn Код:
CMD:createhouse(playerid,params[])
{
    new str[128];
    format(str,sizeof(str),"tmp: %i -- max_houses: %i", HouseCount, MAX_HOUSES);
    SendClientMessage(playerid, 0xFFFFFFFF, str);
    new HousePrice, tmp=HouseCount;
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFF0000FF,"Tu negali naudot sitos komandos,lops");
    if(sscanf(params,"d",HousePrice)) return SendClientMessage(playerid,0xFF0000FF,"Naudojimas /createhouse [Namo Kaina]");
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid,x,y,z);
    HouseInfo[tmp][Price]=HousePrice;
    HouseInfo[tmp][Owned]=0;
    HouseInfo[tmp][PosX]=x;
    HouseInfo[tmp][PosY]=y;
    HouseInfo[tmp][PosZ]=z;
    HouseInfo[tmp][VirtualWorld] = GetPlayerVirtualWorld(playerid);
    HouseEnter[tmp]=CreateDynamicCP(x,y,z,1.5,GetPlayerVirtualWorld(playerid));
    format(HouseInfo[tmp][Owner],24,"None");
    HouseExit[tmp]=CreateDynamicCP(443.9237,509.4609,1001.4195,1.5,GetPlayerVirtualWorld(playerid));
    new query[128], labelstring[126];
    format(query,sizeof(query),"INSERT INTO houses (Owner,Owned,VirtualWorld,PosX,PosY,PosZ,Price) VALUES ('%s',0,%d,%f,%f,%f,%s)",HouseInfo[tmp][Owner],GetPlayerVirtualWorld(playerid),x,y,z,HousePrice);
    mysql_query(query);
    format(labelstring,sizeof(labelstring),"Namas Parduodamas \n Kaina:%d \nNoredamas pirkti rasyk /buyhouse",HousePrice);
    HouseInfo[tmp][HouseLabel] = Create3DTextLabel(labelstring,0x00FF00FF,x,y,z,25,GetPlayerVirtualWorld(playerid),0);
    HouseCount++;
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)