if(strcmp(cmd, "/accent", true) == 0)
{
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[128];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /accent [accentid] (Type /accents for a list of accents)");
return 1;
}
new chooseaccent;
chooseaccent = strval(tmp);
if(chooseaccent == 0)
{
GameTextForPlayer(playerid, "Accent changed to English", 5000, 5);
accent[playerid] = 0;
return 1;
}
else if(chooseaccent == 1)
{
GameTextForPlayer(playerid, "Accent changed to Russian", 5000, 5);
accent[playerid] = 1;
return 1;
}
else if(chooseaccent == 2)
{
GameTextForPlayer(playerid, "Accent changed to Italian", 5000, 5);
accent[playerid] = 2;
return 1;
}
else if(chooseaccent == 3)
{
GameTextForPlayer(playerid, "Accent changed to Gangster", 5000, 5);
accent[playerid] = 3;
return 1;
}
else if(chooseaccent == 4)
{
GameTextForPlayer(playerid, "Accent changed to French", 5000, 5);
accent[playerid] = 4;
return 1;
}
else if(chooseaccent == 5)
{
GameTextForPlayer(playerid, "Accent changed to Japanese", 5000, 5);
accent[playerid] = 5;
return 1;
}
else if(chooseaccent == 6)
{
GameTextForPlayer(playerid, "Accent changed to Korean", 5000, 5);
accent[playerid] = 6;
return 1;
}
else if(chooseaccent == 7)
{
GameTextForPlayer(playerid, "Accent changed to Chinese", 5000, 5);
accent[playerid] = 7;
return 1;
}
else
{
SendClientMessage(playerid, COLOR_RED, "That isn't a valid accent ID!");
return 1;
}
}
|
Originally Posted by Antonio (dominationrp.netii.net)
So, im trying to create an accents section for my script. Im basicly done everything but I cant quite grasp the whole strval(tmp) stuff...
What Im trying to do is.. for example you type /accent 2 it would switch you to Italian (in my code) but it always goes to english... any help? Код:
if(strcmp(cmd, "/accent", true) == 0)
{
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[128];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /accent [accentid] (Type /accents for a list of accents)");
return 1;
}
new chooseaccent;
chooseaccent = strval(tmp);
if(chooseaccent == 0)
{
GameTextForPlayer(playerid, "Accent changed to English", 5000, 5);
accent[playerid] = 0;
return 1;
}
else if(chooseaccent == 1)
{
GameTextForPlayer(playerid, "Accent changed to Russian", 5000, 5);
accent[playerid] = 1;
return 1;
}
else if(chooseaccent == 2)
{
GameTextForPlayer(playerid, "Accent changed to Italian", 5000, 5);
accent[playerid] = 2;
return 1;
}
else if(chooseaccent == 3)
{
GameTextForPlayer(playerid, "Accent changed to Gangster", 5000, 5);
accent[playerid] = 3;
return 1;
}
else if(chooseaccent == 4)
{
GameTextForPlayer(playerid, "Accent changed to French", 5000, 5);
accent[playerid] = 4;
return 1;
}
else if(chooseaccent == 5)
{
GameTextForPlayer(playerid, "Accent changed to Japanese", 5000, 5);
accent[playerid] = 5;
return 1;
}
else if(chooseaccent == 6)
{
GameTextForPlayer(playerid, "Accent changed to Korean", 5000, 5);
accent[playerid] = 6;
return 1;
}
else if(chooseaccent == 7)
{
GameTextForPlayer(playerid, "Accent changed to Chinese", 5000, 5);
accent[playerid] = 7;
return 1;
}
else
{
SendClientMessage(playerid, COLOR_RED, "That isn't a valid accent ID!");
return 1;
}
}
|
COMMAND:accent( playerid, params[] )
{
// For multiple parameters, use sscanf. But we're only going to be parsing one.
switch( strval( params ) ) // Use switch statements where possible for integers.
{
case 1:
{
accent[ playerid ] = 1;
SendClientMessage( playerid, WHITE, "You're now speaking in Russian" );
}
case 2:
{
accent[ playerid ] = 2;
SendClientMessage( playerid, WHITE, "You're now speaking in Italian" );
}
case 3:
{
accent[ playerid ] = 3;
SendClientMessage( playerid, WHITE, "You're now speaking in Gangster" );
}
case 4:
{
accent[ playerid ] = 4;
SendClientMessage( playerid, WHITE, "You're now speaking in French" );
}
case 5:
{
accent[ playerid ] = 5;
SendClientMessage( playerid, WHITE, "You're now speaking in Japanese" );
}
case 6:
{
accent[ playerid ] = 6;
SendClientMessage( playerid, WHITE, "You're now speaking in Korean" );
}
case 7:
{
accent[ playerid ] = 7;
SendClientMessage( playerid, WHITE, "You're now speaking in Chinese" );
}
default:
{
SendClientMessage( playerid, WHITE, "Invalid accent ID (use /accents)." );
}
}
return 1;
}
|
Originally Posted by Antonio (dominationrp.netii.net)
Its nice, but I prefer to stay with the old kind of scripting.
|
|
Originally Posted by Antonio (dominationrp.netii.net)
Its nice, but I prefer to stay with the old kind of scripting.
|
Lazyness? I'm in the middle of converting my gamemode to sscanf(2.0) and ZCMD and I have to say it's really nice. I bet your script is an RP mode, right? I don't get why mostly if not all RP server creators even now, still prefer to use all the old, tired functions to process commands and scripture .. it's beyond me. I told myself that after SA:MP had updated to 0.3 (I created my GM a few months before 0.2x ended) that I'd update to ZCMD and sscanf, and now that I have (or am in the middle of doing) I wouldn't turn back. NO chance! :P