A new question - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: A new question (
/showthread.php?tid=78936)
A new question -
LTomi - 24.05.2009
Hi!
I want to make a script, that searches a character in the name of the player, and returns with the number of the searched character. I have a RP gamemode, and I don't want to allow people to register with names that have more than 1 _ characters. In the basic gamemode, there's a script that don't allows the register with names without _ character, but you can register with names with any _ characters.
I tryed this, but I can't compile it:
Код:
public OnPlayerConnect(playerid)
{
new plname[MAX_PLAYER_NAME];
GetPlayerName(playerid, plname, sizeof(plname));
split(plname, playernamesplit, '_');
if(Security != 0)
{
SendClientMessage(playerid, COLOR_YELLOW, "Host has broken one of the Agreement rules, action has been taken.");
Kick(playerid);
return 1;
}
new namestring = strfind(plname, "_", true);
if(namestring == -1)
{
SendClientMessage(playerid, COLOR_YELLOW2, "Immigration Department: Your name is not acceptable.");
SendClientMessage(playerid, COLOR_YELLOW2, "Hint: Your name must be in the format Firstname_Lastname.");
Kick(playerid);
return 1;
}
else if(playernamesplit >= 2)
{
SendClientMessage(playerid, COLOR_YELLOW2, "Immigration Department: Your name is not acceptable.");
SendClientMessage(playerid, COLOR_YELLOW2, "Hint: Your name must be in the format Firstname_Lastname.");
Kick(playerid);
return 1;
}
[...]
return 1;
}
Compiling:
Код:
C:\Documents and Settings\LTomi\My Documents\Server\gamemodes\rpg.pwn(2900) : error 033: array must be indexed (variable "playernamesplit")
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
1 Error.
Sorry for my bad English.
Re: A new question -
LTomi - 24.05.2009
Anybody?
Please help me!
Re: A new question -
yom - 24.05.2009
Use a function such as this, to count the _ in the name:
pawn Код:
chrcount(str[], chr)
{
new c;
for (new i, j = strlen(str); i < j; i++)
if (str[i] == chr)
c++;
return c;
}
Use like this:
pawn Код:
new c = chrcount(plname, '_');
if (c == 0) // no "_" in the name
Kick(playerid);
Re: A new question -
LTomi - 24.05.2009
Thanks man!