Aller au contenu

Photo

Resource gathering script


  • Veuillez vous connecter pour répondre
24 réponses à ce sujet

#1
DragonDario

DragonDario
  • Members
  • 12 messages
Hi and tanks in advance. I am making a campaing and what I need now i s a script wich would look like this:

oUser // Pc wich is using placable ( tree, ore vein, etc.)
oTool // Tool wich oUser has in inventory, and would be different regarding the oSorce(axe,  pickaxe, etc.)
oSorce // The source that oPc is using (by left click so this script should be on click)
nSkill // I would either use SURVIAVAl or new skill for this
nSkill level //level of selected skill
oMaterial // Material that oUser gets
nSTR // STR level of oUser
nGive // quantitiy od oMaterial to be given to oUser

And now the script checks if required level is matched, if required tool is matched and then makes animation and sound, gives oMaterial to oUser depending on his sternght( if STR<10 give 0,  10-15 give 1,  16-20 give 2 and STR>20 give 3) and then DOESN'T give anything for next 5 minutes. And some messages like "oUser got n Material" and "oSource is empty".

Please help.

#2
Morbane

Morbane
  • Members
  • 1 883 messages
Whilst posting with questions on scripting, it is prudent to skim through the other threads. There is always good information passing through to other yet similar topics. Further, it is also prudent to try to learn a bit on your own before asking for someone to write a script for you - at best having something wrong is better than having nothing at all for others to help out with. Lastly, check out the IGN NWN Vault in the tutorial section - you will surely find some excellent tutorials on scripting - that is how those who might help learnt themselves.

#3
rjshae

rjshae
  • Members
  • 4 485 messages
I'd suggest breaking the problem down into smaller problems and get each one working in turn. For the first entry, one approach would be for the character to either click-to-use the selected placeable, or have some sort of clickable invisible object (like a usable Collision Ball). Try setting that up for one placeable and put a feedback script in the placeable's On Left Click script.

#4
DragonDario

DragonDario
  • Members
  • 12 messages
I see, my most common problem is taht script can't be compiled becuse I did something wrong in 1 part and when I correct it something else manlufuncions.

#5
rjshae

rjshae
  • Members
  • 4 485 messages
Well then try looking for syntax errors and so forth, then keep going until you have all the problems worked out. I'm not sure how we can help you there.

Modifié par rjshae, 28 septembre 2010 - 09:47 .


#6
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
My tutorial may be of some help. There's a section in there on some of the common compile errors and possible causes for them. Linked in signature below.

Also, posting what script you have so far will help us help you.

Modifié par _Knightmare_, 28 septembre 2010 - 09:55 .


#7
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
Not sure i understand what you are trying to do but it sounds a little like a chopping down tree script. I posted one of those here.



Regards

#8
DragonDario

DragonDario
  • Members
  • 12 messages
Thank you for turtorial. And it is similar to your script but without damaging the tree, just clicking on it + animation and sound.

#9
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
It sounds like you may want a customized onUsed script then. Take a look at the onUsed script here. It is a script I wrote and then Uncle FB modified for his Light Keeper that allows various things to happen when someone uses an item. In the case of the Light Keeper it turns on/off lights, but it is a generic script and uses variables on the object used to determine what should be done. You should be able to modify it to suit your purposes.



Regards

#10
DragonDario

DragonDario
  • Members
  • 12 messages
Thanks, now I just have to modify it a little and all done. Ty all.

#11
DragonDario

DragonDario
  • Members
  • 12 messages
Here is the script now, but unfortunally the compiler says:
(22): ERROR: NO RIGHT BRACKET ON EXPRESSION
It's the row with "if" condition, and if I delete whole row, it compiles succesfully.
That is weird because i have equal number of left and right brackets:alien:.
So does anyone know what the problem is?

// Placeable OnUsed Gain some resources
// Created by: DragonDario
// Created on: 01.10.2010.
/*
Required: Static=FALSE, Usable=TRUE, CurrentHP>0, attach script to the OnUsed event
Suggested: Plot=TRUE, DefaultActionPreference="Use"
*/
//

