Author Topic: Save yourself a lot of time - Make The Switch!!  (Read 966 times)

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #30 on: September 06, 2010, 09:47:26 am »


               'B)'

GhostOfGod wrote...

The "scripts" of our lives.

As the "constant" turns.

One "script" to live.

Young and "Switch"less?

':lol:' Sorry. I couldn't help myself.


':blink:'

I approve!  '<img'>
               
               

               
            

Legacy_Redunct

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #31 on: September 06, 2010, 09:05:43 pm »


               It seems like you're trying to make functions.

Let me give you an example:

//In this script, we will create a function to identify if the player has a certain set of varriables.
//Note, that this should only be done with someone you will use often.
int IsDMillia(object oPC)
{
//Declare Variables
int i;
//First, we will see if the player is a member of this group. We will use a local
//int to identify this. Also, if this is false, we will cut the script at that
//point and return the result 1.
if (GetLocalInt(oPC,"IsDMillia")!=1)return i;
i++;
//Next, we'll check to see if the player did anything to upset this faction.
//We can place something somewhere else to allow them to make up for this,
//Or whatever else we may want to do. We will do the same thing as before.
if (GetLocalInt(oPC,"IsInTrouble")==1)return i;
i++;
//After that, we will check to see if the player is wearing his uniform.
object oChest;
oChest = GetItemInSlot(INVENTORY_SLOT_CHEST,oPC);
if (GetTag(oChest)!="DMilliaUniform")return i;
i++;
//Finally, we want to look for a certain integer, let's say for this case the integer
//Represents completing an objective.
if (GetLocalInt(oPC,"didjob")==1)i++;
return i;
}


Save that script as "xc_check_faction".

Then, for an example of an event script:

//Include the script we just made:
#include "xc_check_faction"

//This script will be ran we the player tries to enter the factions head quarters.
//The Guard will be the one who opens the door. Clicking on the guard is used to open the door.
//What the Guard actually does depends on the players condition.
void main()
{
object oPC;
oPC = GetClickingObject();
int x;
x = IsDMillia(oPC);
object oDoor;
oDoor = GetObjectByTag("DMilDoor");
switch (x)
{   //If not a member, the guard will attack.
    case 0:
    ActionAttack(oPC);
    break;
    //If a member but in trouble, the guard will tell the player to get lost, he's
    //not welcome.
    case 1:
    ActionSpeakString("You have some nerve showing your face. You're not welcome here, traitor.");
    break;
    //If a member but not wearing outfit, the Guard will tell the player to put his uniform on.
    case 2:
    ActionSpeakString("Look, buddy, I don't care what you wear at the local inn but 'round here you will dress right.");
    break;
    //If everything is right with the character BUT the character did not finish his job.
    case 3:
    ActionSpeakString("The boss isn't gonna wanna see you until you finish your job. You better finish. Now.");
    break;
    //If mission is complete, guard will open door.

    case 4:
    ActionSpeakString("Bout' time you're back. Boss wants to see you.");
    ActionUnlockObject(oDoor);
    ActionOpenDoor(oDoor);
    break;
}
}


You can, of course, do a variatey of things with this now, including custom conversation scripts amongst members.
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #32 on: September 06, 2010, 11:11:29 pm »


               Redunct, that will only server to confuse the reader further, it's not even remotely close to what I was showing, I was showing how to use constants to control the results of a script, by outlining to the script reader that you can use constants to control a script, which makes it easier for a scripter to modify a script to control how the script functions essentially.  

Where the above argument started was me calling the constants = switches, so to clarify my statement, which was spurred upon the title, more than giving constants another name, I'm using constants as control switches to turn functions on / off or to change how something within the coding of script works...

example:

//Set this # to control what level the PC must be in order for this to happen
const int THIS_CONSTANT = 5;

void main()
{

 object oPC = GetLastUsedBy();

 int nVar = GetHitDice(oPC);

//if the PC is the level set above, then do this...
if (nVar == THIS_CONSTANT)
 {
    //do this..
 } 
}

Very simple scripting, truly..
               
               

               


                     Modifié par Genisys, 06 septembre 2010 - 10:15 .
                     
                  


            

Legacy_Redunct

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #33 on: September 06, 2010, 11:48:17 pm »


               

