Author Topic: How to make an OnPlayerTouchBrick kind of script(not events)  (Read 1935 times)

Yo,

I'm new to scripting, but not new to programming. I want to make an if statement that, when the player touches the brick, something will happen. I'm editing a mod for all of you who say, theres already a OnPlayerTouch event. Events wouldn't be practical for what I'm doing. I just don't know how. I'd appreciate the help.


         Thanks,

                Reinforcements
« Last Edit: May 06, 2010, 12:48:13 PM by Reinforcements »

I would check the Cops and Robbers or CTF scripts..

Package PlayerTouchOverride//You need to override the method
{
    function FXDTSBrick::onPlayerTouch(%player)
    {
        //You can add you script here
        Parent::onPlayerTouch(%player);//initializes the call to its parents
    }
};//don't forget the ;
activatePackage(PlayerTouchOverride);//activate the package to use the function

Package PlayerTouchOverride//You need to override the method
{
    function FXDTSBrick::onPlayerTouch(%player)
    {
        //You can add you script here
        Parent::onPlayerTouch(%player);//initializes the call to its parents
    }
};//don't forget the ;
activatePackage(PlayerTouchOverride);//activate the package to use the function

Code: [Select]
package ReinforcementsMod {
function FXDTSBrick::onPlayerTouch(%obj, %player) {
if(%obj.var $= "varthing") {
//code
}
Parent::onPlayerTouch(%obj, %player);
|
};
activatePackage(ReinforcementsMod);

Code: [Select]
Package PlayerTouchOverride//You need to override the method
{
    function FXDTSBrick::onPlayerTouch(%player)
    {
        //You can add you script here
        Parent::onPlayerTouch(%player);//initializes the call to its parents
    }
};//don't forget the ;
activatePackage(PlayerTouchOverride);//activate the package to use the function

Thanks guys, which one do I use? Also what exactly does this mean?
Code: [Select]
    function FXDTSBrick::onPlayerTouch(%player)

Is this if the player touches any brick? I'm not sure how to apply it. You see, I want to mod the infinite mining mod so when the player touches a brick, it gets mined, but I want the player to be able to type something like "/touchmine"(I already know the server commands BTW) and he will be able to "touch mine" for like 10 sec.(when he touches a brick, it gets mined) So how would I apply this code so every ore/dirt brick the player touches gets mined for like 10 sec after the player says /touchmine?

Code: [Select]
Package PlayerTouchOverride//You need to override the method
{
    function FXDTSBrick::onPlayerTouch(%player)
    {
        //You can add you script here
        Parent::onPlayerTouch(%player);//initializes the call to its parents
    }
};//don't forget the ;
activatePackage(PlayerTouchOverride);//activate the package to use the function

Thanks guys, which one do I use? Also what exactly does this mean?
Code: [Select]
    function FXDTSBrick::onPlayerTouch(%player)

Is this if the player touches any brick? I'm not sure how to apply it. You see, I want to mod the infinite mining mod so when the player touches a brick, it gets mined, but I want the player to be able to type something like "/touchmine"(I already know the server commands BTW) and he will be able to "touch mine" for like 10 sec.(when he touches a brick, it gets mined) So how would I apply this code so every ore/dirt brick the player touches gets mined for like 10 sec after the player says /touchmine?
With the package you just "add" a piece of coding to the existing OnPlayerTouch (function FXDTSBrick::onPlayerTouch(%player))

So using a package, You would just add some if statements to check:
1. The player used the /touchmine
2. The brick is an ore brick (Not sure how to, check the mining mod for this)
and the code to add the ore.

Hope that helped..


fxDTSBrick::onPlayerTouch is only called for bricks which have got events applied to them - for performance enhancement.

So how would I make it so only ore/dirt form the infinite mining mod(your mod) gets mined when the player touches it?
Code: [Select]
function gunProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal)
{

    parent::onCollision(%this, %obj, %col, %fade, %pos, %normal);
    if(%obj.client.isAdmin)
Dig_mineBrick(%obj, %col, %pos);
}
This is from your mod, I want something like this, except that when the player touches it, it gets mined.

EDIT: it didn't work BTW, thanks for trying guys

I tried this, but it didn't work.
Code: [Select]
function player::onCollision(%this, %obj, %col, %fade, %pos, %normal)
{

    parent::onCollision(%this, %obj, %col, %fade, %pos, %normal);
    if(%obj.client.isAdmin)
Dig_mineBrick(%obj, %col, %pos);
}

fxDTSBrick::onPlayerTouch is only called for bricks which have got events applied to them - for performance enhancement.
I just spent ages looking for that quote to put here then it turns out you already had.