Jump to content

Help with a function (please help)


AHSS

Recommended Posts

so this is it

  
function joinHandler() 
    local x = 2228.9583 
    local y = -1722.1108 
    local z = 13.5625 
    spawnPlayer(source, x, y, z) 
    fadeCamera(source, true) 
    setCameraTarget(source, source) 
    outputChatBox("Welcome to My Server", source) 
end 
addEventHandler("onPlayerJoin", getRootElement(), joinHandler) 
  
function SavePlayerName(theplayer) 
    local pname = getPlayerName(theplayer) 
    local pfile = fileCreate(pname) 
    if (pfile) then 
        fileWrite(pfile,pname) 
        fileClose(pfile) 
        outputChatBox(pname.." This Name is saved in a file containing the same name",theplayer,-17,223,-17,true) 
    end 
end 
addEventHandler("onPlayerJoin", getRootElement(), SavePlayerName) 
  

so thats what i did the first work but the second doesnt it doesnt create the file or even output what iam doing wrong?

Link to comment
  
function SavePlayerFileWithName(theplayer) 
    local pname = getPlayerName(theplayer) 
    local pfile = fileCreate(pname..".txt") 
    if(pfile) then 
        fileWrite(pfile,pname) 
        fileClose(pfile) 
        outputChatBox(pname.."Name Succesfully Created The File",theplayer,-17,223,-17,true) 
    else 
        outputChatBox(pname.."Sorry You Failed Again x-(((",theplayer,-17,223,-17,true) 
    end 
end 
addEventHandler("onPlayerSpawn", getRootElement(),SavePlayerFileWithName) 
  

the (MTA Server.exe)

gave me

badarguement @ 'getPlayerName

and

attemp to concatenate local 'pname'

so???

Link to comment

guys please help iam a new scripter and i need help why is this not working? :

  
function SavePLAYERNAME(theplayer) 
    local playerName = getPlayerName(theplayer) 
    local playerfile = fileCreate(playerName..".txt") 
    if(playerFile) then 
        fileWrite(playerFile,playerName) 
        fileClose(playerFile) 
        outputChatBox("OMG File Created Succesfully", source) 
    else 
        outputChatBox("Failed Again !", source) 
    end 
end 
addEventHandler("onPlayerSpawn", getRootElement(), SavePLAYERNAME) 
addCommandHandler("savenow", SavePLAYERNAME) 
  

now its as following

when the event happens which is player spawn i get this error in MTA Server.exe

ERROR:attempt to concatenate local 'playerName' boolean value> 

but when i use the command it works but! it doesnt save like

this works:

  
local playerfile = fileCreate(playerName..".txt") 
  

this doesnt:

  
    if(playerFile) then 
        fileWrite(playerFile,playerName) 
        fileClose(playerFile) 
        outputChatBox("OMG File Created Succesfully", source) 
    else 
        outputChatBox("Failed Again !", source) 
    end 
  

and it shows me Failed Again!

but the file gets created succesfully and with the player name but the name doesn't get saved in the file

why? please help please help

Link to comment
  • Moderators

It's playerfile, not playerFile:

function SavePLAYERNAME() 
    local playerName = getPlayerName(source) 
    local playerfile = fileCreate(playerName..".txt") 
    if(playerfile) then 
        fileWrite(playerFile,playerName) 
        fileClose(playerFile) 
        outputChatBox("OMG File Created Succesfully", source) 
    else 
        outputChatBox("Failed Again !", source) 
    end 
end 
addEventHandler("onPlayerSpawn", getRootElement(), SavePLAYERNAME) 

Link to comment

ok thanks last question how to send a message to all coloured?

i know this

outputChatBox("blabla", source, r, g, b, true) 

this will send a coloured message to a player but i want to send a coloured message to all

how?? sorry thats the last question :D

Link to comment

ok thanks got another question :D

if i got a file in it there is a playername score money guns blabla how to load a specific value

i know this

fileRead(file, bytes) 

this read specific bytes if i make like 1000 bytes it will read all or most of the file i wanna read 1value or specific one how??

Link to comment

ok thanks another question can someone tell me how to make a /goto or /gethere command i did this but it doesnt work

  
function GetPlayerHere(theplayer, command, otherplayer) 
    local x, y, z = getElementPosition(theplayer) 
    succes = setElementPosition(otherplayer, x, y, z) 
    if(succes) then 
        outputChatBox("succes", theplayer) 
    else 
        outputChatBox("fail", theplayer) 
    end 
end 
addCommandHandler("gethere", GetPlayerHere) 
  
function GoToPlayer(theplayer, command, otherplayer) 
    local x, y, z = getElementPosition(otherplayer) 
    succes = setElementPosition(theplayer, x, y, z) 
    if(succes) then 
        outputChatBox("succes", theplayer) 
    else 
        outputChatBox("Fail", theplayer) 
    end 
end 
addCommandHandler("goto", GoToPlayer) 
  

it gives me the "fail" message always why? thanks please give me the right one please

-------------------------------------------------------------

edit:

the first question is still going on so please answer it too

