Scripts can now create action triggers by themselves. Example in tutorial
This commit is contained in:
parent
146a71f46a
commit
540c7818aa
5
data/scripts/added_script.as
Normal file
5
data/scripts/added_script.as
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
void onTrigger()
|
||||||
|
{
|
||||||
|
displayMessage("This trigger was added by another script");
|
||||||
|
jumpKartTo( 0, 67.90, 99.49 );
|
||||||
|
}
|
@ -4,7 +4,7 @@ void onTrigger()
|
|||||||
squashKart(0,35.0); //id of kart,time to squash
|
squashKart(0,35.0); //id of kart,time to squash
|
||||||
//teleportKart(0, 0, 0 ,0); //id of kart, x,y,z
|
//teleportKart(0, 0, 0 ,0); //id of kart, x,y,z
|
||||||
//setVelocity(0, 5, 50 , 8); //id of kart, velocity //components 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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ namespace Scripting{
|
|||||||
r = engine->RegisterGlobalFunction("void enableAnimation(string &in)", asFUNCTION(enableAnimation), asCALL_GENERIC); assert(r >= 0);
|
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 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 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";
|
std::string type = "action-trigger";
|
||||||
World::getWorld()->getTrack()->getTrackObjectManager()->enable(*str, type);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,8 @@ namespace Scripting{
|
|||||||
void enableAnimation(asIScriptGeneric *gen);
|
void enableAnimation(asIScriptGeneric *gen);
|
||||||
void enableTrigger(asIScriptGeneric *gen);
|
void enableTrigger(asIScriptGeneric *gen);
|
||||||
void disableTrigger(asIScriptGeneric *gen);
|
void disableTrigger(asIScriptGeneric *gen);
|
||||||
|
void createTrigger(asIScriptGeneric *gen);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,6 @@ void TrackObjectManager::disable(std::string name , std::string type){
|
|||||||
void TrackObjectManager::enable(std::string name , std::string type){
|
void TrackObjectManager::enable(std::string name , std::string type){
|
||||||
TrackObject* curr;
|
TrackObject* curr;
|
||||||
for_in (curr,m_all_objects){
|
for_in (curr,m_all_objects){
|
||||||
|
|
||||||
if (type != curr->getType())continue;
|
if (type != curr->getType())continue;
|
||||||
|
|
||||||
if (curr->getName() == (name) || curr->getID() == (name))
|
if (curr->getName() == (name) || curr->getID() == (name))
|
||||||
|
@ -740,6 +740,21 @@ TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger(const
|
|||||||
ItemManager::get()->newItem(m_init_xyz, trigger_distance, this);
|
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)
|
void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
||||||
{
|
{
|
||||||
if (!m_action_active) return;
|
if (!m_action_active) return;
|
||||||
|
@ -73,6 +73,10 @@ public:
|
|||||||
m_init_hpr = hpr;
|
m_init_hpr = hpr;
|
||||||
m_init_scale = scale;
|
m_init_scale = scale;
|
||||||
}
|
}
|
||||||
|
TrackObjectPresentation(const core::vector3df& xyz)
|
||||||
|
{
|
||||||
|
m_init_xyz = xyz;
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~TrackObjectPresentation() {}
|
virtual ~TrackObjectPresentation() {}
|
||||||
|
|
||||||
@ -336,6 +340,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
TrackObjectPresentationActionTrigger(const XMLNode& xml_node);
|
TrackObjectPresentationActionTrigger(const XMLNode& xml_node);
|
||||||
|
TrackObjectPresentationActionTrigger(const core::vector3df& xyz,std::string scriptname, float distance);
|
||||||
|
|
||||||
virtual ~TrackObjectPresentationActionTrigger() {}
|
virtual ~TrackObjectPresentationActionTrigger() {}
|
||||||
|
|
||||||
virtual void onTriggerItemApproached(Item* who) OVERRIDE;
|
virtual void onTriggerItemApproached(Item* who) OVERRIDE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user