This topic contains 8 replies, has 0 voices, and was last updated by  ArmorWraith 6 years, 7 months ago.

  • Author
    Posts
  • #7261

    Laptops Daddy
    Participant

    we’re lacking examples. id like to try and help a bit.

    the good thing about having some real lua/scripting functionality available to weapons mods to supplement the xml stuff is that we can have functions, loops, and the option of some nice efficient maths stuff to draw out positions for explosions and events. with a bit trigonometry, we can map out a circle, detect an enemy tank’s proximity, maybe set up death zones.

    the hard part in getting to grips with this kind of thing, i always think, is the mathematical jargon used in the references. it’ll be routine stuff for game programmers, but most of us modders arent, not really. sine, cosine, tangents and radians are a bit scary for some people.

    so, a bit of a maths lesson. maybe we could clean something like this up and add it to the wiki?

    say we want to draw a circle on a plane in the game, maybe place napalm in a ring around a tank. we need to give the game x and y positions for each event we want to fire.

    x = centrex + radius * cos(radians)
    y = centrey + radius * sin(radians)

    k, so, if you want to understand what that does. the circumference of a circle is pi * the diameter. pi is the ratio of a circle to a square. just like you can work out the perimeter of a square by width * 4 (4 sides). a circle has 3.14. so, a circle has 3.14 sides : ) that’s the way i like to think of it. sine and cosine; clever computer stuff for calculating angles, built into the system. wonders of modern technology.

    anyway, radians. a radian is just the angle that gives the bit of a circle’s circumference thatd equal its radius. circumference is 2 pi r. ie, there are 2 pi r’s in a circle, so there are 2 pi radians in a circle. (6.28). so, if you can get your head round that, it’ll make sense that if you do a loop like this:

    rads = 0;
    while (rads < 6.28) do x = player.position.x + 20 * math.cos(rads)
    y = player.position.y + 20 * math.sin(rads)

    //fire a weapon here
    rads = rads + 6.28 / 10.0
    end

    youll end up with a nice 20 radius circle made up of 10 positions.

    if none of that makes sense, dont worry. just copy/paste and experiment a bit. id love to make this a challenge. see who can come up with the best lua script.

    here’s a working example:

    make a mod and put a file named napalmlaser.txt in dataluaaccessories

    function runWeapon(playerId, position, velocity)

    player = s3d.get_tank(playerId)
    tankheight = s3d.get_height(player.position.x, player.position.y)
    rads = 0;
    while (rads < 6.28) do

    pos_x = player.position.x + 20 * math.cos(rads)
    pos_y = player.position.y + 20 * math.sin(rads)

    height = s3d.get_height(pos_x, pos_y)

    s3dweapon.fire_weapon(
    "Firewall",
    playerId,
    {x=pos_x, y=pos_y, z=tankheight + 30},
    {x=0, y=0, z=-1}
    )

    s3dweapon.explosion(
    playerId,
    {x=pos_x, y=pos_y, z=height },
    {
    size=4,
    hurtamount=0,
    deform=1,
    animate=false,
    shake=1
    }
    )

    s3dweapon.napalm(
    playerId,
    {x=pos_x, y=pos_y, z=0},
    {
    napalmtime=8.0,
    napalmheight=0.2,
    steptime=0.1,
    hurtsteptime=2.0,
    hurtpersecond=1.0,
    numberstreams=1,
    effectradius=5
    }
    )

    rads = rads + 6.28 / 10.0
    end

    end

    add this to your accessories.xml file:

      
    Firewall
    2
    0


    4
    200
    200
    40
    40
    7
    false

    0.0
    1.0
    0.0



    data/wav/shoot/laser1.wav





    FirewallScript
    1
    2
    10

    data/lua/accessories/napalmlaser.txt
    runWeapon

    and youll have a cool new lua weapon.

    #60806

    ArmorWraith
    Participant

    that works great! how do i change the napalm texture, tried this

     napalmtime=8.0,
    napalmheight=0.2,
    steptime=0.1,
    hurtsteptime=2.0,
    hurtpersecond=1.0,
    numberstreams=1,
    effectradius=5,
    napalmtexture=nuke }

    but it doesnt change, what did i fail to do?

    oop never mind qoutations needed when referencing textures kanga

    #60807

    ArmorWraith
    Participant

    I did experiment with this when you posted, I actually made a mushroom cloud out of it using some tricky projectile redirections.

    any more examples doc?

    Armor

    #60808

    Laptops Daddy
    Participant

    @armorwraith wrote:

    any more examples doc?

    id like to expand on this:

    …detect an enemy tank’s proximity, maybe set up death zones.

    i’ll try to find time to put something together. land mines, maybe?

    #60809

    ArmorWraith
    Participant

    Sounds great, would this also work for anti air craft guns? Say a boid aiplane flew too close to a flack gun, could it shoot at it?

    Armor

    hey what exactly do you mean by ‘death zones’?

    #60810

    Laptops Daddy
    Participant

    @armorwraith wrote:

    hey what exactly do you mean by ‘death zones’?

    i dont know, really. but it sounds cool.

    imagine someone is running at you with a high powered weapon that has limited range. perhaps it’s a real time game. maybe you could adapt the above example to surround an enemy tank with a cage. detect enemy tank positions within a certain radius of yours, or some other object, and strike down upon them with great vengeance and furious anger.

    i dont know about boids. i think i heard something about possible missile collisions, unless i made that up. i don’t know if it’s been implemented. perhaps some kind of AMS or LAMS.

    have a browse of the docs

    http://scorched3d.co.uk/wiki/index.php/Server_Side_Scripts
    http://scorched3d.co.uk/wiki/index.php/LUA_s3d_library
    http://scorched3d.co.uk/wiki/index.php/LUA_s3dweapon_library

    Perhaps you wish to reward players with a certain clan tag, or award more points for different objectives, or even implement a betting system.

    Note: Currently the framework is in place but the library functions available mean that server side scripting has limited functionality. This will be changed if people show an interest.

    there are huge possibilities. build it and they will come.

    ps:
    clan tags. we need that.

    #60811

    ArmorWraith
    Participant

    yes i have read all of those many times, I still lack time and brainpower to learn lua. I hope to jump on it this summer with a nerdy friend of mine.

    so far all my boids are destructable (...regardless of all the dang work i put into making them look pretty) I made their explosions spectacular imo.

    I have shelved KWA not much interest seemed to be in it.. after almost a full year of labor! sheesh.. hoping this new one im making will lure some main people in, the weapons are all realistic in damage and scope. shields are weak and can mean the difference between win and loss. Powerups, airstrikes, placements all play a key in strategy.

    Ill be posting some teaser stuff soon.. much like the fleet pictures.

    #60812

    ArmorWraith
    Participant

    When you mentioned proximity an idea ive been working on with no success. I would like to launch hellfire missiles from airplane boids, but the missiles will aim backwards if i use the aimed over/under tags. I want them to be able to detect whether a tank is close enough to aim at…after being lauched foreward from wings… if it isnt then collide/explode at a certain height.

    its tricky so far.

    Armor

    #60813

    Laptops Daddy
    Participant

    @armorwraith wrote:

    When you mentioned proximity an idea ive been working on with no success…

    do post the code if you come up with something.

    #60814

    ArmorWraith
    Participant

    oop its the xml game code i was using, I was wondering if you had an idea for implementing it via lua?

    Armor

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.