Jump to content
Chuc

Need help woth removeAction

Recommended Posts

Im having abit of trouble getting my addactions to remove from list.

What I have tried

 

in greeting.sqf //Not the hole sqf file

Guard1 addAction ["What do you do here", "Dialog\Guard1\JobDisc.sqf","((_target distance _this) <2"];

 

in JobDisc.sqf

hint "I guard the entrance to Camp Bravo";
Guard1 addaction ["Anything happen lately?", "Dialog\Guard1\EnemyLoitering.sqf"];
Guard1 removeaction "What do you do here"; //this action is added by a different script file.

 

I got a hole convo working with a few scripts like this. Everything works perfectly except for the remove action. I need the previous actions to be removed because if you ask again they add more. this is on a coop/single player mission where you respawn as a squad mate when you die until everyone is dead.

Share this post


Link to post
Share on other sites
WhatDoYouDoHere = Guard1 addAction ["What do you do here", "Dialog\Guard1\JobDisc.sqf","((_target distance _this) <2"];


Guard1 removeaction WhatDoYouDoHere;
AnythingHappenLately = Guard1 addaction ["Anything happen lately?", "Dialog\Guard1\EnemyLoitering.sqf"];


Guard1 removeaction AnythingHappenLately;

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Okay cool thanks for the reply ill give it ago. Wouldn't of thought to take out the spaces

Share this post


Link to post
Share on other sites
On 3/7/2017 at 7:07 AM, Chris Smith said:

Okay cool thanks for the reply ill give it ago. Wouldn't of thought to take out the spaces

 

You do not necessarily have to take out the spaces, you can go the other way:

// init.sqf
RemoveActionByName = {
	params ["_object", "_name"];
 	{if (_object actionParams _x select 0 == _name) exitWith {_object removeAction _x}} forEach actionIDs _object; 
};


// greeting.sqf
Guard1 addAction ["What do you do here", "Dialog\Guard1\JobDisc.sqf","((_target distance _this) <2"];
 
// JobDisc.sqf
[Guard1, "What do you do here"] call RemoveActionByName;
hint "I guard the entrance to Camp Bravo";
Guard1 addaction ["Anything happen lately?", "Dialog\Guard1\EnemyLoitering.sqf"];

 

Share this post


Link to post
Share on other sites

thanks guys this has worked really well and I got it going really good.

 

Share this post


Link to post
Share on other sites

another thing im sort of looking into is how many scripts I have. I have like 10+ just for one convo. Is it possible to add them all to the same script or is that not possible.

here is a couple I got

 

Greeting.sqf

sleep 1;
titleText ["Go Away", "BLACK", 1];
sleep 1;
Whatdidyoudo = Prisoner1 addAction ["What did you do", "Dialog\Prisoner1\RudeReply.sqf"];
Prisoner1 removeAction Hi;

//used to start Prisoner dialog. place in init of something
//Hi = Prisoner1 addAction ["Hi", "Dialog\Prisoner1\Greeting.sqf", "(_target distance _this) <2"];
//doWatch, doTarget, doFire

Prisoner1 addAction ["Target Prisoner", "Dialog\Prisoner1\TargetPrisoner.sqf"];
Prisoner1 addAction ["Holster Weapon", "Dialog\Prisoner1\HolsterWeapon.sqf"];
Prisoner1 addAction ["Shoot Prisoner", "Dialog\Prisoner1\KillPrisoner.sqf"];

the bottom 3 actions I want available all the time but kept at bottom of list. They don't have to be there its just a thought at this time.

 

RudeReply.sqf

sleep 1;
titleText ["None of your business", "BLACK", 1];
sleep 1;
Justtellme = Prisoner1 addAction ["Just tell me", "Dialog\Prisoner1\Lying.sqf"];
Prisoner1 removeAction Whatdidyoudo;

Lying.sqf

sleep 1;
titleText ["Fine, I was just having a look around. I didnt know anyone was here", "BLACK", 2];
sleep 2;
Idontbelieveyou = Prisoner1 addAction ["I dont believe you", "Dialog\Prisoner1\Atitude.sqf"];
Prisoner1 removeAction Justtellme;

So that's just a couple I have for the Prisoner1 Dialog. Some have more than one answer like this one

EnemyOrders.sqf

sleep 1;
titleText ["I have a radio located near by in a town i have been camping at", "BLACK", 2];
sleep 2;
Whatelseisathiscamp = Prisoner1 addAction ["What else is at this camp", "Dialog\Prisoner1\CampSupplies1"];
Whereisthiscamp = Prisoner1 addAction ["Where is this camp", "Dialog\Prisoner1\CampLocation1"];
Prisoner1 removeAction Wheredoyougetyourordersfrom;

