Jump to content

Scripting Tutorial 8 - Ion Cannon and Nuke (from C&C '95)


Ransom

Recommended Posts

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

Thank you for repeating yourself; as if I didn't see it the first time.

See how the MTA team made one in their scripting tutorial? By saying that you made an Ion Cannon in SA-MP, actually sounds like you made one like MTA's, when in turn, you didn't. What's the significance of a text-based Ion Cannon? lol.

Link to comment
I just thought of an idea. It must be possible to make some kind of DBZ game-mode with this :lol:. That in combination with Low Grav could work. Just make the ION blast smaller and come out of the player's hand. Maybe I should learn scripting and put all these tutorials to good use :P

I actually made a script a while back where you could jump real high, glide on air, teleport around and shoot fireballs using key combinations (think hadooken).

Sweet! Is this script being hosted anywhere? And for which mod? I'd surely give it a go 8).

Link to comment
Ransom, that is really awesome, serious!

I wish I knew how to LUA Script. But it's harder than it look like.

Learn me the power how to script!

lol :oops:

Its actually pretty easy to pickup

But it is hard to test ;)

What do you say about a earlier release :P

Link to comment
  • 3 weeks later...
  • 1 month later...
  • 2 weeks later...

Good tutorial :)

What would be Very nice is if functions like addEventHandler would also take an actual function reference as an argument, instead of a string with the name of the function. That way you'd be able to write compact code like:

addEventHandler("onPlayerJoin", root, function()
   outputChatBox(getClientName(source) .. " has joined the game.")
end)

Just a suggestion of course, not a disaster if it isn't going to be included. :)

(used code tags because [lua][/lua] doesn't work for some reason)

Link to comment
Good tutorial :)

What would be Very nice is if functions like addEventHandler would also take an actual function reference as an argument, instead of a string with the name of the function. That way you'd be able to write compact code like:

addEventHandler("onPlayerJoin", root, function()
   outputChatBox(getClientName(source) .. " has joined the game.")
end)

Just a suggestion of course, not a disaster if it isn't going to be included. :)

(used code tags because [lua][/lua] doesn't work for some reason)

I think you're right, also if we want to pass some custom arguments to the function we can't actually do that.

There is a problem like that in the pawno( :? )timers function, you cant pass arguments to the functions you use if you have to call it in a string..

Link to comment

At the moment you cant pass a function as an argument im afraid. It doesnt really affect things massively - it just means you have to add an extra line of code

addEventHandler("onPlayerJoin", getRootElement(), "myScriptJoin" )

function myScriptJoin()

outputChatBox(getClientName(source) .. " has joined the game.")

end

However, there is a solution to your problem. I could easilly write an alternative function - something like addEventFuncHandler which takes a function instead. it could look something similar to this:

local eventNumber = 0 
function addEventFuncHandler ( eventName, handleFor, func ) 
    local functionName = "dummyFunction"..eventNumber 
    local codeChunk = functionName.." = func" 
    loadstring(codeChunk)() 
    addEventHandler ( eventName, handleFor, functionName ) 
    eventNumber = eventNumber + 1 
end 

Basically it's assigning a random variable as a function and attaching that to the event. Alternatively, you could replace the addEventHandler as a whole

local eventNumber = 0 
local old_addEventHandler = addEventHandler 
function addEventHandler ( eventName, handleFor, func ) 
    if type(func) == "string" then 
        old_addEventHandler ( eventName, handleFor, func ) 
    elseif type(func) == "function" then     
        local functionName = "dummyFunction"..eventNumber 
        local codeChunk = functionName.." = func" 
        loadstring(codeChunk)() 
        old_addEventHandler ( eventName, handleFor, functionName ) 
        eventNumber = eventNumber + 1 
    end 
end 

Here you're defining addEventHandler as old_addEventHandler and effectively replacing it with your own function. It then checks if its a string - if it is then continue as normal, if its a function then do as above. This is entirely untested though it should work.

Also, MTA has and has always had unlimited parameters for timers.

Link to comment
  • 2 months later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...