cannons that really fires

Got any custom JavaScript additions/tweaks you think other people would like to see? Post 'em here!
Post Reply
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

cannons that really fires

Post by dragon slayer »

Yes i seen some requests for cannons that can fire at people. so here is a cannon script.
function onUseChecked( pUser, iUsed )
{
    var socket = pUser.socket;
        var numCannonballs = pUser.ResourceCount( 0x0E73 );

    if( socket && iUsed && iUsed.isItem )
    {
        //Check to see if it's locked down
        if( iUsed.movable == 2 || iUsed.movable == 3 )
        {
            socket.SysMessage( GetDictionaryEntry( 774, socket.Language ) ); //That is locked down and you cannot use it
            return false;
        }
        else if( pUser.isonhorse )
        {
            pUser.SysMessage( "You cannot use this while riding a mount." );
            return false;
        }
                if( numCannonballs >= 1)
                {
            if(pUser.GetTag("Cannon") == null || pUser.GetTag("Cannon") == 0)
            {
            socket.tempObj = iUsed;
            pUser.SetTag("Cannon", 1);
           
            //the addition of the false-flag in the TextMessage below tells the server to only
            //send the message to this character
            pUser.TextMessage("*You begin to load cannon...*", false );
            pUser.StartTimer(3000, 0, true);
             }
             else if(pUser.GetTag("Cannon") == 1)
             {
            pUser.SysMessage("You have to wait a few moments before you can use the cannon!");
             }
             else
            return true;
                }
                if ( numCannonballs < 1 )
                {
                   pUser.SysMessage( "You do not have any cannonballs." );
                   return false;
                }
    }
    return false;
}

function onCallback0( socket, myTarget)
{
    var pUser = socket.currentChar;
    var iUsed = socket.tempObj;

    if( !socket.GetWord( 1 ) && myTarget.isChar )
    {
        if( pUser.InRange( myTarget, 12 ))
        {
            if( myTarget.isonhorse )
            {
                myTarget.Dismount();
                pUser.DoAction( 0x9 );
                DoMovingEffect( pUser, myTarget, 0x0e73, 0x10, 0x00, false );
                myTarget.SysMessage( "You have been knocked off your mount!" );
                                myTarget.stamina = (myTarget.stamina -12);
                                myTarget.health = (myTarget.health -12);
                                pUser.UseResource( 1,  0x0E73 );
                                pUser.SoundEffect( 0x011c, true );
            }
            else
                DoMovingEffect( pUser, myTarget, 0x0e73, 0x10, 0x00, false );
                                myTarget.SysMessage( "You been hit by a cannon ball" );
                                myTarget.stamina = (myTarget.stamina -12);
                                myTarget.health = (myTarget.health -12);
                                pUser.UseResource( 1,  0x0E73 );
                                pUser.SoundEffect( 0x011c, true );
        }
        else
            pUser.SysMessage( "Your target is out of range." );
    }
    else
        pUser.SysMessage( "You cannot target that." );
}

function onTimer(pUser,timerID)
{
    var socket = pUser.socket;

    if(timerID == 0)
    {
        pUser.EmoteMessage( pUser.name + " lights fuse....");
        pUser.StartTimer(1000, 1, true);
    }

    if(timerID == 1)
    {
        pUser.SetTag("Cannon", null);
        socket.CustomTarget(0);
    }
}
I'm still working on attaching this to a boat :) and having it sink them.
Last edited by dragon slayer on Tue Dec 20, 2011 8:43 pm, edited 1 time in total.
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

almost forgot this only works on player chars at the moment not npcs :)
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

Very good script!

A while ago after I see this topic, I created four deed's cannons, where each a is tapped for a position (North, South, East, West).


Put in house.dfn
// CANHÃO SUL

[HOUSE 40]
{ Canhão Sul
ID=0x0001
CHARX=0
CHARY=0
CHARZ=0
HOUSE_ITEM=200
HOUSE_ITEM=201
HOUSE_ITEM=202
}

[HOUSE ITEM 200]
{ canhão sul parte 1/3
ITEM=canhaos1
X=0
Y=0
Z=0
}

[HOUSE ITEM 201]
{ canhão sul parte 2/3
ITEM=canhaos2
X=0
Y=-1
Z=0
}

[HOUSE ITEM 202]
{ canhão sul parte 3/3
ITEM=canhaos3
X=0
Y=-2
Z=0
}


// CANHÃO NORTE

[HOUSE 41]
{ Canhão Norte
ID=0x0001
CHARX=0
CHARY=0
CHARZ=0
HOUSE_ITEM=203
HOUSE_ITEM=204
HOUSE_ITEM=205
}  

[HOUSE ITEM 203]
{ canhão norte parte 1/3
ITEM=canhaon1
X=0
Y=0
Z=0
}