#include "ginc_debug"

void main(string sTool, string sOre)
{
object oUser = GetLastUsedBy();
object oPlaceable = OBJECT_SELF;
int nStack = GetAbilityScore(oUser, ABILITY_STRENGTH, FALSE) - GetHardness(oPlaceable);
location lItem = GetLocation(oPlaceable);
float fDelay = 2.5;
float fDelayAction= 300.0;
string sUsed;
PrettyDebug(GetName(oPlaceable) + "'s was used by " + GetName(oUser));
if((GetItemPossessedBy(oUser, sOre)) ˛˛ (nStack > 0) ˛˛ (GetLocalInt(oUser, sUsed)))
{
CreateItemOnObject(sOre, oUser, nStack, "", TRUE);
SetLocalInt(oUser, sUsed, 1);
DelayCommand(fDelayAction, DeleteLocalInt(oUser, sUsed));
}
else
{
PrettyError("You don't have the right tool or have to low strenght.", fDelay, 16711680);
}
}

#12
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

DragonDario wrote...

Here is the script now, but unfortunally the compiler says:
(22): ERROR: NO RIGHT BRACKET ON EXPRESSION
It's the row with "if" condition, and if I delete whole row, it compiles succesfully.
That is weird because i have equal number of left and right brackets:alien:.
So does anyone know what the problem is?


You have 5 opening/right brackets but 6 closing/left brackets. Delete one of the left brackets.

Also, I see where you declared string sUsed; and later used that as a parameter in a couple functions, but don't see where you assigned sUsed a value.

Modifié par _Knightmare_, 02 octobre 2010 - 12:03 .


#13
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
An onUsed script isn't going to able to pass in variables. So your main statement should just be:
void main()
You will need to define sTool and sOre within the main function. You can get sTool by getting the tag of the object returned by the GetItemInSlot function. For sOre I would get that by checking a local variable on the placeable.

Off hand, I don't see the bracket problem, but usually they aren't hard to figure out. Just comment out different sections of the script and compile until you figure out which section introduces the error. For such a short script it should only take a minute to figure out.

Regards

Modifié par Kaldor Silverwand, 02 octobre 2010 - 11:56 .


#14
DragonDario

DragonDario
  • Members
  • 12 messages
Nope, I counted them I got 6 and 6, but I did what you said and no use, then it says that I got a semicolon missing and if I add a semicolon, it says that "if" statment cannot be followed by null statment. Any other idea?

I have made some improvments on script but still get the same error on same field:

// Placeable OnUsed Gain some resources
// Created by: DragonDario
// Created on: 01.10.2010.
/*
Required: Static=FALSE, Usable=TRUE, CurrentHP>0, attach script to the OnUsed event
Suggested: Plot=TRUE, DefaultActionPreference="Use"
*/
//

#include "ginc_debug"

void main(string sTool, string sOre)
{
object oUser = GetLastUsedBy();
object oPlaceable = OBJECT_SELF;
int nStack = GetAbilityScore(oUser, ABILITY_STRENGTH, FALSE) - GetHardness(oPlaceable);
location lItem = GetLocation(oPlaceable);
float fDelay = 2.5;
float fDelayAction= 300.0;
string sUsed;
PrettyDebug(GetName(oPlaceable) + "'s was used by " + GetName(oUser));
if((GetItemPossessedBy(oUser, sOre)) ˛˛ (nStack > 0) ˛˛ (GetLocalInt(oUser, sUsed) != 1))
{
CreateItemOnObject(sOre, oUser, nStack, "", TRUE);
SetLocalInt(oUser, sUsed, 1);
DelayCommand(fDelayAction, SetLocalInt(oUser, sUsed, 0));
}
else
{
PrettyError("You don't have the right tool or have to low strenght.", fDelay, 16711680);
}
}

