Home   Help Search Login Register  

Author Topic: Unit spawned by script: Once dead and respawned, local actionmenus not working  (Read 2242 times)

0 Members and 3 Guests are viewing this topic.

Offline AA_Chriss

  • Members
  • *
Hi, i have a odd Problem.... Its a bit more to read to explain it properly, and so i hope some of you talented scripting-people might help me.  :D

Situation (4 Scripts):
- A "Drugdealer" (a basic car with a SLA soldier) is driving around some 20 marker-points on the map, halts at each marker-point for a random time between 5 and 25 minutes and then continues to a next point. Once the Dealer is dead or the vehicle destroyed it gets respawned at the next random marker point and continues with the way.
It gets called by the init.sqf and only run on the server (aka. if (!isServer) exitWith {}; )

- A huge script (only run LOCAL on client machines) checks if you are near the Drugdealer Vehicle and if you are nearer than 5m to it, a actionmenu entry appears for buying "drugs" at the vehicles which then opens a other script of course. If you are more than 5m away the action is gone.
Get called by a sub-file from the init.sqf and only runs on client machines to save ressources, as it cointains a big while-loop which fires every second and checks 50 different shop-actionmenus!

- Another script(check) to "arrest" or in other word to delete the Drugdealer (is working also after drugdealer killed and respawned)
This check gets called from the init.sqf from a if-clause
Code: [Select]
if ( ((not(dedicatedServer)) and (isServer)) or (not(isServer)) ) then {. It is the only script which still works when the Drugdealer was dead and respawned!

- A fourth script which has a while-loop and checks if the Drugdealer is alive. Once hes not alive anymore, a hint gets broadcasted telling the Drugdealer is dead/or busted.
this script gets called from the init.sqf and runs only on the server

Problems:

1. As soon as the Drugdealer is dead and respawned, no actionmenu-entry is appearing anymore for buying of drugs.
2. Script Number 4 (the one which checks if the dealer is alive, and as soon as he is not, gives a hint) is only working ONCE.



Now the Scripts used:

1. Drugdealerscript (Version to only randomize at 3 markers to test better):
Code: [Select]
// Drugdealer on Wheels Script
if (!isServer) exitWith {};
while {true} do {
    _spawn_pos = call compile format ["markerPos 'drugstop%1';", ceil random 3];
    drugvehicle = createVehicle ["vil_nysa", _spawn_pos, [] , 0, "NONE"];
    drugvehicle setVehicleInit
      "drugvehicle = this;
      this setVehicleVarName ""drugvehicle"";
      this setVehicleLock ""LOCKED"";
      this setAmmoCargo 0;
  ";
  publicvariable "drugvehicle";
    drggrp = createGroup east;
    drug_einheit =  drggrp createUnit ["SoldierEB", _spawn_pos, [], 1, "NONE"];
    [drug_einheit] join drggrp;
removeallweapons drug_einheit;
    drug_einheit assignAsDriver drugvehicle;
drug_einheit moveindriver drugvehicle;
publicvariable "drug_einheit";
    processInitCommands;
    _old_random_val = -1;
    while {alive drug_einheit && alive drugvehicle} do {
        _random_val = ceil random 3;
        while {_random_val == _old_random_val} do {
            _random_val = ceil random 3;
        };
        _old_random_val = _random_val;
        call compile format ["
            drug_einheit doMove markerPos 'drugstop%1';
            while {drug_einheit distance markerPos 'drugstop%1' > 20 && alive drug_einheit && alive drugvehicle} do {
                sleep 5;
            };
        ", _random_val];
        if (!alive drugvehicle || !alive drug_einheit) exitWith {};
        sleep 200 + random 5;
    };
    deleteVehicle drug_einheit;
deleteVehicle drugvehicle;
deleteGroup drggrp;
};

2. Script to check if Drugdealer is alive and gives hint if not anymore:
Code: [Select]
// Check if Drugvehicle is alive or not and gives a hint if its not alive anymore
if (!isServer) exitWith {};
while {true} do
{
if (!alive drugvehicle || !alive drug_einheit) exitWith {
"hint localize ""STRS_drugdealer_destroyedorbusted"";"
drugvehicle setdamage 1;
drug_einheit setdamage 1;
sleep 5;
deleteVehicle drug_einheit;
deleteVehicle drugvehicle;
};
sleep 2;
};


Please help me with this... its totally overloading for me.
« Last Edit: 10 Jul 2008, 19:47:12 by AA_Chriss »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
And where is the code where you add the action menu to the player?

Offline AA_Chriss

  • Members
  • *
And where is the code where you add the action menu to the player?
Which one? The one for buying the Drugs? Its part of the RPG Mission we are editing. Its a very huge script but its:

Code: [Select]
while {true} DO {
for [{_i=0}, {_i < (count INV_ItemShops)}, {_i=_i+1}] do {
_flag   = ((INV_ItemShops select _i) select 0);
_action = ((INV_ItemShops select _i) select 1);
if ((player distance _flag <= 5) and (_a1 == 0) and (alive _flag)) then {
_h1 = player addaction [_action, "2448171.sqf", [_i]];
_a1 = 1;
_f1 = _i;
};
if ((player distance _flag > 5) and (_i == _f1) and (_a1 == 1)) then {player removeaction _h1; _a1 = 0; _f1 = 0;};
};
.
.
.
.
sleep 1;
};

But i don't think that this is making any Problems, because it is working UNTIL the Vehicle was Destroyed, deleted and respawned again.
So i think there must be a error in the first script which let the Vehicle spawn.
I think somehow the code must tell the addaction-script that the vehicle is back alive again or something...

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
with _flag   = ((INV_ItemShops select _i) select 0);
and then checking distance to the flag, it seems the flag itself should be the car that has been destroyed.
So, what is that flag? the car itself? something that is moved with the car?

Offline AA_Chriss

  • Members
  • *
with _flag   = ((INV_ItemShops select _i) select 0);
and then checking distance to the flag, it seems the flag itself should be the car that has been destroyed.
So, what is that flag? the car itself? something that is moved with the car?
The car (the cars name). One of those arrays in the "INV_ItemShops" is the array of the Drugdealer which has all the items you can buy at him stored and so on. Of course the cars name is also "drugvehicle" like in this scripts.

And as i said, it is working...... ONCE  :( As soon as the vehicle was destroyed and respawned once, it wont work anymore....

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
If that flag is drugvehicle, then there is no apparent reason for it to do not work after first dead and respawn as the new car variable is using the same drugvehicle name.
What if INV_ItemShops content is modified once the car is destroyed?

Offline AA_Chriss

  • Members
  • *
Yes thats what i though that there is no reason to not work.... No content is not being modified of the arrays....

Ill try now to strip-out the drugdealer, modify the code and add a ordinary "this addaction" into the script from the drugdealer-vehicle.

Question: Does this need to come into the setVehicleInit part?
Question2: What is with my loop to check if the thing is alive with the hint... what have i done wrong there? I assume the exitwith, right?

Anyway, if someone has a other idea, let me know as this could save me a lot of work....

Regards, Christian
« Last Edit: 11 Jul 2008, 13:56:29 by AA_Chriss »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
What is that "hint localize ""STRS_drugdealer_destroyedorbusted"";" between quotes?

Offline AA_Chriss

  • Members
  • *
What is that "hint localize ""STRS_drugdealer_destroyedorbusted"";" between quotes?
It is a localized hint. The mission is in two languages and its the stringtable this is the entry-name....

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
What I mean is that the hint itself is between quotes as first code inside the exitWith block.
Code: [Select]
if (!alive drugvehicle || !alive drug_einheit) exitWith {

"hint localize ""STRS_drugdealer_destroyedorbusted"";"
That hint line is a string alone there.
Something like:
Code: [Select]
if (!alive drugvehicle || !alive drug_einheit) exitWith {
hint localize "STRS_drugdealer_destroyedorbusted";
might have sense.

Offline AA_Chriss

  • Members
  • *
Well yes, however i think the Problem is that it exit the whole while-loop with the "exitwith". And never returns.
What is a better loop then ?