SA-MP Forums Archive
[Tutorial] How to create a plugin - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to create a plugin (/showthread.php?tid=253436)

Pages: 1 2 3 4 5 6


Re: How to create a plugin - 1337connor - 30.05.2011

Ok, here's my code
Code:
static cell AMX_NATIVE_CALL printts(AMX *amx, cell *params)
{  
		char* buffer;
		amx_StrParam(amx,params[1],buffer);
        logprintf("%s (PRINTTS PRINT)",buffer);
        // Your codes go in here
        return 1; // Change the return value if need
}
and the erros i get..
Code:
1>------ Build started: Project: printts, Configuration: Debug Win32 ------
1>Compiling...
1>printts.cpp
1>c:\users\smoody\documents\visual studio 2008\projects\printts\printts\printts.cpp(21) : error C2065: 'NULL' : undeclared identifier
1>c:\users\smoody\documents\visual studio 2008\projects\printts\printts\printts.cpp(21) : error C3861: '_alloca': identifier not found
1>c:\users\smoody\documents\visual studio 2008\projects\printts\printts\printts.cpp(21) : error C2065: 'NULL' : undeclared identifier
1>Build log was saved at "file://c:\Users\smoody\Documents\Visual Studio 2008\Projects\printts\printts\Debug\BuildLog.htm"
1>printts - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Re: How to create a plugin - Miguel - 31.05.2011

Can you make a tutorial for Code::Blocks?


Re: How to create a plugin - 1337connor - 31.05.2011

Hmm.. Solved my problem, but now I get a shit load of linker issues, because I'm using "sapi.h", and I fail @ linking.
Im trying to make a printts ( Print Text To Speech ) plugin... which I think would be kinda cool, so that server owners can know when there is a warning of any type like.. for example
printts("Someone is trying to hack the server");
Would use a text to speech voice, and print it.


Re: How to create a plugin - NcP - 31.05.2011

Maaan AWESOME! зok iyi


Re: How to create a plugin - RyDeR` - 01.06.2011

Quote:
Originally Posted by Miguel
View Post
Can you make a tutorial for Code::Blocks?
Google is your friend.


Re: How to create a plugin - mumi38 - 02.06.2011

Thank you dude.


Re: How to create a plugin - Gamer_Z - 08.07.2011

Quote:
Originally Posted by RyDeR`
View Post
@cj101:
Try to compile with F7. Otherwise please try again, all steps are correct.

@sciman001:
So you basicaly want to call a function from SA-MP to your plugin? That's not difficult. Here's the way I'm doing:
In your C++, you create a "function" where you push the parameter and execute the function and retrieve the return the value to return.

Example of IsPlayerConnected in C++. (I used __IsPlayerConnected to prevent collisions)
pawn Code:
int __IsPlayerConnected(int playerid, AMX *amx) // AMX *amx must stay but it's just the playerid parameter that counts in his function.
{
    int
        index
    ;
    if(!amx_FindPublic(amx, "__IsPlayerConnected", &index))
    {
        cell
            retVal
        ;
        amx_Push(amx, playerid);
        amx_Exec(amx, &retVal, index);
        return (int)retVal;
    }
    return -1;
}
Now all you have to do is open PAWN and do a public call where you return IsPlayerConnected with public __IsPlayerConnected.

pawn Code:
#define FunctionCall(%0) \
    forward __%0; public __%0 return %0

FunctionCall(IsPlayerConnected(playerid)); // This will automaticly define the public starting with '__' and return the function.
And you can use "__IsPlayerConnected(playerid, amx)" in your C++ script.

pawn Code:
static cell AMX_NATIVE_CALL __PrintPlayerConnect(AMX *amx, cell *params)
{
    if(__IsPlayerConnected(params[1], amx)) // Never forget to add 'amx'!
    {
        printf("Player %d is connected", params[1]);
    }
    else printf("Player %d is NOT connected", params[1]);
    return 1;
}
Now you can call your native to SA-MP, like I explained in my first post and add this for example under OnPlayerSpawn and see the result!.

Note: You can convert float to cell and vice-versa using "amx_ftoc" and "amx_ctof". Can be useful for pushing float variables.
And If I want to Call for GetPlayerFacingAngle?
Can you maybe explain a bit? :P


