New Way of working with state
#1

https://sampforum.blast.hk/showthread.php?tid=86850 after reading this i want to use these state function but i really got questions. Can state be loaded and changed ?
Like i have 3 different cities that run at different time in same game mode just spawn location are different and etc.

how can i do that when there is specific time game mode ends and restarts and start the other city.

I got LS as my first city
pawn Код:
main ()
{
    state GameCity:LS; // where do i add the first one ? that's what's the problem.
if(GameCity:LS) state GameCity:LV;
else if(GameCity:LV) state GameCity:LS;
}
so the day ends in game with a timer.
and i add this after that.
pawn Код:
state GameCity:LV;
SendRconCommand("gmx");
pawn Код:
public OnPlayerSpawn(playerid) <GameCity:LS>
{
//... code here
}
I want this feature this will give nice look easier editing and more over faster processing as it won't read all code.

I know how to do it with variable it that i can save it then load it. But i want to do it for State.

And another question can switch work with state ? if yes an example please.
Reply
#2

States are lost when the gamemode is restarted because the file gets unloaded.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
States are lost when the gamemode is restarted because the file gets unloaded.
okay so my first question answer is no so there is no way for it ? expect variables.
I got the idea to do it with variables. and state but alone state won't work ?

and can i do something like this ?
pawn Код:
public OnGameModeInit() <GameMode:LV>
{
    //..code here here that LV will use
    return 1;
}

public OnGameModeInit() <GameMode:LS>
{
    //..code here that LS will use only
    return 1;
}

public OnGameModeInit()
{
    //..code here that both cities will use.
    return 1;
}
Edit i tried this :
pawn Код:
#include <a_samp>

main()
{
    state GameMode:LS;
}

public OnGameModeInit() <GameMode:LV>
{
    //..code here here that LV will use
    print("GM for LV");
    return 1;
}

public OnGameModeInit() <GameMode:LS>
{
    //..code here that LS will use only
    print("GM for LS");
    return 1;
}

public OnGameModeInit() <>
{
    //..code here that both cities will use.
    print("GM for All Cities");
    return 1;
}
worked but it only executed the code in "<>"


Edit 2 :

after tries i found this way working
pawn Код:
main()
{
    state GameMode:LS;
    OnGameModeInit();
    print("State Seted to LS");
}

public OnGameModeInit() <GameMode:LV>
{
    //..code here here that LV will use
    print("GM for LV");
    return 1;
}

public OnGameModeInit() <GameMode:LS>
{
    //..code here that LS will use only
    print("GM for LS");
    return 1;
}

public OnGameModeInit() <>
{
    //..code here that both cities will use.
    print("GM for All Cities");
    return 1;
}

but now the problem is i wanted that a callback that should always read and a one that works with city
Reply
#4

OnGameModeInit is executed before main, however illogical it may seem, so it is only natural that it will execute the fallback. So you can load all general stuff in OnGameModeInit, then set the state in main and execute another function to load the city specific stuff.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
OnGameModeInit is executed before main, however illogical it may seem, so it is only natural that it will execute the fallback. So you can load all general stuff in OnGameModeInit, then set the state in main and execute another function to load the city specific stuff.
okay i did that so there is no what that the simple one gets executed every time and the state one too. This will save me code for e.g

pawn Код:
public OnPayerSpawn(playerid) <GameMode:LS>
{
    //..Only spawn location and messages here.
    return 1;
}

public OnPayerSpawn(playerid) <GameMode:LV>
{
    //..Only spawn location and messages here.
    return 1;
}

public OnPayerSpawn(playerid) <>
{
    //..All the spawn code for example giving weapon and setting variables.
    return 1;
}
Reply
#6

Bomb... i mean Bump. i have been trying and searching couldn't find any thing searching state gets me to GetPlayerState... functions
Reply
#7

Quote:
Originally Posted by AroseKhanNaizi
Посмотреть сообщение
i have been trying and searching couldn't find any thing
Maybe have a look at this thread: https://sampforum.blast.hk/showthread.php?tid=86850
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
You mean the link mentioned in the very first post?
Well...that i've not seen

Instead of working with state, it would be smarter just to work with includes, where you hook the callbacks you need.
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
Except that doesn't control which ones get called and which don't.
Of course if you do something like this:

PHP код:
#define LS
#if defined LS
    #include <ls>
#else
    #include <lv>
#endif 
Reply
#10

Quote:
Originally Posted by Kaliber
Посмотреть сообщение
Of course if you do something like this:

PHP код:
#define LS
#if defined LS
    #include <ls>
#else
    #include <lv>
#endif 
this will make scripting complicated as i would have to work on multiple files together, + i can't compile game mode again and again to change city. I don't really know how re-hoking works but i will check your tutorials.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)