Hey all!
im making a lasso script, and need some help.
i need to know how to execute code in attackHook every 2 seconds.
and how to "un lasso" the animal.
Here is the code i have so far:
ModPE.setItem(480, 0, 11, "Lasso")
function attackHook(attacker, victim)
{
if (getCarriedItem() == 480)
{
preventDefault();
Entity.setHealth (victim, Entity.getHealth (victim) + 0);
Entity.setPosition(victim,getPlayerX,getPlayerY,getPlayerZ+1);
}
}
function useItem(x,y,z,itemId,blockId,side)
{
if(itemId==287&&blockId==50) //if string on a torch
{
addItemInventory(480,1);
clientMessage("<Cowboy> You now have a lasso!");
}
else if(itemId==280&&blockId==50)
{
addItemInventory(480,1);
clientMessage("<Sheriff> You found the cheaty way!");
}
}
when i tap a animal it dissapears. IDK where. :$
also, i need the part with the setting it close to the player to be looped, so that when the player moves aroung, the mob "follows".
I also need help with another mod that I am making, it is a mine helping mod, heres the code:
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
var GUI = null;
function newLevel() {
ctx.runOnUiThread(new java.lang.Runnable({ run: function() {
try {
GUI = new android.widget.PopupWindow();
var layout = new android.widget.RelativeLayout(ctx);
var button = new android.widget.Button(ctx);
button.setText("Light");
button.setOnClickListener(new android.view.View.OnClickListener({
onClick: function(viewarg) {
function useItem(x,y,z,itemId,blockId,side)
{
if (getCarriedItem()==50){
Entity.setCarriedItem(getPlayerEnt(),278,1,0);}
else if(getCarrieditem()==278){
Entity.setCarriedItem(getPlayerEnt(),50,1,0);}
}
}
}));
layout.addView(button);
GUI.setContentView(layout);
GUI.setWidth(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
GUI.setHeight(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
GUI.setBackgroundDrawable(new
android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT)); //Specifies whether the button is transparent or not.
GUI.showAtLocation(ctx.getWindow().getDecorView(), android.view.Gravity.RIGHT | android.view.Gravity.BOTTOM, 0, 0);
}catch(problem){
print("The button can't be shown because " + problem);
}
}}));
}[/size]
[size=medium]function leaveGame() { //If we are exiting a world
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get(); //The variable for the MCPE session
ctx.runOnUiThread(new java.lang.Runnable({ run: function() {
if(GUI != null) { //If the button is on the screen
GUI.dismiss(); //Dismiss the button
GUI = null; //Reset the button
}
}}));
}[/size]
[size=medium]
ModPE.setItem(480, 0, 11, "Lasso") //new item lasso introduced
var PositionX; //variable position x
var PositionY; //variable poxition y
var PositionZ; //variable position z
var mob = null; //variable mob is null
function attackHook(attacker, victim) //attack hook code goes here
{
if (getCarriedItem() == 480) //if carried item is a lasso
{
PositionX = getPlayerX(); //get the player posx
PositionY = getPlayerY(); // get the player posy
PositionZ = getPlayerZ(); // get the player pos z
mob = victim; //so the victim are mobs and mobs only
setPosition(mob,PositionX,PositionY,PositionZ+1);
Entity.setHealth(mob, 20);
clientMessage("Lasso Worked"); //I use this as sort of a thing to see if code is working or not, etc
}
}
Ill do it like How I did Pokecube's pokeball, since it is similar i think.
This is an example and It should work O.o
You don't need to do Entity in front of setPosition.
and you have to make the variable mob, and make it so it is the victim.
Also sorry that i didn't reply earlier, but its better later than never.
ModPE.setItem(480, 0, 11, "Lasso") //new item lasso introduced
var PositionX; //variable position x
var PositionY; //variable poxition y
var PositionZ; //variable position z
var mob = null; //variable mob is null
function attackHook(attacker, victim) //attack hook code goes here
{
if (getCarriedItem() == 480) //if carried item is a lasso
{
PositionX = getPlayerX(); //get the player posx
PositionY = getPlayerY(); // get the player posy
PositionZ = getPlayerZ(); // get the player pos z
mob = victim; //so the victim are mobs and mobs only
setPosition(mob,PositionX,PositionY,PositionZ+1);
Entity.setHealth(mob, 20);
clientMessage("Lasso Worked"); //I use this as sort of a thing to see if code is working or not, etc
}
}
Ill do it like How I did Pokecube's pokeball, since it is similar i think.
This is an example and It should work O.o
You don't need to do Entity in front of setPosition.
and you have to make the variable mob, and make it so it is the victim.
Also sorry that i didn't reply earlier, but its better later than never.
Or you can put the positions in a array :
var positions = new Array();//or var positions = []
And if you want to execute code every 2 seconds: (I think 20 ticks is 1 second?)
var start = false;
function attackHook(a,v){
if(!start){start=true;}else{start=false;}
//some more code blabla
}
function modTick(){
if(start){
var ticks = 40; //should be 2 seconds?
ticks--;
if(ticks==0){
//code to run when 2 seconds is hit or make a custom function and call it
ticks = 40;
}
}
}
Just realised that the second script was the template I gave you. lol! With the second script, you can't have a Hook function within another hook function. You have useItem within newLevel(). You need to make a variable which changes when you press the button.
var setter = 0;
//First part of your code here
[size=medium]GUI = new android.widget.PopupWindow();
var layout = new android.widget.RelativeLayout(ctx);
var button = new android.widget.Button(ctx);
button.setText("Light");
button.setOnClickListener(new android.view.View.OnClickListener({
onClick: function(viewarg) {[/size]
[size=medium]if(setter==0){setter = 1;}else{setter = 0;}[/size]
}
}));
[size=medium]//Other part of your code[/size]
function useItem(x,y,z,itemId,blockId,side)
{
if(getCarriedItem()==50 && setter==1)
{
Entity.setCarriedItem(getPlayerEnt(),278,1,0);
}
else if(getCarried()==278 && setter==0)
{
Entity.setCarriedItem(getPlayerEnt(),278,1,0);
}
}
im making a lasso script, and need some help.
i need to know how to execute code in attackHook every 2 seconds.
and how to "un lasso" the animal.
Here is the code i have so far:
ModPE.setItem(480, 0, 11, "Lasso") function attackHook(attacker, victim) { if (getCarriedItem() == 480) { preventDefault(); Entity.setHealth (victim, Entity.getHealth (victim) + 0); Entity.setPosition(victim,getPlayerX,getPlayerY,getPlayerZ+1); } } function useItem(x,y,z,itemId,blockId,side) { if(itemId==287&&blockId==50) //if string on a torch { addItemInventory(480,1); clientMessage("<Cowboy> You now have a lasso!"); } else if(itemId==280&&blockId==50) { addItemInventory(480,1); clientMessage("<Sheriff> You found the cheaty way!"); } }when i tap a animal it dissapears. IDK where. :$
also, i need the part with the setting it close to the player to be looped, so that when the player moves aroung, the mob "follows".
I also need help with another mod that I am making, it is a mine helping mod,
heres the code:
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get(); var GUI = null; function newLevel() { ctx.runOnUiThread(new java.lang.Runnable({ run: function() { try { GUI = new android.widget.PopupWindow(); var layout = new android.widget.RelativeLayout(ctx); var button = new android.widget.Button(ctx); button.setText("Light"); button.setOnClickListener(new android.view.View.OnClickListener({ onClick: function(viewarg) { function useItem(x,y,z,itemId,blockId,side) { if (getCarriedItem()==50){ Entity.setCarriedItem(getPlayerEnt(),278,1,0);} else if(getCarrieditem()==278){ Entity.setCarriedItem(getPlayerEnt(),50,1,0);} } } })); layout.addView(button); GUI.setContentView(layout); GUI.setWidth(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); GUI.setHeight(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); GUI.setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(android.graphics.Color.TRANSPARENT)); //Specifies whether the button is transparent or not. GUI.showAtLocation(ctx.getWindow().getDecorView(), android.view.Gravity.RIGHT | android.view.Gravity.BOTTOM, 0, 0); }catch(problem){ print("The button can't be shown because " + problem); } }})); }[/size] [size=medium]function leaveGame() { //If we are exiting a world var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get(); //The variable for the MCPE session ctx.runOnUiThread(new java.lang.Runnable({ run: function() { if(GUI != null) { //If the button is on the screen GUI.dismiss(); //Dismiss the button GUI = null; //Reset the button } }})); }[/size] [size=medium]when i press the button, nothing happens...
Please help!
Thanks!
~MattdaveMatt
-
View User Profile
-
View Posts
-
Send Message
Curse PremiumModPE.setItem(480, 0, 11, "Lasso") //new item lasso introduced var PositionX; //variable position x var PositionY; //variable poxition y var PositionZ; //variable position z var mob = null; //variable mob is null function attackHook(attacker, victim) //attack hook code goes here { if (getCarriedItem() == 480) //if carried item is a lasso { PositionX = getPlayerX(); //get the player posx PositionY = getPlayerY(); // get the player posy PositionZ = getPlayerZ(); // get the player pos z mob = victim; //so the victim are mobs and mobs only setPosition(mob,PositionX,PositionY,PositionZ+1); Entity.setHealth(mob, 20); clientMessage("Lasso Worked"); //I use this as sort of a thing to see if code is working or not, etc } }Ill do it like How I did Pokecube's pokeball, since it is similar i think.
This is an example and It should work O.o
You don't need to do Entity in front of setPosition.
and you have to make the variable mob, and make it so it is the victim.
Also sorry that i didn't reply earlier, but its better later than never.
Check out my game! It's an open-world, sandbox text adventure.
Follow @hexdro_
Hexdro © 2012-2015
var start = false; function attackHook(a,v){ if(!start){start=true;}else{start=false;} //some more code blabla } function modTick(){ if(start){ var ticks = 40; //should be 2 seconds? ticks--; if(ticks==0){ //code to run when 2 seconds is hit or make a custom function and call it ticks = 40; } } }If you need any help, just ask.var setter = 0; //First part of your code here [size=medium]GUI = new android.widget.PopupWindow(); var layout = new android.widget.RelativeLayout(ctx); var button = new android.widget.Button(ctx); button.setText("Light"); button.setOnClickListener(new android.view.View.OnClickListener({ onClick: function(viewarg) {[/size] [size=medium]if(setter==0){setter = 1;}else{setter = 0;}[/size] } })); [size=medium]//Other part of your code[/size] function useItem(x,y,z,itemId,blockId,side) { if(getCarriedItem()==50 && setter==1) { Entity.setCarriedItem(getPlayerEnt(),278,1,0); } else if(getCarried()==278 && setter==0) { Entity.setCarriedItem(getPlayerEnt(),278,1,0); } }Feel free to modify the code as you will.
Want GUI Templates? Done!
https://github.com/BeATz-UnKNoWN/ModPE_Scripts/wiki/ModPE-Script-Templates
P.S. Feel free to follow me so you know when I post "awesome" content and make the MCForums a brighter place (totally).
If you need to contact me you can either shoot a Kik message to beatz_unknown or send an email to [email protected]