SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 15/06/2012, 08:41 AM   #51
zgintasz
Huge Clucker
 
Join Date: Oct 2011
Posts: 394
Reputation: 8
Default Re: Plugin development guide

What the hell... I'm just trying to use invoke and here is my results . Please, help someone.



Code:
#include "SDK\amx\amx.h"
#include "SDK\plugincommon.h"

#include "Invoke.h"

typedef void (*logprintf_t)(char* format, ...);


logprintf_t logprintf;
extern void *pAMXFunctions;


cell AMX_NATIVE_CALL HelloWorld(AMX* amx, cell* params)
{
    logprintf("This was printed from the Test plugin! Yay!");
    return 1;
}

PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() 
{
    return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
}

PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) 
{
	invoke = new Invoke;
    pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
    logprintf = (logprintf_t) ppData[PLUGIN_DATA_LOGPRINTF];

    logprintf(" * Test plugin was loaded.");

    return true;
}

PLUGIN_EXPORT void PLUGIN_CALL Unload()
{
    logprintf(" * Test plugin was unloaded.");
}

AMX_NATIVE_INFO PluginNatives[] =
{
    {"HelloWorld", HelloWorld},
    {0, 0}
};

PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx ) 
{
	invoke->amx_list.push_back(amx);
    return amx_Register(amx, PluginNatives, -1);
}


PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx ) 
{
	for (std::list<AMX *>::iterator i = invoke->amx_list.begin(); i != invoke->amx_list.end(); ++i)
	{
	    if (* i == amx)
		{
			invoke->amx_list.erase(i);
			break;
		}
	}
    return AMX_ERR_NONE;
}
zgintasz is offline   Reply With Quote
Old 15/06/2012, 08:57 AM   #52
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 17,548
Reputation: 2438
Default Re: Plugin development guide

Have you tried compiling? Those look like IntelliSense errors, which are not always accurate.
Y_Less is offline   Reply With Quote
Old 15/06/2012, 09:18 AM   #53
Cassandra
Little Clucker
 
Cassandra's Avatar
 
Join Date: Jun 2012
Location: Seriously??
Posts: 13
Reputation: 0
Default Re: Plugin development guide

Quote:
Originally Posted by zgintasz View Post
What the hell... I'm just trying to use invoke and here is my results . Please, help someone.



Code:
#include "SDK\amx\amx.h"
#include "SDK\plugincommon.h"

#include "Invoke.h"

typedef void (*logprintf_t)(char* format, ...);


logprintf_t logprintf;
extern void *pAMXFunctions;


cell AMX_NATIVE_CALL HelloWorld(AMX* amx, cell* params)
{
    logprintf("This was printed from the Test plugin! Yay!");
    return 1;
}

PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports() 
{
    return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
}

PLUGIN_EXPORT bool PLUGIN_CALL Load(void **ppData) 
{
	invoke = new Invoke;
    pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
    logprintf = (logprintf_t) ppData[PLUGIN_DATA_LOGPRINTF];

    logprintf(" * Test plugin was loaded.");

    return true;
}

PLUGIN_EXPORT void PLUGIN_CALL Unload()
{
    logprintf(" * Test plugin was unloaded.");
}

AMX_NATIVE_INFO PluginNatives[] =
{
    {"HelloWorld", HelloWorld},
    {0, 0}
};

PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx ) 
{
	invoke->amx_list.push_back(amx);
    return amx_Register(amx, PluginNatives, -1);
}


PLUGIN_EXPORT int PLUGIN_CALL AmxUnload( AMX *amx ) 
{
	for (std::list<AMX *>::iterator i = invoke->amx_list.begin(); i != invoke->amx_list.end(); ++i)
	{
	    if (* i == amx)
		{
			invoke->amx_list.erase(i);
			break;
		}
	}
    return AMX_ERR_NONE;
}
It looks like you are using VS 2010. Can you try compiling manually using GCC++ from Command Prompt?
__________________
XNA Developer.