[HOUSE ITEM 204]
{ canhão norte parte 2/3
ITEM=canhaon2
X=0
Y=1
Z=0
}

[HOUSE ITEM 205]
{ canhão norte parte 3/3
ITEM=canhaon3
X=0
Y=2
Z=0
}


// CANHÃO LESTE

[HOUSE 42]
{ Canhão Leste
ID=0x0001
CHARX=0
CHARY=0
CHARZ=0
HOUSE_ITEM=206
HOUSE_ITEM=207
HOUSE_ITEM=208
}

[HOUSE ITEM 206]
{ canhão leste parte 1/3
ITEM=canhaol1
X=0
Y=0
Z=0
}

[HOUSE ITEM 207]
{ canhão leste parte 2/3
ITEM=canhaol2
X=-1
Y=0
Z=0
}

[HOUSE ITEM 208]
{ canhão leste parte 3/3
ITEM=canhaol3
X=-2
Y=0
Z=0
}


// CANHÃO OESTE

[HOUSE 43]
{ Canhão Oeste
ID=0x0001
CHARX=0
CHARY=0
CHARZ=0
HOUSE_ITEM=209
HOUSE_ITEM=210
HOUSE_ITEM=211
}

[HOUSE ITEM 209]
{ canhão oeste parte 1/3
ITEM=canhaoo1
X=0
Y=0
Z=0
}

[HOUSE ITEM 210]
{ canhão oeste parte 2/3
ITEM=canhaoo2
X=1
Y=0
Z=0
}

[HOUSE ITEM 211]
{ canhão oeste parte 3/3
ITEM=canhaoo3
X=2
Y=0
Z=0
}

Put this inside a dfn file in the folder houseaddons.
// PARTES DA ESCRITURA DO CANHÃO [SUL]

[canhaos1]
{
get=base_item
name=Canhão
id=0x0E91
weight=400
movable=2
decay=0
script=5059
}

[canhaos2]
{
get=base_item
name=Canhão
id=0x0E92
weight=400
movable=2
decay=0
}

[canhaos3]
{
get=base_item
name=Canhão
id=0x0E93
weight=400
movable=2
decay=0
}


// PARTES DA ESCRITURA DO CANHÃO [NORTE]

[canhaon1]
{
get=base_item
name=Canhão
id=0x0E8D
weight=400
movable=2
decay=0
script=5059
}

[canhaon2]
{
get=base_item
name=Canhão
id=0x0E8C
weight=400
movable=2
decay=0
}

[canhaon3]
{
get=base_item
name=Canhão
id=0x0E8B
weight=400
movable=2
decay=0
}


// PARTES DA ESCRITURA DO CANHÃO [LESTE]

[canhaol1]
{
get=base_item
name=Canhão
id=0x0E96
weight=400
movable=2
decay=0
script=5059
}

[canhaol2]
{
get=base_item
name=Canhão
id=0x0E95
weight=400
movable=2
decay=0
}

[canhaol3]
{
get=base_item
name=Canhão
id=0x0E94
weight=400
movable=2
decay=0
}


// PARTES DA ESCRITURA DO CANHÃO [OESTE]

[canhaoo1]
{
get=base_item
name=Canhão
id=0x0E8E
weight=400
movable=2
decay=0
script=5059
}

[canhaoo2]
{
get=base_item
name=Canhão
id=0x0E8F
weight=400
movable=2
decay=0
}

[canhaoo3]
{
get=base_item
name=Canhão
id=0x0E90
weight=400
movable=2
decay=0
}


// BOLAS DE CANHÃO [MUNIÇÃO]

[bolacanhao]
{
get=base_item
name=Bola de Canhão
id=0x0E73
weight=15
movable=1
decay=1
pileable=1
amount=1
}

[bolacanhao25]
{
get=base_item
name=Bola de Canhão
id=0x0E73
weight=15
movable=1
decay=1
pileable=1
amount=25
}

[bolacanhao50]
{
get=base_item
name=Bola de Canhão
id=0x0E73
weight=15
movable=1
decay=1
pileable=1
amount=50
}

Put this inside a dfn file in the folder deeds.
[ecanhaos]
{
NAME=Escritura de Canhão [Sul]
ID=0x14F0
color=2844
MOREX=40
}

[ecanhaon]
{
NAME=Escritura de Canhão [Norte]
ID=0x14F0
color=2844
MOREX=41
}

[ecanhaol]
{
NAME=Escritura de Canhão [Leste]
ID=0x14F0
color=2844
MOREX=42
}

[ecanhaoo]
{
NAME=Escritura de Canhão [Oeste]
ID=0x14F0
color=2844
MOREX=43
}
I did the scriptures (deeds) of cannons in order to gain access to them more easily, however emerged a doubt.

