26.08.2016, 14:23
Hello.
I have an issue with sscanf and storing a note in a enum.
this is my code
So, Barrier[i][Note] only stores the first word, instead of the whole string.
What's the problem and how to fix it?
I have an issue with sscanf and storing a note in a enum.
this is my code
PHP код:
/* ============================================================================ */
COMMAND:barrier(playerid, params[])
{
if(!Player[playerid][Authed]) return SendClientError(playerid, "You are not authed!");
if(!IsFed(playerid)) return SendClientError(playerid,"You are not authorized to use this command!");
new tmp[ 15 ], tmp2[ 15 ],tmp3[200];
if(sscanf(params, "szzz", tmp, tmp2,tmp3))
{
SendClientUsage(playerid,"/barrier [ Deploy / Destroy / List]");
}
else if(!strcmp(tmp, "deploy", true, 5))
{
new type;
if(!strlen(tmp2)) return SendClientUsage(playerid, "/barrier deploy [1/2/3/4] [Note]");
new barriertype = strval(tmp2);
if(barriertype == 1)
{
type=978;
}
else if(barriertype == 2)
{
type=978;
}
else if(barriertype == 3)
{
type=978;
}
else if(barriertype == 4)
{
type=978;
}
else
{
return SendClientUsage(playerid, "/barrier deploy [1/2/3/4] [Note]");
}
for(new i = 1; i < MAX_BARRIERS; i++)
{
if(!Barrier[i][bActive])
{
new Float:X, Float:Y, Float:Z, Float:A;
new string[400];
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, A);
Barrier[i][bObject] = CreateDynamicObject(type, X, Y, Z, 0.0, 0.0, A, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
Barrier[i][bLabel] = Create3DTextLabel(sprintf("Barrier ID %i",i),-1,X,Y,Z,10,GetPlayerVirtualWorld(playerid),0);
Barrier[i][bActive] = 1;
format(string,sizeof(string),"%s",tmp3);
myStrcpy(Barrier[i][Note],string);
SetPlayerPos(playerid, X-1, Y, Z+2);
SendClientMessage(playerid,-1,sprintf("Barrier ID %i has been deployed",i));
break;
}
}
}
else if(!strcmp(tmp, "destroy", true, 5))
{
new bid = strval(tmp2);
if(bid < 1 || bid > MAX_BARRIERS) return SendClientError(playerid,"Invalid barrier id.");
if(!Barrier[bid][bActive]) return SendClientError(playerid,"That barrier isn't deployed.");
DestroyDynamicObject(Barrier[bid][bObject]);
Delete3DTextLabel(Barrier[bid][bLabel]);
Barrier[bid][bActive] = 0;
SendClientMessage(playerid,-1,sprintf("Barrier ID %i has been destroyed.",bid));
}
else if(!strcmp(tmp, "list", true, 5))
{
for(new i = 1; i < MAX_BARRIERS; i++)
{
if(Barrier[i][bActive])
{
SendClientMessage(playerid,-1,sprintf("Barrier ID %i | Note: %s",i,Barrier[i][Note]));
}
}
}
else
{
SendClientUsage(playerid,"/barrier [ Deploy / Destroy / List]");
}
return 1;
}
/* ============================================================================= */
What's the problem and how to fix it?