[Tutorial] How to create a plugin
#61

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 ==========
Reply
#62

Can you make a tutorial for Code::Blocks?
Reply
#63

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.
Reply
#64

Maaan AWESOME! зok iyi
Reply
#65

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

Thank you dude.
Reply
#67

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
Reply
#68

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.
Reply
#69

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.
Reply
#70

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....
Reply
#71

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++
Reply
#72

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 :/
Reply
#73

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
Reply
#74

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.
Reply
#75

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.
Reply
#76

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.
Reply
#77

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++.
Reply
#78

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
Reply
#79

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

Thanks RyDeR`

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)