View Single Post
  #4  
Old 09-12-2017, 08:43 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
You can use findobject("objectname") to check if an object exists before destroying it.

For clearing out GUIs when you leave a level(assuming you are creating the GUI's in a level script) you can try a serverside onPlayerLeaves(), like so:

PHP Code:
function onPlayerLeaves() {
  if (
player != nullplayer.triggerClient("gui","SomeSystemWeapon","clearcontrols","ControlName");

Then have a system weapon to handle the client trigger:

PHP Code:
//#CLIENTSIDE
function onActionClientside() {
  if (
params[0] == "clearcontrols") {
    if (
params[1] != null) {
      
temp.obj findObject(params[1]);
      if (
temp.obj != nulltemp.obj.destroy();
    }
  }

Other methods could be adding the control name to an array to clear out(along with a level name it should be linked to) and in a System weapon scanning through the array onPlayerEnters() and destroying any controls that exist if the player is not in the level name linked to that control.

For the other issue you can try keeping track of when an object is going to be destroyed. Just so you know, objects can also have dynamic variables assigned to them.

PHP Code:
new GuiControl("Control") {
  
10;
  
width height 100;
  
this.isSomeFlag true;

You can now access Control.isSomeFlag as well as something like:

PHP Code:
echo("Flag State: " Control.isSomeFlag);

// Will echo the same state as above
with (Control) {
  echo(
"Flag State: " this.isSomeFlag);

So with that in mind, you can try something like this:
PHP Code:
function CONTROLNAME.onKeyDown(keycodekeytextscancode) {
  if (
keytext == "d") {
    
// Don't try to destroy if already queued to be destroyed;
    
if (CONTROLNAME.isDestroyed == true) return;

    
this.option CONTROLNAME.getselectedrow();
    
CONTROLNAME.isDestroyed true;
    
CONTROLNAME.destroy();
  }

Reply With Quote