[+]: Invalid money [disable to add.] - 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: [+]: Invalid money [disable to add.] (
/showthread.php?tid=604584)
[+]: Invalid money block. -
ProRakNet - 07.04.2016
Hi, the server the player's money, 1000$ 2000$, 3000$ etc. integer how to get the block ..?
The amount of money 1000/2000/3000 server disable money amount.
Example;
PHP код:
GetMoneyFunction(playerid){
InvalidMoney(playerid);
SendClientMessage(playerid, -1, [Incorrect amount]: You do not get that amount.);
}
PHP код:
stock InvalidMoney(playerid){
GivePlayerMoney(playerid, 1000); // Disable
GivePlayerMoney(playerid, 2000); // Disable
GivePlayerMoney(playerid, 3000); // Disable
}
Re: [+]: Invalid money [disable to add.] -
introzen - 07.04.2016
PHP код:
CheckValidMoney(money) {
new index = 0; //define index
switch(money) { //loop through input
case 1000: index = 1; //check 1000
case 2000: index = 1;
case 3000: index = 1;
}
if(index != 0) return false; //return false if player money is not valid.
return true;
}
GivePlayerMoneyEx(playerid, money) {
if(!CheckValidMoney(money)) return SendClientMessage(playerid, -1, "[Incorrect amount]: You do not get that amount."); //If money amount is invalid, return error msg.
GivePlayerMoney(playerid, money); //Give player money if above condition did not escape the function.
return 1;
}
Re: [+]: Invalid money [disable to add.] -
AndySedeyn - 07.04.2016
Quote:
Originally Posted by introzen
PHP код:
CheckValidMoney(money) {
new index = 0; //define index
switch(money) { //loop through input
case 1000: index = 1; //check 1000
case 2000: index = 1;
case 3000: index = 1;
}
if(index != 0) return false; //return false if player money is not valid.
return true;
}
GivePlayerMoneyEx(playerid, money) {
if(!CheckValidMoney(money)) return SendClientMessage(playerid, -1, "[Incorrect amount]: You do not get that amount."); //If money amount is invalid, return error msg.
GivePlayerMoney(playerid, money); //Give player money if above condition did not escape the function.
return 1;
}
|
You're not really looping. You're just checking value cases against the input. You can leave the index variable out:
PHP код:
switch(money) {
case 1000, 2000, 3000: {
return false;
}
default: return true;
}
You would have to add all (n*1000) cases to match the OPs needs.
Something like this would probably be better:
PHP код:
return (input % 1000 == 0) ? true : false;
Re: [+]: Invalid money [disable to add.] -
introzen - 07.04.2016
Quote:
Originally Posted by AndySedeyn
Something like this would probably be better:
PHP код:
return (input % 1000 == 0) ? true : false;
|
You're completely right. Thank you.
I've just started using switch() instead of if() as i've read it should be more memory efficient.
Re: [+]: Invalid money [disable to add.] -
ProRakNet - 07.04.2016
thanks but doesnt work :/