Little coding questions - For general minor queries 5

Thanks ^^,

Another thing,i would like to make admin logs right ik how to make them but how would my administrators get them? what's a good method that i should use,i was thinking of a command and download them all but apparently files only get saved in scripted files,not everyone would have this.
Reply

Quote:
Originally Posted by ISmokezU
Посмотреть сообщение
Thanks ^^,

Another thing,i would like to make admin logs right ik how to make them but how would my administrators get them? what's a good method that i should use,i was thinking of a command and download them all but apparently files only get saved in scripted files,not everyone would have this.
If you save the logs in a database Admins could technically retrieve them via a PHP script.
Reply

I going crazy.
Why I get random values like -164984 when I've [-1000;1000] ?
PHP код:
randomEx(minmax)
{
    static
        
bool:negative;
    if(
min || max 0)
        
negative true;
    if(
min 0)
        
min--;
    else
        
min++;
    if(
max 0)
        
max--;
    else
        
max++;
    if(!
negative)
    {
        return 
random(max min) + min;
    }
    else
    {
        if(
random(2) == 1)
        {
            if(
min == 0)
                return 
min;
            return -
random(-min);
        }
        else
        {
            if(
max == 0)
                return 
max;
            return 
random(max);
        }
    }

EDIT:
10'000 tests, no errors:
PHP код:
main()
{
    const 
        
= -1000,
        
= -a;
    new 
c;
    for(new 
i10000i++)
    {
        
randomEx(ab);
        
//printf("Test [%i] = %i", i, c);
        
if(|| b)
            
printf("[Error]: test %i : %i"ic);
    }

I test like 5 times on my script, I get 2 erroneous values.
Reply

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
I going crazy.
Why I get random values like -164984 when I've [-1000;1000] ?
PHP код:
randomEx(minmax)
{
    static
        
bool:negative;
    if(
min || max 0)
        
negative true;
    if(
min 0)
        
min--;
    else
        
min++;
    if(
max 0)
        
max--;
    else
        
max++;
    if(!
negative)
    {
        return 
random(max min) + min;
    }
    else
    {
        if(
random(2) == 1)
        {
            if(
min == 0)
                return 
min;
            return -
random(-min);
        }
        else
        {
            if(
max == 0)
                return 
max;
            return 
random(max);
        }
    }

EDIT:
10'000 tests, no errors:
PHP код:
main()
{
    const 
        
= -1000,
        
= -a;
    new 
c;
    for(new 
i10000i++)
    {
        
randomEx(ab);
        
//printf("Test [%i] = %i", i, c);
        
if(|| b)
            
printf("[Error]: test %i : %i"ic);
    }

I test like 5 times on my script, I get 2 erroneous values.
First of all what is all that? xD
Your random function is terrible, I couldn't even follow it's logic so it's probably wrong.
PHP код:
RandomEx(minmax)
{
    return 
random(floatround(floatabs(max min))) + (max<min) ? max min ;
}
//That floatround floatabs is very stupid tho, I wrote it in a rush so you might consider finding a replacement. 
Reply

The "normal" RandomEx
PHP код:
RandomEx(minmax) return random(max min) + min
should work for any number IF max > min and (max - min) <= cellmax
well if someone still thinks that -5 > -3 than he probably should add these if statments into his function
Reply

PHP код:
//randomex(min,max)
#define randomex(%0,%1)                             (random((%1)-(%0)+1)+(%0)) 
Reply

Okei, I feel stupid right now. I'll take the last one and come back later if I still have erroneous values.
Reply

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
The "normal" RandomEx
PHP код:
RandomEx(minmax) return random(max min) + min
should work for any number IF max > min and (max - min) <= cellmax
well if someone still thinks that -5 > -3 than he probably should add these if statments into his function
Yup, some people fail to realize that -3 > -5, hence the abs/round in the function I provided, although I fixed the second part to be a little more easy to the eye.
Reply

Ehh, can someone explain me how this code works? I am little confused.

PHP код:
                    intr locker_money;
                    if(
PlayerStat[playerid][DonLV] == 1)
                    {
                        
intr *= 1;
                        
intr /= 500;
                        
format(strsizeof(str), "Interest Rate [0.2%%]: %d$."intr);
                        
SendClientMessage(playeridBRONZEstr);
                    }
                    if(
PlayerStat[playerid][DonLV] == 2)
                    {
                        
intr *= 2;
                        
intr /= 500;
                        
format(strsizeof(str), "Interest Rate [0.4%%]: %d$."intr);
                        
SendClientMessage(playeridSILVERstr);
                    }
                    if(
PlayerStat[playerid][DonLV] == 3)
                    {
                        
intr *= 3;
                        
intr /= 500;
                        
format(strsizeof(str), "Interest Rate [0.6%%]: %d$."intr);
                        
SendClientMessage(playeridGOLDstr);
                    } 
Reply

Quote:
Originally Posted by Logic_
Посмотреть сообщение
Ehh, can someone explain me how this code works? I am little confused.

PHP код:
                    intr locker_money;
                    if(
PlayerStat[playerid][DonLV] == 1)
                    {
                        
intr *= 1;
                        
intr /= 500;
                        
format(strsizeof(str), "Interest Rate [0.2%%]: %d$."intr);
                        
SendClientMessage(playeridBRONZEstr);
                    }
                    if(
PlayerStat[playerid][DonLV] == 2)
                    {
                        
intr *= 2;
                        
intr /= 500;
                        
format(strsizeof(str), "Interest Rate [0.4%%]: %d$."intr);
                        
SendClientMessage(playeridSILVERstr);
                    }
                    if(
PlayerStat[playerid][DonLV] == 3)
                    {
                        
intr *= 3;
                        
intr /= 500;
                        
format(strsizeof(str), "Interest Rate [0.6%%]: %d$."intr);
                        
SendClientMessage(playeridGOLDstr);
                    } 
https://www.math.nmsu.edu/~pmorandi/...eFormulas.html

yours seems like calculating the rate according to the donor level

Like this

Код:
locker_money x level
--------------------------
          500
You could do that calculation simply like this too.

PHP код:
intr locker_money;
if(
PlayerStat[playerid][DonLV])
{
   
intr locker_money;
   
intr *= PlayerStat[playerid][DonLV];
   
intr /= 500;
   
format(strsizeof(str), "Interest Rate [0.%d%%]: %d$.",PlayerStat[playerid][DonLV]*2intr);
   
SendClientMessage(playerid, (PlayerStat[playerid][DonLV] == 1) ? BRONZE : (PlayerStat[playerid][DonLV] == 2) ? SILVER GOLD str);

Reply

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
Is there a limit for pickups? Should I use createpickup for building entrance pickups or use streamer pickups?
4096 is the max pickups that you can create according to: https://sampwiki.blast.hk/wiki/Limits
Reply

Quote:
Originally Posted by Logic_
Посмотреть сообщение
How much further this code can be optimized?

PHP код:
if(PlayerStat[playerid][DonLV] >= 1)
{
    new 
final_priceFloatoriginal_price;
    
original_price gShop[listitem][ItemPrice];
    
original_price *= PlayerStat[playerid][DonLV] * 0.2;
    
final_price floatround(original_price);
    
GiveMoney(playerid, - (gShop[listitem][ItemPrice] - final_price));

Does this work?

Код:
if(PlayerStat[playerid][DonLV] >= 1)
	GiveMoney(playerid, - (gShop[listitem][ItemPrice] - floatround((gShop[listitem][ItemPrice]) * (PlayerStat[playerid][DonLV] * 0.2))));
Reply

The only worthwhile optimisation is if DonLV is an integer and you avoid all float functions
PHP код:
new itemPrice gShop[listitem][ItemPrice];
GiveMoney(playerid, (itemPrice PlayerStat[playerid][DonLV]) / itemPrice); 
Reply

4 dimensions array isn't possible?
Example:
PHP код:
enum second_enum
{
    
firstthing,
    
second
}
enum last_enum
{
    
score,
    
id
}
enum first_enum
{
    
g_Options[second_enum][last_enum]
    ...
}
new 
p_Infos[MAX_PLAYERS][first_enum]; 
Reply

Well....Please I know I may sound even more silly today...
But like I know what is use of enum and especially arrays...
But I really don't know how they what we might say actually works...Yeah you can say that like what's the main reason or main thing it does both enums and arrays...
Please explain it in easiest way possible..
However I watched several tutorials and videos tutorials too..
But got nothing much to learn from them.
Reply

@Dayrion using Zeex's compiler it is possible, but usually it's way more readable to not use single giant PlayerInfo or something similar, but to split it into smaller arrays, like PlayerInfo, PlayerInventory, etc. etc.
Reply

How can I create a command with more options using sscanf?
Reply

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
How can I create a command with more options using sscanf?
by also using strcmp.
Reply

Quote:
Originally Posted by Misiur
Посмотреть сообщение
@Dayrion using Zeex's compiler it is possible, but usually it's way more readable to not use single giant PlayerInfo or something similar, but to split it into smaller arrays, like PlayerInfo, PlayerInventory, etc. etc.
Hmm. If you have any ideas how to split it (100% example):
PHP код:
new PrincipalArray[MAX_PLAYERS][p_Drug]
enum p_Drug
{
    
p_gOptions[DRUG_TYPE][g_arg];
    ...
}
enum SEED_TYPE
{
    
first_type,
    
second_type
}
enum g_arg
{
    
g_Seed,
    
g_Effect,
    ...

Reply

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
How can I create a command with more options using sscanf?
What types of data do you want to enter? Integers? Floats? Strings?
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)