SA-MP Forums Archive
Been looking for about an hour. - 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: Been looking for about an hour. (/showthread.php?tid=85674)



Been looking for about an hour. - whereschris - 08.07.2009

Hello, I'm just wondering if anyone could show me the basics of a command like /buyspaz,

It would give them the spaz if they have enough money, and if they don't have enough money it would give em an error message.


Thanks

And if you could comment where the id of the gun is it would be nice so i could edit it and learn from it.


EDIT: Woops, I think this was suppose to go in the request a script section, but I'm not really requesting, im asking how you would do it.


Re: Been looking for about an hour. - Chaprnks - 08.07.2009

pawn Код:
if(strcmp("/buyspaz ",cmdtext,true) == 0)
{
    if(GetPlayerMoney(playerid) < INSERT_AMOUNT_HERE)
    {
        SendClientMessage(playerid, 0xF0F8FFAA, " You do not have enough money.");
        return 1;
    }
    SendClientMessage(playerid, 0xF0F8FFAA, " You just bought a spaz for $INSERT_AMOUNT_HERE, have fun :)");
    GivePlayerWeapon(playerid, 25, 250);
    return 1;
}
GivePlayerWeapon(%1,%2,%3);
%1 - The players id
%2 - The gun id, (check the wiki link below for more help)
%3 - The amount of ammo

Change "INSERT_AMOUNT_HERE" with the amount you want the money to be. Also if you would like them to get a different amount of ammo, change the 250 to whatever you want.


Also, this may help with weapon codes:
https://sampwiki.blast.hk/wiki/Weapons


Re: Been looking for about an hour. - whereschris - 08.07.2009

Quote:
Originally Posted by ǝɹoɯ‾ʎ
pawn Код:
if(strcmp("/buyspaz ",cmdtext,false,3) == 0)
{
    if(GetPlayerMoney(playerid) < INSERT_AMOUNT_HERE)
    {
        SendClientMessage(playerid, 0xF0F8FFAA, " You do not have enough money.");
        return 1;
    }
    SendClientMessage(playerid, 0xF0F8FFAA, " You just bought a spaz for $INSERT_AMOUNT_HERE, have fun :)");
    GivePlayerWeapon(playerid, 25, 250);
    return 1;
}
GivePlayerWeapon(%1,%2,%3);
%1 - The players id
%2 - The gun id, (check the wiki link below for more help)
%3 - The amount of ammo

Change "INSERT_AMOUNT_HERE" with the amount you want the money to be. Also if you would like them to get a different amount of ammo, change the 250 to whatever you want.


Also, this may help with weapon codes:
https://sampwiki.blast.hk/wiki/Weapons
Wow!

Thank you so much for the fast reply, and I had no idea that "Giveplayerweapon" Even exsisted, haha..

Once again, thanks so much for replying within 2 minutes.


Re: Been looking for about an hour. - Weirdosport - 08.07.2009

pawn Код:
#include <a_samp>

//#############################
//##    Change these:   ##
//#############################

#define GUNID 27
#define GUNCOST 1000
#define AMMO 500
#define COLOR 0xFF00FFFF

//#############################

new String[128];

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/buyspaz", cmdtext, true, 10) == 0)
    {
        if(GetPlayerMoney(playerid) >= GUNCOST)
        {
          GivePlayerWeapon(playerid, GUNID, AMMO);
          GivePlayerMoney(playerid, -GUNCOST);
          SendClientMessage(playerid, COLOR, "Enjoy your spaz!");
        }
        else
        {
          format(String, sizeof(String), "You need at least %d to buy a Spaz!", GUNCOST);
          SendClientMessage(playerid, COLOR, String);
        }
        return 1;
    }
    return 0;
}



Re: Been looking for about an hour. - Chaprnks - 08.07.2009

Quote:
Originally Posted by whereschris
Wow!

Thank you so much for the fast reply, and I had no idea that "Giveplayerweapon" Even exsisted, haha..

Once again, thanks so much for replying within 2 minutes.
No problem

https://sampwiki.blast.hk/wiki/Category:Scripting_Functions
Read up on there, it helps alot to know what your working with


Re: Been looking for about an hour. - whereschris - 08.07.2009

Quote:
Originally Posted by Weirdosport
pawn Код:
#include <a_samp>

//#############################
//##   Change these:  ##
//#############################

#define GUNID 27
#define GUNCOST 1000
#define AMMO 500
#define COLOR 0xFF00FFFF

//#############################

new String[128];

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/buyspaz", cmdtext, true, 10) == 0)
    {
        if(GetPlayerMoney(playerid) >= GUNCOST)
        {
          GivePlayerWeapon(playerid, GUNID, AMMO);
          SendClientMessage(playerid, COLOR, "Enjoy your spaz!");
        }
        else
        {
          format(String, sizeof(String), "You need at least %d to buy a Spaz!", GUNCOST);
          SendClientMessage(playerid, COLOR, String);
        }
        return 1;
    }
    return 0;
}
Wow, another reply within 10 minutes, hehe

Is there a point in defining the numbers the top, since you could put them in the script it self?

For example #define GUNID 27

Couldn't you just type in 27 for the gunID, instead of defining it, just makes more sence to me.



Re: Been looking for about an hour. - Weirdosport - 08.07.2009

ǝɹoɯ‾ʎ, your command wont work as intended. You set the string length to be compared to 3, meaning anyone typing /bu will get a spaz (assuming the correct money etc).

Also, you set ignorecaps to false, not sure if that was intentional or not though..

Quote:
Originally Posted by whereschris
Wow, another reply within 10 minutes, hehe

Is there a point in defining the numbers the top, since you could put them in the script it self?

For example #define GUNID 27

Couldn't you just type in 27 for the gunID, instead of defining it, just makes more sence to me.
You can if you want, I just felt having them at the top would make it easier to change (less trawling).


Re: Been looking for about an hour. - Chaprnks - 08.07.2009

Quote:
Originally Posted by whereschris
Wow, another reply within 10 minutes, hehe

Is there a point in defining the numbers the top, since you could put them in the script it self?

For example #define GUNID 27

Couldn't you just type in 27 for the gunID, instead of defining it, just makes more sence to me.
Its your choice, most scripters define things so its easier to look for / change if you need. Especially if that value is in many parts of a script.

-----

Quote:
Originally Posted by Weirdosport
ǝɹoɯ‾ʎ, your command wont work as intended. You set the string length to be compared to 3, meaning anyone typing /bu will get a spaz (assuming the correct money etc).

Also, you set ignorecaps to false, not sure if that was intentional or not though..
I edited it, didn't notice right away. I normally don't make strcmp commands :P


Re: Been looking for about an hour. - whereschris - 08.07.2009

Just tested the command, and it seems to not take the money away after you buy it.. What would be the function to properly use, like "RemoveMoney" Or something like that.


Re: Been looking for about an hour. - Chaprnks - 08.07.2009

Quote:
Originally Posted by whereschris
Just tested the command, and it seems to not take the money away after you buy it.. What would be the function to properly use, like "RemoveMoney" Or something like that.
https://sampwiki.blast.hk/wiki/GivePlayerMoney

GivePlayerMoney(playerid, -THE_AMOUNT);