Split a sting?
#1

Hello!

I have one file, where are allowed skin numbers and they are seperated by comma. (e.g. 24,25,26,27)
The question is, how can I split this values to use them in FOR loop for classes.

Please help.
Reply
#2

i grabbed this from somewhere off of the forums i don't know who made it but credits to them

Код:
// Skins
#define MIN_SKIN_ID		0
#define MAX_SKIN_ID		299
IsInvalidSkin(skinid)
{  
	#define	MAX_BAD_SKINS  14

	new badSkins[MAX_BAD_SKINS] = {
		3, 4, 5, 6, 8, 42, 65, 74, 86,
		119, 149, 208, 273, 289
	};

	for (new i = 0; i < MAX_BAD_SKINS; i++) {
	  if (skinid == badSkins[i]) return true;
	}

	return false;
}
just shove that in your script somewhere and an example of it in use is :

Код:
if (IsInvalidSkin(moneys[playerid]) || moneys[playerid] < MIN_SKIN_ID || moneys[playerid] > MAX_SKIN_ID)
			{
		    GetPlayerName(ClickedPlayerID[playerid], clickedplayer, sizeof(clickedplayer));
		    format(string, sizeof(string), "Set Skin - %s (ID:%d)",clickedplayer,ClickedPlayerID[playerid]);
		    format(string2, sizeof(string2), "Current Skin: %d\n\nInvalid Skin ID\n\nEnter Skin ID:",GetPlayerSkin(ClickedPlayerID[playerid]));
		    ShowPlayerDialog(playerid, 20, DIALOG_STYLE_INPUT,string,string2,"Set Skin", "Back");
	  		return 1;
			}
this is for my dialogs to check that the player hasn't input a bad skin

i hope this helps


EDIT: i didnt read the post properly if you want to split try using case: ?
Reply
#3

Use this under your OnGameModeInit

pawn Код:
for(new i = 0; i < 299; i++)
  {
    if(IsValidSkin(i))
    {
      AddPlayerClass(i,0.0,0.0,0.0,0.0,0,0,0,0,0,0);
    }
  }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)