Forum Jump :

Author Message


Posts: 33
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 35
In-game name: Officer D

 
#1 Posted at 2017-01-30 10:33        
     
Hello Arma Script wizards!

I'm hoping somebody has a solution to this. The idea is simple but the execution seems to be tricky. I have a DM PVP & PVE mission that gives players gear, the higher their score goes. Basically perks for when they respawn. At some point they will have the best gear and there is no more reason to get a higher score. So I thought it would be nice to have a unti that allows you to buy vehicles for score points.

Here is what I got so far and it works when I'm the host. I need this to work on a dedicated server though.

Unit placed in editor and this in it's initialization :
this setcaptive true; this addEventHandler ["HandleDamage", {false}]; this disableAI "MOVE"; this setUnitPos "up"; this enablesimulation false; this addAction ['<t color="#FF0000">' + "Buy AH-64D Apache for 25 score" + '</t>', "scripts\Dealer_Strelka.sqf",nil,1.5,false,true,"","_this distance _target < 3"];

scripts\Dealer_Strelka.sqf
_unit = _this select 0;

if (score _unit >= 25) then { 

    hint composeText [parsetext format["<t size='1.2' align='center' color='#FF0000'>Sold for 25!</t><br/><t size='1' align='center' color='#FFFFFF'>Enjoy your AH-64D Apache.</t>"]];
	sleep 0.5;
	playSound "sold";
	_unit addscore -25;
	_heli = "AH64D_EP1" createVehicle getMarkerPos "buyarea1";
	_heli setDir 315;
	2 cutText ["Sold!","PLAIN DOWN",0.8];
}
else
{ 
    hint composeText [parsetext format["<t size='1.2' align='center' color='#FF0000'>Not enough score!</t><br/><t size='1' align='center' color='#FFFFFF'>Blow some stuff up and kill more enemies to get higher score.</t>"]];
	sleep 0.5;
	playSound "no";
	2 cutText ["Not enough score","PLAIN DOWN",0.8];
};


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#2 Posted at 2017-01-30 14:59        
     
This is your problem:
_unit = _this select 0;

The first argument returned by addAction is the object which the action is assigned to, so the dealer. You need to get the second parameter and use that:
private _unit = param [1];

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Advertisement


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 57
In-game name: Kobayashi Maru

 
#3 Posted at 2017-01-30 16:12        
     
Some remarks:
- You should avoid such code in the init field of a playable unit. Each JIP will run that and override your states like setCaptive or disableAI "move"!, unless you specify it's for server only.
Yes, JIP reads and runs all codes in description.ext but also mission.sqm where all your init fields are, and each time a code is made of global Effect commands EG, it overrides the value everywhere.

- on the other hand, addAction doesn't have sense on dedicated server (no interface), and furthermore, this command is not respawn persistent.

I suggest you to use:

initServer.sqf for codes which have to run at the start of the mission, regardless of the players' join in. It's roughly the same as if (isServer) then {...} in the init.sqf. The best place for init states of units before then become players.

init.sqf for codes which have to run for every PC (server + clients), with the same behaviour as all init fields of objects, common triggers... A good place for some common functions, global variables initialization (if no need to update them with publicVariable)

initPlayerLocal.sqf for all stuff in regard with JIP, without messing with the other players' status: specific loadout...

onPlayerRespawn.sqf for all non persistent stuff at respawn. Some EH are, addAction aren't.

For addAction, this specific command can have it's own powerful conditions, so you can write it:
- in init.sqf (run at every JIP but addAction is not multiplicated as far as filtered by its own condition),
- or in initPlayerLocal.sqf, the safest place.

Don't forget to place it also in onPlayerRespawn.sqf (or in an equivalent event Handler Respawn)

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 33
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 35
In-game name: Officer D

 
#4 Posted at 2017-01-30 17:23        
     
# 654wak654 : This is your problem:
_unit = _this select 0;

