SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 27/03/2020, 09:33 AM   #1
pollo97
Big Clucker
 
pollo97's Avatar
 
Join Date: Sep 2011
Location: Italy
Posts: 83
Reputation: 4
Default Issue on creating DynamicObject using y_hooks

Hi to everyone!
I'm programming using modules and in a first try I separeted my maps in three different files, hooking those to OnGameModeInit callback, but I noticed that only 1000 out of 1300 objects were created.
I tried to move all the maps under OnGameModeInitEx, that is the first OnGameModeInit being called and it worked!
In the 'main.pwn' I've got this code:

Code:
#include <a_samp>
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
 
// includes and definitions

OnGameModeInitEx()
{
    // maps here works
}
Instead, in one of the map file where I hook OnGameModeInit, the code is:
Code:
#include <YSI_Coding\y_hooks>

hook OnGameModeInit()
{
  // CreateDynamicObject
  return 1;
}
I want to understand if there are some problems related with streamer and hooks or if is due to my inexperience in hooking callbacks.
pollo97 is offline   Reply With Quote
Old 27/03/2020, 10:42 AM   #2
Symon
Gangsta
 
Symon's Avatar
 
Join Date: Apr 2019
Location: Italy
Posts: 884
Reputation: 85
Default Re: Issue on creating DynamicObject using y_hooks

You don't have to hook anything if you're just adding objects (AFAIK).

All you have to do is create a map file which contains all objets (i'd call maps.pwn).

In that file create a function like CreateServerObjects() and put all your objects there.

Then include maps.pwn in your main game using:

pawn Code:
#include "maps.pwn"

After add CreateServerObjects() in OnGameModeInit on your main gamemode as well.

Note the include code i posted retrieves the maps.pwn file from inside gamemodes folder. You might want to change it based on your needs.
Symon is offline   Reply With Quote
Old 27/03/2020, 10:57 AM   #3
pollo97
Big Clucker
 
pollo97's Avatar
 
Join Date: Sep 2011
Location: Italy
Posts: 83
Reputation: 4
Default Re: Issue on creating DynamicObject using y_hooks

Quote:
Originally Posted by Symon View Post
You don't have to hook anything if you're just adding objects (AFAIK).

All you have to do is create a map file which contains all objets (i'd call maps.pwn).

In that file create a function like CreateServerObjects() and put all your objects there.

Then include maps.pwn in your main game using:

pawn Code:
#include "maps.pwn"

After add CreateServerObjects() in OnGameModeInit on your main gamemode as well.

Note the include code i posted retrieves the maps.pwn file from inside gamemodes folder. You might want to change it based on your needs.
I made as you said in my second attempt but I'd like to know why write the map under the hook of OnGameModeInit doesn't work. There is something I don't know about the hooks?

(Btw thank you for respond! I'll use this method for sure, but as I said, I want to know if I'm missing something)

UPDATE:
Solved, my mistake.

Last edited by pollo97; 27/03/2020 at 12:27 PM.
pollo97 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[EasyDB]Creating Issue Yaa Scripting Help 9 03/12/2016 06:38 PM
Dynamicobject on RequestClass DavidBilla Scripting Help 1 12/07/2016 06:27 PM
Dynamicobject Help SequenceCuz Scripting Help 11 13/12/2014 12:21 PM
DynamicObject problem seoseokbin Scripting Help 0 09/03/2013 03:14 PM
Issue creating file Joe Staff Help Archive 6 20/04/2009 02:43 AM


All times are GMT. The time now is 06:44 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.