Current Project: Perplexity Game Engine
Cassandra is offline   Reply With Quote
Old 15/06/2012, 09:30 AM   #54
zgintasz
Huge Clucker
 
Join Date: Oct 2011
Posts: 394
Reputation: 8
Default Re: Plugin development guide

Quote:
Originally Posted by Y_Less View Post
Have you tried compiling? Those look like IntelliSense errors, which are not always accurate.
Yes, I tried and I get these errors :
Code:
1>------ Build started: Project: C++_iScreenFader, Configuration: Debug Win32 ------
1>  main.cpp
1>f:\program files\microsoft visual studio 10.0\vc\include\malloc.h(251): warning C4005: 'alloca' : macro redefinition
1>          c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\sdk\amx\amx.h(87) : see previous definition of 'alloca'
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(26): error C2065: 'invoke' : undeclared identifier
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(48): error C2065: 'invoke' : undeclared identifier
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(48): error C2227: left of '->amx_list' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(48): error C2228: left of '.push_back' must have class/struct/union
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(55): error C2065: 'invoke' : undeclared identifier
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(55): error C2227: left of '->amx_list' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(55): error C2228: left of '.begin' must have class/struct/union
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(55): error C2065: 'invoke' : undeclared identifier
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(55): error C2227: left of '->amx_list' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(55): error C2228: left of '.end' must have class/struct/union
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(59): error C2065: 'invoke' : undeclared identifier
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(59): error C2227: left of '->amx_list' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\gintautas\documents\visual studio 2010\projects\c++_iscreenfader\c++_iscreenfader\main.cpp(59): error C2228: left of '.erase' must have class/struct/union
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Quote:
Originally Posted by Cassandra View Post
It looks like you are using VS 2010. Can you try compiling manually using GCC++ from Command Prompt?
I'm using VC++ 2010 Express... Can you give me a link to tutorial(or something), because I didn't used GCC++ and I don't know how to do that .
zgintasz is offline   Reply With Quote
Old 25/06/2012, 04:53 PM   #55
Rancho
Big Clucker
 
Join Date: Jun 2012
Location: Turkey / GTATurk
Posts: 56
Reputation: 50
Default Re: Plugin development guide

Hello, I'm trying to make something..
C++:
Code:
int playerid = params[1];
	int idx;
	if(!amx_FindPublic(amx,"__GetPlayerName",&idx)){
		cell ret;
		cell* str_phys;
		cell amxaddr;
		amx_Push(amx,playerid);
		amx_Allot(amx,24,&amxaddr,&str_phys);
		
		amx_Push(amx,amxaddr);
		amx_Exec(amx,&ret,idx);

		char name[24];
		amx_GetString(name,str_phys,0,24);
		amx_Release(amx,amxaddr);
		printf("%s",name);
	}else{
		printf("Native");
	}
Pawn:
Code:
forward __GetPlayerName(playerid,name[]);
public __GetPlayerName(playerid,name[]){
	GetPlayerName(playerid,name,MAX_PLAYER_NAME);
}
It doesn't crash but prints player name: "" (empty)

P.S: I don't want to use invoke or gdk.I want to make this.
P.S: playerid is correct.I tested.
Rancho is offline   Reply With Quote
Old 05/07/2012, 04:03 PM   #56
Rancho
Big Clucker
 
Join Date: Jun 2012
Location: Turkey / GTATurk
Posts: 56
Reputation: 50
Default Re: Plugin development guide

Quote:
Originally Posted by Rancho View Post
Hello, I'm trying to make something..
C++:
Code:
int playerid = params[1];
	int idx;
	if(!amx_FindPublic(amx,"__GetPlayerName",&idx)){
		cell ret;
		cell* str_phys;
		cell amxaddr;
		amx_Push(amx,playerid);
		amx_Allot(amx,24,&amxaddr,&str_phys);
		
		amx_Push(amx,amxaddr);
		amx_Exec(amx,&ret,idx);

		char name[24];
		amx_GetString(name,str_phys,0,24);
		amx_Release(amx,amxaddr);
		printf("%s",name);
	}else{
		printf("Native");
	}
