• Content count

  • Joined

  • Last visited

Community Reputation

11 Decent

1 Follower

About Awang

  • Rank


  • Location
  • Interests
    Lua, HTML5, CSS3, JQuery, PHP
  1. Unlimited oxygen.

    I think it's a better way to cancel this damage, than use a client render for it... function stopDrown ( attacker, damage_type) if ( damage_type == 53 ) then -- if the damage type is drowning, check the wiki for more id cancelEvent() --cancel the event end end addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), stopDrown ) Always think about the client's cpu, when you use ClientRender...
  2. [Question]: fpslimit

    An other example for this: In a race server is a quite big problem the different fps... Like who have more fps will be faster than the others, thats why we fix the limit. I usually use 45-50...
  3. Editing client scripts for hack?

    Instead of using Luac, you could delete the file, when it's starting to run from the harddrive, because it's already loaded into the memory... I say this, because there are some guy, who can encrypt your luac file...
  4. Smooth moving health bar

    local dx_healt = getElementHealth(localPlayer) local healt = getElementHealth(localPlayer) function setHealth(_type,_value) if _value >= 5 then if _type == "add" then dx_healt = dx_healt + 5 else dx_healt = dx_healt - 5 end setTimer(function() setHealth(_type,_value-5) end,500,1) elseif _value > 0 then if _type == "add" then dx_healt = dx_healt + _value else dx_healt = dx_healt - _value end end end function healthChecker() if getElementHealth(localPlayer) < healt then setHealth("add",healt-getElementHealth(localPlayer)) elseif getElementHealth(localPlayer) > healt then setHealth("loss",getElementHealth(localPlayer)-healt) end setTimer(function() healthChecker() end,500,1) end addEventHandler("onClientResourceStart",resourceRoot,function() healthChecker() end) Now you can use dx_health variable to draw the animated health for your bar... I used recursive timer instead of "onClientPlayerDamege" because you can detect if the player get an HP and animate the bar filling up... you can change the animation speed and rate by change the Timer milisecond value and the "dx_healt = dx_healt + 5" or "dx_healt = dx_healt - 5" number parameter... Otherway, you should think about what if the player get other damage, while the animation still in progress... Code not tested, maybe you need to correct it...
  5. You can split the string with the basic Lua function, call string.sub(). If I were you, I store the colored name in an elementData, and if the localPlayer set able to see the colors, I used the strings from the elementData, otherway the strings from getPlayerName() function. And if there is a colorcoded nickname, you can use this: function removeHex( s ) return s:gsub( '#%x%x%x%x%x%x', '' ) or s end
  6. I see... Then you need to split the characters which you want to be colored and go ahead with hexameter colors. For the nametag, you should do a trick with the getScreenFromWorldPosition() wich can help you to calculate screen position from World postion and make a feel that is in the 3D world, but actually, its not....
  7. You can use Hexameter colorcodes in the string, for example: dxDrawBorderedText("#F44242@#FFFFFF"..getPlayerName(player), x - w / 2 + 35, y - h + 6, w, h, tocolor(255,255,255,255), scale, font, "left", "top", false, false, false, true, false) For the automatically change you can use a string variable to store the actually color code for the changing part: local colorcode = "#F44242" dxDrawBorderedText(colorcode.."@#FFFFFF"..getPlayerName(player), x - w / 2 + 35, y - h + 6, w, h, tocolor(255,255,255,255), scale, font, "left", "top", false, false, false, true, false) And by change the value of 'colorcode' variable, you can do, want you want...
  8. What will affect performance the most?

    With these instructions, I think, if you calculate in client side, you should only calculate peds, which are in the streamed zone. Use an if branching with isElementStreamedIn(), or if you really want to reduce the peds table, you should use "onClientElementStreamedIn" and "onClientElementStreamedOut" events and a table, where you push and remove the peds. Good to know, that if you restart the resource while you have peds already in the srteamed zone, they will not trigger this event, so you need to loop peds table with getElementsByType("ped",root,true), where the last param choose you only the streamed peds, then you can add to the table. Anyway, making AIs in Mta is very interesting, have a good luck with this!
  9. onClientPlayerQuit is not working!

    Because this event can't use detect if the player quit and this player is himself... This event can use to detect other clients quite in client side... With onClientResourceStop () you can do it, if you want to push the local data to serverside, in this case: --- Client side items = {1,2} function saveItems() triggerServerEvent ("listItems", localPlayer, items) end addEventHandler ("onClientResourceStop", resourceRoot, saveItems) Serverside should be good, but I have doubt about get the player name... Anyway, you can read all of these usefull advice in wiki, It's good to use it... You can read also great examples and I'ts always uptodate.
  10. Teams and markers

    Or in clientside: addEventHandler("onClientMarkerHit",theMarker,function(hitPlayer, matchingDimension) if matchingDimension and hitPlayer == localPlayer then if getPlayerTeam(localPlayer) == team1 then outputChatbox("You are in team 1") elseif getPlayerTeam(localPlayer) == team2 then outputChatbox("You are in team 2") elseif getPlayerTeam(localPlayer) == false then outputChatbox("You are not member of any team") end end end)
  11. [Question] Reduce the damage

    You shuld check this by matematically... For example, the loss is 10, 10/50 will not the 50% of 10.... if you really want to do with percent parameter, you need to use like this: local reductionPercent = 50 addEventHandler('onClientPlayerDamage',root,function(attacker,weapon,bodypart,loss) if loss then local health = getElementHealth(localplayer) setElementHealth(localplayer,health+(loss*(reductionPercent/100)) end end) Still I think, cancel the root damage and recalculate it will be the simpliest way to understand how this event work... Even the question was reduce the damage for a specific player, not for everbody... With elementData you can change it real time in the server, like an admin can take this ability or give it to a player by using setElementData()
  12. [Question] Reduce the damage

    Or if you add a specific elementData, you can write something like this: addEventHandler("onClientPlayerDamage",root,function(attacker, weapon, bodypart,loss) if source == localPlayer and getElementData(localPlayer,"less.damage") == true then cancelEvent() setElementHealt(localPlayer,getElementHealt(localPlayer)-loss*0.8) end end) For the player, who have the elementData will only get the 80% of the real damage.
  13. destroyElement

    Your way, but you need to use client side, or maybe an assoc server table with the car elements ( where the table keys can be the player name) , but I don't really suggest that... Just a little communication between the client and server...
  14. destroyElement

    You can't use only serverside for that problem if you want to delete only the clien's car on the client death... Try the code, what I'm wrote...
  15. destroyElement

    You should use not only server side... I don't know well, what you want to make, but here is, how I understand your problem: Make a marker for all: Server side: car_marker = createMarker( 0,0,0 , "checkpoint",4,0,0,255,255) setElementData(car_marker,"type","car") You can check the hit on client side: addEventHandler ( "onClientMarkerHit", getRootElement(), function() if getElementData(source,"type") == "car" then local x,y,z = getElementPosition(getLocalPlayer()) triggerServerEvent("createVeh",root,getLocalPlayer(),x,y,z) end end) Now create veh on Server: addEvent("createVeh",true) addEventHandler("createVeh",getRootElement(),function(player,x,y,z) local veh = createVehicle ( 432,x+10,y+10,z+3) triggerClientEvent(player,"synMyVeh",player,veh) end) Receive and save the car element on client and write a death handler: addEvent("synMyVeh",true) local myCar = nil addEventHandler("synMyVeh",root,function(veh) myCar = veh end) addEventHandler("onClientPlayerWasted",root,function() triggerServerEvent("deleteMyVeh",root,myCar) end) And delete only the client car in server side(maybe you can solve this in client side, not tested) addEvent("deleteMyVeh",true) addEventHandler("deleteMyVeh",getRootElement(),function(vehicle) destroyElement(vehicle) end) All the code not tested....