Re: Little coding questions - For general minor queries 5 -
ISmokezU - 14.01.2017
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.
Re: Little coding questions - For general minor queries 5 -
Jeroen52 - 14.01.2017
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.
Re: Little coding questions - For general minor queries 5 -
Dayrion - 15.01.2017
I going crazy.
Why I get random values like -164984 when I've [-1000;1000] ?
PHP код:
randomEx(min, max)
{
static
bool:negative;
if(min < 0 || 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
a = -1000,
b = -a;
new c;
for(new i; i < 10000; i++)
{
c = randomEx(a, b);
//printf("Test [%i] = %i", i, c);
if(c < a || c > b)
printf("[Error]: test %i : %i", i, c);
}
}
I test like 5 times on my script, I get 2 erroneous values.
Re: Little coding questions - For general minor queries 5 -
PrO.GameR - 15.01.2017
Quote:
Originally Posted by Dayrion
I going crazy.
Why I get random values like -164984 when I've [-1000;1000] ?
PHP код:
randomEx(min, max)
{
static
bool:negative;
if(min < 0 || 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
a = -1000,
b = -a;
new c;
for(new i; i < 10000; i++)
{
c = randomEx(a, b);
//printf("Test [%i] = %i", i, c);
if(c < a || c > b)
printf("[Error]: test %i : %i", i, c);
}
}
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(min, max)
{
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.
Re: Little coding questions - For general minor queries 5 -
Nero_3D - 15.01.2017
The "normal" RandomEx
PHP код:
RandomEx(min, max) 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
Re: Little coding questions - For general minor queries 5 -
AbyssMorgan - 16.01.2017
PHP код:
//randomex(min,max)
#define randomex(%0,%1) (random((%1)-(%0)+1)+(%0))
Re: Little coding questions - For general minor queries 5 -
Dayrion - 16.01.2017
Okei, I feel stupid right now. I'll take the last one and come back later if I still have erroneous values.
Re: Little coding questions - For general minor queries 5 -
PrO.GameR - 16.01.2017
Quote:
Originally Posted by Nero_3D
The "normal" RandomEx
PHP код:
RandomEx(min, max) 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.
Re: Little coding questions - For general minor queries 5 -
Logic_ - 16.01.2017
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(str, sizeof(str), "Interest Rate [0.2%%]: %d$.", intr);
SendClientMessage(playerid, BRONZE, str);
}
if(PlayerStat[playerid][DonLV] == 2)
{
intr *= 2;
intr /= 500;
format(str, sizeof(str), "Interest Rate [0.4%%]: %d$.", intr);
SendClientMessage(playerid, SILVER, str);
}
if(PlayerStat[playerid][DonLV] == 3)
{
intr *= 3;
intr /= 500;
format(str, sizeof(str), "Interest Rate [0.6%%]: %d$.", intr);
SendClientMessage(playerid, GOLD, str);
}
Re: Little coding questions - For general minor queries 5 -
SyS - 16.01.2017
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(str, sizeof(str), "Interest Rate [0.2%%]: %d$.", intr);
SendClientMessage(playerid, BRONZE, str);
}
if(PlayerStat[playerid][DonLV] == 2)
{
intr *= 2;
intr /= 500;
format(str, sizeof(str), "Interest Rate [0.4%%]: %d$.", intr);
SendClientMessage(playerid, SILVER, str);
}
if(PlayerStat[playerid][DonLV] == 3)
{
intr *= 3;
intr /= 500;
format(str, sizeof(str), "Interest Rate [0.6%%]: %d$.", intr);
SendClientMessage(playerid, GOLD, str);
}
|
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(str, sizeof(str), "Interest Rate [0.%d%%]: %d$.",PlayerStat[playerid][DonLV]*2, intr);
SendClientMessage(playerid, (PlayerStat[playerid][DonLV] == 1) ? BRONZE : (PlayerStat[playerid][DonLV] == 2) ? SILVER : GOLD , str);
}
Re: Little coding questions - For general minor queries 5 -
Runn3R - 02.02.2017
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
Re: Little coding questions - For general minor queries 5 -
Jeroen52 - 02.02.2017
Quote:
Originally Posted by Logic_
How much further this code can be optimized?
PHP код:
if(PlayerStat[playerid][DonLV] >= 1)
{
new final_price, Float: original_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))));
Re: Little coding questions - For general minor queries 5 -
Nero_3D - 02.02.2017
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]) / 5 - itemPrice);
Re: Little coding questions - For general minor queries 5 -
Dayrion - 03.02.2017
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];
Re: Little coding questions - For general minor queries 5 -
princejeet1510 - 03.02.2017
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.
Re: Little coding questions - For general minor queries 5 -
Misiur - 03.02.2017
@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.
Re: Little coding questions - For general minor queries 5 -
AndreiWow - 03.02.2017
How can I create a command with more options using sscanf?
Re: Little coding questions - For general minor queries 5 -
GangstaSunny. - 03.02.2017
Quote:
Originally Posted by AndreiWow
How can I create a command with more options using sscanf?
|
by also using strcmp.
Re: Little coding questions - For general minor queries 5 -
Dayrion - 03.02.2017
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,
...
}
Re: Little coding questions - For general minor queries 5 -
Jeroen52 - 03.02.2017
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?