All pastes #1589917 Raw Edit

Someone

public cpp v1 · immutable
#1589917 ·published 2009-10-02 21:18 UTC
rendered paste body
#include <a_samp>#define dcmd(%1,%2,%3) if((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1#define RED 0xFF0000AA#define GREEN 0x33AA33AA#define WHITE 0xFFFFFFFFpublic OnPlayerCommandText(playerid, cmdtext[]){	dcmd(l, 1, cmdtext);	dcmd(s, 1, cmdtext);	return 0;}dcmd_s(playerid, cmdtext[]){   	new idx;	new tmp[128];	tmp = strtok(cmdtext, idx, ' ');	if(!strlen(tmp))	{		SendClientMessage(playerid, WHITE, "UŻYJ: /s [Nazwa].");		return 1;	}	if(strlen(tmp) <= 30)	{	    new str[100];		new Nick[MAX_PLAYER_NAME];		GetPlayerName(playerid, Nick, sizeof(Nick));		format(str, sizeof(str), "%s.tp", Nick);		if(!fexist(str))		{			new File:Plik = fopen(str, io_write);			fclose(Plik);		}		if(SzukajWpisu(Nick, tmp) == 0)		{		    new Float:Koordy[3];		    GetPlayerPos(playerid, Koordy[0], Koordy[1], Koordy[2]);			new File:Plik = fopen(str, io_append);			format(str, sizeof(str), "%s-%f,%f,%f,\r\n", tmp, Koordy[0], Koordy[1], Koordy[2]);			fwrite(Plik, str);			fclose(Plik);			format(str, sizeof(str), "Pozycja o nazwie %s została zapisana!", tmp);			SendClientMessage(playerid, GREEN, str);		}	}	else	    SendClientMessage(playerid, RED, "Nazwa nie może być dłuższa niż 30 znaków!");	return 1;}dcmd_l(playerid, cmdtext[]){   	new idx;	new tmp[128];	tmp = strtok(cmdtext, idx, ' ');	if(!strlen(tmp))	{		SendClientMessage(playerid, WHITE, "UŻYJ: /l [Nazwa].");		return 1;	}	new Nick[MAX_PLAYER_NAME];	GetPlayerName(playerid, Nick, sizeof(Nick));	if(strlen(tmp) <= 30)	{	    new str[100];	    format(str, sizeof(str), "%s.tp", Nick);		if(!fexist(str))		{			new File:Plik = fopen(str, io_write);			fclose(Plik);		}	    if(SzukajWpisu(Nick, tmp) == 1)	    {	        new Float:Koordy[3];	        Extract(Nick, tmp, Koordy[0], Koordy[1], Koordy[2]);	        SetPlayerPos(playerid, Koordy[0], Koordy[1], Koordy[2]);	        format(str, sizeof(str), "Pozycja %s została wczytana!", tmp);			SendClientMessage(playerid, GREEN, str);	    }	    else	    	SendClientMessage(playerid, RED, "Wpis nie został odnaleziony!");	}	else	    SendClientMessage(playerid, RED, "Nazwa nie może być dłuższa niż 30 znaków!");	return 1;}SzukajWpisu(Nick[], const Wpis[]) //By Przemcio{	new tmp[128];	strcat(Nick, ".tp", 30);  	new File:Plik = fopen(Nick, io_read);   	while(fread(Plik, tmp, sizeof(tmp)))    {    	new idx;     	tmp = strtok(tmp, idx, '-');		if(strcmp(tmp, Wpis, true) == 0)		    return 1;	}	fclose(Plik);	return 0;}Extract(Nick[], const Wpis[], &Float:X, &Float:Y, &Float:Z) //By Przemcio{    new tmp[128];    new tmp2[128];  	new File:Plik = fopen(Nick, io_read);   	while(fread(Plik, tmp, sizeof(tmp)))    {    	new idx;     	tmp2 = strtok(tmp, idx, '-');		if(strcmp(tmp2, Wpis, true) == 0)		{			X = floatstr(strtok(tmp, idx, ','));			Y = floatstr(strtok(tmp, idx, ','));			Z = floatstr(strtok(tmp, idx, ','));		}	}}strtok(const string[], &index, seperator = ' ') //By Jan "DracoBlue" Schütze (Optimized by Przemcio){	new length = strlen(string);	new offset = index;	new result[128];	while((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))	{		result[index - offset] = string[index];		index++;	}	result[index - offset] = EOS;    index = (index < length) && (string[index] == seperator) ? index + 1 : index;	return result;}