Genisys wrote...

Redunct, that will only server to confuse the reader further, it's not even remotely close to what I was showing, I was showing how to use constants to control the results of a script, by outlining to the script reader that you can use constants to control a script, which makes it easier for a scripter to modify a script to control how the script functions essentially.  

Where the above argument started was me calling the constants = switches, so to clarify my statement, which was spurred upon the title, more than giving constants another name, I'm using constants as control switches to turn functions on / off or to change how something within the coding of script works...

example:

//Set this # to control what level the PC must be in order for this to happen
const int THIS_CONSTANT = 5;

void main()
{

 object oPC = GetLastUsedBy();

 int nVar = GetHitDice(oPC);

//if the PC is the level set above, then do this...
if (nVar == THIS_CONSTANT)
 {
    //do this..
 } 
}

Very simple scripting, truly..


Why not just declare 5? It seems like that is a big waste of time if all you're doing is making a constant for 5. Hell, writing 5 is about as simple as you can get.

void main()

{



 object oPC = GetLastUsedBy();



 int nVar = GetHitDice(oPC);



//if the PC is the level set above, then do this...

if (nVar == 5)

 {

    //do this..

 } 

}

From what I saw, you were trying to Declare a universal varriable, which can be applied in multiple situations, in which case declaring a function would be a million times simpler, plus, it would allow for more control in what it does. If your variable already has a default function that would run it, just use that. The only case you would use constants is for something that would never change. There's no point in doing what you just showed me. Why declare 5 as a constant?

If you're saying the stuff above the constant does something to reach 5, it would be much simpler and more productive to use a custom function.


I'm just not seeing where you're coming from. Show me an example of usage of a constant that would make things easier were a function wouldn't serve better.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #34 on: September 07, 2010, 02:36:05 am »


               Something like this, redunct:

//////////////////////////////GOGS AutoAFK System///////////////////////////////
//Name: "gogs_afk_inc"
//Date: 8-4-2010
//Type: include
////////////////////////////////////////////////////////////////////////////////
#include "x3_inc_string"
/////////////////////////////CONFIGURABLE OPTIONS///////////////////////////////

                             //!!!IMPORTANT!!//
//!!Be sure to "Build" you module after making any changes to this script!!

//Set timer for chat check and movement detection. After this time has expired
//for both checks then the AFK effect type will be applied.
//Default: 600 seconds(10 minutes)
const int TIMER = 600;//Seconds
//If using the RP XP option, decreasing the chat timer will mean that players
//will have to chat more often to recieve the XP reward.
const int CHAT_TIMER = 600;//Seconds

//Available AFK types:
//1 = Repeating floating text on player.
//2 = A visual effect will be applied to the player.
//3 = Transport player to an object in AFK area.
//4 = Boot player.
//5 = Play Animation(looping type only).
const int AFK_TYPE = 1;

//Options for AFK_TYPE 1:
//Enter message that you want to float over the players head when he/she is AFK.
//Default: "AFK"
const string AFK_FLOATING_MESSAGE = "AFK";
//Change the color of the floating text. Options for colors:
//STRING_COLOR_BLACK
//STRING_COLOR_BLUE
//STRING_COLOR_GREEN
//STRING_COLOR_PINK
//STRING_COLOR_RED
//STRING_COLOR_ROSE
//STRING_COLOR_WHITE
const string FLOATY_COLOR = STRING_COLOR_RED;
//Allow floaty text with all AFK types. Default: FALSE
const int FLOATY_TEXT_ALWAYS = FALSE;

//Option for AFK_TYPE 2:
//Enter desired VFX number or constant. Default: VFX_DUR_FLAG_GOLD
const int AFK_EFFECT = VFX_DUR_FLAG_GOLD;