Even with the cannon parts already linked to a script, when the cannon is created by deed it comes without the script, however if you put the separate piece without be by deed, now works normally. Is how to make the cannon created by deed already came up with the script? Or always have to put manual if created by a scripture (deed)?
Last edited by Blue Dragon on Tue Jan 10, 2012 12:53 pm, edited 1 time in total.
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

I will see if i can tie this scripts to the cannon script thank you for scripting them all.. keep up the good work.


Plus on a nother note i will see if i can come up with a new ai for you.
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

Thanks.

Humm ... The script supposedly did not come together when the cannon was created by deed because I had two scripts with the same ID, and one of these was the cannon, soon apparently an annulling another, LOL. Fixed it, now the script is already in the cannon, however talks that cannot use the cannon because it is locked ...

Has as script work with it locked?? Because it is a composite object, even if it were not already locked, it should be locked.
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

If its lock down or setmovable 2 cannons can't be used but if you want them to be used all you would have to do is rmeove the if movable 2 and 3 part i can post a script where cannons fire even locked down :)
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

If you can make the script work with cannon locked would be great.

And if attacking npcs would be even better, hehehe

But in any case is already a very good script!
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

Ill add a nother version where if its lock down still fires. I almost got the npc attack worked out.
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Post by dragon slayer »

here you go my friend a version that can be used even locked down
function onUseChecked( pUser, iUsed )
{
    var socket = pUser.socket;
        var numCannonballs = pUser.ResourceCount( 0x0E73 );

    if( socket && iUsed && iUsed.isItem )
    {
                if( pUser.isonhorse )
        {
            pUser.SysMessage( "You cannot use this while riding a mount." );
            return false;
        }
                if( numCannonballs >= 1)
                {
            if(pUser.GetTag("Cannon") == null || pUser.GetTag("Cannon") == 0)
            {
            socket.tempObj = iUsed;
            pUser.SetTag("Cannon", 1);
           
            //the addition of the false-flag in the TextMessage below tells the server to only
            //send the message to this character
            pUser.TextMessage("*You begin to load cannon...*", false );
            pUser.StartTimer(3000, 0, true);
             }
             else if(pUser.GetTag("Cannon") == 1)
             {
            pUser.SysMessage("You have to wait a few moments before you can use the cannon!");
             }
             else
            return true;
                }
                if ( numCannonballs < 1 )
                {
                   pUser.SysMessage( "You do not have any cannonballs." );
                   return false;
                }
    }
    return false;
}

function onCallback0( socket, myTarget)
{
    var pUser = socket.currentChar;
    var iUsed = socket.tempObj;

    if( !socket.GetWord( 1 ) && myTarget.isChar )
    {
        if( pUser.InRange( myTarget, 12 ))
        {
            if( myTarget.isonhorse )
            {
                myTarget.Dismount();
                pUser.DoAction( 0x9 );
                DoMovingEffect( pUser, myTarget, 0x0e73, 0x10, 0x00, false );
                myTarget.SysMessage( "You have been knocked off your mount!" );
                                myTarget.stamina = (myTarget.stamina -12);
                                myTarget.health = (myTarget.health -12);
                                pUser.UseResource( 1,  0x0E73 );
                                pUser.SoundEffect( 0x011c, true );
            }
            else
                DoMovingEffect( pUser, myTarget, 0x0e73, 0x10, 0x00, false );
                                myTarget.SysMessage( "You been hit by a cannon ball" );
                                myTarget.stamina = (myTarget.stamina -12);
                                myTarget.health = (myTarget.health -12);
                                pUser.UseResource( 1,  0x0E73 );
                                pUser.SoundEffect( 0x011c, true );
        }
        else
            pUser.SysMessage( "Your target is out of range." );
    }
    else
        pUser.SysMessage( "You cannot target that." );
}

function onTimer(pUser,timerID)
{
    var socket = pUser.socket;

    if(timerID == 0)
    {
        pUser.EmoteMessage( pUser.name + " lights fuse....");
        pUser.StartTimer(1000, 1, true);
    }

    if(timerID == 1)
    {
        pUser.SetTag("Cannon", null);
        socket.CustomTarget(0);
    }
}
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

Thanks, the script is working perfectly! Very good!
Blue Dragon
UOX3 Apprentice
Posts: 159
Joined: Mon Jan 09, 2012 1:43 am
Has thanked: 0
Been thanked: 0

Post by Blue Dragon »

Dragon Slayer, I made some updates to your script.

1-If your target is innocent, and not pet of you, the cannon user will be criminal.
2-It is no longer possible to shoot in yourself.
3-The cannon ball animation now leaves the cannon at the target and not your player to the target.
4-If you move away from the cannon during the period in which the character reload it, the action is canceled.
5-You must necessarily be beside the cannon to use it.
6-If your target is out of range ("x" tiles that can be changed to any value), the user will receive a message that the target was out of reach and the action is canceled.

