xeon17 Posted November 30, 2014 Share Posted November 30, 2014 So , the script works on clientside i mean it create a weapon and attact everyone who is near. But the problem is , the weapon isn't visible to all players and doesen't make any damage. The weapon is visible to me and damage me when i'm alone in server. But when someone else enter the weapon isn't visible to him and doesen't damage him. A friend said me i should try to trigger the event from clientside and it would work. But it doesen't work,the weapon isn't created. Hope someone can help me. Debugscript3: ERROR: Server is triggered server side,but not added on clientside. addEvent("onPlayerCreateMiniGun",true) addEventHandler("onPlayerCreateMinigun",root, function () local xx,yy,zz = getElementPosition ( localPlayer ) local minigunw = createWeapon ( 'minigun', xx, yy, zz +1 ) setWeaponClipAmmo ( minigunw,99999) setWeaponState ( minigunw,"firing") setWeaponProperty( minigunw, "fire_rotation", 0, -30, 0 ) for _, nMax in ipairs ( getElementsByType ('player' )) do local nx, ny, nz = getElementPosition ( nMax ) setWeaponTarget ( minigunw ,nMax, 255 ) end end) function greetingCommand ( playerSource, commandName ) triggerClientEvent ("onPlayerCreateMiniGun", playerSource, "Hello World!" ) end addCommandHandler ( "minigun", greetingCommand ) Link to comment
xeon17 Posted November 30, 2014 Author Share Posted November 30, 2014 Ok , i found a way to fix this. The minigun is created now when you write /minigun and they are visible to all players. But the problem is they still doesen't make damage. Help. No errors in debugscript 3 now. Here is a screenshot of the problem, http://imgur.com/r3iIFiM.png Link to comment
Anubhav Posted November 30, 2014 Share Posted November 30, 2014 Maybe trigger from client again while firing> Link to comment
xeon17 Posted November 30, 2014 Author Share Posted November 30, 2014 The problem still continue. help Link to comment
Moderators IIYAMA Posted December 1, 2014 Moderators Share Posted December 1, 2014 You have a lot of problems with synchronising serverside data to clientside, this is a very hard learning process. I don't think you are ready for those knowledge yet. But there is another way you can do it, without that required knowledge. Which is creating those custom weapons, based on the player his actions. So when you start your resource and when a player joins. Require no extra communication, because of the events that already exist. You can't trust fully on this because of communication problems, caused by unstable ping and connection timed outs. But for the basic it would work. addEventHandler("onClientPlayerJoin",root, function() -- attach the weapon to the variable source end) addEventHandler("onClientResourceStart",resourceRoot, function () local players = getElementsByType("player") for i-1,#players do local player = players[i] -- attach the weapon to the variable player end end) Link to comment
xeon17 Posted December 1, 2014 Author Share Posted December 1, 2014 Thanks for trying to help me, but this isn't what i want. I'll continue in creating this if you know what's wrong please tell me. Link to comment
Moderators IIYAMA Posted December 1, 2014 Moderators Share Posted December 1, 2014 You want to know what is wrong? Well lets see if you are up to that. 1. You attach the weapons only at the localPlayer, the source of the event should be used instead. (so use source) 2. You trigger to all players when you use the command. But when a player joins after, nothing is sending this trigger to him. (use a table for the late joiner, when the player loads his resource = "onClientResourceStart", trigger serverside to get this table > trigger client again with the table) 2.1. Clean this table of that player when he leaves, 3. When you trigger an element to the other side(client< >server) this element can be destroyed and the code starts giving warnings. This is caused by critical network traffic. Good code never gives warnings or errors, if it does it gives lagg. So use: if isElement(source) then 4. Makes totally no sense: for _, nMax in ipairs ( getElementsByType ('player' )) do local nx, ny, nz = getElementPosition ( nMax ) setWeaponTarget ( minigunw ,nMax, 255 ) end Link to comment
xeon17 Posted December 1, 2014 Author Share Posted December 1, 2014 Thanks , i'll try it soon and i'll answer here. I can't answer everything because i need to go now. About this part of the code for _, nMax in ipairs ( getElementsByType ('player' )) do local nx, ny, nz = getElementPosition ( nMax ) setWeaponTarget ( minigunw ,nMax, 255 ) end It get the position of every player in server and set the minigun target to every player , i don't see any other way to do it.. I'm trying to create a weapon which kill everyone who is near the weapon , but the problem is the weapon work only when i'm alone in the server. When someone else enter the weapon doesn't make any damage,the weapon wasn't visible to all players before but with triggerClientEvent i solved that problem. As i said, i'll try that you said later and i'll answer. Link to comment
Hex547 Posted December 1, 2014 Share Posted December 1, 2014 The weapon can only target 1 person at a time, I'd imagine. You're better off creating a colshape around the weapon of the desired radius, then catching only the elements within the colshape, verify they're humans, then make a function that will select one of them, start firing, catch their death, and signal it should stop firing and move on to the next target. Also, be distrustful of the MTA commands regarding weapon firing. My first ever script in MTA was a shooter mod with all types of guns attached to vehicles, it went really well, and I made the first proper version in about 6-8 hours, but I found that most of the weapon functions are useless. Want to fire the gun? Use createProjectile. For it to work effectively, every thing needs to absolutely synced with the server, so it's always in the same position on everyone's screen, facing the same direction, and firing more or less the same amount. To do this I caught when the player started/stopped pressing down on the fire button, and then just used timers to iterate automatic fire. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now