//AFK OBJECT. This object is used for AFK_TYPE 2 and AFK_TYPE 3.
//Simply pick any placeable of your choosing and give it the tag below.
//Also make sure the object is checked "plot".If using the object for TYPE 2 you
//can put it in any area. If using it for TYPE 3 place it in the AFK area that
//players will be teleported to.
//Note for AFK_TYPE 3: This option sets a location on the player that they can
//be auto-ported back to. However should the player log out and log back in or
//if the server crashes, this location will be lost. Therefore you should have
//an alternate way of leaving the AKF area.
//Default: "GOGS_AFK_OBJECT"
const string AFK_OBJECT = "GOGS_AFK_OBJECT";
//Additional note for AFK type 3: I have made it so that a player who is in the
//AFK area must type something/anything in the chat bar for them to return to
//their stored location. This is to prevent other players from simply pushing
//the player around and causing a change in location which would teleport them.
//A repeating message is sent to the player until they type something.
//Message:
const string AFK_AREA_MESSAGE = "Type anything in the chat bar to be ported back to saved location.";
//Select color of message. Same color options as above apply.
const string AREA_MESSAGE_COLOR = STRING_COLOR_RED;

//Option for AFK_TYPE 5:
//Enter desired looping animation constant for the AFK animation.
//Default: ANIMATION_LOOPING_SIT_CROSS
const int AFK_ANIMATION = ANIMATION_LOOPING_SIT_CROSS;

//Send a message to the party members of the player that is AFK. This will
//display a message once when the player has gone AFK and once when the player
//is no longer AFK.
//If TRUE, message will be displayed to all party members. DEFAULT: TRUE
const int SEND_FACTION_MESSAGE = TRUE;
//Select color of message. Same color options as above apply.
const string FACTION_MESSAGE_COLOR = STRING_COLOR_PINK;

//Options for awarding RP XP. Basically, if the player is not AFK and has
//chatted within the last timer delay, the player will receive XP.
//Set to TRUE to give RP XP.
const int RP_XP_REWARD = FALSE;
//Set desired amount of XP to give every cycle.
const int XP_AMOUNT = 100;

////////////////////////////END CONFIGURABLE OPTIONS////////////////////////////

