Archived copy of war3source.com, the War3Source forum (2009–2020), rebuilt from the Internet Archive by wc3mods.net. This page was captured on 2012-10-25 (original capture). Forum · All archived topics · Wiki · Bug tracker · Blog
Chat

War3:Source
October 24, 2012, 10:54:13 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Download: http://war3source.com/index.php?board=9.0
What is War3Source?: http://war3source.com/index.php?topic=200.0
Sample Stats: http://war3source.com/war3stats
Steam Community Group: http://steamcommunity.com/groups/war3source
War3Source SVN Checkout: http://ownageclan.com/svn/war3source/
War3Source servers: http://www.game-monitor.com/search.php?vars=war3_version=
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: OldRace parameter in OnRaceSelected event  (Read 592 times)
Frenzzy
Full Member
***
Posts: 217


337905984 frenzzy@live.ru
View Profile WWW
« on: December 24, 2010, 06:38:00 PM »

There are more and more races, which reset their skills in event OnRaceSelected:

Quote
public OnRaceSelected(client, newrace) {
    if (newrace != thisRaceID) {
        // Reset the passive skills of race (sometimes contains a lot of code and checks)
        // This code is executed every time a player changes the race
        // The more races on the server, the more code is executed when the player changes the race (there are lags)
    } else {
        // Activate race's skills
    }
}

I suggest adding in OnRaceSelected event new parameter "oldrace":

/**
 * Gets called when someone changes their race.
 * @param client: The client's index.
 * @param newrace: The player's new race.
 * @param oldrace: The player's old race.
 */


forward OnRaceSelected(client, newrace, oldrace);

Now slightly different picture:

Quote
public OnRaceSelected(client, newrace, oldrace) {
    if (newrace != thisRaceID && oldrace == thisRaceID) {
        // Reset the passive skills of race (sometimes contains a lot of code and checks)
    } else if (newrace == thisRaceID) {
        // Activate race's skills
    }
}

I think this will solve the problem. What do you think about this?
Logged

O_o
Frenzzy
Full Member
***
Posts: 217


337905984 frenzzy@live.ru
View Profile WWW
« Reply #1 on: December 24, 2010, 07:56:04 PM »

Or...
Maybe better make a new event: OnRaceDeselect(client, race);

Can add a mandatory return, to the OnRaceSelected event performed only after executing all OnRaceDeselect events.
It's can be used to prohibit change of race, for example:

OnRaceDeselect(client, race) {
     if (some_condition) {
         War3_ChatMessage(client, "To change the race you have to kill at least one player");
         return false;
     }
     return true;
}
Logged

O_o
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2046



View Profile WWW Email
« Reply #2 on: December 24, 2010, 08:53:23 PM »

W3GetVar(OldRace);
Logged

DarkEnergy
Frenzzy
Full Member
***
Posts: 217


337905984 frenzzy@live.ru
View Profile WWW
« Reply #3 on: December 24, 2010, 09:22:07 PM »

Why then in official races do not used this code?

Quote
public OnRaceSelected(client, newrace) {
    if (W3GetVar(OldRace) == thisRaceID) {
        // Deactivate race's skills
    } else if (newrace == thisRaceID) {
        // Activate race's skills
    }
}

It allows execute less code when changing the race, or am I wrong?
Logged

O_o
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2046



View Profile WWW Email
« Reply #4 on: December 24, 2010, 09:26:15 PM »

default races directly deactivate if not their race, yes its not really optimized, but it works and we dont have to worry about leaks as much

public OnRaceSelected(client,newrace)
{
   if(newrace!=thisRaceID)
   {
      deactivate
   }
   else
   {   
      activate
   }
}
Logged

DarkEnergy
Frenzzy
Full Member
***
Posts: 217


337905984 frenzzy@live.ru
View Profile WWW
« Reply #5 on: January 08, 2011, 09:11:07 PM »

Please, tell me how use custom models in races..

For example on my server no standard models. To all players connected to server is set custom model "BabanModel" (for one - T, for other - CT).
When player selects any race, he is set model from this race. Almost all races use custom models. When player changes race to one which has no model, him must be set "BabanModel".
If player changerace fifty times, model setup code will be launched 50 times in a row. This affects server performance.

How optimize my code? How to use custom models in races?

Quote
new String:g_RaceModelCT[PLATFORM_MAX_PATH] = "models/player/myrace/ct_model.mdl";
new String:g_RaceModelT[PLATFORM_MAX_PATH] = "models/player/myrace/t_model.mdl";
new String:g_OldModelCT[MAXPLAYERS+1][PLATFORM_MAX_PATH];
new String:g_OldModelT[MAXPLAYERS+1][PLATFORM_MAX_PATH];

