Setproperty

From SA-MP Wiki

Jump to: navigation, search

setproperty

Image:Farm-Fresh text lowercase.png Note: This function name starts with a lowercase letter.


Description:

Add a new property or change an existing property.


Parameters:
(id=0, const name[]="", value=cellmin, const string[]="")
idThe virtual machine to use, you should keep this zero.
name[]Used in combination with value when storing integers; don't use this if you want to store a string.
valueThe integer value to store or the property's unique ID if storing a string. Use the hash-function to calculate it from a string.
string[]The value of the property, as a string. Don't use this if you want to store an integer.


Return Values:

This function does not return any specific values.


Storing Integers

setproperty(.name = "MyInteger", .value = 42);
 
new value = getproperty(.name = "MyInteger");
printf("Value that was stored is: %d", value);

Storing Strings

setproperty(0, "", 123984334, ":)");
 
new value[4];
getproperty(0, "", 123984334, value);
strunpack(value, value, sizeof(value)); // we need to unpack the string first
print(value);
 
//should print :)

Or... seeing as all the parameters are optional, a piece of code like this similar:

setproperty(.value = 123984334, .string = ":)");
 
// The rest is the same as above.

Related Functions

The following functions may be useful, as they are related to this function in one way or another.