Jump to content

help im new to this ...


destunter

Recommended Posts

ok so i want to know how to make a variable that is for everything

so i have this code

function playerDied(totalAmmo, killer, killerWeapon, bodypart)
local pname = GetPlayerName( theplayer )
local pname2 = GetPlayerName( killer )
outputChatBox(pname2.. "Has Killed Player" ..pname)
end
addEventHandler("onPlayerWasted",getRootElement(),playerDied)

is there a way to make a it so i can do

Deaths = Deaths+1

so i can make a stats command that shows all the players kills deaths and so on.

and ...

how can i just load my maps objects into the script if i am making a free roam server

Link to comment

Your code contains invalid function name: GetPlayerName, Lua is case-sensitive and all MTA functions start with lower case letters: getPlayerName.

Loading maps is simply adding tag to meta.xml.

To make stats command you can use element data to store player's stats.

function playerDied(totalAmmo, killer, killerWeapon, bodypart)
local pname = getPlayerName( source )
local pname2 = getPlayerName( killer )
outputChatBox(pname2.. " has Killed " ..pname)
setElementData( source, "deaths", getElementData( source, "deaths" ) + 1 ); -- increase previous death count
setElementData( killer, "kills", getElementData( killer, "kills" ) + 1 ); -- increase previous kill count
end
addEventHandler("onPlayerWasted",getRootElement(),playerDied)
 
addEventHandler( "onPlayerJoin", getRootElement(),  -- reset all the stats when they join
function()
setElementData( source, "deaths", 0 );
setElementData( source, "kills", 0 );
end
)
 
addCommandHandler( "stats", -- command to show player's stats
function( plr )
outputChatBox( "Your current stats (K/D):  " .. getElementData( plr, "kills" ) .. "/" .. getElementData( plr, "deaths" ), plr );
end
)

I set player's stats to 0 when they join so that getElementData will not return nil in onPlayerWasted and that saves you typing of "if" statements to make sure that getElementData returns number.

Link to comment

You already did it nicely, but the error is:

Make sure you use the correct capital letter.

It's not "GetPlayerName", but "getPlayerName" (Note that every functions never use capital letters on the front)

So the result must be:

function playerDied(totalAmmo, killer, killerWeapon, bodypart)
local pname = getPlayerName( theplayer )
local pname2 = getPlayerName( killer )
outputChatBox(pname2.. "Has Killed Player" ..pname)
end
addEventHandler("onPlayerWasted",getRootElement(),playerDied)

It's untested. You can try kill someone if you want.

To start a map, just write /start and stop it (means removing it from the server) by /stop

But first you have to be admin. If you don't know how, look here: https://wiki.multitheftauto.com/wiki/Admin or https://wiki.multitheftauto.com/wiki/Ser ... nistrators

Then you can easily start or stop resources.

Note: Location of your MTA SA files is C:\Program Files\MTA San Andreas Deathmatch\server\mods

If you open in here: C:\Program Files\MTA San Andreas Deathmatch\mods, then it's wrong.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...