SA-MP Forums Archive
Multidimensional Array - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Multidimensional Array (/showthread.php?tid=658854)



Multidimensional Array - NealPeteros - 14.09.2018

So I was planning to create an array for the messages of 4 textdraws

PHP код:
static const Msgs[][2][50] = //[] is for the id, [2] is to declare a multidimensional array, [50] is the maxlength of the string
{
    {
"Together forever!"1},
    {
"Long live!"2},
    {
"Test Server"3},
    {
"It's a great day!"4}
};
//the second values (numerical ones) are the ids of the textdraw 
And I was trying to create a command that would pick out the message and the textdraw id it's assigned to

PHP код:
CMD:findmsg(playeridparams[])
{
    new 
msg[64];
    if(
sscanf(params"s"msg))
    {
        
SendClientMessage(playerid, -1"USAGE: /findmsg [part of word]");
        return 
1;
    }
    return 
1;

That's as far as I can go in the command. dunno how to pick out something from the array with just a part of its word

Tryna' learn how Multidimensional arrays work =)


Re: Multidimensional Array - v1k1nG - 14.09.2018

You can give a try using strfind.


Re: Multidimensional Array - NealPeteros - 14.09.2018

Quote:
Originally Posted by v1k1nG
Посмотреть сообщение
You can give a try using strfind.
PHP код:
new string[128];
    for(new 
0sizeof(Msgs); i++)
    {
         if(
strfind(msgMsgs[i], true) != -1)
        {
            return 
1;
        }
    } 
Dunno how to go further than that


Re: Multidimensional Array - Shinja - 14.09.2018

PHP код:
new textdrawid = -1
for(new 
isizeof Msgsi<ji++)
{
    if(!
strfind(Msgs[i][0], msgtrue)) continue;
    
textdrawid Msgs[i][1];
    break;
}
if(
textdrawid == -1// no similiar msg found 
EDIT: you must use enum, thats not how to define a string in array

PHP код:
enum MSG_INFO
{
    
TEXT[50],
    
PlayerText:TXDID // or Text:
};
static const 
Msgs[][MSG_INFO] =

    {
"Together forever!"1}, 
    {
"Long live!"2}, 
    {
"Test Server"3}, 
    {
"It's a great day!"4
}; 



Re: Multidimensional Array - AmirSavand - 14.09.2018

Why would you need multiple textdraws? Can't you use 1 textdraw and show a message from your messages (array of strings)?

Like do you want to show multiple textdraw messages at the same time?


Re: Multidimensional Array - NealPeteros - 14.09.2018

Quote:
Originally Posted by Shinja
Посмотреть сообщение
PHP код:
new textdrawid = -1
for(new 
isizeof Msgsi<ji++)
{
    if(!
strfind(Msgs[i][0], msgtrue)) continue;
    
textdrawid Msgs[i][1];
    break;
}
if(
textdrawid == -1// no similiar msg found 
EDIT: you must use enum, thats not how to define a string in array

PHP код:
enum MSG_INFO
{
    
TEXT[50],
    
PlayerText:TXDID // or Text:
};
static const 
Msgs[][MSG_INFO] =

    {
"Together forever!"1}, 
    {
"Long live!"2}, 
    {
"Test Server"3}, 
    {
"It's a great day!"4
}; 
Forgot to thank you =)


Re: Multidimensional Array - v1k1nG - 14.09.2018

Hey sorry for the delay, you had the solution yet I wanted to suggest
PHP код:
static const Msgs[][50] = 
{
    {
"Together forever!"},
    {
"Long live!"},
    {
"Test Server"},
    {
"It's a great day!"}
};
main(){ 
    for(new 
04++){
        if(
strfind(Msgs[x], "Long"true) != -1){ // Looking for Long Live! string, edit this line how you look for it
            
printf("String found: %s"Msgs[x]); // printing the found string for debugging purposes
            
switch(x) {
                case 
0printf("CASE 1 : %s"Msgs[x]); // Together Forever! Won't be found
                
case 1printf("CASE 2 : %s"Msgs[x]); // <-- Long Live! Will be found.
                
case 2printf("CASE 3 : %s"Msgs[x]); // Test Server Won't be found
                
case 3printf("CASE 4 : %s"Msgs[x]); // It's a great day! Won't be found
                // Instead of printing the strings, use TextDrawSetString on the desired textdraw
            
}
        }
    }
    return 
1;    
}  
[
15:26:16String foundLong live!
[
15:26:16] CASE Long live
In case you were looking for something plainer