diff --git a/data/scripts/added_script.as b/data/scripts/added_script.as new file mode 100644 index 000000000..b7f570d5c --- /dev/null +++ b/data/scripts/added_script.as @@ -0,0 +1,5 @@ +void onTrigger() +{ + displayMessage("This trigger was added by another script"); + jumpKartTo( 0, 67.90, 99.49 ); +} diff --git a/data/scripts/tutorial_bananas.as b/data/scripts/tutorial_bananas.as index 5d9b04205..79413eee4 100644 --- a/data/scripts/tutorial_bananas.as +++ b/data/scripts/tutorial_bananas.as @@ -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 } diff --git a/src/scriptengine/script_track.cpp b/src/scriptengine/script_track.cpp index 597ff5393..5d1a25de2 100644 --- a/src/scriptengine/script_track.cpp +++ b/src/scriptengine/script_track.cpp @@ -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); + } } diff --git a/src/scriptengine/script_track.hpp b/src/scriptengine/script_track.hpp index 95c4ab441..588313ee0 100644 --- a/src/scriptengine/script_track.hpp +++ b/src/scriptengine/script_track.hpp @@ -37,6 +37,8 @@ namespace Scripting{ void enableAnimation(asIScriptGeneric *gen); void enableTrigger(asIScriptGeneric *gen); void disableTrigger(asIScriptGeneric *gen); + void createTrigger(asIScriptGeneric *gen); + } } diff --git a/src/tracks/track_object_manager.cpp b/src/tracks/track_object_manager.cpp index 7566cc90c..ccc7ce5e8 100644 --- a/src/tracks/track_object_manager.cpp +++ b/src/tracks/track_object_manager.cpp @@ -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)) diff --git a/src/tracks/track_object_presentation.cpp b/src/tracks/track_object_presentation.cpp index a6f5f06f3..72af89c43 100644 --- a/src/tracks/track_object_presentation.cpp +++ b/src/tracks/track_object_presentation.cpp @@ -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; diff --git a/src/tracks/track_object_presentation.hpp b/src/tracks/track_object_presentation.hpp index 962d01715..33fe1390b 100644 --- a/src/tracks/track_object_presentation.hpp +++ b/src/tracks/track_object_presentation.hpp @@ -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;