Jump to content

IIYAMA

Moderators
  • Posts

    6,085
  • Joined

  • Last visited

  • Days Won

    215

Everything posted by IIYAMA

  1. Hi, I was curious when the garbage collector would clean something like this: function testFunction () local testVariable = 100 local function firstFunctionInBlock () print("first function, testVariable: " .. testVariable ) testVariable = testVariable + 1 end local function secondFunctionInBlock () print("second function, testVariable: " .. testVariable) testVariable = testVariable + 1 end return function () firstFunctionInBlock() secondFunctionInBlock () end end function testFunction () -------------------------- -- function block -- -------------------------- end Executed with: local newCreatedFunction = testFunction() newCreatedFunction() newCreatedFunction() newCreatedFunction() -- print("--") -- local newCreatedFunction2 = testFunction() newCreatedFunction2() newCreatedFunction2() newCreatedFunction2() Results: first function, testVariable: 100 second function, testVariable: 101 first function, testVariable: 102 second function, testVariable: 103 first function, testVariable: 104 second function, testVariable: 105 -- first function, testVariable: 100 second function, testVariable: 101 first function, testVariable: 102 second function, testVariable: 103 first function, testVariable: 104 second function, testVariable: 105 I assume when I nil the function that is active in the block. newCreatedFunction = nil It will clear the first created function block by the garbage collector. newCreatedFunction2 = nil Same goes for clearing the second created function block. I did like to hear your opinion about this matter!
  2. Replace line 5 and line 5 at both of the scripts. With the almost identical code from my post.
  3. triggerClientEvent(sourcePlayer, "onPayPhone", resourceRoot, sourcePlayer) < server (3e argument is the source of the event that will be executed. The source isn't a parameter.) The source is now the resourceRoot. ------- Client > addEventHandler("onPayPhone", resourceRoot, onPayPhone) The resourceRoot element is shared over client and serverside. This eventhandler will only accept the resourceRoot of this resource.
  4. Make sure you break the loop after cancelling the event. (performance) break
  5. My last code post will help you out with that problem, since it isn't corner based but distance based.
  6. How about you try to pre render it? > onClientPreRender < Maybe the GTA is re-adjusting the wheels every frame.
  7. I wonder if you can rotate tires like that. Why don't you try it with: https://wiki.multitheftauto.com/wiki/SetAnalogControlState ? Since you are only rotating the Z as.
  8. You might want to reply @klaw , it is a bit rude if you do not.
  9. You might want to reply @pepsi18 it is a bit rude if you do not.
  10. I could have written it better. I skipped here and there some words, but I am happy that you like it. P.s: Learning tables will make you a god at scripting systems like this.
  11. I came up with an easier concept for it. This will compare the centres of the rectangles with each other, which only requires 4 conditions. local rectangleX1, rectangleY1 = 25, 0 local rectangleX2, rectangleY2 = -25, 10 local rectangleSizeX, rectangleSizeY = 50, 50 function isRectangleInRectangle(X1, Y1, sizeX1, sizeY1, X2, Y2, sizeX2, sizeY2) local centreX1, centreY1 = X1 + sizeX1 / 2, Y1 + sizeY1 / 2 local centreX2, centreY2 = X2 + sizeX2 / 2, Y2 + sizeY2 / 2 local distanceX = centreX1 - centreX2 local distanceY = centreY1 - centreY2 if distanceX < 0 then distanceX = -distanceX end if distanceY < 0 then distanceY = -distanceY end if distanceX <= sizeX1 / 2 + sizeX2 / 2 and distanceY <= sizeY1 / 2 + sizeY2 / 2 then return true end return false end iprint(tostring(isRectangleInRectangle(rectangleX1, rectangleY1, rectangleSizeX, rectangleSizeY, rectangleX2, rectangleY2, rectangleSizeX, rectangleSizeY)))
  12. nvm you are right. I think I am a bit tired, that must be the problem. I will solve it for you tomorrow if nobody already solved it for you.
  13. sides should be included afaik, my bad for forgetting to mention that. It is untested, so test it with all possible combinations you can come up with.
  14. local posX = posX + sX * 0.025 + 61 Try to play with line 82 a bit. It will not fix all your problems, but it is a start.
  15. local rectangleX1, rectangleY1 = 20, -48 local rectangleX2, rectangleY2 = 60, -5 local rectangleSizeX, rectangleSizeY = 50, 50 function isRectangleInRectangle (X1, Y1, sizeX1, sizeY1, X2, Y2, sizeX2, sizeY2) if (X1 > X2 and Y1 > Y2 and X1 < X2 + sizeX2 and Y1 < Y2 + sizeY2) or (X1 + sizeX1 < X2 + sizeX2 and Y1 + sizeY1 < Y2 + sizeY2 and X1 + sizeX1 > X2 and Y1 + sizeY1 > Y2) then return true end return false end iprint(tostring(isRectangleInRectangle(rectangleX1, rectangleY1, rectangleSizeX, rectangleSizeY, rectangleX2, rectangleY2, rectangleSizeX, rectangleSizeY))) try this, untested. It will check if the TOP+LEFT or BOTTOM+RIGHT is inside the other rectangle. (This doesn't work when you rotate the rectangle)
  16. Elementdata: Uses ~7x times less data in comparison with the triggerEvent. (I haven't been able to test it with accurate results, but you can assume it is 7 times less usage.) Automatic send to new joiners, because it becomes part of the element itself. Disable synchronization can be useful for sharing data between resources without wasting the network. triggerEvent: Normal triggerEvent variant sends faster data than elementdata. Latent trigger event can be used. (The latent variable, which makes it possible to send it slowly and without blocking the network) Can be send to a specific player / list. (Which makes it possible to reduce network usage for clients that don't need the data.) Afaik it can handle large amount of data better. For a nametag, elementdata wouldn't be a bad idea. Since everybody in the server need to see that a specific player is admin, right? So it is better to pick the method that suits best for the situation. And it is even better if you mind disabling synchronization when you only need it one side. Elementdata can indeed ruin your server if you use it not carefully enough. Take a look at the mini-mission server, it laggs like hell.
  17. The concept of letting serverside and clientside work together isn't very difficult. It actually the same as you and me having a conversation. You communicate with me that you have a problem with a script. Noah > IIYAMA Then I reply on your topic and gave you some tips. IIYAMA > Noah Then you process those tips and send me request to send you more information. Noah > IIYAMA Which I am sending you back now. IIYAMA > Noah During this conversation you have send me 2 messages and I have send you 2 messages back. @koragg showed you the functions you can use to start a conversation. Lets start a conversation between the Server and all clients! So a part of the conversation goes like this: (the rest of the conditions you have to fill in by yourself) Server: A lonely player named <John> enters a lonely vehicle. 'onVehicleEnter' gets triggered on serverside. Lets give the vehicle weapon so it can kill other lonely players!!! The server saves that the vehicle has a weapon now(for example in to a table). Oh great it has been saved! Now let all lonely players know that a vehicle has super weapons! triggerClientEvent to all the players. Clients: Oh man we all got mail from the server!! It said that a lonely vehicle has weapons now!! Now we all have to attach weapons to it on all our computers! Noooo!! This sucks damn. setElementParent(weapon, vehicle) Client: The lonely player named <John> pushed his left mouse button down! Yes, I am an a vehicle. Yes, it is a hydra. Yes, I am happy to be alive. Server, I am firing up!!! setElementData on his vehicle firing true. Clients: I received element:~yData oh oh. It said that a lonely hydra is firing fire! Which weapons did I attach on it? Ah wait I added them a few seconds ago, when a lonely player entered his lonely vehicle! Lets fire these hydra flame weapons! setWeaponState firing true Server: A lonely player named <John> crashed his hydra into his mother. There was nothing left of his mother, neither of his poor hydra dragon. setElementData on his vehicle firing false. Clients: I received element:~yData oh oh. It said that a lonely hydra isn't firing any more. What could have happened? setWeaponState firing false.
  18. local progress = 55 -- 55% local amountOfSegments = 5 -- the amount of bars / segments local progressPerSegment = (100 / amountOfSegments) -- when you devide the total progress over the segment count, you will know how much percentage every segment is. local remainingProgress = progress % progressPerSegment -- the next step is to calculate how much percentage is left over after removing all full bars of it. So for example ever segment is 10% and you have 95% health, it will subtrack 10 from 95 as much as possible. At the end 5% will remain. local segmentsFull = math.floor(progress / progressPerSegment) -- it is usefull to know how much bars are full, so that you can fill those up. local segmentsInUse = math.ceil(progress / progressPerSegment) -- This will show you have many bars do contain any health. iprint("segmentsFull: " .. segmentsFull) iprint("segmentsInUse: " .. segmentsInUse) iprint("remainingProgress: " .. remainingProgress) for i=1, amountOfSegments do if i <= segmentsFull then -- draw a fulled health line iprint("full") else -- draw a fulled [gray] health line iprint("background") if i == segmentsInUse and remainingProgress > 0 then -- draw a health line depending on the remainingProgress iprint("remaining " .. tostring(remainingProgress)) else iprint("empty") end end end
  19. First of all you have to make a choice: Do you you want to use serverside as support for security and data validation? If not, then here are some reasons why the code isn't synchronized correctly and also how to counter those problems. You can't share client created elements with elementdata. To counter this you have to create for every client those weapons and set elementdata at the vehicle instead. So setElementData(vehicle, "weaponHydraL", weapon, false) -- disable the synchronization, else you will get trouble. You attach those weapons at the moment the vehicle gets streamed in or when it is already streamed in. There are events and functions for that. Sync weapon fire isn't working because of the first reason. setElementData(vehicle, "weaponFire", true, true) -- do sync this and catch up with: https://wiki.multitheftauto.com/wiki/OnClientElementDataChange > setWeaponState Keep debugging:
  20. I am using elementdata now with sync off. Using an export function might also be a good idea. Yea strange that wasEventCancelled didn't work.
  21. onClientRender is fine, just the id check and communication between the server can be optimised. Update time to check the distance You also increase (~50ms) the update time with getTickCount as you did before. (that gives you somehow less lagg than a 50 ms timer)
  22. elseif id == 602 or id == 496 or id == 401 or id == 518 or id == 527 or id == 589 or id == 419 or id == 587 or id == 533 or id == 526 or id == 474 or id == 545 or id == 517 or id == 410 or id == 600 or id == 436 or id == 439 or id == 549 or id == 491 or id == 485 or id == 431 or id == 438 or id == 437 or id == 574 or id == 420 or id == 525 or id == 408 or id == 552 or id == 416 or id == 433 or id == 427 or id == 490 or id == 528 or id == 407 or id == 544 or id == 523 or id == 470 or id == 596 or id == 598 or id == 599 or id == 597 or id == 432 or id == 601 or id == 428 or id == 499 or id == 609 or id == 498 or id == 524 or id == 532 or id == 578 or id == 486 or id == 406 or id == 573 or id == 455 or id == 588 or id == 403 or id == 423 or id == 414 or id == 443 or id == 515 or id == 514 or id == 531 or id == 456 or id == 459 or id == 422 or id == 482 or id == 605 or id == 530 or id == 418 or id == 572 or id == 582 or id == 413 or id == 440 or id == 543 or id == 583 or id == 478 or id == 554 or id == 579 or id == 400 or id == 404 or id == 489 or id == 505 or id == 479 or id == 442 or id == 458 or id == 536 or id == 575 or id == 534 or id == 567 or id == 535 or id == 576 or id == 412 or id == 402 or id == 542 or id == 603 or id == 475 or id == 429 or id == 541 or id == 415 or id == 480 or id == 562 or id == 565 or id == 434 or id == 494 or id == 502 or id == 503 or id == 411 or id == 559 or id == 561 or id == 560 or id == 506 or id == 451 or id == 558 or id == 555 or id == 477 or id == 441 or id == 464 or id == 594 or id == 501 or id == 465 or id == 564 or id == 606 or id == 607 or id == 610 or id == 584 or id == 611 or id == 608 or id == 435 or id == 450 or id == 591 or id == 590 or id == 538 or id == 570 or id == 569 or id == 537 or id == 449 or id == 568 or id == 424 or id == 504 or id == 457 or id == 483 or id == 508 or id == 571 or id == 500 or id == 444 or id == 556 or id == 557 or id == 471 or id == 495 or id == 539 then Woow, this very very very inefficient. O_o + > onClientRender < I suggest to follow a table tutorial. local vehicleIDs = { car = { [501] = true, [465] = true, [607] = true, [571] = true } boat = { -- etc. } } elseif vehicleIDs.car[id] then -- do your stuff elseif vehicleIDs.boat[id] then -- do your stuff and you might want to consider using: https://wiki.multitheftauto.com/wiki/TriggerLatentServerEvent Since you trigger it every second, you have to take in account that not everybody has great internet. I would strongly recommend to send it every 10 or even 20 seconds. What does 10 seconds matter when they are an hour in the server?
  23. addEventHandler ( "onClientPlayerDamage", localPlayer, function (attacker, weapon, bodypart, loss) if attacker and attacker ~= localPlayer and bodypart == 9 and instandHeadshotKillWeapons[weapon] and not isPedDead(localPlayer) then iprint(wasEventCancelled ()) if not wasEventCancelled () then triggerServerEvent("onPlayerSyncHeadshot", resourceRoot, attacker, weapon, bodypart, loss) setElementHealth(localPlayer, 0) startBlockingPlayerControls() end end end, false, "low-100") Headshot script. local function stopDamage ( attacker, weapon, bodypart ) if isTimer(spawnProtectionTimer) then cancelEvent() outputDebugString("event is cancelled") end end addEventHandler ( "onClientPlayerDamage", localPlayer, stopDamage, false, "high+100" ) Spawnprotection script. I am trying to let the client cancel the player damage for spawnprotecion. But it seems like wasEventCancelled doesn't detect that the event was cancelled on the headshot script. I already changed the event order. Do you guys have any idea?
  24. Using elementdata is fine, just make sure you disable the syncronization when you don't need it. ElementData is absolute not for important information. It is very foolish to save passwords or similar data in it. bool setElementData ( element theElement, string key, var value [, bool synchronize = true ] ) You could also use: bool setElementParent ( element theElement, element parent ) element getElementParent ( element theElement ) table getElementChildren ( element parent [, string theType = nil ] ) element getElementChild ( element parent, int index ) Or learn tables.
×
×
  • Create New...