SA-MP Forums Archive
string into array - 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)
+--- Thread: string into array (/showthread.php?tid=665700)



string into array - ghostbalkan - 13.04.2019

CODE:
Code:
CMD:vipboja(playerid, const params[])
{
	if(vip_Info[playerid][VIPBodovi] <= 0)
        return SendClientMessage(playerid, vip_Info[playerid][VIPBoja], "VIP | {FFFFFF}Nemate VIP bodova.");

    extract params -> new string:vipboja[11]; else
	{
        return SendClientMessage(playerid, vip_Info[playerid][VIPBoja], "VIP | {FFFFFF}/vipboja (boja - primjer 0x8b9940FF)");
    }

    strins(vipboja, vip_Info[playerid][VIPBodovi], 0);
    vip_Info[playerid][VIPBodovi] --;
    
	format(game_string, sizeof(game_string), "VIP | {FFFFFF}Postavili ste sebi VIP boju  na %s.", vipboja);
	SendClientMessage(playerid, vip_Info[playerid][VIPBoja], game_string);
	game_string[0] = EOS;
	format(game_string, sizeof(game_string), "VIP | {FFFFFF}Trenutni VIP bodovi %i", vip_Info[playerid][VIPBodovi]);
	SendClientMessage(playerid, vip_Info[playerid][VIPBoja], game_string);
	game_string[0] = EOS;
	return true;
}
my brain just blocked lmao
https://imgur.com/BgNfvrP and the string when I print it is that letter y.


Re: string into array - coool - 13.04.2019

Can you give a detailed explanation of the bug that is occurring to you?

Strings are arrays. Maybe, look into this wiki article about "string into array" https://wiki.alliedmods.net/index.ph...torial#Strings


Re: string into array - ghostbalkan - 13.04.2019

I fixed it on this way
Code:
CMD:vipboja(playerid, const params[])
{
	if(vip_Info[playerid][VIPBodovi] <= 0)
        return SendClientMessage(playerid, vip_Info[playerid][VIPBoja], "VIP | {FFFFFF}Nemate VIP bodova.");

    extract params -> new string:vipboja[11]; else
	{
        return SendClientMessage(playerid, vip_Info[playerid][VIPBoja], "VIP | {FFFFFF}/vipboja (boja - primjer 0x8b9940FF)");
    }

    strcpy(vip_Info[playerid][VIPBoja], vipboja, sizeof(vipboja));
    vip_Info[playerid][VIPBodovi] --;
    
	format(game_string, sizeof(game_string), "VIP | {FFFFFF}Postavili ste sebi VIP boju  na %s.", vipboja);
	SendClientMessage(playerid, vip_Info[playerid][VIPBoja], game_string);
	game_string[0] = EOS;
	format(game_string, sizeof(game_string), "VIP | {FFFFFF}Trenutni VIP bodovi %i", vip_Info[playerid][VIPBodovi]);
	SendClientMessage(playerid, vip_Info[playerid][VIPBoja], game_string);
	game_string[0] = EOS;
	return true;
}
Code:
strcpy(dest[], src[], size = sizeof(dest))
{
    dest[0] = EOS;
    return strcat(dest, src, size);
}
it is working now but color is always black?
I put VIP Color ein enumator and I SendClientMessage like this
Code:
	format(game_string, sizeof(game_string), "VIP | {FFFFFF}Postavili ste sebi VIP boju na %s.", vipboja);
	SendClientMessage(playerid, vip_Info[playerid][VIPBoja], game_string);


I am really confused rn haha


Re: string into array - TokicMajstor - 13.04.2019

Quote:
Originally Posted by ghostbalkan
View Post
I fixed it on this way
Code:
CMD:vipboja(playerid, const params[])
{
	if(vip_Info[playerid][VIPBodovi] <= 0)
        return SendClientMessage(playerid, vip_Info[playerid][VIPBoja], "VIP | {FFFFFF}Nemate VIP bodova.");

    extract params -> new string:vipboja[11]; else
	{
        return SendClientMessage(playerid, vip_Info[playerid][VIPBoja], "VIP | {FFFFFF}/vipboja (boja - primjer 0x8b9940FF)");
    }

    strcpy(vip_Info[playerid][VIPBoja], vipboja, sizeof(vipboja));
    vip_Info[playerid][VIPBodovi] --;
    
	format(game_string, sizeof(game_string), "VIP | {FFFFFF}Postavili ste sebi VIP boju  na %s.", vipboja);
	SendClientMessage(playerid, vip_Info[playerid][VIPBoja], game_string);
	game_string[0] = EOS;
	format(game_string, sizeof(game_string), "VIP | {FFFFFF}Trenutni VIP bodovi %i", vip_Info[playerid][VIPBodovi]);
	SendClientMessage(playerid, vip_Info[playerid][VIPBoja], game_string);
	game_string[0] = EOS;
	return true;
}
Code:
strcpy(dest[], src[], size = sizeof(dest))
{
    dest[0] = EOS;
    return strcat(dest, src, size);
}
it is working now but color is always black?
I put VIP Color ein enumator and I SendClientMessage like this
Code:
	format(game_string, sizeof(game_string), "VIP | {FFFFFF}Postavili ste sebi VIP boju na %s.", vipboja);
	SendClientMessage(playerid, vip_Info[playerid][VIPBoja], game_string);


I am really confused rn haha
Aj brate pisi priv, objasnit cu ti.


Re: string into array - ghostbalkan - 13.04.2019

anyone any solution?


Re: string into array - SyS - 14.04.2019

I'm not sure what you trying to achieve.. But my best guess would be
Are you trying to convert hexadecimal value in string to integer?


Re: string into array - NaS - 14.04.2019

If you want to extract the color from the string you can use sscanf (using the x specifier for hexadecimal). You can also change your extract line to use hex instead of string (not sure if "hex" is the actual name since I mostly use the sscanf function).