Been looking for about an hour.
#1

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.
Reply
#2

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
Reply
#3

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.
Reply
#4

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;
}
Reply
#5

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
Reply
#6

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.
Reply
#7

ǝɹ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).
Reply
#8

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
Reply
#9

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.
Reply
#10

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);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)