Random Weapon with Rate Percentage
#1

Код:
							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
Reply
#2

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

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

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

Thank everyone, SOLVED XD
Thank very much, <3
Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)