#15
DragonDario

DragonDario
  • Members
  • 12 messages
Ok, I remodified the script and now complies succesfully. Now just few little modifications and I'll publish it here.:wizard:

Modifié par DragonDario, 03 octobre 2010 - 11:19 .


#16
DragonDario

DragonDario
  • Members
  • 12 messages
Hi again, I was working on that script for 6 days and got this:



// Placeable OnUsed Gain some resources

// Created by: DragonDario

// Created on: 01.10.2010.

/*

Required: Static=FALSE, Usable=TRUE, CurrentHP>0, attach script to the OnUsed event

Suggested: Plot=TRUE, DefaultActionPreference="Use"

*/

//



#include "ginc_debug"



void main(string sTool, string sRaw, string sSound, string nUsed, string nXP)

{

object oUser = GetLastUsedBy();

object oPlaceable = OBJECT_SELF;

int nStack = GetAbilityScore(oUser, ABILITY_STRENGTH, FALSE) - GetHardness(oPlaceable);

location lItem = GetLocation(oPlaceable);

float fDelay = 2.5;

float fDelayAction= 300.0;

PrettyDebug(GetName(oPlaceable) + "'s was used by " + GetName(oUser));

if(GetItemInSlot(INVENTORY_SLOT_CWEAPON_B, oUser) == GetItemPossessedBy(oUser, GetLocalString(oPlaceable, sTool)))

{

if(nStack > 0)

{

if(GetLocalInt(oPlaceable, nUsed) != 1)

{

ActionPlayAnimation(ANIMATION_LOOPING_CRAFT01, 1.50, 5.00);

PlaySound(sSound, FALSE);

GiveXPToCreature(oUser, GetLocalInt(oPlaceable, nXP));

CreateItemOnObject(GetLocalString(oPlaceable, sRaw), oUser, nStack, "", TRUE);

SetLocalInt(oPlaceable, nUsed, 1);

DelayCommand(fDelayAction, SetLocalInt(oPlaceable, nUsed, 0));

}

else

{

PrettyError("You have already used this resource out.", fDelay, 16711680);

}

}

else

{

PrettyError("You have too low strenght.", fDelay, 16711680);

}



}

else

{

PrettyError("You don't have the right tool.", fDelay, 16711680);

}

}









And script compiles successfully but doesn't work at all so if any1 got any suggestion, idea or anything else please let me know.

#17
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
void main(string sTool, string sRaw, string sSound, string nUsed, string nXP)



The above is your biggest problem. Scripts of this sort, where there is paramters listed in the ( ) of the void main line, only work when fired from a conversation.



If you are looking to do it so when a player somehow interacts with a placeable or whatever, you will need to remove everything inside those ( ) and set their values within the script itself.

#18
DragonDario

DragonDario
  • Members
  • 12 messages
It still doesn't work:

// Placeable OnUsed Gain some resources
// Created by: DragonDario
// Created on: 01.10.2010.
/*
Required: Static=FALSE, Usable=TRUE, CurrentHP>0, attach script to the OnUsed event
Suggested: Plot=TRUE, DefaultActionPreference="Use"
*/
//

#include "ginc_debug"

void main()
{
object oUser = GetLastUsedBy();
string sTool;
string sRaw;
string sSound;
string nUsed;
string nXP;
object oPlaceable = OBJECT_SELF;
int nStack = GetAbilityScore(oUser, ABILITY_STRENGTH, FALSE) - GetHardness(oPlaceable);
location lItem = GetLocation(oPlaceable);
float fDelay = 2.5;
float fDelayAction= 300.0;
PrettyDebug(GetName(oPlaceable) + "'s was used by " + GetName(oUser));
if(GetItemInSlot(INVENTORY_SLOT_CWEAPON_B, oUser) == GetItemPossessedBy(oUser, GetLocalString(oPlaceable, sTool)))
{
if(nStack > 0)
{
if(GetLocalInt(oPlaceable, nUsed) != 1)
{
ActionPlayAnimation(ANIMATION_LOOPING_CRAFT01, 1.50, 5.00);
PlaySound(sSound, FALSE);
GiveXPToCreature(oUser, GetLocalInt(oPlaceable, nXP));
CreateItemOnObject(GetLocalString(oPlaceable, sRaw), oUser, nStack, "", TRUE);
SetLocalInt(oPlaceable, nUsed, 1);
DelayCommand(fDelayAction, SetLocalInt(oPlaceable, nUsed, 0));
}
else
{
PrettyError("You have already used this resource out.", fDelay, 16711680);
}
}
else
{
PrettyError("You have too low strenght.", fDelay, 16711680);
}

}
else
{
PrettyError("You don't have the right tool.", fDelay, 16711680);
}
}