another question is how to make a function happens on a certain time or a fucntion that goes arround and arround if someone know samp i mean a SetTimer something like this i thought of

local hour, min = getTime() 
  

and i was gonna do like this

if(min == 30) then  

but then i i remembered that it must be with an event so i wanna know how to make something that checks like a function that happens each 5 min or any other timer if you didnt get it tell me i will explain

Edited by Guest
Link to comment
  • Moderators

In the command, you specify the player's name so...:

  
function GetPlayerHere(theplayer, command, otherplayerName ) 
    local x, y, z = getElementPosition(theplayer) 
    otherplayer = getPlayerFromName( otherplayerName ) 
    succes = setElementPosition(otherplayer, x, y, z) 
    if(succes) then 
        outputChatBox("succes", theplayer) 
    else 
        outputChatBox("fail", theplayer) 
    end 
end 
addCommandHandler("gethere", GetPlayerHere) 
  
function GoToPlayer(theplayer, command, otherplayer) 
    otherplayer = getPlayerFromName( otherplayerName ) 
    local x, y, z = getElementPosition( otherplayer ) 
    succes = setElementPosition(theplayer, x, y, z) 
    if(succes) then 
        outputChatBox("succes", theplayer) 
    else 
        outputChatBox("Fail", theplayer) 
    end 
end 
addCommandHandler("goto", GoToPlayer) 
  

Link to comment

ok thanks again

how to make a weapon save?

how to get the weapon and the ammo and save it i know how to save but i dont know how to get the weapon and the ammo

please tell me

thanks citizen your really helping me :D

Link to comment
function getPlayerWeapons(player) 
local weaponsTable = {} 
for slot=0, 12 do 
    local ammo = getPedTotalAmmo(player, slot) 
    if (getPedWeapon(player, slot) ~= 0) then 
        local weapon = getPedWeapon(player, slot) 
        local ammo = getPedTotalAmmo(player, slot) 
        table.insert(weaponsTable, {weapon, ammo}) 
    end 
    end 
       return weaponsTable 
end 

Should work.

Link to comment
  • Moderators
edit:

the first question is still going on so please answer it too

another question is how to make a function happens on a certain time or a fucntion that goes arround and arround if someone know samp i mean a SetTimer something like this i thought of

local hour, min = getTime() 

and i was gonna do like this

if(min == 30) then 
  

but then i i remembered that it must be with an event so i wanna know how to make something that checks like a function that happens each 5 min or any other timer if you didnt get it tell me i will explain

if you want to check if min == 30, you have to call your function every 1 min ( = 60 sec = 60000ms ) with a setTimer:

function yourFunction() 
    local hour, mins = getTime() 
    if( tonumber( mins ) == 30 ) then 
        outputChatBox("It's now "..hour..":30 !") 
    end 
end 
setTimer( yourFunction, 60000, 0 ) 

Link to comment

ok another question :D

i wanna make when someone dies he respawns again cuz in my server when someone dies he have to /reconnect

how to make something happens when a player die or how to make a player respawn when he dies?? thanks

----------------------------

also how to move and existing object that is in a diffrent MAP file and move it when any player is in a certain distance?? how?

notice that the object is created in a MAP file while i am making the CMD in lua !

-----------------------------------

also how to make a lets say a /pm CMD i can make it but i wanna make it without names but with ID

is there is a player id in MTA?? like getPlayerIDFromName??

thanks again

Link to comment

MTA has no ID's, you have to make your own script (look at community.multitheftauto.com, there was one).

about move objects from maps, you can give the object an ID if i'm right.

Example:

map file:

<map> 
    <object id="a51MainGateKeypadCode" model="971" posX="96.736" posY="1918.352" posZ="20.694" rotX="0" rotY="0" rotZ="270.40" newPosX="96.751" newPosY="1914.474" newPosZ="20.694" /> 
</map> 

then in your script you can do:

gate = getElementByID("a51MainGateKeypadCode") 
if gate then 
local x = tonumber(getElementData(gate,"newPosX")) 
local y = tonumber(getElementData(gate,"newPosY")) 
local z = tonumber(getElementData(gate,"newPosZ")) 
moveObject(gate,1500,x,y,z) 
  
x = tonumber(getElementData(gate,"posX")) 
y = tonumber(getElementData(gate,"posY")) 
z = tonumber(getElementData(gate,"posZ"))    
setTimer(moveObject,5000,1,gate,1500,x,y,z) 
end 

Link to comment
ok another question :D

i wanna make when someone dies he respawns again cuz in my server when someone dies he have to /reconnect

how to make something happens when a player die or how to make a player respawn when he dies?? thanks

----------------------------

also how to move and existing object that is in a diffrent MAP file and move it when any player is in a certain distance?? how?

notice that the object is created in a MAP file while i am making the CMD in lua !

-----------------------------------

also how to make a lets say a /pm CMD i can make it but i wanna make it without names but with ID

is there is a player id in MTA?? like getPlayerIDFromName??

thanks again

Yes, there is Player ID if you mean that.

You can do this for testing:

for i,v in ipairs ( getElementsByType ( 'player' ) ) do 
    outputChatBox ( i ) 
end 

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...