How can i check this?
#1

Hello,

I have tried for ages and ages now but i was wondering how i can check the string in this?

pawn Код:
new Lent[MAX_PLAYERS];
Btw i dont know how to make it a string AND use playerid
Anyway can someone tell me how i can set Lent to lets say "Torran0"
And how i can also check if it is "Torran0"

Thanks
Reply
#2

You want to make a multi-dimensional array and do some string comparison? Well here's a simple example.

pawn Код:
new Lent[MAX_PLAYERS][128]; // This initializes a multi-dimensional array with one cell of 500 length and a second cell with 128 length.
pawn Код:
if(strcmp(Lent[playerid],"Torran0",true) == 0) // Use strcmp to compare strings
{
    // The string stored in the playerid's cell in the Lent array is "Torran0"
}
Reply
#3

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
You want to make a multi-dimensional array and do some string comparison? Well here's a simple example.

pawn Код:
new Lent[MAX_PLAYERS][128]; // This initializes a multi-dimensional array with one cell of 500 length and a second cell with 128 length.
pawn Код:
if(strcmp(Lent[playerid],"Torran0",true) == 0) // Use strcmp to compare strings
{
    // The string stored in the playerid's cell in the Lent array is "Torran0"
}
How would i set it?
Reply
#4

The same way you'd do with any string except by adding in the playerid in the first cell.

Assuming you use GetPlayerName for example:

pawn Код:
GetPlayerName(playerid,Lent[playerid],sizeof(Lent[playerid]));
Reply
#5

Like this then?

pawn Код:
format(Lent, Lent[targetid], "Torran0");
Reply
#6

Quote:
Originally Posted by iTorran
Посмотреть сообщение
Like this then?

[pawn]format(Lent, Lent[targetid], "Torran0");/pawn]
No, like this.

pawn Код:
format(Lent[playerid],sizeof(Lent[playerid]),"Torran0");
Reply
#7

Код:
C:\Freeroam\Server\filterscripts\cars.pwn(103) : error 001: expected token: "]", but found "-identifier-"
C:\Freeroam\Server\filterscripts\cars.pwn(103) : warning 215: expression has no effect
C:\Freeroam\Server\filterscripts\cars.pwn(103) : error 001: expected token: ";", but found "]"
C:\Freeroam\Server\filterscripts\cars.pwn(103) : error 029: invalid expression, assumed zero
C:\Freeroam\Server\filterscripts\cars.pwn(103) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
Reply
#8

Thanks that worked but now i have another problem.

This code:

pawn Код:
else if(strcmp(Lent[playerid], "Torran0", true) == 0)
Is stopping the script from doing this:

pawn Код:
RemovePlayerFromVehicle(playerid);
Heres the whole callback:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new vehicleid = GetPlayerVehicleID(playerid);
       
        if(vehicleid == Torran[0])
        {
            if(strcmp(GetName(playerid), "JoeTorran", true) == 0 || strcmp(Lent[playerid], "Torran0", true) == 0)
            {
                print(" ");
            }
            else
            {
                RemovePlayerFromVehicle(playerid);
            }
        }
        else if(vehicleid == Torran[1])
        {
            if(strcmp(GetName(playerid), "JoeTorran", true) == 0 || strcmp(Lent[playerid], "Torran1", true) == 0)
            {
                print(" ");
            }
            else
            {
                RemovePlayerFromVehicle(playerid);
            }
        }
        else if(vehicleid == Tik[0])
        {
            if(strcmp(GetName(playerid), "Tik", true) == 0 || strcmp(Lent[playerid], "Tik0", true) == 0)
            {
                print(" ");
            }
            else
            {
                RemovePlayerFromVehicle(playerid);
            }
        }
        else if(vehicleid == Tik[1])
        {
            if(strcmp(GetName(playerid), "Tik", true) == 0 || strcmp(Lent[playerid], "Tik1", true) == 0)
            {
                print(" ");
            }
            else
            {
                RemovePlayerFromVehicle(playerid);
            }
        }
        else if(vehicleid == Tik[2])
        {
            if(strcmp(GetName(playerid), "Tik", true) == 0 || strcmp(Lent[playerid], "Tik2", true) == 0)
            {
                print(" ");
            }
            else
            {
                RemovePlayerFromVehicle(playerid);
            }
        }
    }
    return 1;
}
Like if i try and enter Tik[0] with the name JoeTorran it dosent kick me out but it should,
does anyone know why?
Reply
#9

I have my own that i made, Il merge them
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
OK, I'm just going to stop you there. I don't know why the code isn't working, but it's not important - you can't restrict access to vehicles based purely on name. SA:MP has no global name registration, so anyone can join your server with any name, including "Torran", or any of the other specified names. To do this you need a full user system with password protected accounts - there are plenty of those available in the release sections, get one of those, integrate it, then come back to this issue.
He sent me some code via PM regarding the "Lend[]" array, it's just a single-thingy array (Array[]): new Lent[MAX_PLAYERS];.

in that code he had the following:
pawn Код:
format(Lent, Lent[playerid], "Torran0");
What obviously isn't going to work rofl.

I'm trying to get him a workaround now (Won't be too hard) but I agree what you say about name registration ^^.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)