View Single Post
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-17-2012 , 15:21   Re: [EXTENSION] SHVector with example usage
Reply With Quote #43

For people who want to port code from shvector to adt_array, here's how the commands map to adt_array:

PHP Code:
// Handle:vector = SHVectorCreate(TYPE_CELL);
new Handle:array = CreateArray();

// Handle:vector = SHVectorCreate(TYPE_STRING);
new Handle:array = CreateArray(ByteCountToCells(64)); // for 64 character strings

// SHVectorFree_Cell(vector);
// SHVectorFree_String(vector);
CloseHandle(array);

// new value = SHVectorAt_Cell(vector, pos);
new value GetArrayCell(array, pos);

// new Handle:value = SHVectorAt_Cell(vector, pos);
new Handle:value Handle:GetArrayCell(array, pos);
// GetArrayFloat also exists

decl String:myString[64];
// SHVectorAt_String(vector, pos, myString, sizeof(myString));
GetArrayString(array, posmyStringsizeof(myString));

// SHVectorSetAt_Cell(vector, pos, value);
SetArrayCell(array, posvalue)
PushArrayCell(array, value); // To add new items to the end of the array
//SetArrayFloat and PushArrayFloat also exist

// SHVectorSetAt_String(vector, pos, value);
SetArrayString(array, posvalue);
PushArrayString(array, value); // To add new items to the end of the array

// SHVectorClear_Cell(vector);
// SHVectorClear_String(vector)
ClearArray(array);

// if (SHVectorIsEmpty_Cell(vector))
// if (SHVectorIsEmpty_String(vector))
if (GetArraySize(array) == 0)

// SHVectorSwap_Cell(vector, pos1, pos2)
// SHVectorSwap_String(vector, pos1, pos2)
SwapArrayItems(array, pos1pos2)

// SHVectorInsert_Cell(vector, where, value);
InsertArrayCell(array, wherevalue)
// InsertArrayFloat also exists

// SHVectorInsert_String(vector, where, value);
InsertArrayString(array, wherevalue);

// SHVectorErase_Cell(vector, pos);
// SHVectorErase_String(vector, pos)
RemoveFromArray(array, pos);

// SHVectorSize_Cell(vector)
// SHVectorSize_String(vector)
GetArraySize(vector
Keep in mind that you can't SetArrayCell or SetArrayString to cells that don't exist... you can ResizeArray(array, 30) to resize the array to have 30 elements (for example) which will create new, empty values in the array is smaller than 30 (or get rid of elements past pos 29 if larger than 30). You can also ShiftArrayUp(array, pos) to create a new empty value in the middle of an array at position pos
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 11-17-2012 at 15:28.
Powerlord is offline