Jump to content


Photo

How do I add a working grenade?

flash grenade problem scripting help grenade molotov

  • Please log in to reply
8 replies to this topic

#1 mindcore

mindcore

    Lieutenant

  • Members
  • 41 posts
  • Gender:Male
  • Location:Scotland

Posted 18 November 2012 - 10:33 PM

Hey Emergency Planet.

I am trying to make a submod for Hoppah's Los Angeles Mod 2.1.
I have very little experience with scripting in Emergency 4 (although I do know some C++).

I am trying to add a new command to soldiers: Get Grenade. I pretty much want to make a copy of the flashbang but make it explosive, and make a secondary command to retrieve and use it.

This is for a military submod I am making... I'm not a trigger-happy maniac.

Any ideas? As I am a complete newbie, I really need all the help I can get. My code so far is:

object ThrowMolotov : CommandScript
{
ThrowMolotov()
{
  SetValidTargets(ACTOR_FLOOR | ACTOR_OBJECT | ACTOR_VIRTUAL | ACTOR_HOUSE | ACTOR_OPEN_HOUSE);
  SetPossibleCallers(ACTOR_PERSON);
  SetIcon("throwmolotov");
  SetCursor("throwmolotov");
}
bool CheckPossible(GameObject *Caller)
{
  if(!Caller->IsValid() || Caller->GetType() != ACTOR_PERSON || Caller->GetEquipment()!=EQUIP_BOTTLE)
   return false;
  return true;
}

bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
{
  if(!Caller->IsValid() || Caller->GetEquipment()!=EQUIP_BOTTLE || Caller->GetID() == Target->GetID())
   return false;
  if (Caller->GetType() != ACTOR_PERSON)
   return false;
  Person p(Caller);
  if(p.GetEnteredCarID() != -1)
   return false;
  return true;
}

void PushActions(GameObject *Caller, Actor *Target, int childID)
{
  Vector CmdPos, TargetPos;
  CmdPos = Game::GetCommandPos();
  TargetPos = CmdPos;
 
  Person p(Caller);
  if(!p.IsValid())
   return;
  if (p.GetThrowPosition(TargetPos))
  {
   Caller->PushActionmove(ACTION_NEWLIST, TargetPos);
   Caller->PushActionTurnTo(ACTION_APPEND, CmdPos);
  }
  else
  {
   Caller->PushActionTurnTo(ACTION_NEWLIST, CmdPos);
  }
  Caller->PushActionThrowMolotov(ACTION_APPEND, CmdPos, 150000.f);
  Caller->PushActionRemoveEquipment(ACTION_APPEND); 
}
};

object GetMolotov : CommandScript
{
GetMolotov()
{
  SetValidTargets(ACTOR_FLOOR | ACTOR_OBJECT | ACTOR_VIRTUAL | ACTOR_HOUSE | ACTOR_OPEN_HOUSE);
  SetGroupID(CGROUP_GETEQUIPMENT);
  SetPossibleCallers(ACTOR_PERSON);
  SetNeedsCarWithFlagSet(OF_HAS_FLASHGRENADE);
  SetIcon("getmolotov");
  SetCursor("getmolotov");
}
bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
{
   if (!Caller->IsValid() || !Target->IsValid() || (Caller->GetID()==Target->GetID()))
    return false;
   if (Target->GetType()==ACTOR_VEHICLE)
   {
    Vehicle v(Target);
    if ((v.HasCommand("FlyTo") || v.HasCommand("VcmdDeInstallRope")) && !v.IsOnGround())
     return false;
   }
  
   Person p(Caller);
   if(p.IsValid() && (p.IsCarryingPerson()||p.IsLinkedWithPerson()|| p.IsPulling() || p.GetEnteredCarID() != -1))
    return false;
  
   GameObject obj(Target);
   if (Caller->GetObjectType()==TYPE_PERSON && Caller->GetEquipment()!=EQUIP_FLASHGRENADE &&
    obj.IsValid() && obj.IsFlagSet(OF_HAS_FLASHGRENADE))
   {
    return true;
   }
  
   return true;
}
void PushActions(GameObject *Caller, Actor *Target, int childID)
{
  Vector TargetPos = Target->GetTargetPoint(Caller, TARGET_EQUIPMENTDOOR);
 
  Caller->PushActionmove(ACTION_NEWLIST, TargetPos);
  Caller->PushActionTurnTo(ACTION_APPEND, Target);
  Caller->PushActionGetEquipment(ACTION_APPEND, Target, EQUIP_BOTTLE);
}
};


#2 Stan

Stan

    Webmaster

  • Webmaster
  • 6,911 posts
  • Gender:Male
  • Location:Vaals - Nederland

Posted 19 November 2012 - 09:21 AM

I will give Hoppah a hint about it, maybe he has an idea :)
Webmaster & Technical Support

#3 Rlast

Rlast

    Captain

  • Members
  • 196 posts
  • Gender:Male
  • Location:EU
  • Interests:Aviation, Geography and Geopolitics, Graphic Design, French, Modding, Photoshop.

Posted 19 November 2012 - 07:41 PM

Just out of interest, have you created a model to go with it or are you just going to edit the properties of the flashbang? :D

k9rm.png


#4 Newfoundking

Newfoundking

    The Real Slim Shady

  • Moderator
  • 7,253 posts
  • Gender:Male
  • Location:Newfoundland

Posted 19 November 2012 - 08:05 PM

That's what I was thinking too, essentially create a new flashbang but instead of it exploding and disorienting people, have people in XYZ dustance injured by fire, and give it the other properties of an explosion.

I think the retrieving and using function though would be a little foolhardy

Wanna play multiplayer without any of the commitment? Emergency Planet hosts casual multiplayer to all its members! Contact me for more information

 

Executive Director: EMP Gulag

 

Do you have a warning that you want to go away, or are you facing another punishment you don't want? Contact me for the NEW alternative!


#5 mindcore

mindcore

    Lieutenant

  • Members
  • 41 posts
  • Gender:Male
  • Location:Scotland

Posted 20 November 2012 - 07:41 AM

Yes, you are probably right. I just have no idea what I am doing, so I used the first (and only) example script I could find!

#6 Rlast

Rlast

    Captain

  • Members
  • 196 posts
  • Gender:Male
  • Location:EU
  • Interests:Aviation, Geography and Geopolitics, Graphic Design, French, Modding, Photoshop.

Posted 20 November 2012 - 08:02 PM

Made this model as a tester if it's of any interest to you; I'm not even sure if you wanted an explosive grenade, but what the heck', someone might :D.

Posted Image

k9rm.png


#7 Miercolini

Miercolini

    Captain

  • Members
  • 180 posts
  • Gender:Male
  • Location:NYC

Posted 20 November 2012 - 09:08 PM

Not sure if this will help, but during those riots they sometime throw Molotov. Not sure if they helps.

Geposte afbeelding


#8 Hoppah

Hoppah

    Boss cat

  • Administrators
  • 3,879 posts
  • Gender:Male
  • Location:Special Needs Department

Posted 21 November 2012 - 07:44 PM

In addition to Voodoo, it should be possible by using a modified version of the flashbang script.
You cannot edit the flashbang code itself to make it injure or kill people as that code can only stun persons within a certain range.

I suggest you modify the Flashbang-script though and make it spawn an invisible object on the location where the flashgrenade is thrown (CmdPos).
Make the spawned object explode and voilá you will have something that looks like an exploding grenade. :happy:
The only problem you might encounter, is the timing of the explosion, but I'm sure thats resolvable too.

Don't forgot to change the Explosion Effect in the editor (Edit Traits menu) to an 'explosion type' of your choice, like 'explosioncar01'.
Also, change the 'material setting' of the invisible object in the editor. If I recall correctly, the material is related to the force of the explosion.

I'm not sure if the ThrowMolotov code will work. I've never used that code.

Good luck,

Mr Hop

#9 mindcore

mindcore

    Lieutenant

  • Members
  • 41 posts
  • Gender:Male
  • Location:Scotland

Posted 22 November 2012 - 07:42 AM

Thanks for all the responses! I will try what you guys have said and see what I can get working.





Also tagged with one or more of these keywords: flash grenade, problem, scripting, help, grenade, molotov