Custom function hook (y_hooks)
#1

Hi,

So I am scripting modular and I have come across several situations where I have to reset player variables upon connect. I made a

public ResetData(playerid) function in my main file and when i try to use hook ResetData(playerid) in my modular scripts it does not work..

core/vehicles/data.pwn(7 : error 010: invalid function or declaration

is it even possible, if yes how?
Reply
#2

Mind showing us some snippets to your code. Especially where it states that there is an error.
Reply
#3

Quote:
Originally Posted by iSpark
Посмотреть сообщение
Mind showing us some snippets to your code. Especially where it states that there is an error.
Код:
public OnPlayerConnect(playerid) {
	ResetData(playerid);
	return 1;
}

public ResetData(playerid)
{
	Character[playerid] = resetCData; //sets all the value to 0.
	User[playerid] = resetUData; //sets all the value to 0.
}
Inside my modular script piece:
Код:
hook ResetData(playerid)
{
	//reset data
}
Error: core/vehicles/data.pwn(7 : error 010: invalid function or declaration
Which is the hook line.
Reply
#4

Just curious. In the modular script since you're re-defining ResetData(). Are you adding new functions to it. Or is it the same as the public one?
Reply
#5

Quote:
Originally Posted by iSpark
Посмотреть сообщение
Just curious. In the modular script since you're re-defining ResetData(). Are you adding new functions to it. Or is it the same as the public one?
Let me try to explain it briefly.

Character[playerid] = resetCData; belongs to my characterdata.pwn file to reset characterdata
User[playerid] = resetUData; belongs to my userdata.pwn file to reset userdata

inside those files I want to make a hook ResetData so, if I call the public ResetData in my main.pwn under onplayerconnect, it goes through all the hook ResetData's
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
Are you actually including y_hooks?
Yeah I #include it at the top of my files
Reply
#7

Код:
#include <a_samp>
#include <mysql>
#include <zcmd>
#include <foreach>
#include <YSI\y_timers>
#include <YSI\y_hooks>


public OnGameModeInit()
{

	OnGameModeInitEx();

	#if defined main_OnGameModeInit
		return main_OnGameModeInit();
	#else
		return 1;
	#endif
}

	#if defined _ALS_OnGameModeInit
		#undef OnGameModeInit
	#else
		#define _ALS_OnGameModeInit
	#endif

#define OnGameModeInit main_OnGameModeInit
#if defined main_OnGameModeInit
	forward main_OnGameModeInit();
#endif

main(){}

/*======================================================================================================
										[Modules]
=======================================================================================================*/

//Player
#include "core/player/data.pwn"

//Vehicles
#include "core/vehicles/data.pwn"


/*======================================================================================================
										[Main]
======================================================================================================*/




OnGameModeInitEx()
{
	
}


main_OnGameModeInit()
{
	ResetDataTest();
	return 1;
}

public OnGameModeExit()
{

	return 1;
}


Public:ResetDataTest()
{
	printf("test1");
	return 1;
}
Код:
==========core/vehicles/data.pwn file===========
#include <YSI\y_hooks>

hook OnGameModeInit()
{
	print("core/vehicles/data.pwn loaded");
}

hook ResetDataTest(){
	printf("Data vehicles");
}


==========core/player/data.pwn file===========
#include <YSI\y_hooks>

hook OnGameModeInit()
{
	print("core/player/data.pwn loaded");
}

hook ResetDataTest(){
	printf("Data players");
}
And at both hook's it says invalid function
Reply
#8

Solution was updating to YSI version 4+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)