#19
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
You are getting closer. Now you need to assign a value to those (set them equal to something):

string sTool;
string sRaw;
string sSound;
string nUsed;
string nXP;

The concept is similar to what you did with these other types of things:

object oUser = GetLastUsedBy();
object oPlaceable = OBJECT_SELF;
int nStack = GetAbilityScore(oUser, ABILITY_STRENGTH, FALSE) - GetHardness(oPlaceable);
location lItem = GetLocation(oPlaceable);
float fDelay = 2.5;
float fDelayAction= 300.0;

You need to tell the script what those things in the first list represent, otherwise the script has no idea what they are supposed to be.

Its sort of like if I walked up to you out of nowhere and said "its blue." Well ok sure its blue, but that doesn't help you to know what I'm talking about. I need to tell you what "it" is, and then in that context the fact "its blue" makes more sense...

Modifié par _Knightmare_, 10 octobre 2010 - 12:32 .


#20
DragonDario

DragonDario
  • Members
  • 12 messages
I see, but those vlues variaet from placeable to placeable, that way I would have to make 9 scripts forr metal veins, 9 scripts for three types, 9 scripts for skin hides and 3 scripts for clothes. And I defined them at variables at placeable taht uses them, I said there what each of those is.

#21
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
Ok, that's totally fine and probably the correct method of going about this so you don't need all the different scripts which are essentially the same. You just need to tell the script where to look for those variables. Here's a couple examples as I don't know exactly what you named those variables you stored on the placeables:

// Get the Local String Variable set on the Placeable (OBJECT_SELF) that we named "Tool_Type"
string sTool = GetLocalString (OBJECT_SELF, "Tool_Type");

// Get the Local String Variable set on the Placeable (OBJECT_SELF) that we named "Raw_Material"
string sRaw = GetLocalString (OBJECT_SELF, "Raw_Material");

This tells the script to look on the placeable which this script is attached to, look for a variable that we set there, find the value of that variable we entered, and in the rest of this script use/insert that value anywhere we have used "sTool" or "sRaw".

Modifié par _Knightmare_, 10 octobre 2010 - 06:53 .


#22
DragonDario

DragonDario
  • Members
  • 12 messages
The script does nothing: It doesn't give me anything, nor sends a message back. What is wrong with it?





// Placeable OnUsed Gain some resources

// Created by: DragonDario

// Created on: 01.10.2010.

/*

Required: Static=FALSE, Usable=TRUE, CurrentHP>0, attach script to the OnUsed event

Suggested: Plot=TRUE, DefaultActionPreference="Use"

*/

//



#include "ginc_debug"



void main()