public OnRaceSelected(client, newrace)
{
   if (newrace != thisRaceID)
   {
      if (IsPlayerAlive(client)) // This check is needed ??
      {
         /**
          * If a player has played this race, this command is executed each time a player changes the race.
          * Necessary that it was running ONLY when a player changes this race to any other.
          */

         new team = GetClientTeam(client);
         if (team == CS_TEAM_CT && IsModelPrecached(g_OldModelCT[client]))
         {
            SetEntityModel(client, g_OldModelCT[client]);
         }
         else if (team == CS_TEAM_T && IsModelPrecached(g_OldModelT[client]))
         {
            SetEntityModel(client, g_OldModelT[client]);
         }
      }
   }
   else
   {
      if (IsPlayerAlive(client)) // This check is needed ??
      {
         new team = GetClientTeam(client);
         if (team == CS_TEAM_CT && IsModelPrecached(g_RaceModelCT))
         {
            GetClientModel(client, g_OldModelCT[client], sizeof(g_OldModelCT));
            SetEntityModel(client, g_RaceModelCT);
         }
         else if (team == CS_TEAM_T && IsModelPrecached(g_RaceModelT))
         {
            GetClientModel(client, g_OldModelT[client], sizeof(g_OldModelT));
            SetEntityModel(client, g_RaceModelT);
         }
      }
   }
}

public OnWar3EventSpawn(client)
{
   if (War3_GetRace(client) == thisRaceID)
   {
      new team = GetClientTeam(client);
      if (team == CS_TEAM_CT && IsModelPrecached(g_RaceModelCT))
      {
         GetClientModel(client, g_OldModelCT[client], sizeof(g_OldModelCT));
         SetEntityModel(client, g_RaceModelCT);
      }
      else if (team == CS_TEAM_T && IsModelPrecached(g_RaceModelT))
      {
         GetClientModel(client, g_OldModelT[client], sizeof(g_OldModelT));
         SetEntityModel(client, g_RaceModelT);
      }
   }
}
Logged

O_o
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2046



View Profile WWW Email
« Reply #6 on: January 08, 2011, 09:18:36 PM »

launched 50 times in a row? how? is this because 50 races have this code?
Logged

DarkEnergy
zero
Full Member
***
Posts: 191



View Profile WWW Email
« Reply #7 on: January 09, 2011, 02:07:38 AM »

launched 50 times in a row? how? is this because 50 races have this code?

I bet my bottom dollar.

The problem is not in the code it is in the way it is implemented. If a totally separate program that simply checks race on spawn and assigned the correct model was used then it would be fifty times more efficient.

Also why is this even in this thread?!
Logged

zero
Full Member
***
Posts: 191



View Profile WWW Email
« Reply #8 on: January 09, 2011, 02:10:04 AM »

So what is better then:
Code:
public OnRaceSelected(client,newrace)
{
   if(newrace!=thisRaceID)
   {
      deactivate
   }
   else
   {   
      activate
   }
}

or

Code:
public OnRaceSelected(client, newrace) {
    if (W3GetVar(OldRace) == thisRaceID) {
        // Deactivate race's skills
    } else if (newrace == thisRaceID) {
        // Activate race's skills
    }
}

Ideally I would like to make my code as efficient as possible.
Logged

Ownz
Developer
Administrator
Hero Member
*****
Posts: 2046



View Profile WWW Email
« Reply #9 on: January 09, 2011, 02:23:13 AM »

a model handling system u say?
Logged

DarkEnergy
Frenzzy
Full Member
***
Posts: 217


337905984 frenzzy@live.ru
View Profile WWW
« Reply #10 on: January 09, 2011, 10:34:02 AM »

launched 50 times in a row? how? is this because 50 races have this code?

Yes, almost all races use custom models.

a model handling system u say?

I dont understand what do you meant.
Logged

O_o
Frenzzy
Full Member
***
Posts: 217


337905984 frenzzy@live.ru
View Profile WWW
« Reply #11 on: January 09, 2011, 10:41:47 AM »

Is there any guarantee that code1 be launched earlier than code2/code3?
When a player change race 1 to race 2.

Race1:
Quote
public OnRaceSelected(client, race)
{
    if (race != thisRaceID) {
        // code1
    }
    else {   
        // Activate skills
    }
}

Race2:
Quote
public OnRaceSelected(client, race)
{
    if (race != thisRaceID) {
        // code2
    }
    else {   
        // code3
    }
}
Logged

O_o
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2046



View Profile WWW Email
« Reply #12 on: January 09, 2011, 11:23:30 AM »

no
Logged

DarkEnergy
Frenzzy
Full Member
***
Posts: 217


337905984 frenzzy@live.ru
View Profile WWW
« Reply #13 on: January 09, 2011, 11:41:59 AM »

Then need OnRaceDeselect(client,race) event.
With guarantee that OnRaceSelected(client,race) event will be execut only after full execution OnRaceDeselect event..
Embarrassed
Logged

O_o
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2046



View Profile WWW Email
« Reply #14 on: January 09, 2011, 11:45:06 AM »

a model handling system u say?
an authoritative buff system for models handling
Logged

DarkEnergy
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!