Re: Little coding questions - For general minor queries 5 -
Karolukas123 - 26.11.2016
Quote:
Originally Posted by Garwan50
hey,
in the beginning of my filterscript i load all animations, just to be sure that they will be played without having to type the command twice.
However it crashed the player, is there a safer way to do it ? Or is it just impossible to load every libraries at the same time?
thanks!
|
its easy mate.. just create for example
StartingSomeAnimation(playerid) {
ApplyAnimation(playerid, "CHAINSAW", "CSAW_1", 4.1, 1, 0, 0, 0, 0, 1);
How to use:
in command or else
StartingSomeAnimation(playerid);
Re: Little coding questions - For general minor queries 5 -
SickAttack - 26.11.2016
Quote:
Originally Posted by Garwan50
hey,
in the beginning of my filterscript i load all animations, just to be sure that they will be played without having to type the command twice.
However it crashed the player, is there a safer way to do it ? Or is it just impossible to load every libraries at the same time?
thanks!
|
Preload the libraries when the player spawns, or wherever you want.
Re: Little coding questions - For general minor queries 5 -
Garwan50 - 26.11.2016
hey,
i did that, i tried when the player connect, and then when the player spawn.
Maybe i'll try to load animations with a timer, not everything at once
Re: Little coding questions - For general minor queries 5 -
Hansrutger - 01.12.2016
What is ackslimit for precisely? I've read
here, which redirected me
here. So I'm guessing it has to do with allowed connections or something, but is there an exact definition somewhere? (Sorry if it's stated somewhere obvious, I have not been able to reach there then...).
Re: Little coding questions - For general minor queries 5 -
Dayrion - 02.12.2016
There is a way to detect the number of time a numeral is repeated in a number?
Example:
3331 : 3 is repeated 3 times and 1, one time.
9955: 9 & 5 2 times
Re: Little coding questions - For general minor queries 5 -
SickAttack - 02.12.2016
Quote:
Originally Posted by Dayrion
There is a way to detect the number of time a numeral is repeated in a number?
Example:
3331 : 3 is repeated 3 times and 1, one time.
9955: 9 & 5 2 times
|
Loop, array, done.
Re: Little coding questions - For general minor queries 5 -
Dayrion - 02.12.2016
Quote:
Originally Posted by SickAttack
Loop, array, done.
|
I've already tried.
PHP Code:
Repeat(number)
{
static
nb[4],
done[10],
a[4] = {1, 1, 1};
#pragma unused done, nb, a
nb[0] = number / 1000;
nb[1] = (number % 1000) / 100;
nb[2] = (number % 100) / 10;
nb[3] = number % 10;
printf("%i & %i & %i & %i", nb[0], nb[1], nb[2], nb[3]);
for(new i; i < 4; i++)
{
printf("\n i: %i", i);
for(new j; j < 4; j++)
{
printf("j: %i » %i & %i", j, nb[i], nb[j]);
if(nb[i] == nb[j] && i != j)
{
printf("Le nombre %i est repete (i: %i & j: %i)", nb[i], i, j);
done[nb[i]]++;
// if(a[i] >= 3)
// return a[i];
}
}
}
for(new i; i < 10; i++)
{
printf("Le nombre %i est repete %ix", i, done[i]);
}
return 1;
}
Re: Little coding questions - For general minor queries 5 -
SickAttack - 02.12.2016
Quote:
Originally Posted by Dayrion
I've already tried.
|
PHP Code:
// ** INCLUDES
#include <a_samp>
// ** MAIN
main()
{
print("Loaded \"count_numbers_in_string.amx\".");
new array[10];
CountNumbersInString("1672893871653409172564", array);
for(new i = 0; i < sizeof(array); i ++)
{
printf("%d was found %d time(s) in string", i, array[i]);
}
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
// ** FUNCTIONS
stock CountNumbersInString(const string[], array[])
{
new temp[2];
for(new i = 0, j = strlen(string); i < j; i ++)
{
temp[0] = string[i];
array[strval(temp)] ++;
}
return 1;
}
Re: Little coding questions - For general minor queries 5 -
Dayrion - 02.12.2016


Thanks...
Re: Little coding questions - For general minor queries 5 -
RaZVaN ^ xD - 02.12.2016
Quote:
Originally Posted by Dayrion
|
That code reminds me of the first year of C programming courses in highschool. I remember this was one of our homeworks.
Let me fix that for you:
Code:
Repeat(number) {
new count[10];
if(number < 0)
number = -number; // this algorithm won't work properly on negative number since array indexes must be positive
while(number) {
new digit = number%10;
count[digit]++;
number /= 10;
}
for(new i = 0; i < 10; ++i) {
printf("Digit %d - %d times", i, count[i]);
}
}
The difference between my code and SickAttack's is that mine takes the number as an integer, while his takes it as a string.
Re: Little coding questions - For general minor queries 5 -
SickAttack - 02.12.2016
Quote:
Originally Posted by RaZVaN ^ xD
That code reminds me of the first year of C programming courses in highschool. I remember this was one of our homeworks.
Let me fix that for you:
Code:
Repeat(number) {
new count[10];
if(number < 0)
number = -number; // this algorithm won't work properly on negative number since array indexes must be positive
while(number) {
new digit = number%10;
count[digit]++;
number /= 10;
}
for(new i = 0; i < 10; ++i) {
printf("Digit %d - %d times", i, count[i]);
}
}
The difference between my code and SickAttack's is that mine takes the number as an integer, while his takes it as a string.
|
You can use valstr to convert an integer to a string.
"new digit" should be out of the loop
the function is just ridiculous
Re: Little coding questions - For general minor queries 5 -
RaZVaN ^ xD - 03.12.2016
Quote:
Originally Posted by SickAttack
You can use valstr to convert an integer to a string.
"new digit" should be out of the loop
the function is just ridiculous
|
I respected the function header he provided in his post, where number was an integer, not a string. Also, this code is just a snippet I wrote in 2 minutes, based on a simple algorithm, sorry for not having enough time to optimize the hell out of it, even if these micro optimizations have little to no impact in reality.
However, if we're at this subject, then your function is not that bright, too:
- you don't check anywhere if array used to store the counter is large enough
- function would return invalid results for negative numbers
- instead of creating a 2 cell string, copying every character to that string, and then converting it to a number, you could have done something like this instead: "array[(string[i]-'0')] ++;"
- should I bring into discussion the differencies between pre- and post- increments? nah
So, why is my function ridiculous?
Re: Little coding questions - For general minor queries 5 -
Dayrion - 03.12.2016
Quote:
Originally Posted by RaZVaN ^ xD
That code reminds me of the first year of C programming courses in highschool. I remember this was one of our homeworks.
Let me fix that for you:
Code:
Repeat(number) {
new count[10];
if(number < 0)
number = -number; // this algorithm won't work properly on negative number since array indexes must be positive
while(number) {
new digit = number%10;
count[digit]++;
number /= 10;
}
for(new i = 0; i < 10; ++i) {
printf("Digit %d - %d times", i, count[i]);
}
}
The difference between my code and SickAttack's is that mine takes the number as an integer, while his takes it as a string.
|
This is my first year of C programming. ;p
Thanks for your code. It's clear. I don't know why I didnt' tough about this kind of version.
EDIT: I can't +rep because I already did it.
Re: Little coding questions - For general minor queries 5 -
Logic_ - 04.12.2016
Is there any possible way to get the first letter of a string only?
PHP Code:
new _test[1];
strcat(_test, pName(playerid));
// or
format(_test, sizeof(_test), "%s", pName(playerid));
Found a function called 'Strmid' that may be useful in this @
https://sampwiki.blast.hk/wiki/Strmid but how can i use it?
Re: Little coding questions - For general minor queries 5 -
Bolex_ - 04.12.2016
Maybe this ?
https://sampwiki.blast.hk/wiki/Firstchars
Re: Little coding questions - For general minor queries 5 -
Dignity - 04.12.2016
Quote:
Originally Posted by ALiScripter
Is there any possible way to get the first letter of a string only?
PHP Code:
new _test[1];
strcat(_test, pName(playerid));
// or
format(_test, sizeof(_test), "%s", pName(playerid));
Found a function called 'Strmid' that may be useful in this @ https://sampwiki.blast.hk/wiki/Strmid but how can i use it?
|
strmid(dest, source, 0, 1);
Re: Little coding questions - For general minor queries 5 -
Logic_ - 04.12.2016
Thanks both of you, but which one will you prefer the most?
Re: Little coding questions - For general minor queries 5 -
Bolex_ - 04.12.2016
Quote:
Originally Posted by ALiScripter
Thanks both of you, but which one will you prefer the most?
|
I think a strmid bring in unnecessary lines and usage! I prefer to use Firstchar or do it with strmid on easy way!
Re: Little coding questions - For general minor queries 5 -
Dayrion - 05.12.2016
What that mean ' :: ' ?
I guess : Custom:Variable = 5;
And this ? Custom::Variable = 5;
Re: Little coding questions - For general minor queries 5 -
Hansrutger - 05.12.2016
Check the script defines: "#define Custom::" and you should see an explanation hopefully. If that is actually thing, it's the first time I am seeing that and am sorry for misleading.