Raised This Month: $ Target: $400
 0% 

Problem with fake natives & forwards


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 05-31-2006 , 22:10   Problem with fake natives & forwards
Reply With Quote #1

With the below code, specifically the CreateOneForward line, I have been having some difficulty getting the forwards to actually function correctly.

Another thing I noticed is that register_plugin seems to always return 1, which according to Bail should not happen (it should return plugin id)

The first section is the API, the second is the test plugin, and the third is the include file.

Code:
/* AMX Mod X script. *   Voting API * * by the AMX Mod X Development Team *  originally developed by OLO * * This file is part of AMX Mod X. * * *  This program is free software; you can redistribute it and/or modify it *  under the terms of the GNU General Public License as published by the *  Free Software Foundation; either version 2 of the License, or (at *  your option) any later version. * *  This program is distributed in the hope that it will be useful, but *  WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *  General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software Foundation, *  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *  In addition, as a special exception, the author gives permission to *  link the code of this program with the Half-Life Game Engine ("HL *  Engine") and Modified Game Libraries ("MODs") developed by Valve, *  L.L.C ("Valve"). You must obey the GNU General Public License in all *  respects for all of the code used other than the HL Engine and MODs *  from Valve. If you modify this file, you may extend this exception *  to your version of the file, but you are not obligated to do so. If *  you do not wish to do so, delete this exception statement from your *  version. */ // Error codes: // -1       The voting system is already in use by another plugin // -2       Forward execution/creation error #include <amxmodx> #include <amxmisc> // there are 9 menu items, -1 due to exit #define MAX_ANSWERS 9 new g_szAnswers[MAX_ANSWERS][32] new g_iAnswers new g_szMenuTitle[] = "mVote" new const g_iKeys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9 new g_iTally[MAX_ANSWERS] new bool:g_bInUse new g_iPlugin public plugin_init() {     g_iPlugin = register_plugin("Vote API",AMXX_VERSION_STR,"AMXX Dev Team")         register_menucmd(register_menuid(g_szMenuTitle),g_iKeys,"fnVoteTally")         register_clcmd("amx_plugin1","fnCmdPlugin") } public fnCmdPlugin(id)     client_print(id,print_chat,"Vote API: [%i]",g_iPlugin) public plugin_natives() {     register_library("vote")         register_native("vote_clear","fnVoteClear")     register_native("vote_add_answer","fnVoteAddAnswer")     register_native("vote_begin","fnVoteBegin") } public fnVoteClear() {     g_iAnswers = 0         for(new iCount = 0;iCount < MAX_ANSWERS;iCount++)         g_szAnswers[iCount][0] = 0 }         public fnVoteAddAnswer(iPlugin,iParams) {     if(g_bInUse)         return -1             new szAnswer[33]     get_string(1,szAnswer,32)         format(g_szAnswers[g_iAnswers++],31,"%s",szAnswer)         return PLUGIN_CONTINUE } public fnVoteBegin(iPlugin,iParams) {     if(g_bInUse)         return -1         new szQuestion[33],Float:flTime,szFunction[33]     get_string(1,szQuestion,32)     flTime = get_param_f(2)     get_string(3,szFunction,32)         client_print(0,print_chat,"[%s][%f][%s]",szQuestion,flTime,szFunction)         g_bInUse = true         // slightly bigger in order to accomodate the actual menu     new szMenu[MAX_ANSWERS * 35],iPos         iPos += format(szMenu[iPos],(MAX_ANSWERS * 35) - iPos,"%s^n^n",szQuestion)     for(new iCount = 0;iCount < g_iAnswers;iCount++)         iPos += format(szMenu[iPos],(MAX_ANSWERS * 35) - iPos,"%i. %s^n",iCount + 1,g_szAnswers[iCount])     format(szMenu[iPos],(MAX_ANSWERS * 35) - iPos,"^n0. Exit")         show_menu(0,g_iKeys,szMenu,floatround(flTime),g_szMenuTitle)         set_task(flTime,"fnVoteFinish",iPlugin,szFunction,32)         return PLUGIN_CONTINUE } public fnVoteFinish(szFunction[],iPlugin) {       client_print(0,print_chat,"szFunction: [%s], iPlugin: [%i]",szFunction,iPlugin)         g_bInUse = false         fnVoteClear         new iVoteEnd = CreateOneForward(iPlugin,szFunction,FP_ARRAY)     client_print(0,print_chat,"iVoteEnd: [%i]",iVoteEnd)             new pTally = PrepareArray(g_iTally,MAX_ANSWERS)         client_print(0,print_chat,"ExecuteForward: [%i]",ExecuteForward(iVoteEnd,pTally))             return PLUGIN_CONTINUE } public fnVoteTally(id,iKey) {     if(iKey == 9 || iKey > g_iAnswers)         return PLUGIN_CONTINUE             g_iTally[iKey]++         new szName[33]     get_user_name(id,szName,32)         client_print(0,print_chat,"[AMXX] %s voted for %s.",szName,g_szAnswers[iKey])         return PLUGIN_CONTINUE }