////////////////////////////////////////////////////////////////////////////////
void SendAFKFactionMessage(object oPC)
{
.............


Changing the constants in the beginning of the script will change how the script works below it. Thus acting as a kind of switch. And of course doing this allows for easy customization for other people who might use the script/system.
               
               

               


                     Modifié par GhostOfGod, 07 septembre 2010 - 01:44 .
                     
                  


            

Legacy_Redunct

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #35 on: September 07, 2010, 07:06:37 pm »


               

GhostOfGod wrote...

Something like this, redunct:

//////////////////////////////GOGS AutoAFK System///////////////////////////////
//Name: "gogs_afk_inc"
//Date: 8-4-2010
//Type: include
////////////////////////////////////////////////////////////////////////////////
#include "x3_inc_string"
/////////////////////////////CONFIGURABLE OPTIONS///////////////////////////////

                             //!!!IMPORTANT!!//
//!!Be sure to "Build" you module after making any changes to this script!!

//Set timer for chat check and movement detection. After this time has expired
//for both checks then the AFK effect type will be applied.
//Default: 600 seconds(10 minutes)
const int TIMER = 600;//Seconds
//If using the RP XP option, decreasing the chat timer will mean that players
//will have to chat more often to recieve the XP reward.
const int CHAT_TIMER = 600;//Seconds

//Available AFK types:
//1 = Repeating floating text on player.
//2 = A visual effect will be applied to the player.
//3 = Transport player to an object in AFK area.
//4 = Boot player.
//5 = Play Animation(looping type only).
const int AFK_TYPE = 1;

//Options for AFK_TYPE 1:
//Enter message that you want to float over the players head when he/she is AFK.
//Default: "AFK"
const string AFK_FLOATING_MESSAGE = "AFK";
//Change the color of the floating text. Options for colors:
//STRING_COLOR_BLACK
//STRING_COLOR_BLUE
//STRING_COLOR_GREEN
//STRING_COLOR_PINK
//STRING_COLOR_RED
//STRING_COLOR_ROSE
//STRING_COLOR_WHITE
const string FLOATY_COLOR = STRING_COLOR_RED;
//Allow floaty text with all AFK types. Default: FALSE
const int FLOATY_TEXT_ALWAYS = FALSE;

//Option for AFK_TYPE 2:
//Enter desired VFX number or constant. Default: VFX_DUR_FLAG_GOLD
const int AFK_EFFECT = VFX_DUR_FLAG_GOLD;

//AFK OBJECT. This object is used for AFK_TYPE 2 and AFK_TYPE 3.
//Simply pick any placeable of your choosing and give it the tag below.
//Also make sure the object is checked "plot".If using the object for TYPE 2 you
//can put it in any area. If using it for TYPE 3 place it in the AFK area that
//players will be teleported to.
//Note for AFK_TYPE 3: This option sets a location on the player that they can
//be auto-ported back to. However should the player log out and log back in or
//if the server crashes, this location will be lost. Therefore you should have
//an alternate way of leaving the AKF area.
//Default: "GOGS_AFK_OBJECT"
const string AFK_OBJECT = "GOGS_AFK_OBJECT";
//Additional note for AFK type 3: I have made it so that a player who is in the
//AFK area must type something/anything in the chat bar for them to return to
//their stored location. This is to prevent other players from simply pushing
//the player around and causing a change in location which would teleport them.
//A repeating message is sent to the player until they type something.
//Message:
const string AFK_AREA_MESSAGE = "Type anything in the chat bar to be ported back to saved location.";
//Select color of message. Same color options as above apply.
const string AREA_MESSAGE_COLOR = STRING_COLOR_RED;

//Option for AFK_TYPE 5:
//Enter desired looping animation constant for the AFK animation.
//Default: ANIMATION_LOOPING_SIT_CROSS
const int AFK_ANIMATION = ANIMATION_LOOPING_SIT_CROSS;

//Send a message to the party members of the player that is AFK. This will
//display a message once when the player has gone AFK and once when the player
//is no longer AFK.
//If TRUE, message will be displayed to all party members. DEFAULT: TRUE
const int SEND_FACTION_MESSAGE = TRUE;
//Select color of message. Same color options as above apply.
const string FACTION_MESSAGE_COLOR = STRING_COLOR_PINK;

//Options for awarding RP XP. Basically, if the player is not AFK and has
//chatted within the last timer delay, the player will receive XP.
//Set to TRUE to give RP XP.
const int RP_XP_REWARD = FALSE;
//Set desired amount of XP to give every cycle.
const int XP_AMOUNT = 100;

////////////////////////////END CONFIGURABLE OPTIONS////////////////////////////

////////////////////////////////////////////////////////////////////////////////
void SendAFKFactionMessage(object oPC)
{
.............


Changing the constants in the beginning of the script will change how the script works below it. Thus acting as a kind of switch. And of course doing this allows for easy customization for other people who might use the script/system.


That's all well and good, but that's not what he was talking about. I believe I mentioned that constant should only be used for things that do not change, and are used constantly. If not, I meant to.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #36 on: September 07, 2010, 07:25:08 pm »


               

Redunct wrote...

That's all well and good, but that's not what he was talking about.


Actually that is what he has been talking about. There was just a bit of confusion about it.(either that or I am reconfused ':lol:')
And of course using constants in this fashion does not make then no longer constant. They are still constant "in game" and can not be changed. They are just something that you can change in the toolset before running the game to alter the script. As the original OP was trying to get across was that this could be useful for template/reusable type scripts. Instead of having three or four scripts to change back and forth between while your messing around with stuff in the tool set, you can make 1 script with a const int at the top to switch which way/version of the one script you want to go with.

Again this would mainly be for multiple use systems and can help cut back the number of scripts used in certain situations.
               
               

               


                     Modifié par GhostOfGod, 07 septembre 2010 - 06:27 .
                     
                  


            

Legacy_Redunct

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +0/-0
Save yourself a lot of time - Make The Switch!!
« Reply #37 on: September 07, 2010, 07:29:29 pm »


               

GhostOfGod wrote...

Redunct wrote...

That's all well and good, but that's not what he was talking about.


Actually that is what he has been talking about. There was just a bit of confusion about it.(either that or I am reconfused ':lol:')
And of course using constants in this fashion does not make then no longer constant. They are still constant "in game" and can not be changed. They are just something that you can change in the toolset before running the game to alter the script. As the original OP was trying to get across was that this could be useful for template/reusable type scripts. Instead of having three or four scripts to change back and forth between while your messing around with stuff in the tool set, you can make 1 script with a const int at the top to switch which way/version of the one script you want to go with.

Again this would mainly be for multiple use systems and can help cut back the number of scripts used in certain situations.


Well, his example was nothing like that.