mikeee324 Posted November 1, 2011 Share Posted November 1, 2011 How would I go about doing this? For example I have my vehicle spawning command that uses vehicle names. I enter /spawnveh hotring racer It'll only try "hotring" and won't spawn anything. How would I make it take the whole string? Also is there a way i can search for just parts of vehicle names instead of the whole names? Link to comment
50p Posted November 1, 2011 Share Posted November 1, 2011 https://wiki.multitheftauto.com/wiki/AddCommandHandler Check the server example number 3. It explains what you need. Link to comment
Charlie_Jefferson Posted November 1, 2011 Share Posted November 1, 2011 Having the same problem. Got this code: function vehicle(thePlayer, cmd, carname) local x, y, z = getElementPosition ( thePlayer ) local id = getVehicleModelFromName ( carname ) spawnVehicle( id, x+3, y+3, z ) end addCommandHandler("spawnveh", vehicle) function checkArg( ... ) local argumentNumber = #arg local parameters = table.concat( arg, " " ) end And from that, I'm stuck. No idea how to make it check every time I do my /spawnveh. Link to comment
BinSlayer1 Posted November 1, 2011 Share Posted November 1, 2011 function vehicle(thePlayer, cmd, ...) local vehName = table.concat({...}, " ") local x, y, z = getElementPosition ( thePlayer ) local id = getVehicleModelFromName ( vehName ) spawnVehicle( id, x+3, y+3, z ) end addCommandHandler("spawnveh", vehicle) Link to comment
BinSlayer1 Posted November 1, 2011 Share Posted November 1, 2011 I'm dumb . why? just use the code.. if it doesnt work post here Link to comment
mikeee324 Posted November 1, 2011 Author Share Posted November 1, 2011 https://wiki.multitheftauto.com/wiki/AddCommandHandlerCheck the server example number 3. It explains what you need. Cheers for that. Anyone know how i could do the second part of my first post though? Would it just involve creating a table with the names and going through it with string.find or is there a quicker way? Link to comment
revivaL Posted November 1, 2011 Share Posted November 1, 2011 https://wiki.multitheftauto.com/wiki/Get ... elFromName Link to comment
^Dev-PoinT^ Posted November 1, 2011 Share Posted November 1, 2011 Try This local distance = 5 function consoleCreateVehicle ( sourcePlayer, commandName, ... ) if ( sourcePlayer ) then local x, y, z = getElementPosition ( sourcePlayer ) local rotZ = getPedRotation ( sourcePlayer ) x = x + ( ( math.cos ( math.rad ( rotZ ) ) ) * distance ) y = y + ( ( math.sin ( math.rad ( rotZ ) ) ) * distance ) local vehicleName = table.concat({...}, " ") local vehicleID = getVehicleModelFromName ( vehicleName ) if vehicleID then local newVehicle = createVehicle ( vehicleID, x, y, z, 0, 0, rotZ ) if not newVehicle then outputConsole ( "Failed to create vehicle.", sourcePlayer ) end end end end addCommandHandler ( "createvehicle", consoleCreateVehicle ) Link to comment
mikeee324 Posted November 1, 2011 Author Share Posted November 1, 2011 https://wiki.multitheftauto.com/wiki/GetVehicleModelFromName I'm already using that function but it only seems to work with full words. What I'm after is being able to type "/v inf" and it spawn an infernus. If i do that with getVehicleModelFromName it just returns false. Link to comment
mikeee324 Posted November 1, 2011 Author Share Posted November 1, 2011 The command I've already written gets the model the same way... If you give it "inf" or "sult" it'll return false. Link to comment
Castillo Posted November 1, 2011 Share Posted November 1, 2011 vehicleIDS = { 602, 545, 496, 517, 401, 410, 518, 600, 527, 436, 589, 580, 419, 439, 533, 549, 526, 491, 474, 445, 467, 604, 426, 507, 547, 585, 405, 587, 409, 466, 550, 492, 566, 546, 540, 551, 421, 516, 529, 592, 553, 577, 488, 511, 497, 548, 563, 512, 476, 593, 447, 425, 519, 520, 460, 417, 469, 487, 513, 581, 510, 509, 522, 481, 461, 462, 448, 521, 468, 463, 586, 472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 485, 552, 431, 438, 437, 574, 420, 525, 408, 416, 596, 433, 597, 427, 599, 490, 432, 528, 601, 407, 428, 544, 523, 470, 598, 499, 588, 609, 403, 498, 514, 524, 423, 532, 414, 578, 443, 486, 515, 406, 531, 573, 456, 455, 459, 543, 422, 583, 482, 478, 605, 554, 530, 418, 572, 582, 413, 440, 536, 575, 534, 567, 535, 576, 412, 402, 542, 603, 475, 449, 537, 538, 441, 464, 501, 465, 564, 568, 557, 424, 471, 504, 495, 457, 539, 483, 508, 571, 500, 444, 556, 429, 411, 541, 559, 415, 561, 480, 560, 562, 506, 565, 451, 434, 558, 494, 555, 502, 477, 503, 579, 400, 404, 489, 505, 479, 442, 458, 606, 607, 610, 590, 569, 611, 584, 608, 435, 450, 591, 594 } function vehicle(thePlayer, cmd, ...) local vehName = table.concat({...}, " ") local x, y, z = getElementPosition ( thePlayer ) local id = getVehicleModelFromPartName ( vehName ) if id and tonumber(id) then createVehicle ( id, x+3, y+3, z ) end end addCommandHandler("spawnveh", vehicle) function getVehicleModelFromPartName(partName) local model = getVehicleModelFromName(partName) if model then return tonumber(model) else for index, id in ipairs (vehicleIDS) do if (string.find(getVehicleNameFromModel(id), tostring(partName))) then return tonumber(id) end end end end Seems to be working. Link to comment
^Dev-PoinT^ Posted November 1, 2011 Share Posted November 1, 2011 how about This? function vehicle(thePlayer, command) local x, y, z = getElementPosition(thePlayer) local myShit = createVehicle ( 411, 0, 0, 0 ) local spawnVeh = spawnVehicle ( myShit, x+3, y+3, z ) if spawnVeh then outputChatBox("Vehicle was spawned!", thePlayer)else outputChatBox("Error!!",thePlayer) end end addCommandHandler("spawnvehicle", vehicle) Link to comment
Castillo Posted November 1, 2011 Share Posted November 1, 2011 First, that would be the same, second, you're just copying the code from the wiki, and editing the variable names. My code works perfectly, I've tested it. Link to comment
^Dev-PoinT^ Posted November 1, 2011 Share Posted November 1, 2011 and i say your code dont work? your code work but we all here To Help each other Link to comment
mikeee324 Posted November 1, 2011 Author Share Posted November 1, 2011 Thanks solidsnake! Combined your code with a function I found on the net to capitalize the first letter of a string and it's working just as I need it now. Link to comment
50p Posted November 2, 2011 Share Posted November 2, 2011 vehicleIDS = { 602, 545, 496, 517, 401, 410, 518, 600, 527, 436, 589, 580, 419, 439, 533, 549, 526, 491, 474, 445, 467, 604, 426, 507, 547, 585, 405, 587, 409, 466, 550, 492, 566, 546, 540, 551, 421, 516, 529, 592, 553, 577, 488, 511, 497, 548, 563, 512, 476, 593, 447, 425, 519, 520, 460, 417, 469, 487, 513, 581, 510, 509, 522, 481, 461, 462, 448, 521, 468, 463, 586, 472, 473, 493, 595, 484, 430, 453, 452, 446, 454, 485, 552, 431, 438, 437, 574, 420, 525, 408, 416, 596, 433, 597, 427, 599, 490, 432, 528, 601, 407, 428, 544, 523, 470, 598, 499, 588, 609, 403, 498, 514, 524, 423, 532, 414, 578, 443, 486, 515, 406, 531, 573, 456, 455, 459, 543, 422, 583, 482, 478, 605, 554, 530, 418, 572, 582, 413, 440, 536, 575, 534, 567, 535, 576, 412, 402, 542, 603, 475, 449, 537, 538, 441, 464, 501, 465, 564, 568, 557, 424, 471, 504, 495, 457, 539, 483, 508, 571, 500, 444, 556, 429, 411, 541, 559, 415, 561, 480, 560, 562, 506, 565, 451, 434, 558, 494, 555, 502, 477, 503, 579, 400, 404, 489, 505, 479, 442, 458, 606, 607, 610, 590, 569, 611, 584, 608, 435, 450, 591, 594 } function vehicle(thePlayer, cmd, ...) local vehName = table.concat({...}, " ") local x, y, z = getElementPosition ( thePlayer ) local id = getVehicleModelFromPartName ( vehName ) if id and tonumber(id) then createVehicle ( id, x+3, y+3, z ) end end addCommandHandler("spawnveh", vehicle) function getVehicleModelFromPartName(partName) local model = getVehicleModelFromName(partName) if model then return tonumber(model) else for index, id in ipairs (vehicleIDS) do if (string.find(getVehicleNameFromModel(id), tostring(partName))) then return tonumber(id) end end end end Seems to be working. What's the point of having such a huge table if vehicle ID range from 400-611? If some vehicles tend to crash MTA, then just make a small table of those IDs and skip them. function getVehicleModelFromPartName(partName) local model = getVehicleModelFromName(partName) if model then return tonumber(model) else for id = 400, 611 do if (string.find(getVehicleNameFromModel(id), tostring(partName))) then return tonumber(id) end end end end Link to comment
Charlie_Jefferson Posted November 2, 2011 Share Posted November 2, 2011 I'm dumb . why? just use the code.. if it doesnt work post here I'm dumb because it was simple and I didn't figure it out. 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