SA-MP Forums Archive
Split a sting? - 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: Split a sting? (/showthread.php?tid=139250)



Split a sting? - MummyKillerSLO - 04.04.2010

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.


Re: Split a sting? - Beaver07 - 04.04.2010

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: ?


Re: Split a sting? - Backwardsman97 - 04.04.2010

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);
    }
  }