Sorry, but I let the phrases in Portuguese.

And two things that make me pensive about it...

1-I do not know why the script does not take damage from the life of NPCs...
2-It is working perfectly, but every time he uses appears the phrase "invalid socket" in the emulator. I do not know why...
function onUseChecked( pUser, iUsed )
{
    var socket = pUser.socket;
    var BolasCanhão = pUser.ResourceCount( 0x0E73 );

    if( socket && iUsed && iUsed.isItem )
    {
        if( pUser.InRange( iUsed, 1 ) )
        {
            if( BolasCanhão >= 1 )
            {
                if( pUser.GetTag( "CanhãoUso" ) == null || pUser.GetTag( "CanhãoUso" ) == 0 )
                {
                socket.tempObj = iUsed;
                pUser.SetTag( "CanhãoUso", 1 );
                pUser.EmoteMessage( "*"+pUser.name+" esta carregando o canhao...*" );
                pUser.StartTimer( 4000, 0, true );
                }
                else if( pUser.GetTag( "CanhãoUso" ) == 1 )
                {
                pUser.SysMessage( "Voce esta ocupado no momento." );
                }
            }
            else
            {
            pUser.SysMessage( "Voce nao tem nenhuma bola de canhao em sua mochila!" );
            }
        }
        else
        {
        pUser.SysMessage( "Voce esta muito longe do canhao!" );
        }
    }
return false;
}


function findNearbyItems( pUser, trgItem, pSock )
{
    if( trgItem && trgItem.isItem && trgItem.id == 0x0E91 || trgItem.id == 0x0E92 || trgItem.id == 0x0E93 || trgItem.id == 0x0E8D || trgItem.id == 0x0E8C || trgItem.id == 0x0E8B || trgItem.id == 0x0E96 || trgItem.id == 0x0E95 || trgItem.id == 0x0E94 || trgItem.id == 0x0E8E || trgItem.id == 0x0E8F || trgItem.id == 0x0E90 )
    {
    return true;
    }
    else
    {
    return false;
    }
}


function onCallback0( socket, myTarget )
{
    var pUser = socket.currentChar;
    var iUsed = socket.tempObj;

    if( !socket.GetWord( 1 ) && myTarget.isChar && myTarget.vulnerable && myTarget.serial != pUser.serial )
    {
        if( pUser.InRange( myTarget, 12 ) )
        {
        pUser.DoAction( 9 );
        pUser.TextMessage( "FOGO!" )

            if( myTarget.innocent && myTarget != pUser.Serial && myTarget.owner != pUser )
            {
            pUser.criminal = true;
            }
            else
            {
            pUser.criminal = false;
            }
                if( myTarget.isonhorse )
                {
                pUser.UseResource( 1, 0x0E73 );
                pUser.SoundEffect( 0x011c, true );
                DoMovingEffect( iUsed, myTarget, 0x0e73, 0x10, 0x00, false );
                myTarget.SysMessage( "Voce foi atingido por uma bola de canhao e caiu de sua montaria!" );
                myTarget.Dismount();
                myTarget.health = ( myTarget.health -70 );
                myTarget.stamina = ( myTarget.stamina -5 );
                }
                else
                {
                pUser.UseResource( 1, 0x0E73 );
                pUser.SoundEffect( 0x011c, true );
                DoMovingEffect( iUsed, myTarget, 0x0e73, 0x10, 0x00, false );
                myTarget.SysMessage( "Voce foi atingido por uma bola de canhao!" );
                myTarget.health = ( myTarget.health -60 );
                myTarget.stamina = ( myTarget.stamina -5 );
                }
        }
        else
        {
        pUser.SysMessage( "Seu alvo esta fora de alcance." );
        }
    }
    else
    {
    pUser.SysMessage( "Alvo invalido!" );
    }
}


function onTimer( pUser,timerID )
{
    var Canhão = AreaItemFunction( "findNearbyItems", pUser, 2, pUser );

    if( timerID == 0 )
    {
        if( Canhão > 0 )
        {
        pUser.TextMessage( "Preparar, apontar..." );
        pUser.StartTimer( 1000, 1, true );
        }
        else
        {
        pUser.SetTag( "CanhãoUso", 0 );
        pUser.SysMessage( "Voce se afastou muito do canhao." );
        }
    }

    if(timerID == 1)
    {
        if( Canhão > 0 )
        {
        pUser.SetTag( "CanhãoUso", 0 );
        pUser.CustomTarget( 0 );
        }
        else
        {
        pUser.SetTag( "CanhãoUso", 0 );
        pUser.SysMessage( "Voce se afastou muito do canhao." );
        }
    }
}
Post Reply