Re: How to create a plugin - RyDeR` - 08.07.2011

Quote:
Originally Posted by gamer_Z
View Post
And If I want to Call for GetPlayerFacingAngle?
Can you maybe explain a bit? :P
http://forum.sa-mp.com/showpost.php?...93&postcount=8

Invoke makes it very easy to call PAWN natives.


Re: How to create a plugin - Guest3598475934857938411 - 25.07.2011

Nice work RyDeR keep up your good work, I managed to compile the SA-MP SDK long time ago. But your tutorial is awesome for starters though. I would really like to go advanced with SA-MP plugins someday.


Re: How to create a plugin - DRIFT_HUNTER - 26.07.2011

Well its actually hard cos you need to connect your plugin to sa-mp server
You need to use samp native (to hook on them) and that is a hard part also c++ does not have simple functions like SetTimer,GivePlayerWeapon and other....


Re: How to create a plugin - dr.pepper - 26.07.2011

I'm not even going to try to make a plugin. Already looks complicated, and it was a great tutorial. I'm not going to use C++


Re: How to create a plugin - DRIFT_HUNTER - 26.07.2011

Quote:
Originally Posted by RyDeR`
View Post
http://forum.sa-mp.com/showpost.php?...1&postcount=17

You can also use invoke or ZeeX / 0x...'s SDK package.
Where can i get it? i mean i trying to get working invoke for a two days now...always fail :/


Re: How to create a plugin - Unknown1234 - 26.07.2011

why i cant compile irc plugin source ... i did everything well, include, added boost but it doesnt seems to work. shows me error that "no such file or directory" like this post
i just posted here because i use visual c++ for that


Re: How to create a plugin - Guest3598475934857938411 - 26.07.2011

Quote:
Originally Posted by DRIFT_HUNTER
View Post
Well its actually hard cos you need to connect your plugin to sa-mp server
You need to use samp native (to hook on them) and that is a hard part also c++ does not have simple functions like SetTimer,GivePlayerWeapon and other....
If you don't know why plugins are used don't talk. Pawn language can run 1 process at a time, like if its running to a loop other code is waiting for the loop to be finished then continue. Not good for a streamer, due it uses too many resources and will lag a server. Also it is used for things that uses many resources not just streamers.


Re: How to create a plugin - iggy1 - 26.07.2011

Quote:
Originally Posted by expertprogrammer
View Post
If you don't know why plugins are used don't talk.
Shut up. How does that relate to what DRIFT_HUNTER said?
You shouldn't talk then. Forgive me if I'm wrong but plugins are not just for scripts that use high resources. Plugins are used for many things mainly being adding more functionality, the efficiency is a bonus.


Re: How to create a plugin - Guest3598475934857938411 - 27.07.2011

Quote:
Originally Posted by iggy1
View Post
Shut up. How does that relate to what DRIFT_HUNTER said?
You shouldn't talk then. Forgive me if I'm wrong but plugins are not just for scripts that use high resources. Plugins are used for many things mainly being adding more functionality, the efficiency is a bonus.
Yes OFC they are, sorry forget to mention it. I was in a rush to go to the beach :P Also no need to get angry really, I just told him that plugins are supposed to be hard to write due they does not have in built natives like PAWN but you got to import your own.


Re: How to create a plugin - FireCat - 27.07.2011

Quote:
Originally Posted by expertprogrammer
View Post
Yes OFC they are, sorry forget to mention it. I was in a rush to go to the beach :P Also no need to get angry really, I just told him that plugins are supposed to be hard to write due they does not have in built natives like PAWN but you got to import your own.
You don't have to import your own.
All you have to do is make a specie of "callback" in c++.


Re: How to create a plugin - DRIFT_HUNTER - 27.07.2011

Quote:
Originally Posted by expertprogrammer
View Post
If you don't know why plugins are used don't talk. Pawn language can run 1 process at a time, like if its running to a loop other code is waiting for the loop to be finished then continue. Not good for a streamer, due it uses too many resources and will lag a server. Also it is used for things that uses many resources not just streamers.
I know what are plugins and for what they are here but you dont know
Plugins can be used for anything not just to improve speed...plugins are also to make things that are impossible with pawn (for example Mysql plugin) or just to make things simple in pawn


Re: How to create a plugin - iPLEOMAX - 04.10.2011

That's amazing. I've created my first test plguin.

Thanks RyDeR`

btw, Is it better to use SA-MP GDK by Zeex?


Re: How to create a plugin - RyDeR` - 04.10.2011

Quote:
Originally Posted by iPLEOMAX
Посмотреть сообщение
That's amazing. I've created my first test plguin.

Thanks RyDeR`

btw, Is it better to use SA-MP GDK by Zeex?
Yes ─ SA:MP GDK by Zeex is better in performance and easier to use as far as I'm know. I will also switch over in future projects I guess.