SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 14/09/2018, 10:59 AM   #1
NealPeteros
Gangsta
 
NealPeteros's Avatar
 
Join Date: Dec 2015
Location: GetPlayerCountry(playerid);
Posts: 632
Reputation: 51
Default Multidimensional Array

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

PHP Code:
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 Code:
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 =)
__________________
Quote:
SA-MP is like a drug or alcohol or smoking.. you really get used to it and can not leave it.
NealPeteros is offline   Reply With Quote
Old 14/09/2018, 11:00 AM   #2
v1k1nG
Big Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Location: Kattegat
Posts: 125
Reputation: 9
Default Re: Multidimensional Array

You can give a try using strfind.
__________________
My (beta) projects
v1k1nG is offline   Reply With Quote
Old 14/09/2018, 11:17 AM   #3
NealPeteros
Gangsta
 
NealPeteros's Avatar
 
Join Date: Dec 2015
Location: GetPlayerCountry(playerid);
Posts: 632
Reputation: 51
Default Re: Multidimensional Array

Quote:
Originally Posted by v1k1nG View Post
You can give a try using strfind.
PHP Code:
new string[128];
    for(new 
0sizeof(Msgs); i++)
    {
         if(
strfind(msgMsgs[i], true) != -1)
        {
            return 
1;
        }
    } 
Dunno how to go further than that
__________________
Quote:
SA-MP is like a drug or alcohol or smoking.. you really get used to it and can not leave it.
NealPeteros is offline   Reply With Quote
Old 14/09/2018, 11:19 AM   #4
Shinja
Gangsta
 
Shinja's Avatar
 
Join Date: Jan 2016
Posts: 975
Reputation: 100
Default Re: Multidimensional Array

PHP Code:
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 Code:
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
}; 
Shinja is offline   Reply With Quote
Old 14/09/2018, 12:02 PM   #5
AmirSavand
Big Clucker
 
AmirSavand's Avatar
 
Join Date: Sep 2018
Location: Behind Schedule
Posts: 50
Reputation: 1
Default Re: Multidimensional Array

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

GitHub - Website - Contact

C# - Python - PHP - Angular
Unity 3D - Django - Electron

AmirSavand is offline   Reply With Quote
Old 14/09/2018, 12:54 PM   #6
NealPeteros
Gangsta
 
NealPeteros's Avatar
 
Join Date: Dec 2015
Location: GetPlayerCountry(playerid);
Posts: 632
Reputation: 51
Default Re: Multidimensional Array

Quote:
Originally Posted by Shinja View Post
PHP Code:
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 Code:
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 =)
__________________
Quote:
SA-MP is like a drug or alcohol or smoking.. you really get used to it and can not leave it.
NealPeteros is offline   Reply With Quote
Old 14/09/2018, 01:35 PM   #7
v1k1nG
Big Clucker
 
v1k1nG's Avatar
 
Join Date: Feb 2018
Location: Kattegat
Posts: 125
Reputation: 9
Default Re: Multidimensional Array

Hey sorry for the delay, you had the solution yet I wanted to suggest
PHP Code:
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
__________________
My (beta) projects
v1k1nG is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Foreach - Multidimensional Array Noliax8 Scripting Help 3 07/07/2014 07:20 PM
Is it possible to use char-array in multidimensional array? newbienoob Scripting Help 8 24/02/2014 12:22 PM
Problem with multidimensional array... Crayder Scripting Help 2 02/01/2014 04:40 AM
Multidimensional Array Help 2KY Scripting Help 3 22/06/2013 03:07 AM
Multidimensional array's Aleks7 Help Archive 0 07/10/2010 03:53 PM


All times are GMT. The time now is 11:51 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.