[Include] Unsigned Long 61 bit
#1

Hello, I would like to present the function to use the "unsigned long", or at least to increase the limit of numbers to

2 147 483 647 000 000 000

PHP Code:
/**********************************************************************************************************************************
 *                                                                                                                                *
 *                                           )(   Unsigned Long 61 Bit [Long Yoyo]   )(                                           *
 *                                                                                                                                *
 * Copyright © 2019 Abyss Morgan. All rights reserved.                                                                            *
 *                                                                                                                                *
 * Website:  adm.ct8.pl                                                                                                           *
 * Download: adm.ct8.pl/r/download                                                                                                *
 *                                                                                                                                *
 * Plugins: None                                                                                                                  *
 * Modules: None                                                                                                                  *
 *                                                                                                                                *
 * File Version: 1.6.1                                                                                                            *
 *                                                                                                                                *
 * Pawn Unsigned Long for 32 Bit language (precision 61-bit)                                                                      *
 * Available limit:                                                                                                               *
 * 0 - 2 147 483 647 000 000 000                                                                                                  *
 * 0 - 2 000 000 000 000 000 000                                                                                                  *
 *                                                                                                                                *
 * Functions:                                                                                                                     *
 * IsValueContainLY(prefix,suffix,value);                                                                                         *
 * GetLYString(prefix,suffix,string[],maxdest = sizeof(string));                                                                  *
 * LYStringToLY(&prefix,&suffix,string[]); //Reverse to GetLYString                                                               *
 * UpdateLY(&prefix,&suffix,value,limitprefix = DEFAULT_MAX_LY_PREFIX);                                                           *
 * AddSeparatorLY(string[],separator[]);                                                                                          *
 * DeleteSeparatorLY(string[],separator[]);                                                                                       *
 * CalculatePercentLY(&prefix,&suffix,Float:percent = 0.0,increase = true,limitprefix = DEFAULT_MAX_LY_PREFIX);                   *
 * GetPercentLY(prefix,suffix,&o_prefix,&o_suffix,Float:percent = 0.0,limitprefix = DEFAULT_MAX_LY_PREFIX);                       *
 *                                                                                                                                *
 * Operators:                                                                                                                     *
 * IsLYEqual(prefix,suffix,from_prefix,from_suffix);                                                                              *
 * IsLYSmallerThan(prefix,suffix,from_prefix,from_suffix);                                                                        *
 * IsLYSmallerThanOrEqual(prefix,suffix,from_prefix,from_suffix);                                                                 *
 * IsLYBiggerThan(prefix,suffix,from_prefix,from_suffix);                                                                         *
 * IsLYBiggerThanOrEqual(prefix,suffix,from_prefix,from_suffix);                                                                  *
 *                                                                                                                                *
 **********************************************************************************************************************************/ 
Example for bank system:
PHP Code:
pVar[playerid][pMoney] - your variable suffix 
pVar
[playerid][pMoneyLY] - your variable prefix 
//adding money to the bank 
UpdateLY(pVar[playerid][pMoneyLY], pVar[playerid][pMoney], amount); //<-- set your amount 
GivePlayerMoney(playerid,-amount); 
//the payment from the bank 
if(IsValueContainLY(pVar[playerid][pMoneyLY], pVar[playerid][pMoney], amount)){ //<-- set your amount 
    
UpdateLY(pVar[playerid][pMoneyLY], pVar[playerid][pMoney], -amount); 
    
GivePlayerMoney(playerid,amount); 
} else { 
    
//you do not have enough money 
}
//The amount of money in bank 
new mymoney[LY_STRING_LEN], buffer[128]; 
GetLYString(pVar[playerid][pMoneyLY], pVar[playerid][pMoney], mymoney); 
format(buffer,sizeof buffer,"You money in bank: %s",mymoney); 
SendClientMessage(playerid,-1,buffer); 
Download:
LY.inc

Non-Registered Users:
Bug Report
Reply
#2

1. Use strcat instead of your strcopy stock. Your stock function is insanely slow compared to strcat.

Code:
str[0] = 0;
strcat(dest, source);
2.
Code:
stock GetLYString(prefix,sufix,string[]){
	new buffer[20];
	if(prefix == 0){
		format(buffer,sizeof(buffer),"%d",sufix);
	} else {
		format(buffer,sizeof(buffer),"%d%09d",prefix,sufix);
	}
	strcopy(buffer,string);
}
What is the point of using format then strcopy?

Code:
stock GetLYString(prefix,sufix,string[], len = sizeof(string)){
	if(prefix == 0){
		format(string, len, "%d", sufix);
	} else {
		format(string, len, "%d%09d", prefix, sufix);
	}
}
Actually, the include can be rewritten using assembly/bitwise operations using a different algorithm of combining two cells into one. And a long var can be declared using tag, "new Long:number" (using defines, you can change that to new _long:number, _long:numberMS, _long:numberLS). One can even overload operators to carry out the basic operations on these number. I might work on this sometime in future.
Reply
#3

Quote:
Originally Posted by Yashas
View Post
1. Use strcat instead of your strcopy stock. Your stock function is insanely slow compared to strcat.

Code:
str[0] = 0;
strcat(dest, source);
2.
Code:
stock GetLYString(prefix,sufix,string[]){
	new buffer[20];
	if(prefix == 0){
		format(buffer,sizeof(buffer),"%d",sufix);
	} else {
		format(buffer,sizeof(buffer),"%d%09d",prefix,sufix);
	}
	strcopy(buffer,string);
}
What is the point of using format then strcopy?

Code:
stock GetLYString(prefix,sufix,string[], len = sizeof(string)){
	if(prefix == 0){
		format(string, len, "%d", sufix);
	} else {
		format(string, len, "%d%09d", prefix, sufix);
	}
}
Already removed strcpy. I had not thought about it


Current algorithm works in my script where players experience includes large numbers
http://i.imgur.com/mNNCTSz.png


However, if you have ideas that would be happy to see them.
Reply
#4

wtf is this system point, like its most fucked up system ever.
Reply
#5

Update LY.inc to v1.5 now

Added extended functions:
PHP Code:
bool:IsValueContainLY(prefix,suffix,value);
AddSeparatorLY(string[],separator[]);

//increases / decreases the value of a given percentage
CalculatePercentLY(&prefix,&suffix,Float:percent 0.0,increase true,limitprefix DEFAULT_MAX_LY_PREFIX);

//Get a percentage of a given number
GetPercentLY(prefix,suffix,&o_prefix,&o_suffix,Float:percent 0.0,limitprefix DEFAULT_MAX_LY_PREFIX); 
Reply
#6

Update 1.6:


Added new Functions:
PHP Code:
DeleteSeparatorLY(string[],separator[]);  
LYStringToLY(&prefix,&suffix,string[]); //Reverse to GetLYString 
Added new Operators:
PHP Code:
bool:IsLYEqual(prefix,suffix,from_prefix,from_suffix); 
bool:IsLYSmallerThan(prefix,suffix,from_prefix,from_suffix); 
bool:IsLYSmallerThanOrEqual(prefix,suffix,from_prefix,from_suffix); 
bool:IsLYBiggerThan(prefix,suffix,from_prefix,from_suffix); 
bool:IsLYBiggerThanOrEqual(prefix,suffix,from_prefix,from_suffix); 
Reply
#7

Very useful! I just implemented it in my Gamemode and it works perfectly
Reply
#8

I'm glad the page is back.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)