With each question changing the out come of the conversation

I also have Dialog for Guard1, Guard2, and Soldier1,2,3. So I have a lot of small scripts like these. Does it make a difference game wise to have so many scripts?

Share this post


Link to post
Share on other sites

You can define functions in script files:

// myfile.sqf

FunctionABC = {
	systemChat "Hello from function ABC";
  	// put other commands here
};

FunctionDEF = {
	systemChat "Hello from function DEF";
  	// put other commands here
};

 

Before use functions script must be compiled:

// at this point our functions is not initialized
call compile preprocessFileLineNumbers "myfile.sqf";
// at this point our functions initialized if script file contains no erros

 

Special file init.sqf -  this file auto-compiled and executed by game immediately after mission starts:

// init.sqf

// it is very useful to compile all code from init.sqf
call compile preprocessFileLineNumbers "myfile.sqf";
call compile preprocessFileLineNumbers "myanotherfile.sqf";
call compile preprocessFileLineNumbers "myfunctions.sqf";
call compile preprocessFileLineNumbers "somethingelse.sqf";
// at this point all scrpts compiled and we can call functions defined in scripts

 

Usage:

// when functions defined we can call it from anywhere until missions ends:

call FunctionABC; // Result: "Hello from function ABC";

call FunctionDEF; // Result: "Hello from function DEF";

 

Passing arguments to functions:

X = {	
  	systemChat str _this; // _this variable always references argument(s) passed to function
};

"Hello" call X;  // Result (in chat): Hello

[1, "black", false] call X; // Result (in chat): [1, "black", false]

 

Accessing individual arguments:

ABC = {
	params ["_a", "_b", "_xyz"];
  	// here we can operate with _a, _b, _xyz variables
};

[1, "white", true] call ABC;  // in this call inside ABC variable _a = 1, _b = "white", _xyz = true

 

Functions can return results:

ByeFunc = {"Bye"}; // function always return same string

private _result = call ByeFunc; // Result: _result = "Bye";



SummFunc = { // function return summ of two arguments
	params ["_a", "_b"];
  	_a + _b;
};

private _summ = [10, 5] call SummFunc; // Result: _summ = 15;

 

  • Like 1

Share this post


Link to post
Share on other sites

That is great. but my scripting knownledge atm isn't really good enough yet. I barely understood that, most of it went over my head. But I have saved it and will learn but may take me some time before I use it. 

 

I want to understand it fully before I use it so I can fix it if there is a problem.

 

Until then is there a way to display multiple addactions when you look at something thing? You know how you get the first action infront of you and the rest show up top left after you scroll. Is there a way to get them all to show up in the middle not just the first one.

Share this post


Link to post
Share on other sites
37 minutes ago, Chris Smith said:

Until then is there a way to display multiple addactions when you look at something thing?

 

Working sample: link  (Virtual reality map, all code inside init.sqf)

 

Actions map:

A1	->	A2	->	A3
		B1	->	B2
	

 

Share this post


Link to post
Share on other sites

cool will give it ago thank you so much. Thanks to the other guys as well been a huge help

Share this post


Link to post
Share on other sites

Okay had a look but still a little hard to understand. ill get there don't worry.

 

with this

