SetPVarString in GameModeInit/Main not work?
#1

Hello. I've... weird issue - for several minutes trying to simplify the function to create pvars using macros. Unfortunately - standard PVars didn't want to run in OnGameModeInit and Main too.

Code, that I'm use:
pawn Код:
#include <a_samp>
#define sprintf(%0,%1,%2)               format(%0, sizeof(%0), %1, %2)
public OnGameModeInit()
{
    new playerid;
    new date[3];
    new test[128];
    gettime(date[0], date[1], date[2]);
    sprintf(test, "Hello. Server start at: %d:%d:%d", date[0], date[1], date[2]);
    SetPVarString(playerid, "TEST", test);
    return true;
}

main()
{
    new playerid = 0, test[128];
    GetPVarString(playerid, "TEST", test, sizeof(test));
    printf(#%s, test);
    return false;
}
I don't know why this code won't work, especially since OnGameModeInit always performed first, and Main - second (though, even if I change the order of PVars, in the sense - in the main is set and GameModeInit downloaded, they don't work).
Reply
#2

They're PLAYER variables, not gamemode variables. I'm pretty sure that there are inbuilt checks that prevent you from setting data for a player that is not connected.
Reply
#3

But IT CAN BE gamemode variable. Look - if I'm set variable = 0 at OnGameModeInit or Main, it can be called and it work:
pawn Код:
main() // Or OnGameModeInit()
{
    new playerid;
    new date[3];
    new test[128];
    gettime(date[0], date[1], date[2]);
    sprintf(test, "Hello. Server start at: %d:%d:%d", date[0], date[1], date[2]);
    SetPVarString(playerid, "TEST", test);
    GetPVarString(playerid, "TEST", test, sizeof(test));
    // GetPVarStringEx(y, test, 128, "TEST");
    printf(#%s, test);
    return false; // or true in OnGameModeinit
}
Log:
Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3x, ©2005-2013 SA-MP Team

[18:12:35] 
[18:12:35] Server Plugins
[18:12:35] --------------
[18:12:35]  Loading plugin: whirlpool
[18:12:35]  
[18:12:35]  ==================
[18:12:35]  
[18:12:35]   Whirlpool loaded
[18:12:35]  
[18:12:35]  ==================
[18:12:35]  
[18:12:35]   Loaded.
[18:12:35]  Loading plugin: YSF
[18:12:35] logprintf = 0x00488060

[18:12:35] 

[18:12:35]  ===============================

[18:12:35]         YSF 0.4.01 loaded

[18:12:35]    © 2013 Alex "******" Cole

[18:12:35]     Server version: 0.3x R1-2

[18:12:35]     Operating System: Windows

[18:12:35]  ===============================

[18:12:35] m_pServer = 4f23c8
[18:12:35]   Loaded.
[18:12:35]  Loaded 2 plugins.

[18:12:35] 
[18:12:35] Filterscripts
[18:12:35] ---------------
[18:12:35]   Loaded 0 filterscripts.

[18:12:35]  
[18:12:35]  
[18:12:35]  
[18:12:35]  ======================================= 
[18:12:35]  |                                     | 
[18:12:35]  |        YSI version 1.06.0002        | 
[18:12:35]  |        By Alex "******" Cole        | 
[18:12:35]  |                                     | 
[18:12:35]  ======================================= 
[18:12:35]  
[18:12:35]  
[18:12:35]  
[18:12:35] Hello. Server start at: 18:12:35
@edit: I've found another issue - setting PVar before the loop and get it in a loop doesn't work:
pawn Код:
new pl;
SetPVarInt(pl, "BREAK_ME", 1000);
for(new y = 0; y <= 5000; y++)
{
    if(GetPVarInt(pl, "BREAK_ME") == 1000) break; // without == 1000 didn't work too...
    printf(#%d, y);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)