[Help] Points System [+rep] -
Arxalan - 17.01.2015
Hello , i have points system . I want to have a function in it that admin can only give the points that can be divide with 0.25 . So admin can only give 0.25 , 0.50 , 0.75 , 1.00 , 1.25 and so on.
Following is my command.
PHP код:
CMD:givepp(playerid, params[])
{
LoginCheck(playerid);
if(User[playerid][accountAdmin] >= 3)
{
new string[150], id, amount;
if(sscanf(params, "ui", id, amount)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /givepp [playerid] [amount]");
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "» "red"Player not connected.");
if(User[id][accountLogged] == false) return SendClientMessage(playerid, -1, "» "red"Player not logged in.");
format(string, 150, "[PREMIUM POINTS] "red"%s has given %s [%d] Premium Points.", GetName(playerid), GetName(id), amount);
SendAMessage(-1, string);
format(string, 150, ""green"[PREMIUM POINTS] "white"You have received "grey"%d "white"premium points from an "red"admin"white".", amount, User[id][accountPP]+amount);
SendClientMessage(id, -1, string);
format(string, 150, "» You have given {%06x}%s "white"premium points of "grey"%d"white".", GetPlayerColor(id) >>> 8, GetName(id), amount);
SendClientMessage(playerid, -1, string);
format(string, 128, "%s received %d Premium Points from %s.", GetName(id), amount, GetName(playerid));
User[id][accountPP] += amount;
return 1;
Respuesta: [Help] Points System [+rep] -
JuanStone - 17.01.2015
You can only give integer values to integers, i believe that you should use float, or its variable is float ?.
Re: [Help] Points System [+rep] -
Arxalan - 17.01.2015
i don't know how to use float and i also just want that player can give only 0.25 , 0.50 , 0.75 , 1.00 .
Respuesta: Re: [Help] Points System [+rep] -
JuanStone - 17.01.2015
Quote:
Originally Posted by SA-MP Wiki
Floats and Integers
Float -> Integer
Converting a float to an integer is quite easy, as an integer doesn't have a tag and a float does. All we have to do is change the tag:
pawn Код:
new Float:fMyFloat = 1.3; new nSomeInt = _:fMyFloat; //nSomeInt is now 1.
You can also convert floats to integers with floatround:
pawn Код:
new Float:fMyFloat = 1.3; new nSomeInt = floatround( fMyFloat ); //nSomeInt is now 1.
Integer -> Float
Converting an integer to a Float can be done various ways:
pawn Код:
new nSomeInt = 5; new Float:fMyFloat; //By changing the tag: fMyFloat = Float:nSomeInt; //By using float(): fMyFloat = float( nSomeInt ); //Or just by assigning it: fMyFloat = nSomeInt; //fMyFloat is now 5.0.
|
I think it would be easier to use a float, but you could look at this.
Float is:
Quote:
Originally Posted by SA-MP Wiki
Floats are a type of tagged variable in PAWN and they are "floating point numbers", hence the name Float. This basically means that they support decimal places, such as 1.2, 1.1, 5.32, 64.21 - where as normal integers (untagged) don't support decimal places.[]
|
Re: [Help] Points System [+rep] -
Arxalan - 17.01.2015
Don't post tutorial . I am 0 at floats , strings and varibale. I can't solve it with the Wiki tutorials.
Re: [Help] Points System [+rep] -
BroZeus - 17.01.2015
Like this
pawn Код:
CMD:givepp(playerid, params[])
{
LoginCheck(playerid);
if(User[playerid][accountAdmin] >= 3)
{
new string[150], id, Float:amount;//note that Float: is added to make it a float
//in sscanf 'f' is used for floats
if(sscanf(params, "uf", id, amount)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /givepp [playerid] [amount]");
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "» "red"Player not connected.");
if(User[id][accountLogged] == false) return SendClientMessage(playerid, -1, "» "red"Player not logged in.");
//see the line below
if(amount % 0.25 != 0.0)return SendClientMessage(playerid, -1, "» "red"Only amounts that are divisible by 0.25 can be given.");
format(string, 150, "[PREMIUM POINTS] "red"%s has given %s [%d] Premium Points.", GetName(playerid), GetName(id), amount);
SendAMessage(-1, string);
format(string, 150, ""green"[PREMIUM POINTS] "white"You have received "grey"%d "white"premium points from an "red"admin"white".", amount, User[id][accountPP]+amount);
SendClientMessage(id, -1, string);
format(string, 150, "» You have given {%06x}%s "white"premium points of "grey"%d"white".", GetPlayerColor(id) >>> 8, GetName(id), amount);
SendClientMessage(playerid, -1, string);
format(string, 128, "%s received %d Premium Points from %s.", GetName(id), amount, GetName(playerid));
User[id][accountPP] += amount;
return 1;
Re: [Help] Points System [+rep] -
Arxalan - 17.01.2015
Quote:
Originally Posted by BroZeus
Like this
pawn Код:
CMD:givepp(playerid, params[]) { LoginCheck(playerid); if(User[playerid][accountAdmin] >= 3) { new string[150], id, Float:amount;//note that Float: is added to make it a float //in sscanf 'f' is used for floats if(sscanf(params, "uf", id, amount)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /givepp [playerid] [amount]"); if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "» "red"Player not connected."); if(User[id][accountLogged] == false) return SendClientMessage(playerid, -1, "» "red"Player not logged in."); //see the line below if(amount % 0.25 != 0.0)return SendClientMessage(playerid, -1, "» "red"Only amounts that are divisible by 0.25 can be given.");
format(string, 150, "[PREMIUM POINTS] "red"%s has given %s [%d] Premium Points.", GetName(playerid), GetName(id), amount); SendAMessage(-1, string); format(string, 150, ""green"[PREMIUM POINTS] "white"You have received "grey"%d "white"premium points from an "red"admin"white".", amount, User[id][accountPP]+amount); SendClientMessage(id, -1, string); format(string, 150, "» You have given {%06x}%s "white"premium points of "grey"%d"white".", GetPlayerColor(id) >>> 8, GetName(id), amount); SendClientMessage(playerid, -1, string);
format(string, 128, "%s received %d Premium Points from %s.", GetName(id), amount, GetName(playerid));
User[id][accountPP] += amount; return 1;
|
Got an Error :
function "operator%(Float:,Float

" is not implemented
Re: [Help] Points System [+rep] -
BroZeus - 17.01.2015
Line of error?
Re: [Help] Points System [+rep] -
Arxalan - 17.01.2015
The following line
PHP код:
if(amount % 0.25 != 0.0)return SendClientMessage(playerid, -1, "» "red"Only amounts that are divisible by 0.25 can be given.");
I tried to put "/" instead of "%" (with quotes) but now it is debugging only that line . I mean if i use /givepp 0 1 (as 1 is divisible by 0.25 and it divides 1 totally without any remainder ) it gives me the error "only amounts that are divisble by 0.25 can be given and if i use and number that isn't divisble by 0.25 then i have that same error e.g. 2.10
Re: [Help] Points System [+rep] -
BroZeus - 17.01.2015
Just found out that modulo operator is not supported with Floats in PAWN
I found this stock by MadeMan maybe this may work
pawn Код:
stock Float:modulus(Float:a, Float:b)
{
while(a > b)
a -= b;
return a;
}
//the if line -->
if(modulus(0.25, amount) != 0.0)return ...