OnActionA2 = {
   params ["_target", "_caller", "_id", "_args"];
   _target removeAction _id;
   systemChat "Hello from A2 action. Next actions is A3 and B1";
   player addAction ["Action A3", OnActionA3];
   player addAction ["Action B1", OnActionB1];

how do I put it into my already made scripts? Or how do I rewrite mine to work like this? Does it have to be put in the init or can I run it fron its own script like I am doing?

I also found this

https://community.bistudio.com/wiki/setUserActionText

Which has this example

_id = billboard addAction ["Some Action", {}];
billboard setUserActionText [
   _id, 
   "Some Action", 
   "<t color='#ff0000'>Background-----------------</t><br/>Multiline<br/>Multiline<br/>Multiline<br/>. . .", 
   "<t color='#00ff00'>-----------------Foreground</t>"
];

But with out any of it put into a real example with context its hard to understand. If you could add what I got up top into one of your descriptions I could probably pick it up quicker.

 

Thank you again for your help and thank you for getting back to me so fast

Share this post


Link to post
Share on other sites
private _id = player addAction ["Action A3", OnActionA3];
player setUserActionText [_id, "Some Action",
   "<t color='#ff0000'>Background-----------------</t><br/>Multiline<br/>Multiline<br/>Multiline<br/>. . .", 
   "<t color='#00ff00'>-----------------Foreground</t>"];

 

 

Share this post


Link to post
Share on other sites

So im still a little lost but is this in the right direction

 

Whatelseisathiscamp = Prisoner1 addAction ["What else is at this camp", "Dialog\Prisoner1\CampSupplies1"];
Whereisthiscamp = Prisoner1 addAction ["Where is this camp", "Dialog\Prisoner1\CampLocation1"];
//trying to put ^ into what you sent and i got this.
private _id = Prisoner1 addAction ["What else is at this camp", OnActionA3]; //Is this Action and OnActionA3 part of what you wrote b4?
Prisoner1 setUserActionText [_id, "What else is at this camp", //Is this right
   "<t color='#ff0000'>Background-----------------</t><br/>Multiline<br/>Multiline<br/>Multiline<br/>. . .",
   "<t color='#00ff00'>-----------------Foreground</t>"];

One good thing about all this is I know a lot more than I did when I started. Is there a limit on how many files you have in your mission folder? Even if there not activated till a certain time and deactivated when finished being used? Atm my mission file has 319 files and 43 folders in it. Mainly my dialog and computer scripts

Share this post


Link to post
Share on other sites
2 hours ago, Chris Smith said:

So im still a little lost but is this in the right direction

If you do not know which way to go any direction is correct XD

 

2 hours ago, Chris Smith said:

Atm my mission file has 319 files and 43 folders in it. Mainly my dialog and computer scripts

If it's convenient for you and does not worsen performance of the game, then why not?

Share this post


Link to post
Share on other sites

Hey i know the thread ist old but..no no not gold ^^

 

i would like to know how ich can return a bool value from this example.

 

So if i have a match true else false. i get alle the time "<null>" when i format the result.

 

// init.sqf
RemoveActionByName = {
	params ["_object", "_name"];
 	{if (_object actionParams _x select 0 == _name) exitWith {_object removeAction _x}} forEach actionIDs _object; 
};

 

Ich know the last result is the return value. So i tried.

 

// init.sqf
RemoveActionByName = {
	params ["_object", "_name"];
 	{if (_object actionParams _x select 0 == _name) exitWith {_result = true}} forEach actionIDs _object; 
	result = false;
};

 

Share this post


Link to post
Share on other sites
RemoveActionByName = 
{
 params ["_object", "_name"];
 ((actionIDs _object) findIf {_object actionParams _x select 0 == _name} > -1)
};

not tested

 

EDIT: deleted nonsense stuff :-)

Edited by sarogahtyp

Share this post


Link to post
Share on other sites
20 hours ago, sarogahtyp said:

then {true} else {false}

That does nothing.

 

Btw your code is broken:
Code_2019-04-24_10-52-55.png

 

Here ya go:

RemoveActionByName = {
    params ["_object", "_name"];

    private _actions = actionIDs _object;
    private _actionIndex = _actions findIf {(_object actionParams _x) select 0 == _name};

    if (_actionIndex == -1) exitWith {false}; //Action doesn't exist

    _object removeAction _actionIndex;
    true //Action has been removed
};


 

 

On 4/21/2019 at 12:29 AM, fortune144 said:

Hey i know the thread ist old

Yes. And you should have a read of our forum rules:

https://forums.bohemia.net/forums/topic/54604-forum-rules/

 

Share this post


Link to post
Share on other sites
24 minutes ago, Dedmen said:

That does nothing.

the if returns true or false to the code block and this is the return value of the function... I guess that works but as I told I did not test, did you?

 

26 minutes ago, Dedmen said:

Btw your code is broken:
Code_2019-04-24_10-52-55.png

Its not!

This is a known copy/paste-forum bug. In my code block there are no special chars. I checked it.

Share this post


Link to post
Share on other sites
9 minutes ago, sarogahtyp said:

the if returns true or false to the code block and this is the return value of the function... I guess that works but as I told I did not test, did you?

It does that yes. But it's nonsense and serves no purpose. Don't need to test it to see that.


You are doing
if X then true else false.
Which is the same as just writing X without any if/then/else.

 

9 minutes ago, sarogahtyp said:

Its not!

This is a known copy/paste-forum bug. In my code block there are no special chars. I checked it.

 

I tried 3 times and could reproduce it. But now after reloading the page I also can't reproduce it anymore. Annoying.

  • Like 1

Share this post


Link to post
Share on other sites
8 minutes ago, Dedmen said:

It does that yes. But it's nonsense and serves no purpose.

good point, thx.

Share this post


Link to post
Share on other sites
9 minutes ago, Dedmen said:

I tried 3 times and could reproduce it. But now after reloading the page I also can't reproduce it anymore. Annoying.

 

I encountered this several times in the close past. As I told it's a bug. A "Code Copy"-button would be nice which hopefully avoids this.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×