Implent a function?
#1

Hi'
I'm here to ask you, how to implent a function ? I've the error 004
Код:
error 004: function "OnPlayerKilledPlayer" is not implemented
I know what this mean, I've just to write
PHP код:
OnPlayerKilledPlayer(playeriddeathid)
{
    
// Codee..
    
return 1;

But this is not the purpose here. I'm looking for implementing a function without creating it like showed before.
Code:
PHP код:
#include <a_samp>
public OnPlayerDeath(playeridkilleridreason)
{
    
#if defined OnPlayerKilledPlayer
        
if(killerid != INVALID_PLAYER_IDOnPlayerKilledPlayer(playeridreason);
    
#endif
    
return 1;
}
forward OnPlayerKilledPlayer(playeriddeathid); 
Thanks for helping.
NB: This is only optimization.
Reply
#2

If you don't want to have it in the code (Maybe you're creating an include or something), you need to check if it's defined before forwarding it.

Код:
#if defined OnPlayerKilledPlayer
    forward OnPlayerKilledPlayer(playerid, deathid);
#endif
Reply
#3

CallLocalFunction
You're directly calling a callback which doesn't exist, so normally compiler raises an error. Using CallLocalFunction is slow, but it wouldn't raise an error if the callback doesn't exist.
Reply
#4

Maybe you should put forward declartion BEFORE OnPlayerDeath public?
Reply
#5

Quote:
Originally Posted by Stinged
Посмотреть сообщение
If you don't want to have it in the code (Maybe you're creating an include or something), you need to check if it's defined before forwarding it.

Код:
#if defined OnPlayerKilledPlayer
    forward OnPlayerKilledPlayer(playerid, deathid);
#endif
Alright, I got it. I didn't think about this way. This is simple optimization exercise but I was stuck. Thanks you.
Quote:
Originally Posted by PawnHunter
Посмотреть сообщение
CallLocalFunction
You're directly calling a callback which doesn't exist, so normally compiler raises an error. Using CallLocalFunction is slow, but it wouldn't raise an error if the callback doesn't exist.
Stinged gave the solution.
Quote:
Originally Posted by TheMallard
Посмотреть сообщение
Maybe you should put forward declartion BEFORE OnPlayerDeath public?
Nothing change about the forward placement, that's why when you declare a public function, usually, you put the forward before.
Reply
#6

Erm, isn't this simply because you forwarded a function but forgot to put public in front of it?

#E: Oh, sorry, misread stuff.
Reply
#7

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Erm, isn't this simply because you forwarded a function but forgot to put public in front of it?
No, the function isn't declared so I can't forward it.
Reply
#8

The "#if defined" solution tends to cause problems when working with certain hooking methods and other #define stuff. CallLocalFunction is the way you normally do this, as PawnHunter posted. This wont cause any problems with hooking.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)