Sunday, November 21, 2010

SAMP Scripting Tutorial: Factions | Multi-Dimensional Arrays

Here is the code

// Declarations and Defines
#define Passw 1
#define Skinid 2
#define Money 3
#define Faction 4
#define Job 5
#define AdminLevel 6
#define Level 7
///////////////////
#define Civilian 0
#define Police 1
#define Taxi 2
//-----------------//
new player[MAX_PLAYERS][8];

// OnPlayerSpawn
GivePlayerMoney(playerid,player[playerid][Money]);
SetPlayerScore(playerid,player[playerid][Level]);

// OnPlayerCommandText
if(strcmp(cmdtext,"/myfaction",true)==0)
{
 switch(player[playerid][Faction])
 {
  case 0: SendClientMessage(playerid,WHITE,"You are Civilian!");
  case 1: SendClientMessage(playerid,WHITE,"You are a Police Officer!");
  case 2: SendClientMessage(playerid,WHITE,"You are TaxiDriver!");
 }
 return 1;
}

// Read/Write Player Functions
ReadPlayer(players[][],playerid,maxset)
{
 new string[256],name[MAX_PLAYER_NAME];
 new File:acc;
 GetPlayerName(playerid,name,sizeof(name));
 format(string,256,"Players/%s.ini",name);
 acc = fopen(string, io_read);
 for(new i=1; i<maxset; i++)
 {
  fread(acc,string);
  if(i==1)
  {
   SetPVarString(playerid,"passw",string);
  }
  else players[playerid][i] = strval(string);
 }
 fclose(acc);
}

WritePlayer(text[],playerid, bool:filestart)
{
 new string[256],name[MAX_PLAYER_NAME];
 new File:acc;
 GetPlayerName(playerid,name,sizeof(name));
 format(string,256,"Players/%s.ini",name);
 acc = fopen(string, io_append);
 if(filestart)
 {
  fwrite(acc,text);
 }
 else
 {
  format(string,256,"\r\n%s",text);
  fwrite(acc,string);
 }
 fclose(acc);
}

1 comment:

  1. Hello

    You are awsome! But can you please put this apart whit your
    login/register sys because i tryed to put them apart but both of them comes whit errors.

    ReplyDelete