SA-MP Forums Archive
Random Weapon with Rate Percentage - 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: Random Weapon with Rate Percentage (/showthread.php?tid=656799)



Random Weapon with Rate Percentage - Dawkin - 24.07.2018

Код:
							else if(level >= 101 && level <= 200) // truck level 3
							{
								switch(random(3)) // random 9mm va sdpistol
								{
									case 0: // 9mm
									{
										SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "* Ban nhan duoc mien phi 9mm cho viec van chuyen vu khi trai phep.");
										SendClientMessageEx(playerid, COLOR_YELLOW, "* Khong duoc su dung vu khi duoc thuong cho muc dich xau nhu KOS/DM nonRP, neu vi pham se bi han che vu khi.");
										GivePlayerValidWeapon(playerid, 22, 60000);
									}
									case 1: // sdpistol
									{
										SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "* Ban nhan duoc mien phi sdpistol cho viec van chuyen vu khi trai phep.");
										SendClientMessageEx(playerid, COLOR_YELLOW, "* Khong duoc su dung vu khi duoc thuong cho muc dich xau nhu KOS/DM nonRP, neu vi pham se bi han che vu khi.");
										GivePlayerValidWeapon(playerid, 23, 60000);
									}	
									case 2: // shotgun
									{
										SendClientMessageEx(playerid, COLOR_LIGHTBLUE, "* Ban nhan duoc mien phi Shotgun cho viec van chuyen vu khi trai phep.");
										SendClientMessageEx(playerid, COLOR_YELLOW, "* Khong duoc su dung vu khi duoc thuong cho muc dich xau nhu KOS/DM nonRP, neu vi pham se bi han che vu khi.");
										GivePlayerValidWeapon(playerid, 25, 60000);
									}										
								}
							}
I have this code, It will give weapon random for player when their complete job
But I want shotgun rate percentage become rare
Example: 9mm 45% - sdpistol 45% - shotgun only 10%

Sorry, my English kinda weak


Re: Random Weapon with Rate Percentage - jlalt - 24.07.2018

do a random with number of 100
compare the returned value...
->
PHP код:
                            else if(level >= 101 && level <= 200// truck level 3
                            
{
                                switch(
random(100)) // random 9mm va sdpistol
                                
{
                                    case 
0..44// 9mm
                                    
{
                                        
SendClientMessageEx(playeridCOLOR_LIGHTBLUE"* Ban nhan duoc mien phi 9mm cho viec van chuyen vu khi trai phep.");
                                        
SendClientMessageEx(playeridCOLOR_YELLOW"* Khong duoc su dung vu khi duoc thuong cho muc dich xau nhu KOS/DM nonRP, neu vi pham se bi han che vu khi.");
                                        
GivePlayerValidWeapon(playerid2260000);
                                    }
                                    case 
45..89// sdpistol
                                    
{
                                        
SendClientMessageEx(playeridCOLOR_LIGHTBLUE"* Ban nhan duoc mien phi sdpistol cho viec van chuyen vu khi trai phep.");
                                        
SendClientMessageEx(playeridCOLOR_YELLOW"* Khong duoc su dung vu khi duoc thuong cho muc dich xau nhu KOS/DM nonRP, neu vi pham se bi han che vu khi.");
                                        
GivePlayerValidWeapon(playerid2360000);
                                    }
                                    case 
90..99// shotgun
                                    
{
                                        
SendClientMessageEx(playeridCOLOR_LIGHTBLUE"* Ban nhan duoc mien phi Shotgun cho viec van chuyen vu khi trai phep.");
                                        
SendClientMessageEx(playeridCOLOR_YELLOW"* Khong duoc su dung vu khi duoc thuong cho muc dich xau nhu KOS/DM nonRP, neu vi pham se bi han che vu khi.");
                                        
GivePlayerValidWeapon(playerid2560000);
                                    }
                                }
                            } 



Re: Random Weapon with Rate Percentage - coool - 24.07.2018

Using some thing like "case 0..44" is in-efficient because it is like creating 44 if statements.
source: http://forum.sa-mp.com/showpost.php?...0&postcount=15


Re: Random Weapon with Rate Percentage - jlalt - 24.07.2018

Quote:
Originally Posted by coool
Посмотреть сообщение
Using some thing like "case 0..44" is in-efficient because it is like creating 44 if statements.
source: http://forum.sa-mp.com/showpost.php?...0&postcount=15
Код:
#include <a_samp>

public OnFilterScriptInit()
{
	new tick = GetTickCount();
	for(new i = 0; i < 1000000; i++)
	{
		switch(random(100))
		{
		    case 0..44:
		    {
		    }
		    case 45..89:
		    {
		    }
		    case 90..99:
		    {
		    }
		}
	}
	printf("Took: %d", GetTickCount() - tick);
	
	tick = GetTickCount();
	for(new i = 0; i < 1000000; i++)
	{
	    new val = random(100);
	    if(val >= 0 && val <= 44)
	    {
	    }
		else if(val >= 45 && val <= 89)
		{
		}
	    else if(val >= 90 && val <= 99)
	    {
	    }
	}
	printf("Took: %d", GetTickCount() - tick);
}
PHP код:
  Filterscript 'w.amx' unloaded.
Took92
Took
232
  Filterscript 
'w.amx' loaded
and its only one hundred.


Re: Random Weapon with Rate Percentage - Dawkin - 24.07.2018

Thank everyone, SOLVED XD
Thank very much, <3


Re: Random Weapon with Rate Percentage - NaS - 24.07.2018

Quote:
Originally Posted by coool
Посмотреть сообщение
Using some thing like "case 0..44" is in-efficient because it is like creating 44 if statements.
source: http://forum.sa-mp.com/showpost.php?...0&postcount=15
And 44 if statements don't even take an amount of time that would be noticable.
This is more about ranges like 10000 where it would actually make a difference (objectively even 10000 wouldn't be noticable).