Little coding questions - For general minor queries 5

Quote:
Originally Posted by Garwan50
View Post
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);
Reply

Quote:
Originally Posted by Garwan50
View Post
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.
Reply

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
Reply

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

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
Reply

Quote:
Originally Posted by Dayrion
View Post
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.
Reply

Quote:
Originally Posted by SickAttack
View Post
Loop, array, done.
I've already tried.
PHP Code:
Repeat(number)
{
    static
        
nb[4],
        
done[10],
        
a[4] = {111};
    
#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 
i4i++)
    {
        
printf("\n i: %i"i);
        for(new 
j4j++)
        {
            
printf("j: %i » %i & %i"jnb[i], nb[j]);
            if(
nb[i] == nb[j] && != j)
            {
                
printf("Le nombre %i est repete (i: %i & j: %i)"nb[i], ij);
                
done[nb[i]]++;
                
// if(a[i] >= 3)
                //     return a[i];
            
}
        }
    }
    for(new 
i10i++)
    {
        
printf("Le nombre %i est repete %ix"idone[i]);
    }
    return 
1;

Reply

Quote:
Originally Posted by Dayrion
View Post
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 
0sizeof(array); ++)
    {
        
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 
0strlen(string); j++)
    {
        
temp[0] = string[i];
        array[
strval(temp)] ++;
    }
    return 
1;

Reply


Thanks...
Reply

Quote:
Originally Posted by Dayrion
View Post
PHP Code:
//code 
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.
Reply

Quote:
Originally Posted by RaZVaN ^ xD
View Post
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
Reply

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?
Reply

Quote:
Originally Posted by RaZVaN ^ xD
View Post
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.
Reply

Is there any possible way to get the first letter of a string only?

PHP Code:
new _test[1];
strcat(_testpName(playerid));
// or
format(_testsizeof(_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?
Reply

Maybe this ?

https://sampwiki.blast.hk/wiki/Firstchars
Reply

Quote:
Originally Posted by ALiScripter
View Post
Is there any possible way to get the first letter of a string only?

PHP Code:
new _test[1];
strcat(_testpName(playerid));
// or
format(_testsizeof(_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);
Reply

Thanks both of you, but which one will you prefer the most?
Reply

Quote:
Originally Posted by ALiScripter
View Post
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!
Reply

What that mean ' :: ' ?
I guess : Custom:Variable = 5;
And this ? Custom::Variable = 5;
Reply

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


Forum Jump:


Users browsing this thread: 2 Guest(s)