AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Random Item Chance (https://forums.alliedmods.net/showthread.php?t=274586)

Depresie 11-10-2015 13:36

[HELP] Random Item Chance
 
So i took this from the supply box code, this is used to give a player a random item written in a file
I want to remove the code that is using the .ini file for listing the items, and add them manualy in the script
I also want to know how i can create chances for each item in this given function with the following method

PHP Code:

random_num(1,100)
{
case 
1..20: { item name }
case 
211:100 item name }


here is the function that needs to be edited
PHP Code:

public load_supplybox_item() 
{
    new 
filepath[64]
    
get_configsdir(filepathcharsmax(filepath))
    
format(filepathcharsmax(filepath), god_item_filefilepath)
    
    if (!
file_exists(filepath))    
    {
        new 
error_msg[100]
        
formatex(error_msgcharsmax(error_msg), "[zp_supply_box][Error] Item File Not Found")
        
set_fail_state(error_msg)
        return
    }
    
    new 
line[1024], key[64], value[960]
    new 
file fopen(filepath"rt")
    
    while (!
feof(file) && file)
    {
        
fgets(filelinecharsmax(line));
        
replace(linecharsmax(line), "^n""")
        
        if (!
line[0] || line[0] == ';')
            continue
        
        
strtok(linekeycharsmax(key), valuecharsmax(value), '=')
        
trim(key)
        
trim(value)
        
        if (
equali(key"SUPPLYBOX_ITEM")) 
        {
            while (
value[0] != && strtok(valuekeycharsmax(key), valuecharsmax(value), ',')) 
            {
                
trim(key)
                
trim(value)
                
ArrayPushString(supplybox_itemkey)
            }
        }
    }


Here is the Full Code
Spoiler


All times are GMT -4. The time now is 17:49.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.