Jump to content

onElementDataChange Help


mremin

Recommended Posts

Posted

local rootElement = getRootElement() 
levels = {} 
levels[0] = {"Test 0", "10"} 
levels[1] = {"Test 1", "20"} 
levels[2] = {"Test 2", "100"} 
levels[3] = {"Test 3", "150"} 
levels[4] = {"Test 4", "200"} 
  
function ResourceStart () 
executeSQLCreateTable("levels", "accountname STRING, level INT") 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), ResourceStart) 
  
function addPlayer() 
local account = getPlayerAccount(source) 
local playername = getPlayerName(source) 
CheckPlayer = executeSQLSelect ( "levels", "accountname", "accountname = '" .. getAccountName(account) .. "'" ) 
if ( type( CheckPlayer ) == "table" and #CheckPlayer == 0 ) or not CheckPlayer then  
executeSQLInsert ( "levels", "'".. getAccountName(account) .."','0'" ) 
    end 
end 
addEventHandler("onPlayerLogin",rootElement,addPlayer) 
  
addEventHandler( "onElementDataChange", rootElement,  
function () 
if getElementType(source) == "player" then 
    local acc = getPlayerAccount(source) 
    local accountname = getAccountName(acc) 
    local playername = getPlayerName(source) 
    local data = getElementData(source,"exp") 
    local sqldata = executeSQLSelect ( "levels", "level","accountname = '" .. accountname .. "'") 
    lvl = sqldata[1]["level"] 
    if tostring(data) == tostring(levels[lvl][2]) then 
    outputChatBox("*Level system: congratulations ".. playername .." you're now a ".. levels[lvl][1] .."!",getRootElement(),0,255,0) 
    local textDis = textCreateDisplay () 
    local item = textCreateTextItem( "LEVEL UP! YOU'RE NOW LEVEL ".. tostring(sqldata[1]["level"]), 0.5, 0.4, 2, 0, 255, 0, 255, 4, "center", "center" ) 
    textDisplayAddText ( textDis, item ) 
    textDisplayAddObserver ( textDis, source ) 
    setTimer ( textDestroyTextItem, 5000, 1, item ) 
    setTimer ( textDestroyDisplay, 5000, 1, textDis ) 
    sql = tonumber(sqldata[1]["level"]) + 1 
    executeSQLUpdate("levels", "level = '".. sql .."'", "accountname = '".. accountname .."'")   
       end 
    end 
end) 

-24. Error in row-I could not, please help me

https://community.multitheftauto.com/index.php?p= ... 253&vote=5 <-------the real link here

Posted
you changed something?

and type /debugscript 3 in game and show error.

that script is from community so it should work.

not changed but Add anything he says. I could not do it

Posted

script doesnt work? and doesnt show the error? ;o

You kill peds or players ? and dont work? this is problem?

edit:

1. You haven't got mysql database

2. You haven't got reward on wasted

  
  
function rewardOnWasted ( ammo, killer, killerweapon, bodypart ) 
if (killer) and (killer ~=source) then 
local exp = getElementData(killer,"exp") 
if exp then 
setElementData(killer,"exp",tonumber(getElementData(killer,"exp"))+5) 
outputChatBox("Experience gained +5! total ".. tonumber(exp)+5,killer,0,255,0) 
else 
setElementData(killer,"exp",0) 
end 
end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), rewardOnWasted ) 

~by Solidsnake14

16211.gif

dukenukem3Dsa project, mta interfaces

I wanna kick your ass!

Posted

dukenukem, this uses sqlite not mysql, the database is created when resource starts and when a player logs-in he will be added with level 1 or 0 (i don't remember) and when the element data changes he will raise up, i made an example of how to use it with onPlayerWasted event and works fine, he may edited it or not using it right.

btw, could mremin show us the code he use to make it work?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Well, someone was asking for a experience/level system in mta forums so i didn't had anything to do and made it :P

(i hope this is what they mean :D)

script works like this:

the script works onElementDataChange that means when you do like: setElementData(playerElement,"exp",10) will raise your level to 1, the script checks for a data in a sql database that is created when resource starts and when a player logins the data will be set to 0 if he doesn't had any data yet.

then the script finds that data and compares it.

P.S: i'm bad in explaining :P

Would you make i could not

Posted

lol? you gotta be kidding me, you just pasted my post.. can you show us your CODE where you implement my system?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

line 24 = addEventHandler( "onElementDataChange", rootElement, :roll::roll::roll:

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

'''onElementDataChange that means when you do like: setElementData(playerElement,"exp",10) will raise your level to 1'''

what is this??

Posted

use the example of killing,

function rewardOnWasted ( ammo, killer, killerweapon, bodypart ) 
if (killer) and (killer ~=source) then 
local exp = getElementData(killer,"exp") 
if exp then 
setElementData(killer,"exp",tonumber(getElementData(killer,"exp"))+5) 
outputChatBox("Experience gained +5! total ".. tonumber(exp)+5,killer,0,255,0) 
else 
setElementData(killer,"exp",0) 
end 
end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), rewardOnWasted ) 

now go kill players and you will raise levels..

I think you don't get how it works,

levels[0] = {"Test 0", "10"}

levels[0] = level number

Test 0 = level name or whatever you want example: Level 1

10 = experience required to reach that level

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

yes, but you must have scripting knowlage to create it.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

omfg!!!!!!! you just don't understand how it works, you have a script to win money when win a DD/DM or race?!

If yes then post it here.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

you can't even understand what i post.. how can i help you if you don't understand me?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

i copied a small code from race_starter_pack and added to set experience on DD/DM win

function DestructionMoney() 
local alivePlayers = getAlivePlayers() 
if info == "Destruction derby" then 
   if #alivePlayers == 1 then 
   local playername = getPlayerName(alivePlayers[1]) 
   outputChatBox("*Wins: "..playername.." took $2500 for surviving!",getRootElement(),255,255,0) 
   setElementData(alivePlayers[1] ,"exp",tonumber(getElementData(alivePlayers[1],"exp"))+5) 
   end  
end 
end 
addEventHandler("onPlayerWasted",gtRootElement(),DestructionMoney) 

try it (not tested)

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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