{

object oUser = GetLastUsedBy();

object oPlaceable = OBJECT_SELF;

string sToolType = GetLocalString(oPlaceable, "sTool");

string sRaw = GetLocalString(oPlaceable, "sMaterial");

string sSoundByJob = GetLocalString(oPlaceable, "sSound");

int nUsed = GetLocalInt(oPlaceable, "sUsed");

int nXP = GetLocalInt(oPlaceable, "nXp");

int nStack = GetAbilityScore(oUser, ABILITY_STRENGTH, FALSE) - GetHardness(oPlaceable);

location lItem = GetLocation(oPlaceable);

float fDelay = 2.5;

float fDelayAction= 300.0;

PrettyDebug(GetName(oPlaceable) + "'s was used by " + GetName(oUser));

if(GetItemInSlot(INVENTORY_SLOT_CWEAPON_B, oUser) == GetItemPossessedBy(oUser, sToolType))

{

if(nStack > 0)

{

if(nUsed != 1)

{

ActionPlayAnimation(ANIMATION_LOOPING_CRAFT01, 1.50, 5.00);

PlaySound(sSoundByJob, FALSE);

GiveXPToCreature(oUser, nXP);

CreateItemOnObject(sRaw, oUser, nStack, "", TRUE);

SetLocalInt(oPlaceable, "sUsed", 1);

DelayCommand(fDelayAction, SetLocalInt(oPlaceable, "sUsed", 0));

}

else

{

PrettyError("You have already used this resource out.", fDelay, 16711680);

}

}

else

{

PrettyError("You have too low strenght.", fDelay, 16711680);

}

}

else

{

PrettyError("You don't have the right tool.", fDelay, 16711680);

}

}

#23
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
Are you intending to be checking the creature bite inventory slot?

#24
Olblach

Olblach
  • Members
  • 175 messages
PrettyError relies on nwn.ini settings, you should see something in your logfile though.

#25
DragonDario

DragonDario
  • Members
  • 12 messages
The script is now working :wizard:. Thanks to all who helped and here is the script for those who wanna to use it:

// Placeable OnUsed Gain some resources
// Created by: DragonDario
// Created on: 30.10.2010.
/*
Required: Static=FALSE, Usable=TRUE, CurrentHP>0, attach script to the OnUsed event
Suggested: Plot=TRUE, DefaultActionPreference="Use"
sTool = Tool required to do the job
sMaterial = Product you get
sSound = Sound you get when doing the job
sUsed = Is it used already or not(0 for unused)
nXp = Amount of XP you get by job
*/
//

#include "ginc_debug"

void main()
{
    object oUser = GetLastUsedBy();
    object oPlaceable = OBJECT_SELF;
    string sToolType = GetLocalString(oPlaceable, "sTool");
    string sRaw = GetLocalString(oPlaceable, "sMaterial");
    string sSoundByJob = GetLocalString(oPlaceable, "sSound");
    int nUsed = GetLocalInt(oPlaceable, "sUsed");
    int nXP = GetLocalInt(oPlaceable, "nXp");
    int nStack = GetAbilityScore(oUser, ABILITY_STRENGTH, FALSE) - GetHardness(oPlaceable);
    location lItem = GetLocation(oPlaceable);
    float fDelay = 2.5;
    float fDelayAction= 300.0;
    PrettyDebug(GetName(oPlaceable) + "'s was used by " + GetName(oUser));
    if(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oUser) == GetItemPossessedBy(oUser, sToolType) || GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oUser) == GetItemPossessedBy(oUser, sToolType))
    {
        if(nStack > 0)
        {
            if(nUsed != 1)
            {
                ActionPlayAnimation(ANIMATION_LOOPING_CRAFT01, 1.50, 5.00);
                PlaySound(sSoundByJob, FALSE);
                GiveXPToCreature(oUser, nXP);
                CreateItemOnObject(sRaw, oUser, nStack, "", TRUE);
                SetLocalInt(oPlaceable, "sUsed", 1);
                DelayCommand(fDelayAction, SetLocalInt(oPlaceable, "sUsed", 0));
            }
            else
            {
                FloatingTextStringOnCreature("You have already used this resource out.", oUser, FALSE, fDelay);
            }
        }
        else
        {
            FloatingTextStringOnCreature("You have too low strenght.", oUser, FALSE, fDelay);
        }
    }
    else
    {
        FloatingTextStringOnCreature("You don't have the right tool.", oUser, FALSE, fDelay);
    }
}