how to implement "Give ... to ..."

Started by fanton, Wed 26/05/2004 03:01:31

Previous topic - Next topic

fanton

I am trying to make a for a give command. Give "item" to "character." The problem is that it always crashes because of invalid name. That make sense, in a way. But I cannot repair the problem.

I have this script:

else if (cur_mode == 9) {
if (GetGlobalInt(80) == 2) StrCat(madetext,"Give "); {
GetInvName (player.activeinv, buffer);
StrCat(madetext,buffer);
  StrCat(madetext," to ");
}

the GetInvName does not make sence. That is the reason why it crashes, and I can see the problem. But i don't know a way around it.

I just need to ad a "to" after give. The demo does not help me at all. When trying to give any item the character speaks out "not available at this time."

I will try to look at the other commands. But use is the only one that allows active-inventory.

Do i have to script it manually?

e.g.

click Give on item
and put in the item interaction, run script
and the script should be something like
make lucasarts status = Give
then change the cursor to that item
then change the text to that item
then run some action (the character accepts it or not)

but that means a script for each item i use give. and I will probably use it a lot.  :( :'( :-[ ??? >:(

I don't know. I just need an aswer to see what i can do. Otherwise I will have a script for each item.

Can i use, get object name under mouse. I don't know the function name, but there is one.

strazer

Does

...
  else if(cur_mode == 9) { // Additional cursor modes
    if (GetGlobalInt(80) == 2) { // "Give" mode
      string madetext, givewhat, giveto; // declare local variables
      GetInvName(player.activeinv, givewhat);
      StrToLowerCase(givewhat); // no capitals; keep in mind other languages
      GetLocationName(mouse.x, mouse.y, giveto); // what's under the mouse cursor
      StrToLowerCase(giveto);
      StrFormat(madetext, "Give %s to %s", givewhat, giveto); // create sentence
      SetLabelText(GUI, LABEL, madetext); // show sentence on gui
    }
    // more modes here
  }
...

work?

fanton

#2
It does not.

error: GetInvName: invalid inventory item specified.

which makes sense since Give does not work with active-inventory.

the Give command is but another version of active-inventory. but I don't undrstand HOW use works with active-inventory?!?

if i click, use <item> it switches automatically to use-active-inventory, which is not the same as interact/use.

in lucasarts status there are two options

MODE_USE
and cur == 4 (active_inventory)

HOW CAN ONE USE THE ACTIVE INVENTORY MODE?!?!?!?!?!?!?!?

I am not shure about your code, but is simmliar to what I had before. both don't work.

Is GIVE supposed to be used ONLY from cur_mode == 8? I will try switching around. But in the demo it says "not available yet" so I suspect is not available yet :PPPP

So, no, it doesn't work that way. there is a trick to it, I can sense it.

[edit] do i have to initialise the global variable? SetGlobalVariable(80,2) == 0;

but the error is simple, i have no active inventory, therfore no item name, therefore crash :P

Proskrito

i think you could share the mode USE_INV (cursor mode 4) and then check if the player chose give or use with the global int.
Instead of using mode 9 for give, use initially mode 2 (mode use), and then you'll be able to select a inv. item.
Don't forget to check with the globalint which mode was used, or 'give' and 'use' will do the same.


fanton

but one cannot use 2 modes at a time.

so Give should set a flag as checked. then before running the use command, check if the flag was set then do the give, rather than the use, if set, if not, do the usual.

that's what you mean. but I don't really know how. i mean I do, in theory, but I have a feeling it will not work. i think I will have to give up "give" :P but I am interested how the other users implemented give option. because i have seens some games having "give" as a mode.

I think the code strazer gave me would work in specific circumstances. I might be missing something. I don't really know.

I will retry both ways and look trough the demo, since give does work but it displays not available for everything i click on, but for me, when I click give, it crashes.

Edwin Xie

Well, giving something to an NPC isn't that right but usually if you give something to an NPC you have to use the inventory item with the NPC.
Moving at superhigh speed getting to the planet called Earth. But it is boxed in white......thing.....

Proskrito

thats how i made it, if i remember well. What i meant, is that, ie:
in the interface_click function, when you click the GIVE button, you have:
Code: ags

if (button==GIVEBUTTON){
Ã,  Ã,  SetCursorMode(2);
Ã,  Ã,  SetGlobalInt(80,2);
}

then, you should change the script to somethong like this:
Code: ags

if (cur_mode == 4) {
 if (GetGlobalInt(80) == 2) StrCat(madetext,"Give "); //give
 else StrCat(madetext,"Use "); //use
 GetInvName (player.activeinv, buffer);
 StrCat(madetext,buffer);
 if (GetGlobalInt(80) == 2) StrCat(madetext," to "); //give
 else StrCat(madetext," with "); //use
}

maybe the same with cursor mode 2, if globalint 80 == 2, write give, if not, write use.

And then, imagine you want something to happen if you give some item to a character, then you would do in the 'Use inventory on character':
Code: ags

//use inventory on character
if (GetGlobalInt(80)==2){
 if (character[X].activ....
 //put here all the interactions with give
}
else{
//put here interactions with 'use'
}

i hope i made more sense! : )

fanton

Yes, makes more sense. I will try is out. Thank you.

[edit]  ;D

monkey0506

I realize that this topic is rather old, but I have a problem with it. The script Proskrito provided allows you to use an inventory item on itself! Unless I'm doing something wrong. I don't have time to elaborate, so if it's just me, I'll upload my script later. Thanks!

Mr Jake

you could just use  properties. Search the manual for info on them, I managed to do this with just a few lines of code and properties (lots it now >:|)

monkey0506

#10
Oh... Well, custom properties confuse me, and I found a different way using ints. I just set one int to the value of the Inventory item at (mouse.x, mouse.y) and another to the active inventory item, and if they aren't equal then parse my string ext which holds the name of the object/hotspot/inventory item/character at (mouse.x, mouse.y) to the end of my label. Sorry for bringing up such an old topic... I just didn't want to create a new topic for an existing one. Thanks anyway.

EDIT: I realized I don't need to use an int for the active inventory. Just player.activeinv. That's better.

SMF spam blocked by CleanTalk