SA-MP Forums Archive
[Tutorial] How to make a simple Search system - 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: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to make a simple Search system (/showthread.php?tid=537655)



How to make a simple Search system - DTV - 16.09.2014

This is my first tutorial, I hope you like it :)

What you'll need:

ZCMD - Link

First, be sure to include zcmd on top of the script

pawn Code:
#include <a_samp>
#include <zcmd>
Next thing is to forward and create the SearchSystem function

pawn Code:
forward SearchSystem();
public SearchSystem()
{
    new string[128], moneyamount = 1000 + random(1000);  //This is setting up the variables that will show the amount of money you find.
    GivePlayerMoney(playerid, moneyamount); //This is giving the player the random amount of money that was generated.
    format(string, sizeof(string), "You have found $%i.", moneyamount);  //This is formatting the string to be used in the SendClientMessage.
    SendClientMessage(playerid, 0xFFFFFFF, string);  //This will display the message to the player.
    return 1;
}
Next thing is to create the search command (with zcmd, you don't need to use OnPlayerCommandText, but you can just place this anywhere in the script. I'd post it under OnPlayerCommandText for organizing reasons)

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

CMD:search(playerid, params[]) //This is stating what the command will be named between the "CMD:" and "(", in this case, it's 'search'.
{
    SetTimerEx("SearchSystem", 5000, false, "i", playerid);  //This is the timer that will go off for the player when he types the command in.
    GameTextForPlayer(playerid, "Searching...", 4500, 3); //A message that will appear on the screen, showing that it's working.
    return 1;
}
I know it's a simply tutorial, but it can help give you ideas on where to apply this in other cases. I hope this helped you guys, especially for those who are new to pawn :)


Re: How to make a simple Search system - Mrashad - 17.09.2014

Great guide.


Re: How to make a simple Search system - Rudy_ - 17.09.2014

more like settimerex tut...


Re: How to make a simple Search system - Stinged - 17.09.2014

Quote:
Originally Posted by DTV
View Post
This is my first tutorial, I hope you like it
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

CMD:search(playerid, params[]) //This is stating what the command will be named between the "CMD:" and "(", in this case, it's 'search'.
{
    SetTimerEx("SearchSystem", 5000, false, "i", playerid);  //This is the timer that will go off for the player when he types the command in.
    GameTextForPlayer(playerid, "Searching...", 4500, 3); //A message that will appear on the screen, showing that it's working.
    return 1;
}
NEVER return 0 under OnPlayerCommandText if you're using zcmd. It will not work correctly.
Return 1 or remove the OnPlayerCommandText callback.


Re: How to make a simple Search system - TheRaGeLord - 16.01.2015

As Rudy Said.. Its More Like a Timer Tut... But Still Nice


Re: How to make a simple Search system - ikkentim - 16.01.2015

@DTV here is a useful tutorial for you: https://sampforum.blast.hk/showthread.php?tid=65567

You just know a tutorial can't be good when there are more lines of code than explanation.
This is just a code snippet with some accompanied text saying what it does.


Re: How to make a simple Search system - Schneider - 16.01.2015

@TheRaGeLord, no it's not good.
Especially if this is a SetTimerEx-tutorial, it's a very bad one.... It doens't work, and wouldn't even compile...

Spot the error:
pawn Code:
SetTimerEx("SearchSystem", 5000, false, "i", playerid);
pawn Code:
forward SearchSystem();
public SearchSystem()
{
 ...
Don't teach people about things you don't know anything about! You won't become a math-teacher if you don't even know what 2+2 is, right?


Re: How to make a simple Search system - Rufio - 18.01.2015

Quote:
Originally Posted by Schneider
View Post
@TheRaGeLord, no it's not good.
Especially if this is a SetTimerEx-tutorial, it's a very bad one.... It doens't work, and wouldn't even compile...

Spot the error:
pawn Code:
SetTimerEx("SearchSystem", 5000, false, "i", playerid);
pawn Code:
forward SearchSystem();
public SearchSystem()
{
 ...
Don't teach people about things you don't know anything about! You won't become a math-teacher if you don't even know what 2+2 is, right?
You could politely tell him his mistake instead of telling him he doesn't know anything right? Your post is nothing but slandering, just saying.