#1

So i have been FAILING these days, I have a bonus zone timer, and my server keeps shutting down for no reason in my friend's VPS, Don't you think it's because of it?

Can someone tell me if i scripted it wrong which causes a lot of troubles with in the VPS?

PHP код:

#define MAX_WAR 100
new SpecialZone[MAX_WAR];
stock AvailableZone(id)
{
    switch(
id)
    {
        case 
SnakeFarmCiaHeadquartersCluckinBellPetrolStationBaitShopRanchRadarBaseOilDepotQuarryTheBigSpreadRanch: return 1;
    }
    return 
0;
}
public 
SpecialTimer()
{
    new 
random(MAX_WAR+1);
    new 
string[128];
    
    if(
AvailableZone(i) == 1)
    {
        if(
SpecialZone[i] == 0)
        {
            
format(stringsizeof(string), "* Zone %s is now a bonus zone, Capture it to get a special/additional rewards."GetZoneName(i));
            
SendClientMessageToAll(COLOR_PINKstring);
            
SpecialZone[i] = 1;
            print(string);
        }
        else
        {
            
format(stringsizeof(string), "* Zone %s is no longer a bonus zone, It will be replaced in the next 3 minutes."GetZoneName(i));
            
SendClientMessageToAll(COLOR_PINKstring);
            
SpecialZone[i] = 0;
            print(string);
        }
    }
    else
    {
        
SpecialTimer();
    }
    return 
1;

Reply
#2

SpecialZone must be a boolean if you are just setting its value b/w 0-1. But thats not the problem.

Why are you adding 1 to to random statement? It will probably crash because the result from the random statement is b/w (0, 1...., 99, 100); 100 is the drawback. Cause your MAX_WAR is limited to other vars only till (0, ...., 99).
Reply
#3

That is what i am trying to prevent, I don't kno any other efficient way to do so, Can you suggest me an idea?
Reply
#4

Just replace the statement with:
pawn Код:
new i = random(MAX_WAR);
And the var SpecialZone as a boolean.
pawn Код:
new bool:SpecialZone[MAX_WAR];
TIP: You can do that stuff with loops and sorting. Will be more efficient than calling SpecialTimer in else statement.
Reply
#5

So basically i have made another boolean var which indicates if the zoneID from MAX_WAR is taken or not.
I have made a loop of setting each of the zoneID to false (invalid), when the zones are loaded, i set each of them to true (valid).

Now, tell me, did i scripted this correctly?

PHP код:
public SpecialTimer()
{
    new 
random(MAX_WAR);
    new 
string[128];

    if(
Taken[i] == true)
    {
        if(
SpecialZone[i] == 0)
        {
            
format(stringsizeof(string), "* Zone %s is now a bonus zone, Capture it to get a special/additional rewards."GetZoneName(i));
            
SendClientMessageToAll(COLOR_PINKstring);

            
SpecialZone[i] = 1;

            print(string);
        }
        else
        {
            
format(stringsizeof(string), "* Zone %s is no longer a bonus zone, It will be replaced in the next 3 minutes."GetZoneName(i));
            
SendClientMessageToAll(COLOR_PINKstring);

            
SpecialZone[i] = 0;

            print(string);
        }
    }
    else
    {
        
SpecialTimer();
    }
    return 
1;

I still dont know what you meant on your post's TIP.

( RIP Grammar )
Reply
#6

I think he meant of using loops[ for(..) ].
BTW, i dont see any flaw in your code, do that still crash?
Reply
#7

pawn Код:
public SpecialTimer()
{
     for(new i; i < MAX_WAR; i++)
     {
          if(Taken[i])
          {
               if(SpecialZone[i])
               {
                    SpecialZone[i] = false;
                    //your code
                    OnSpecialZoneChange();
                    break;
               }
          }
     }
}

forward OnSpecialZoneChange();
public OnSpecialZoneChange()
{
     new x = random(MAX_WAR);
     if(Taken[x])
     {
          SpecialZone[x] = true;
          //your code
     } else return OnSpecialZoneChange();
     return 1;
}
Are you declaring only one special zone or multiple?
If your game supports only one special zone at a time, then use global var, it will help alot. The code below supports only one special zone but its very very easy to edit.

And your code isnt what you meant! I mean it bypass other zones and only handles a random zone id. Maybe one time in game, all the zones become special.

And secondally you must set MAX_WAR value to the amount of zones you have avaliable; if not used in game for building more. That will save speed & memory.
Reply
#8

The code i have given to y'all isn't exactly doing the original plans i had in my mind, It is more likely rapidly increase all the bonus zone, While deleting the bonus zone is almost impossible as the random function rarely hits the bonus zoneIDs.

Is there anyway that i could script this in a proper/neat way (I am not being lazy but, Could you give me an example of a code).

I am re-working on this code system.
Reply
#9

Have you tried Gammix's code?

Just tell what you actually want?
Reply
#10

Without testing it, I can see it from my POV that my code (nor his code) will not do the plans i had on my mind @ Neufox
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)