SA-MP Forums Archive
Why does this do this - 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)
+--- Thread: Why does this do this (/showthread.php?tid=340873)



Why does this do this - Scripter12345 - 08.05.2012

Well i have made my own system but when i try and sell to some one it says this


"You have offered to sell your house to (NAME) for (AMOUNT)"


But the amount always shows " 0 " in game why does it do that


pawn Code:
CMD:sellhouse(playerid,params[])
{
    for(new i = 0; i<MAX_PLAYERS; i++)
    {
        new Target;
        new Amount;
        if(sscanf(params, "i", Target, Amount)) return SendClientMessage(playerid, COLOR_GREEN, "/sellhouse [ID] [Amount]");
        if(!IsPlayerConnected(Target))
            return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected");
        if(HInfo[playerid][Owned] == 0) return SendClientMessage(playerid, COLOR_RED, "You do not own a house");
        new tname[MAX_PLAYER_NAME];
        GetPlayerName(Target,tname,sizeof(tname));
        GetPlayerName(playerid,pname,sizeof(pname));
        new pstring[256];
        new tstring[256];
        format(pstring,sizeof(pstring),"You have offered to sell your house to %s for %d",tname, Amount);
        format(tstring,sizeof(tstring),"You have been offered to buy %s's house for %d",pname, Amount);
        SendClientMessage(Target, COLOR_GREEN, tstring);
        SendClientMessage(playerid, COLOR_GREEN, pstring);
    }
    return 1;
}

Thank You


Please Help Me Please


Re: Why does this do this - warcodes_ - 08.05.2012

Found a flaw.

Code:
if(sscanf(params, "i", Target, Amount))
Try,

Code:
if(sscanf(params, "ii", Target, Amount))
EDIT:

Although i would preffer

Code:
if(sscanf(params, "ui", Target, Amount))
So both a player name or playerid can be used.


Re: Why does this do this - Vince - 08.05.2012

I do not know why you have wrapped the entire thing in a loop, because it serves absolutely no purpose.


Re: Why does this do this - ReneG - 08.05.2012

Quote:
Originally Posted by Vince
View Post
I do not know why you have wrapped the entire thing in a loop, because it serves absolutely no purpose.
I was wondering the exact same thing.


@OP.

You should try coding smaller things, and gradually progress. Judging by this code, you have almost no idea what you are doing.


Re: Why does this do this - warcodes_ - 08.05.2012

Wow, didn't see the loop..its not even used.


Re: Why does this do this - Scripter12345 - 08.05.2012

Quote:
Originally Posted by ******
View Post
There is something to be said for both approaches. My very first mode I had no idea what I was doing so I came up with an idea that I'd never seen done before and just figured out how to do it (and some parts took a long time to do - I still remember testing those things vividly). The trick is to learn how to debug your code and figure out where what you think is happening differs from what is really happening.
But every thing works so far


Re: Why does this do this - kaisersouse - 08.05.2012

Because "Amount" is being initialized in that terrible loop...and since its never assigned a value its always 0;

If you want to keep track of houses/businesses you need to pack that stuff into an array and not create those arrays from within loops and commands and really anything else.

Initialize outside of all the callbacks, change values inside the script.


Re: Why does this do this - Scripter12345 - 08.05.2012

Quote:
Originally Posted by kaisersouse
View Post
Because "Amount" is being initialized in that terrible loop...and since its never assigned a value its always 0;

If you want to keep track of houses/businesses you need to pack that stuff into an array and not create those arrays from within loops and commands and really anything else.

Initialize outside of all the callbacks, change values inside the script.
How would i do that


Thank You


Please Help Me Please


Re: Why does this do this - ReneG - 08.05.2012

I would start off by learning what a loop actually is, and what it does.

https://sampwiki.blast.hk/wiki/Control_S...res#for_.28.29

Also, please stop putting "Please Help Me Please". Kind of annoying.


Re: Why does this do this - kaisersouse - 08.05.2012

Quote:
Originally Posted by Scripter12345
View Post
How would i do that


Thank You


Please Help Me Please
Ummm...according to the code you posted originally you already know how to do it (because you are already using arrays).