[HELP]Redefine a native function
#1

i want to redefine the SetPlayerAttachedObject, and when it used i want to call the function "OnSetPlayerAttachedObjectToPlayer(playerid,index) "

I'm not sure how to do this because I have a lot of dexterity with the define and undefine can you help me?

This is a small draft of what I tried to do but it is not correct:
PHP код:
stock N_SetPlayerAttachedObject(playeridindexmodelidboneFloat:fOffsetX=0.0Float:fOffsetY=0.0Float:fOffsetZ=0.0Float:fRotX=0.0Float:fRotY=0.0Float:fRotZ=0.0 Float:fScaleX=0.0Float:fScaleY=0.0Float:fScaleZ=0.0materialcolor1=0materialcolor2=0)
    {
        
SetPlayerAttachedObject(playeridindexmodelidbonefOffsetXfOffsetYfOffsetZfRotXfRotYfRotZfScaleXfScaleYfScaleZmaterialcolor1materialcolor2);
        
CallRemoteFunction("OnSetPlayerAttachedObjectToPlayer""dd"playerid,index);
    }
    
#if defined _ALS_SetPlayerAttachedObject
        #undef SetPlayerAttachedObject
    #else
        #define _ALS_SetPlayerAttachedObject
    #endif
    #define SetPlayerAttachedObject N_SetPlayerAttachedObject 
Reply
#2

Looks okay to me. What is the problem?

I THINK function/callback/etc names are limited to 32 characters, but don't hold me to that. Try changing it to something shorter i.e. OnPlayerAttachObject(playerid, index).
Reply
#3

I dont test but in this way not else is an infinite loop ??

N_SetPlayerAttachedObject call "SetPlayerAttachedObject"&"OnSetPlayerAttachedObje ctToPlayer"
"SetPlayerAttachedObject" call "N_SetPlayerAttachedObject" because i define it
N_SetPlayerAttachedObject recall "SetPlayerAttachedObject"&"OnSetPlayerAttachedObje ctToPlayer"
and so on

and so in theory it does not continue indefinitely?
Reply
#4

No, it's not recursive. If it was your server would freeze.
Reply
#5

Tanks it didn't work for me becouse i use ****** fixes.inc and it is been redefinited by it but now work
another little question
where are the default value for materialcolor1 and materialcolor2 ?
are 0 or -1
Reply
#6

Look in a_samp.inc (or whatever include the 'native' line for it is).
Reply
#7

ah right LOL I had not thought
however it's in a_players.inc and the value are 0
Tanks for you Help
REP+
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
The idea of ALS is that it means that multiple includes can hook the same functions. If that isn't working then something has gone wrong somewhere...

Did you put that function at the top of your mode before all the places it is used in?
sure the error was in fact now works in the code that I entered when I insert this

both before and after your includes its compile perfectly

PHP код:
stock N_SetPlayerAttachedObject(playeridindexmodelidboneFloat:fOffsetX 0.0Float:fOffsetY 0.0Float:fOffsetZ 0.0Float:fRotX 0.0Float:fRotY 0.0Float:fRotZ 0.0Float:fScaleX 1.0Float:fScaleY 1.0Float:fScaleZ 1.0materialcolor1=0materialcolor2=0)
    {
        
SetPlayerAttachedObject(playeridindexmodelidbonefOffsetXfOffsetYfOffsetZfRotXfRotYfRotZfScaleXfScaleYfScaleZmaterialcolor1materialcolor2);
        
CallRemoteFunction("OnSetPlayerAttachedObjectToPlayer""dd"playerid,index);
        return 
1;
    }
    
#if defined _ALS_SetPlayerAttachedObject
        #undef SetPlayerAttachedObject
    #else
        #define _ALS_SetPlayerAttachedObject
    #endif
    #define SetPlayerAttachedObject N_SetPlayerAttachedObject 
But i prefer use your redefinition in fixes.ini and now work perfectly
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)