I've been trying to count how many trolls get killed in one area so stuck this script on the on death section of each troll but it doesn't work, could somebody please point me in the right direction. This is it..
void main()
{
object oPC=GetFirstPC();
int nDeadTrolls = GetGlobal Int("dead_trolls");
nDeadTrolls =+1;
}
Now after slaying the trolls the PC heads off to the troll hunter ad the conversation should change if the global int is 4 but it doesn't. Is there something I should put instead of the GetFirstPC for dead things ? and will this work if anybody else kills the trolls.
Any and all help appreciated thank you..
Simple script ? What have I done wrong ?
Débuté par
Guest_Iveforgotmypassword_*
, janv. 27 2012 10:49
#1
Guest_Iveforgotmypassword_*
Posté 27 janvier 2012 - 10:49
Guest_Iveforgotmypassword_*
#2
Posté 27 janvier 2012 - 12:11
What have you done wrong ? hahahaah !!!! Everything !!!!! Just kidding.
void main()
{
object oPC=GetFirstPC(); /* oPC is used nowhere in this script, that ligne is useless if the full script is nothing more than this.*/
int nDeadTrolls = GetGlobalInt("dead_trolls");
nDeadTrolls ++;
//here what you are missing
SetGlobalInt("dead_trolls",nDeadTrolls); /* without this ligne the global int will never evolve nDeadTrolls is destroyed at the end ofg the script, when the script is loaded again it will be at the init value.*/
}
Well instead of all of this you can just use :
void main(){
SetGlobalInt("dead_trolls",GetGlobalInt("dead_trolls")+1);
}
and an other thing you can write
nDeadTrolls =+1;
that mean nDeadTroll will always be at +1.
But i think what you want is :
nDeadTrolls =nDeadTrolls+1;
wich can be writed
nDeadTrolls ++;
or
++nDeadTrolls ;
now having ++ before or after doesn't do the same thing.
void main{
int n = 1;
//teaching :
int x1 = n++; //this mean x1 value is 1 but n value moved to 2
x1 = ++n; //this mean x1 value is 2 and n value moved to 2
//pratical :
x2 = n++; //n is at 1 x2 is set at 1, and n is moved to 2.
x2 =++n; // n was at 2 and is moved to 3, and x2 is set at 3
}
void main()
{
object oPC=GetFirstPC(); /* oPC is used nowhere in this script, that ligne is useless if the full script is nothing more than this.*/
int nDeadTrolls = GetGlobalInt("dead_trolls");
nDeadTrolls ++;
//here what you are missing
SetGlobalInt("dead_trolls",nDeadTrolls); /* without this ligne the global int will never evolve nDeadTrolls is destroyed at the end ofg the script, when the script is loaded again it will be at the init value.*/
}
Well instead of all of this you can just use :
void main(){
SetGlobalInt("dead_trolls",GetGlobalInt("dead_trolls")+1);
}
and an other thing you can write
nDeadTrolls =+1;
that mean nDeadTroll will always be at +1.
But i think what you want is :
nDeadTrolls =nDeadTrolls+1;
wich can be writed
nDeadTrolls ++;
or
++nDeadTrolls ;
now having ++ before or after doesn't do the same thing.
void main{
int n = 1;
//teaching :
int x1 = n++; //this mean x1 value is 1 but n value moved to 2
x1 = ++n; //this mean x1 value is 2 and n value moved to 2
//pratical :
x2 = n++; //n is at 1 x2 is set at 1, and n is moved to 2.
x2 =++n; // n was at 2 and is moved to 3, and x2 is set at 3
}
Modifié par Shallina, 27 janvier 2012 - 12:28 .
#3
Posté 27 janvier 2012 - 12:31
The really fancy coders, when they're not admonishing you about the horrid indecency of using GetFirstPC(), will also warn you to avoid using global variables. The problem is that if you want to do this kind of code again in the same module, there might be some conflict with using the same variable over again. You could either think of a more specific name for the variable (i.e. "iQuestTrollSlayer_numDeadTrolls", or set the variable on another object, like the area or an i-point that you can access by tag. If there's a known and limited number of trolls to kill, you might even stick the variable into the quest journal, like where quest states 10-20 correspond to 0 to 10 dead trolls.
#4
Posté 27 janvier 2012 - 12:38
GlobalInt is accross the whole campaign.
If your action happen only in a single area, the best is to store the number in the area
SetLocalInt(GetArea(OBJECT_SELF),"nameVar","value");
if your count is accross many area use the module :
SetLocalInt(GetModule(),"nameVar","value");
And to finish is the count is across many module, use GlobalInt.
CampaignInt exist but they aren't impacted by save game.
Wich mean if you save, and reload later, the value of the campaign int won"t be reloaded at its previous value.
Good luck out there, you'll need it .
If your action happen only in a single area, the best is to store the number in the area
SetLocalInt(GetArea(OBJECT_SELF),"nameVar","value");
if your count is accross many area use the module :
SetLocalInt(GetModule(),"nameVar","value");
And to finish is the count is across many module, use GlobalInt.
CampaignInt exist but they aren't impacted by save game.
Wich mean if you save, and reload later, the value of the campaign int won"t be reloaded at its previous value.
Good luck out there, you'll need it .
Modifié par Shallina, 27 janvier 2012 - 12:41 .
#5
Guest_Iveforgotmypassword_*
Posté 27 janvier 2012 - 01:24
Guest_Iveforgotmypassword_*
Wow ! thanks Shalina no wonder it went wrong ! So scrap the PC bit and set the int I think I've got it I'll have a fiddle around soon but the dog is harrassing me for a walk !
Lugaid of the Red Stripes.. Don't worry I'm on the case with my Ints I've got a notebook old fashioned but always reliable ( so long as I can read my own writing ).
Lugaid of the Red Stripes.. Don't worry I'm on the case with my Ints I've got a notebook old fashioned but always reliable ( so long as I can read my own writing ).
#6
Guest_Iveforgotmypassword_*
Posté 27 janvier 2012 - 02:39
Guest_Iveforgotmypassword_*
Well I tried this and nothing happened, nobody knows what a hero my PC has been !
void main()
{
int nDeadTrolls=SetGlobalInt("dead_trolls",GetGlobalInt("dead_trolls"));
nDeadTrolls=nDeadTrolls+1;
}
Can I have another lesson please ?
void main()
{
int nDeadTrolls=SetGlobalInt("dead_trolls",GetGlobalInt("dead_trolls"));
nDeadTrolls=nDeadTrolls+1;
}
Can I have another lesson please ?
#7
Posté 27 janvier 2012 - 02:44
I am not a sensible coder, but I trust myself to be smart enough not to do something stupid. As such, I don't care about things like global ints because if you are careful they will work fine. However, if you only need this variable locally, it's better to store it as a local, perhaps on the area in question. What if you want to count the number of trolls killed in another area later?
I should note a very minor point about what Shallina wrote, this:
nDeadTrolls = +1;
if perfectly valid, but does indeed simply set nDeadTrolls to 1. However, instead of writing:
nDeadTrolls = nDeadTrolls +1;
you can just write:
nDeadTrolls += 1;
which is I think what you were trying to do in the first place. However, when you're adding only one, it is better to write:
nDeadTrolls++;
because it's less typing. But then, that's C for you.
I should note a very minor point about what Shallina wrote, this:
nDeadTrolls = +1;
if perfectly valid, but does indeed simply set nDeadTrolls to 1. However, instead of writing:
nDeadTrolls = nDeadTrolls +1;
you can just write:
nDeadTrolls += 1;
which is I think what you were trying to do in the first place. However, when you're adding only one, it is better to write:
nDeadTrolls++;
because it's less typing. But then, that's C for you.
#8
Posté 27 janvier 2012 - 03:43
SetGlobalInt("dead_trolls",GetGlobalInt("dead_trolls")+1);
use this. Your code can't work BTW beceause you set nothing new.
use this. Your code can't work BTW beceause you set nothing new.
Modifié par Shallina, 27 janvier 2012 - 03:43 .
#9
Guest_Iveforgotmypassword_*
Posté 27 janvier 2012 - 03:51
Guest_Iveforgotmypassword_*
The Fred.. I did a double + and scrapped the nDeadTrolls = part but it's still not registering that any trolls were killed. I've checked the conversation condition and the trolls have the right script on their ondeath section. The Global Int doesn't seem to exist at all as my conversation has 3 nodes, one for no global int (go get the trolls ) one for when it equals 1 ( there are more out there )and one for greater than 1 (good job mate ) but still fires the go and get the trolls line. What's missing ?
#10
Guest_Iveforgotmypassword_*
Posté 27 janvier 2012 - 03:58
Guest_Iveforgotmypassword_*
Shalina.. I just missed your post, but I've stuck that line in and wiped out the rest and nothing happens again I'm even starting to feel sorry for my trollsbut now I know why I avoid scripts like the plague !
#11
Posté 27 janvier 2012 - 04:04
int nDeadTrolls=SetGlobalInt("dead_trolls",GetGlobalInt("dead_trolls"));
I think this isn't even compiling.
SetGlobalInt can only return TRUE of FALSE if it return something.
Set store a value.
Get Fetch a value.
In your case you want to update an existing value and increase it by 1.
So First you need to get that value.
int nDeadTrolls = GetGlobal Int("dead_trolls");
Then you need to increase that value :
nDeadTrolls = nDeadTrolls+1;
Then you need to store that new value or else it will be lost at the end of the script.
SetGlobalInt("dead_trolls",nDeadTrolls);
Given the trouble you have to write this, there are probably problems in the way you check it in the conversation as well.
You need a gc_ script that check the number of dead troll in the condition panel (green one). Post it as well.
I think this isn't even compiling.
SetGlobalInt can only return TRUE of FALSE if it return something.
Set store a value.
Get Fetch a value.
In your case you want to update an existing value and increase it by 1.
So First you need to get that value.
int nDeadTrolls = GetGlobal Int("dead_trolls");
Then you need to increase that value :
nDeadTrolls = nDeadTrolls+1;
Then you need to store that new value or else it will be lost at the end of the script.
SetGlobalInt("dead_trolls",nDeadTrolls);
Given the trouble you have to write this, there are probably problems in the way you check it in the conversation as well.
You need a gc_ script that check the number of dead troll in the condition panel (green one). Post it as well.
#12
Guest_Iveforgotmypassword_*
Posté 27 janvier 2012 - 04:27
Guest_Iveforgotmypassword_*
Shalina.. I have used global int conditions on conversations many many times and they've never failed but this is the first time using them on a scripted int. I put the gc_global int condition in the box click and refresh,then fill in dead_trolls in the string section and put !0 with the not box checked for no trolls, 1 for one troll and >1 for all of them in the last box.
Now I have just changed the script to..
void main();
{
int nDeadTrolls = GetGlobalInt("dead_trolls");
nDeadTrolls =nDeadTrolls+1;
SetGlobalInt("dead_trolls",nDeadTrolls):
}
Nothing happens !
I'm going away for a bit as this is driving me round the bend.
Now I have just changed the script to..
void main();
{
int nDeadTrolls = GetGlobalInt("dead_trolls");
nDeadTrolls =nDeadTrolls+1;
SetGlobalInt("dead_trolls",nDeadTrolls):
}
Nothing happens !
I'm going away for a bit as this is driving me round the bend.
Modifié par Iveforgotmypassword, 27 janvier 2012 - 04:28 .
#13
Posté 27 janvier 2012 - 04:38
this script work, it increase the dead_trolls count each time the script is called.
Wich mean now the problems is somewhere else :
Is the script called ?
and if the script is correctly called, is the dead_troll value correctly checked in the gc_script.
Now that you learned the basic of scripting, it's time for you to learn the basic of debugging "evil laught"
void main();
{
int nDeadTrolls = GetGlobalInt("dead_trolls");
nDeadTrolls =nDeadTrolls+1;
SetGlobalInt("dead_trolls",nDeadTrolls):
SendMessageToPC(GetFirstPC(FALSE),"I have killed "+ IntToString(GetGlobalInt("dead_trolls"))+ " trolls");
}
Each time you kill a troll you should have a message.
You should post your Gc script just in case, and I also could give you a line for debugging for it.
int StartingConditional(){
SendMessageToPC(GetFirstPC(FALSE), IntToString(GetGlobalInt("dead_trolls"))+ " trolls are dead");
if (GetGlobalInt("dead_trolls")==5){
return TRUE;
}
return FALSE;
}
Wich mean now the problems is somewhere else :
Is the script called ?
and if the script is correctly called, is the dead_troll value correctly checked in the gc_script.
Now that you learned the basic of scripting, it's time for you to learn the basic of debugging "evil laught"
void main();
{
int nDeadTrolls = GetGlobalInt("dead_trolls");
nDeadTrolls =nDeadTrolls+1;
SetGlobalInt("dead_trolls",nDeadTrolls):
SendMessageToPC(GetFirstPC(FALSE),"I have killed "+ IntToString(GetGlobalInt("dead_trolls"))+ " trolls");
}
Each time you kill a troll you should have a message.
You should post your Gc script just in case, and I also could give you a line for debugging for it.
int StartingConditional(){
SendMessageToPC(GetFirstPC(FALSE), IntToString(GetGlobalInt("dead_trolls"))+ " trolls are dead");
if (GetGlobalInt("dead_trolls")==5){
return TRUE;
}
return FALSE;
}
Modifié par Shallina, 27 janvier 2012 - 04:44 .
#14
Guest_Iveforgotmypassword_*
Posté 27 janvier 2012 - 06:10
Guest_Iveforgotmypassword_*
Shalina.. You can put away your evil laugh and debugging implements for a while the conditions were fine. But it still was my mistake, one of my "dead trolls" had a capital letter in the script !
Thank you for your patience mine's just about ran out now and the trolls are looking rather miserable but then again they have been fireballed rather a lot lately.This script will be kept as a treasure and copied many times I am sure. .
Once again many thanks.
Tsongo.
Thank you for your patience mine's just about ran out now and the trolls are looking rather miserable but then again they have been fireballed rather a lot lately.This script will be kept as a treasure and copied many times I am sure. .
Once again many thanks.
Tsongo.
#15
Posté 27 janvier 2012 - 06:34
One last suggestion....
Instead of replacing the standard death script, you just have to store a local string on the creature and name it "DeathScript". The value of the string should be the name of the script you want to fire on the creature's death. This allows you to keep all the functionality of the standard on-death script and insert your own custom code.
Instead of replacing the standard death script, you just have to store a local string on the creature and name it "DeathScript". The value of the string should be the name of the script you want to fire on the creature's death. This allows you to keep all the functionality of the standard on-death script and insert your own custom code.
#16
Guest_Iveforgotmypassword_*
Posté 27 janvier 2012 - 07:26
Guest_Iveforgotmypassword_*
M.Reider.. Thank's for the suggestion but for now I'm just happy with what I've got and don't want to confuse myself any more but I'll bear it in mind.
#17
Posté 28 janvier 2012 - 02:20
Think of a script as a small short story. It has subjects and predicates, clauses and a plot sequence:
- subjects are like objects, ints, strings, etc.
- predicates (verbs) tell the game to do things to subjects.
- clauses are things like if(), while(), & for() 'scopes'.
- the plot sequence can be, and is altered by functions like DelayCommand(), AssignCommand(), ActionDoCommand(). aka The Epilogue (these happen only after the script completes)
hth
- subjects are like objects, ints, strings, etc.
- predicates (verbs) tell the game to do things to subjects.
- clauses are things like if(), while(), & for() 'scopes'.
- the plot sequence can be, and is altered by functions like DelayCommand(), AssignCommand(), ActionDoCommand(). aka The Epilogue (these happen only after the script completes)
hth
#18
Guest_Iveforgotmypassword_*
Posté 28 janvier 2012 - 03:18
Guest_Iveforgotmypassword_*
KevL.. Thank you for the advice, I understand the principles but I just think of a script as something to be avoided however sometimes I dig a hole for myself and need one and slowly but surely they are creeping into my modules. Such as the troll problem above caused when I decided it was too small to turn into a quest and the whole point of it was to not tell the troll hunters you'd killed them so I needed a way to check without a journal.
This script however will now be added to my small collection to be used over and over in future stuff and increase my possibilities eg stealthy areas with penalties for killing.
This script however will now be added to my small collection to be used over and over in future stuff and increase my possibilities eg stealthy areas with penalties for killing.





Retour en haut






