SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 18/01/2012, 08:26 AM   #1
Slice
High-roller
 
Join Date: Mar 2008
Location: Sweden
Posts: 1,835
Reputation: 1607
Spray pointers.inc - Pointers for PAWN!

Hey,

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:
new
    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.
    print(buf);
}

// Append all strings to szOutput
stock concat(output[], maxsize = sizeof(output), ...) {
    new
        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);
    }
}

Syntax:
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)

Download: pointers.inc

Last edited by Slice; 13/06/2012 at 02:09 PM.
Slice is offline   Reply With Quote
Old 18/01/2012, 08:33 AM   #2
Ronaldo_raul™
Gangsta
 
Ronaldo_raul™'s Avatar
 
Join Date: Jun 2010
Location: .
Posts: 999
Reputation: 67
Default Re: pointers.inc - Pointers for PAWN!

:O WTF ! omg this is fucking awesome.Great release Sir Slice as usual
Ronaldo_raul™ is offline   Reply With Quote
Old 18/01/2012, 08:39 AM   #3
SoUrAv
Little Clucker
 
Join Date: Jan 2012
Posts: 12
Reputation: 1
Default Re: pointers.inc - Pointers for PAWN!

That's great.
SoUrAv is offline   Reply With Quote
Old 18/01/2012, 08:43 AM   #4
[Nikk]
High-roller
 
[Nikk]'s Avatar
 
Join Date: Jun 2011
Location: Argentina.
Posts: 1,473
Reputation: 63
Default Respuesta: pointers.inc - Pointers for PAWN!

Exelent script for get to Hight Roller Exelent Include (999 Messages )
Good job
__________________


[Nikk] is offline   Reply With Quote
Old 18/01/2012, 08:50 AM   #5
Lorenc_
High-roller
 
Lorenc_'s Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 3,803
Reputation: 1160
Default Re: pointers.inc - Pointers for PAWN!

Excellent release!
__________________
Join the best Cops And Robbers in SA-MP, today. svr.sfcnr.com:7777

Lorenc_ is offline   Reply With Quote
Old 18/01/2012, 09:16 AM   #6
T0pAz
Guest
 
Posts: n/a
Default Re: pointers.inc - Pointers for PAWN!

I was waiting for this! But I cannot give you rep
  Reply With Quote
Old 18/01/2012, 09:48 AM   #7
CaHbKo
Huge Clucker
 
Join Date: Nov 2007
Posts: 399
Reputation: 41
Default Re: pointers.inc - Pointers for PAWN!

Could someone give me an example of what it can be used for?
CaHbKo is offline   Reply With Quote
Old 18/01/2012, 10:20 AM   #8
[S]trong
Guest
 
Posts: n/a
Default Re: pointers.inc - Pointers for PAWN!

Thank you dude, this is f*ucking awesome!
  Reply With Quote
Old 18/01/2012, 10:23 AM   #9
steki.
High-roller
 
steki.'s Avatar
 
Join Date: Nov 2010
Location: São Paulo, Brasil
Posts: 2,557
Reputation: 315
Default Re: pointers.inc - 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] ?
__________________
Rio
steki. is offline   Reply With Quote
Old 18/01/2012, 11:07 AM   #10
Niko_boy
High-roller
 
Niko_boy's Avatar
 
Join Date: Aug 2010
Location: Somewhere i belong
Posts: 1,338
Reputation: 138
Default Re: pointers.inc - Pointers for PAWN!

OmMa GawD Freaka amaaaaazing!
__________________
nope[IMG]http://*******/1r0SOkH_[/IMG]
•••[CLOSED]LCS•Freeroam•DM•Stunts•••AutoArena [0.3z][No SkinShot][sixtytiger.com]Want a decent Attack Defend Gamemode?
N/A176.31.229.148:7830Get This! Attack-Defend(v2.3.1)
Niko_boy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New to pawn, trying to convert some C code to pawn CHC Scripting Help 2 22/06/2012 05:09 AM
[HELP] [pawn][/pawn] bbcode for phpbb3 Kasura Help Archive 4 20/11/2010 04:35 AM
getting this tommorow!!!need a few pointers!! SAMPfan109 General 4 04/03/2010 08:14 PM
Pointers to an admin IRC bot Michael_Corleone Help Archive 5 21/07/2009 11:05 AM


All times are GMT. The time now is 11:09 AM.


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