The first argument returned by addAction is the object which the action is assigned to, so the dealer. You need to get the second parameter and use that:
private _unit = param [1];
Ok, that works partially. It seems that "_unit addscore -25" does not get send to the server. Is there a way to implement a function to do this?

# Pierre MGI : Some remarks:
- You should avoid such code in the init field of a playable unit. Each JIP will run that and override your states like setCaptive or disableAI "move"!, unless you specify it's for server only.
Yes, JIP reads and runs all codes in description.ext but also mission.sqm where all your init fields are, and each time a code is made of global Effect commands EG, it overrides the value everywhere.

- on the other hand, addAction doesn't have sense on dedicated server (no interface), and furthermore, this command is not respawn persistent.

I suggest you to use:

initServer.sqf for codes which have to run at the start of the mission, regardless of the players' join in. It's roughly the same as if (isServer) then {...} in the init.sqf. The best place for init states of units before then become players.

init.sqf for codes which have to run for every PC (server + clients), with the same behaviour as all init fields of objects, common triggers... A good place for some common functions, global variables initialization (if no need to update them with publicVariable)

initPlayerLocal.sqf for all stuff in regard with JIP, without messing with the other players' status: specific loadout...

onPlayerRespawn.sqf for all non persistent stuff at respawn. Some EH are, addAction aren't.

For addAction, this specific command can have it's own powerful conditions, so you can write it:
- in init.sqf (run at every JIP but addAction is not multiplicated as far as filtered by its own condition),
- or in initPlayerLocal.sqf, the safest place.

Don't forget to place it also in onPlayerRespawn.sqf (or in an equivalent event Handler Respawn)
The addaction is assigned to a non playable unit. Basically a dealer to buy stuff from. Question though : Are the intiServer.sqf, initPlayerLocal.sqf, etc. all executed in the init.sqf or will they initiate by themselves?


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 57
In-game name: Kobayashi Maru

 
#5 Posted at 2017-01-30 18:05        
     
Understood. For an AI unit supposed to never change for another behavior, your init field is fine! You have to run it for each JIP and you don't care with respawn problem.
And No! the first use of initServer.sqf or initPlayerlocal.sqf is to be run apart! not called by the init.sqf. Just add these specific sqf in the mission directory (where mission.sqm is, like init.sqf or description.ext if any).
Same for onPlayerRespawn.sqf

This post was edited by Pierre MGI (2017-01-31 01:53, 316 days ago)

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Author Message


Posts: 33
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 35
In-game name: Officer D

 
#6 Posted at 2017-01-30 19:24        
     
That looks a lot cleaner than the one I found. I'll have to try that. I found a other script that seems to work as well.
	_unit setVehicleInit "[this,-25] exec 'scripts\cly_score.sqs'";
	processInitCommands;

cly_score.sqs :
?!isServer:exit

_unit=_this select 0
_score=_this select 1

_unit addScore _score

exit



Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#7 Posted at 2017-01-30 19:34        
     
The thing you found is ancient. Both setVehicleInit and processInitCommands are not in Arma 3, and the other part of the script uses sqs.

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 33
Rank:


Level: Member

Country: de
Location: K-Town
Occupation: Medic
Age: 35
In-game name: Officer D

 
#8 Posted at 2017-01-31 05:01        
     
I understand that. But this is Arma 2 we are talking about after all. Pierre MGI seems to have deleted his post with his example, so I assume that was a Arma 3 function he was proposing.


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 57
In-game name: Kobayashi Maru

 
#9 Posted at 2017-01-31 05:21        
     
Yep, not sure remoteExec works in Arma2 OA.
I spent some times to find how to remote execute this command (addScore) in Arma2 for nuts.
Bis_fnc_MP seems to be also for arma3...
call RE perhaps? I can't check that, I don't have Arma2.
The true thing is you must find a way to run the code on server only. It's easy on Arma3 (remoteExec the command or even this EH). But for Arma2...

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS