SA-MP Forums

SA-MP Forums (
-   Includes (
-   -   [Include] - Pointers for PAWN! (

Slice 18/01/2012 08:26 AM - Pointers for PAWN!

Here's a neat implementation of pointers for PAWN! This include makes it a lot easier to deal with variadic functions (functions that can take a varying number of arguments), but also allows you to, for example, have pointers from large enum structures into other arrays, parts of strings, etc.
One example would be to have an array for player gangs, then use a pointer from a player array into the player's gang (think C structures, sort of).

A quick example:
pawn Code:
    g_Test[] = {123, 456, 789}

public OnGameModeInit() {
    new address = GetVariableAddress(g_Test);
    // Change the 2nd value
    @ptr[address][1] = 444;
    // Print out the values
    printf("%d, %d, %d", @ptr[address][0], @ptr[address][1], @ptr[address][2]);

Here's an example of a function that appends all string arguments to a given string.
pawn Code:
public OnGameModeInit() {
    new buf[128] = "Lorem";
    concat(buf, sizeof(buf), "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing.");
    // Prints out: Lorem ipsum dolor sit amet, consectetur adipiscing.

// Append all strings to szOutput
stock concat(output[], maxsize = sizeof(output), ...) {
        arg_count = numargs()
    for (new i = 2; i < arg_count; i++) {
        // First add a space
        strcat(output, " ", maxsize);
        // Then add the string
        strcat(output, @arg[i], maxsize);

pawn Code:
@ptr[address] // This is now a pointer to "address"
@arg[2] // This is now a pointer to the 3rd argument (0 is the first)


Ronaldo_raul™ 18/01/2012 08:33 AM

Re: - Pointers for PAWN!
:O WTF ! omg this is fucking awesome.Great release Sir Slice as usual ;D

SoUrAv 18/01/2012 08:39 AM

Re: - Pointers for PAWN!
That's great.

[Nikk] 18/01/2012 08:43 AM

Respuesta: - Pointers for PAWN!
Exelent script for get to Hight Roller :D Exelent Include :D (999 Messages :D)
Good job

Lorenc_ 18/01/2012 08:50 AM

Re: - Pointers for PAWN!
Excellent release!

T0pAz 18/01/2012 09:16 AM

Re: - Pointers for PAWN!
I was waiting for this! But I cannot give you rep :(

CaHbKo 18/01/2012 09:48 AM

Re: - Pointers for PAWN!
Could someone give me an example of what it can be used for?

[S]trong 18/01/2012 10:20 AM

Re: - Pointers for PAWN!
Thank you dude, this is f*ucking awesome!

steki. 18/01/2012 10:23 AM

Re: - Pointers for PAWN!
Can I point a part of an array to make it easier, like:
The variable: PlayerInfo[playerid][gPlayerPos][3].

I make a pointer _point that points to PlayerInfo[playerid] and I just use (example) _point[gPlayerPos][3] ?

Niko_boy 18/01/2012 11:07 AM

Re: - Pointers for PAWN!
OmMa GawD Freaka amaaaaazing!

All times are GMT. The time now is 07:56 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.