AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Array Operations (https://forums.alliedmods.net/showthread.php?t=140170)

S34Qu4K3 10-09-2010 12:09

Array Operations
 
Hi I have this

PHP Code:

new Password[4]
new 
szArg[192]

//.........


public RegisterPassword(id)
{
    
client_cmd(id"messagemode Register_Pwd")
    
    
client_print(idprint_center"Write Password  Numbers")
    
set_hudmessage(255000.00.000.14.00.010.01, -1)
    
ShowSyncHudMsg(idg_MsgSync"^n^n^n  Write Password  Numbers")
    
    return 
PLUGIN_CONTINUE;
}

public 
Pwd_register(id)
{
    
read_argsszArg191 )
    
remove_quotesszArg )
    
trim szArg )
    
    if( !
isdigit(szArg[0]) )
    {
        
RegisterPassword(id)
        return 
PLUGIN_HANDLED;
    }
        
    
copyPassword[id], charsmaxPassword[] ), szArg )
    
    
client_printidprint_chat"Tu password es: %s"Password[id] )
    
CheckValidPassword(id)
    return 
PLUGIN_CONTINUE;
    
}  
public 
CheckValidPassword(id)
{
    
client_print(idprint_chat"[DEBUG]public CheckValidPassword")
    if((
Password[0]*Password[3])-(Password[1]*Password[2]) == 1)
    {
        
client_print(idprint_chat"[DEBUG]Password Acepted")
        
InverseArray(id)
    }
    else
    {
        
client_print(idprint_chat"[DEBUG]Array Determinant Not 1")
        
RegisterPassword(id)
    }


When the player write 4 numbers for the array Password, i want to check if the determinat of the array is 1 but when i put my four numbers, the plugin say that the determinat of the array is not 1. Why?

wrecked_ 10-09-2010 12:15

Re: Array Operations
 
What do you mean by determinat?

Exolent[jNr] 10-09-2010 12:19

Re: Array Operations
 
The password only allows 3 characters and then the last slot is ^0 because Password is a string with a size of 4, giving it a max length of 3.
Also, Password is not a 2D array for players, so you should not index it by the player id when copying it from szArg.

PHP Code:

if( !isdigit(szArg[0]) ) 

Should be
PHP Code:

if( !is_str_num(szArg[0]) || strlen(szArg) != 

So it checks if the whole string is a number than that it has 4 numbers.

PHP Code:

copyPassword[id], charsmaxPassword[] ), szArg 

Should be
PHP Code:

new iArg str_to_numszArg )
Password[0] = iArg 1000
Password
[1] = (iArg 100) % 10
Password
[2] = (iArg 10) % 10
Password
[3] = iArg 10
// 1234 / 1000 = 1
// (1234 / 100) % 10 = (12) % 10 = 2
// (1234 / 10) % 10 = (123) % 10 = 3
// 1234 % 10 = 4 

@wrecked_
It's a math term for matrices.
http://en.wikipedia.org/wiki/Determinant

S34Qu4K3 10-09-2010 12:21

Re: Array Operations
 
a b
X=
c d

Determinant= a × d − c ×b = 1

@Exolent
Now the plugin works but I don´t understand what mean the operations :S

// 1234 / 1000 = 1
// (1234 / 100) % 10 = (12) % 10 = 2
// (1234 / 10) % 10 = (123) % 10 = 3
// 1234 % 10 = 4

More: Why i can´t use this to make the inverse array?
PHP Code:


public InverseArray(id)
{
    
InversePassword[0] = Password[3]
    
InversePassword[1] = -Password[1]
    
InversePassword[2] = -Password[2]
    
InversePassword[3] = Password[1]
    
client_print(idprint_center"[DEBUG]Array Inversed, now is %s"InversePassword)
    



Exolent[jNr] 10-09-2010 12:36

Re: Array Operations
 
Those calculations get the 4 digits of the number you need.

That is now an array of numbers, not a string.
So you can't just print it out like that.
You must print it as an integer.
PHP Code:

client_print(idprint_center"[DEBUG]Array Inversed, now is %d%d%d%d"InversePassword[0], InversePassword[1], InversePassword[2], InversePassword[3]) 


S34Qu4K3 10-09-2010 12:45

Re: Array Operations
 
Thank you again Exolent and i´ve found an error:

PHP Code:

    InversePassword[0] = Password[3]
    
InversePassword[1] = -Password[1]
    
InversePassword[2] = -Password[2]
    
InversePassword[3] = Password[1

Should be:
PHP Code:

    InversePassword[0] = Password[3]
    
InversePassword[1] = -Password[1]
    
InversePassword[2] = -Password[2]
    
InversePassword[3] = Password[0

And a last question: Exists any plugin for encrypt text or i´m trying to make the first??

fysiks 10-09-2010 18:38

Re: Array Operations
 
Quote:

Originally Posted by S34Qu4K3 (Post 1320247)
And a last question: Exists any plugin for encrypt text or i´m trying to make the first??

md5?

Quote:

Originally Posted by wrecked_ (Post 1320203)
What do you mean by determinat?

Quote:

Originally Posted by S34Qu4K3 (Post 1320209)
a b
X=
c d

Determinant= a × d − c ×b = 1


A determinant is NOT an array operation. It is a matrix operation. Matrix != Array.

S34Qu4K3 10-09-2010 19:04

Re: Array Operations
 
Quote:

Originally Posted by fysiks (Post 1320616)
md5?
A determinant is NOT an array operation. It is a matrix operation. Matrix != Array.

Can you show me an example?

Yeah, i´m mistaken xD

Exolent[jNr] 10-09-2010 19:28

Re: Array Operations
 
When you code a matrix in Pawn, you will use arrays.

S34Qu4K3 10-09-2010 19:41

Re: Array Operations
 
Im thinking, is not the same, array=matrix?

THis code can be optimized?:

PHP Code:

        TextEncrypted[0][0] = (szPieces[0][0] * Password[0]) + (szPieces[0][1] * Password[2])
    
TextEncrypted[0][1] = (szPieces[0][1] * Password[1]) + (szPieces[0][1] * Password[3])
    
TextEncrypted[1][0] = (szPieces[1][0] * Password[0]) + (szPieces[1][1] * Password[2])
    
TextEncrypted[1][1] = (szPieces[1][1] * Password[1]) + (szPieces[1][1] * Password[3])
    
TextEncrypted[2][0] = (szPieces[2][0] * Password[0]) + (szPieces[2][1] * Password[2])
    
TextEncrypted[2][1] = (szPieces[2][1] * Password[1]) + (szPieces[2][1] * Password[3]) 



All times are GMT -4. The time now is 10:17.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.