Code:
#include <amxmodx> #include <amxmisc> #include <vote> new g_iPlugin public plugin_init() {     g_iPlugin = register_plugin("Vote API Test","1.0","Hawk552")         register_clcmd("vote_add_answer","fnAddAnswer")     register_clcmd("vote_begin","fnBegin")         register_clcmd("amx_plugin2","fnCmdPlugin") } public fnCmdPlugin(id)     client_print(id,print_chat,"Vote Test: [%i]",g_iPlugin) public fnAddAnswer(id) {     new szArg[33]     read_argv(1,szArg,32)         vote_add_answer(szArg) } public fnBegin(id) {     new szArg[2][33]     read_argv(1,szArg[0],32)     read_argv(2,szArg[1],32)         client_print(0,print_chat,"Vote begin ret: [%i]",vote_begin(szArg[0],floatstr(szArg[1]),"fnVoteEnd")) } public fnVoteEnd(iTally[9])     client_print(0,print_chat,"[%i] [%i] [%i] [%i]",iTally[0],iTally[1],iTally[2],iTally[3])

Code:
/* Voting natives * * by the AMX Mod X Development Team *  originally developed by OLO * * This file is provided as is (no warranties). */ #if defined _vote_included     #endinput #endif #define _vote_included #pragma library "vote" // clears all answers native vote_clear() // add an answer to the vote // answer[]     Add an answer to the vote, up to 7 native vote_add_answer(const answer[]) // begin the voting process // question[]       Question to be asked // time         Time until function listed is called // function     Function to call when completed native vote_begin(const question[],const Float:time,const function[])
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 06-01-2006 , 08:01  
Reply With Quote #2

It was to my understanding that CreateOneForward was to supercede callfunc for internal function calling.

So why not use CreateMultiForward for external plugins? Example
Orangutanz is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-01-2006 , 08:15  
Reply With Quote #3

Quote:
Originally Posted by Orangutanz
It was to my understanding that CreateOneForward was to supercede callfunc for internal function calling.

So why not use CreateMultiForward for external plugins? Example
Because I want to call this only on one plugin. Say, for example, plugin "x" calls a vote and it gets passed through this api. When it is finished, I do not want it to call function "vote_end" (or whatever it is) in all other plugins as well, as they may happen to have the same name.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 06-01-2006 , 08:37  
Reply With Quote #4

Ah I see, so you mean this is broken or not working correctly?
public fnVoteBegin(iPlugin,iParams)

I looked at register_plugin and that is returning the ID fine. What you could do is the 1st parameter for the fnVoteBegin could be the pluginID that each plugin sends.

Code:
public fnVoteBegin(iPlugin,iParams) {     if(g_bInUse)         return -1      new plug = get_param(1)
Then in the plugin calling this:
Code:
public fnBegin(id) {     new szArg[2][33]     read_argv(1,szArg[0],32)     read_argv(2,szArg[1],32)         client_print(0,print_chat,"Vote begin ret: [%i]",vote_begin(g_iPlugin, szArg[0],floatstr(szArg[1]),"fnVoteEnd")) }
Orangutanz is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-01-2006 , 08:40  
Reply With Quote #5

No, because register_plugin returns 1 always on my current build.

I'm trying to get VC++ set up so I can compile 1.75 and try now, but I'd rather not use this method as I was making this API to be simple and easy to use.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 06-01-2006 , 08:48  
Reply With Quote #6

Scrap what I previously said

I see that was commited on the 14th April, 1.71 was released on the 2nd April.

Just tested with that iPlugin in the prototype, that was also returning fine for me. If its still not working for you the only thing you can do is get hold of 1.75 in CVS and also delay your plugin release until this super version is out

Either way its not an issue for the upcoming build of AMXX 1.75
Orangutanz is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-01-2006 , 08:52  
Reply With Quote #7

Quote:
Originally Posted by Orangutanz
Yep I see it now, that was commited on the 14th April, 1.71 was released on the 2nd April.

Just tested with that iPlugin in the prototype, that was also returning fine for me. If its still not working for you the only thing you can do is get hold of 1.75 in CVS and also delay your plugin release until this super version is out

Either way its not an issue for the upcoming build of AMXX 1.75
Yes, I'll try compiling from CVS then. I still don't want to use the return from register_plugin if the dynamic natives come with the plugin id already, but I guess it's a good idea to test it and see if it's a bug or just my code.

I wasn't planning on releasing this, I was going to give it to Bail in the hopes he would add it to the next release (1.80 I guess?), but it's just not working out.

After this is all done, I'm going to write an article in the wiki about plugin API stuff. I couldn't find any documentation on it (other than your post in Cheap_Suit's thread and Bail's example in the bug reports after it was added), and I don't want others to go through what I did just to do this simple plugin.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 06-01-2006 , 08:57  
Reply With Quote #8

You don't need to capture the ID of register_plugin at all mate.

How I did my tests was I altered my create_bot to include the prototypes, and even the calling plugin doesn't capture the id of register_plugin, its done automactically through the native system.

That iPlugin, iNumParams prototypes are powerful enough to work out what plugin is calling it and with how many parameters
Orangutanz is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-01-2006 , 09:03  
Reply With Quote #9

Quote:
Originally Posted by Orangutanz
You don't need to capture the ID of register_plugin at all mate.

How I did my tests was I altered my create_bot to include the prototypes, and even the calling plugin doesn't capture the id of register_plugin, its done automactically through the native system.

That iPlugin, iNumParams prototypes are powerful enough to work out what plugin is calling it and with how many parameters
Then why isn't it working?

I just thought of one thing though. Instead of calling a function after flTime, maybe I could add a fake native like "vote_end" and let the plugin handle the time between?

That would avoid the API issue entirely, and it also allows you to stop the vote at any time (ex. amx_cancelvote in the core)
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 06-01-2006 , 09:08  
Reply With Quote #10

Its more than likely not working since it might of been added as well after AMXX 1.71 was released.

I've been using the CVS builds for ages, since FakeMeta didn't have the capability of some things that I required with 1.71 release
Orangutanz is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 16:34.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode