Scripts can now create action triggers by themselves. Example in tutorial

This commit is contained in:
Sachith Hasaranga Seneviratne 2014-06-03 10:09:03 +05:30
parent 146a71f46a
commit 540c7818aa
7 changed files with 48 additions and 4 deletions

View File

@ -0,0 +1,5 @@
void onTrigger()
{
displayMessage("This trigger was added by another script");
jumpKartTo( 0, 67.90, 99.49 );
}

View File

@ -4,7 +4,7 @@ void onTrigger()
squashKart(0,35.0); //id of kart,time to squash
//teleportKart(0, 0, 0 ,0); //id of kart, x,y,z
//setVelocity(0, 5, 50 , 8); //id of kart, velocity //components x,y,z
jumpKartTo(0, 0.02, 2.82); //id of kart, target x,y, initial //0.02,2.82 is default start
jumpKartTo(0, 0, 0); //id of kart, target x,y
createTrigger("added_script",0,0,0,30.0); //name,x,y,z,trigger distance
}

View File

@ -43,6 +43,8 @@ namespace Scripting{
r = engine->RegisterGlobalFunction("void enableAnimation(string &in)", asFUNCTION(enableAnimation), asCALL_GENERIC); assert(r >= 0);
r = engine->RegisterGlobalFunction("void enableTrigger(string &in)", asFUNCTION(enableTrigger), asCALL_GENERIC); assert(r >= 0);
r = engine->RegisterGlobalFunction("void disableTrigger(string &in)", asFUNCTION(disableTrigger), asCALL_GENERIC); assert(r >= 0);
r = engine->RegisterGlobalFunction("void createTrigger(string &in,float x,float y,float z, float distance)",
asFUNCTION(createTrigger), asCALL_GENERIC); assert(r >= 0);
}
@ -81,7 +83,22 @@ namespace Scripting{
std::string type = "action-trigger";
World::getWorld()->getTrack()->getTrackObjectManager()->enable(*str, type);
}
void createTrigger(asIScriptGeneric *gen)
{
std::string *script_name = (std::string*)gen->GetArgAddress(0);
float x = gen->GetArgFloat(1);
float y = gen->GetArgFloat(2);
float z = gen->GetArgFloat(3);
float distance = gen->GetArgFloat(4); //triggering distance
core::vector3df posi(0, 0, 0);
core::vector3df hpr(0, 0, 0);
core::vector3df scale(1.0f, 1.0f, 1.0f);
TrackObjectPresentationActionTrigger* newtrigger =
new TrackObjectPresentationActionTrigger(posi, *script_name, distance);
TrackObject* tobj = new TrackObject(posi, hpr, scale,
"none", newtrigger, false /* isDynamic */, NULL /* physics settings */);
World::getWorld()->getTrack()->getTrackObjectManager()->insertObject(tobj);
}
}

View File

@ -37,6 +37,8 @@ namespace Scripting{
void enableAnimation(asIScriptGeneric *gen);
void enableTrigger(asIScriptGeneric *gen);
void disableTrigger(asIScriptGeneric *gen);
void createTrigger(asIScriptGeneric *gen);
}
}

View File

@ -106,7 +106,6 @@ void TrackObjectManager::disable(std::string name , std::string type){
void TrackObjectManager::enable(std::string name , std::string type){
TrackObject* curr;
for_in (curr,m_all_objects){
if (type != curr->getType())continue;
if (curr->getName() == (name) || curr->getID() == (name))

View File

@ -740,6 +740,21 @@ TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger(const
ItemManager::get()->newItem(m_init_xyz, trigger_distance, this);
}
TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger
(const core::vector3df& xyz,std::string script_name, float distance)
:TrackObjectPresentation(xyz)
{
m_init_xyz = core::vector3df(0, 0, 0);
m_init_hpr = core::vector3df(0, 0, 0);
m_init_scale = core::vector3df(1, 1, 1);
float trigger_distance = distance;
m_action = script_name;
m_action_active = true;
ItemManager::get()->newItem(m_init_xyz, trigger_distance, this);
}
void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
{
if (!m_action_active) return;

View File

@ -73,6 +73,10 @@ public:
m_init_hpr = hpr;
m_init_scale = scale;
}
TrackObjectPresentation(const core::vector3df& xyz)
{
m_init_xyz = xyz;
}
virtual ~TrackObjectPresentation() {}
@ -336,6 +340,8 @@ public:
TrackObjectPresentationActionTrigger(const XMLNode& xml_node);
TrackObjectPresentationActionTrigger(const core::vector3df& xyz,std::string scriptname, float distance);
virtual ~TrackObjectPresentationActionTrigger() {}
virtual void onTriggerItemApproached(Item* who) OVERRIDE;