Pawn:
Code:
forward __GetPlayerName(playerid,name[]);
public __GetPlayerName(playerid,name[]){
	GetPlayerName(playerid,name,MAX_PLAYER_NAME);
}
It doesn't crash but prints player name: "" (empty)

P.S: I don't want to use invoke or gdk.I want to make this.
P.S: playerid is correct.I tested.

Up+++
Rancho is offline   Reply With Quote
Old 09/07/2012, 08:26 AM   #57
zgintasz
Huge Clucker
 
Join Date: Oct 2011
Posts: 394
Reputation: 8
Default Re: Plugin development guide

What I'm doing wrong? plugin_test prints wrong values.

pawn Code:
forward plugin_test( itg_MinX, itg_MinY, itg_MaxX, itg_MaxY );
public plugin_test( itg_MinX, itg_MinY, itg_MaxX, itg_MaxY )
{
    printf( "comes from c++: %d, %d, %d, %d", itg_MinX, itg_MinY, itg_MaxX, itg_MaxY );
}

Code:
// calling:
testfunc( amx, 5, 3, 2, 8 );

// function:

void testfunc( AMX* amx, int itg_MinX, int itg_MinY, int itg_MaxX, int itg_MaxY )
{
    int idx;

    const cell arr[] = { itg_MinX, itg_MinY, itg_MaxX, itg_MaxY };

    if(!amx_FindPublic(amx, "plugin_test", &idx))
    {
        cell
            ret, 
            addr = 0;

        cell
            amx_addr, 
            *phys_addr;

	amx_Allot(amx, sizeof(arr) / sizeof(cell), &amx_addr, &phys_addr);
        memcpy(phys_addr, arr, sizeof(arr));
        amx_Push(amx, amx_addr);
        amx_Exec(amx, &ret, idx);
        amx_Release(amx, addr);
    }
}

Last edited by zgintasz; 09/07/2012 at 09:20 AM.
zgintasz is offline   Reply With Quote
Old 09/07/2012, 10:32 AM   #58
JoBullet
Big Clucker
 
Join Date: Mar 2012
Posts: 66
Reputation: 65
Default Re: Plugin development guide

@Rancho
use amx_PushString, you can get working examples in some of plugins(just look up some with callbacks that receive strings)
@zgintasz
You must amx_Push all values in reverse order(right-to-left), push theirs' amx addr of course.
JoBullet is offline   Reply With Quote
Old 09/07/2012, 11:12 AM   #59
zgintasz
Huge Clucker
 
Join Date: Oct 2011
Posts: 394
Reputation: 8
Default Re: Plugin development guide

Quote:
Originally Posted by JoBullet View Post
@Rancho
use amx_PushString, you can get working examples in some of plugins(just look up some with callbacks that receive strings)
@zgintasz
You must amx_Push all values in reverse order(right-to-left), push theirs' amx addr of course.
Can you give me a fixed code? I'm just trying to learn it.
zgintasz is offline   Reply With Quote
Old 09/07/2012, 01:39 PM   #60
JoBullet
Big Clucker
 
Join Date: Mar 2012
Posts: 66
Reputation: 65
Default Re: Plugin development guide

Quote:
Originally Posted by zgintasz View Post
Can you give me a fixed code? I'm just trying to learn it.
There are plenty of plugins which shows exactly that and by the way, do not be lazy
JoBullet 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
[Question] Plugin Load Failed : Plugin Does not conform to architecture. Gamer_Z Plugin Development 2 09/06/2011 06:42 AM
SA-MP 0.3c in development Kalcor News and Updates 886 23/04/2011 06:18 AM
0.3b Development bar gone WackoX General 94 02/08/2010 10:17 PM
A guide to install Jacob's IRC plugin? Celson Server Support 5 09/06/2009 07:06 AM


All times are GMT. The time now is 06:14 AM.


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