Raised This Month: $51 Target: $400
 12% 

Solved [SOLVED] FM_GetGameDescription & Score


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 01-06-2017 , 11:43   [SOLVED] FM_GetGameDescription & Score
Reply With Quote #1

Hi!
My idea is to make score team shows in Game Description
I tried
PHP Code:

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_forward(FM_GetGameDescription    "fwd_GetGameDescription");
}

public 
fwd_GetGameDescription()

    
forward_return(FMV_STRING"blue %d|%d red"ScoreBlueScoreRed);
    
server_print("===========^n%d ^n %d^n==========="ScoreBlueScoreRed);
    return 
FMRES_SUPERCEDE;

But I did not get it i see like that : ( blue %d|%d red)
without value scores
i try dubug using server_print it succeeded with me and i get the value
Quote:
===========
-1
0
===========
===========
-1
0
===========
What is the Problem in that?
__________________

Last edited by abdobiskra; 09-18-2017 at 06:53.
abdobiskra is offline
Send a message via Skype™ to abdobiskra
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 01-06-2017 , 19:19   Re: [HELP] FM_GetGameDescription & Score
Reply With Quote #2

forward_return(FMV_STRING, fmt("blue %d|%d red", ScoreBlue, ScoreRed));
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 01-07-2017 , 00:59   Re: [HELP] FM_GetGameDescription & Score
Reply With Quote #3

Quote:
Originally Posted by PRoSToTeM@ View Post
forward_return(FMV_STRING, fmt("blue %d|%d red", ScoreBlue, ScoreRed));
thx for rply
error compile ? this ==> (fmt)
did you mean format ? (i test it also error argument)
__________________
abdobiskra is offline
Send a message via Skype™ to abdobiskra
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-07-2017 , 01:13   Re: [HELP] FM_GetGameDescription & Score
Reply With Quote #4

fmt is only available in 1.8.3-dev. If you are using 1.8.2 then you will have to format your string with formatex.

Anyway it's cool to see that someone is actually aware of fmt and is using it.

Last edited by klippy; 01-07-2017 at 01:14.
klippy is offline
abdobiskra
Veteran Member
Join Date: Jul 2014
Location: Algeria
Old 01-07-2017 , 09:15   Re: [HELP] FM_GetGameDescription & Score
Reply With Quote #5

Quote:
Originally Posted by KliPPy View Post
fmt is only available in 1.8.3-dev. If you are using 1.8.2 then you will have to format your string with formatex.

Anyway it's cool to see that someone is actually aware of fmt and is using it.
Yes thx bro))
__________________

Last edited by abdobiskra; 01-07-2017 at 09:28.
abdobiskra is offline
Send a message via Skype™ to abdobiskra
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 01-07-2017 , 15:16   Re: [SLOVED] FM_GetGameDescription & Score
Reply With Quote #6

You can use it in 1.8.2:
PHP Code:
#include <amxmodx>

#if !defined MAX_FMT_LENGTH
const MAX_FMT_LENGTH 256;

stock fmt(const format[], any:...)
{
    static 
formatted[MAX_FMT_LENGTH];
    
vformat(formattedcharsmax(formatted), format2);
    
// We can't use code without emitting opcodes because the compiler can't find hidden return argument correctly in variadic functions (the compiler generates code like for fmt(a, b) function)
#emit LOAD.S.PRI 0x8 // Get size of arguments (count of arguments multiply by sizeof(cell))
#emit ADDR.ALT 0xC // This is the pointer to first argument
#emit ADD // Now in PRI we have the pointer to hidden return argument
#emit LOAD.I // Now in PRI we have the pointer to return buffer
#emit MOVE.ALT
#emit CONST.PRI formatted
    
const MAX_FMT_LENGTH_X4 MAX_FMT_LENGTH 4;
#emit MOVS MAX_FMT_LENGTH_X4 // Copy from formatted buffer to return buffer
#emit RETN // Don't execute the code for copy return generated by compiler
    
return formatted;
}
#endif

public plugin_init()
{
    
server_print("%s"fmt("%s %d %f"fmt("%d"55), 5555.0));

And also the optimized version:
PHP Code:
#include <amxmodx>

#if !defined MAX_FMT_LENGTH
const MAX_FMT_LENGTH 256;

#if !defined __vformat_allower
#define __vformat_allower __vformat_allower_
__vformat_allower_()
{
    
vformat(""0""0);
}
#endif

stock fmt(const format[], any:...)
{
    static 
formatted[MAX_FMT_LENGTH];
#emit PUSH.C 0x2
#emit PUSH.S format
    
const FORMATTED_CHARSMAX charsmax(formatted);
#emit PUSH.C FORMATTED_CHARSMAX
#emit LOAD.S.PRI 0x8 // Get size of arguments (count of arguments multiply by sizeof(cell))
#emit ADDR.ALT 0xC // This is the pointer to first argument
#emit ADD // Now in PRI we have the pointer to hidden return argument
#emit LOAD.I // Now in PRI we have the pointer to return buffer
#emit PUSH.PRI
#emit PUSH.C 0x10
#emit SYSREQ.C vformat
#emit STACK 0x14
#emit RETN // Don't execute the code for copy return generated by compiler
    
__vformat_allower();
    return 
formatted;
}
#endif

public plugin_init()
{
    
server_print("%s"fmt("%s %d %f"fmt("%d"55), 5555.0));

__________________

Last edited by PRoSToTeM@; 01-07-2017 at 16:22.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-07-2017 , 17:54   Re: [SLOVED] FM_GetGameDescription & Score
Reply With Quote #7

So, that's basically returning a string instead of passing it by ref? The thing that approvers say is "stupid". Are all of those #emit things needed? What could go wrong without them? It's a simple stock that uses vformat and returns the string, nothing else.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 01-07-2017 , 18:24   Re: [SLOVED] FM_GetGameDescription & Score
Reply With Quote #8

Quote:
Originally Posted by OciXCrom View Post
So, that's basically returning a string instead of passing it by ref?
The main purpose of fmt is inlining string formatting in function calls like:
PHP Code:
forward_return(FMV_STRINGfmt("blue %d|%d red"ScoreBlueScoreRed)); 
Quote:
Originally Posted by OciXCrom View Post
Are all of those #emit things needed? What could go wrong without them?
There is a problem with variadic functions, you can read about it in my code comments.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
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 04:24.


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