Jump to content

[HELP] NPC-system (community bpeds)


Recommended Posts

Hello, I got the bpeds resource from community, I changed it a bit, and I got rid of anim.lua, info_c.lua and info_s.lua as I need just the gui and the normal script. When I press the create button (CREAZA) all I get is an error in the console, a outputChatBox bad argument at like 103 on server.lua...

capturecfa.png

server.lua:

-- outputChatBox: 
  
pedCreateText = "Ai creat un nou NPC cu ID-ul #FFFF00" 
pedCreateError = "Introdu toate detaliile!" 
  
deletePedInfo = "Ai sters NPC-ul cu ID-ul #FFFF00" 
deletePedError = "Introdu ID-ul !" 
  
-- Comenzi 
  
pedCreatorCommand = "addnpc" 
  
pedDeleteCommand = "delnpc" 
  
helpCommand = "npchelp" 
  
-- Functii 
  
function pomocHelp() 
outputChatBox("----------------------",source,0,255,0,false) 
outputChatBox("Ajutor Creaza NPC",source,255,255,0,false) 
outputChatBox("/"..pedCreatorCommand.."",source,255,255,255,false) 
outputChatBox("",source,255,255,0,false) 
outputChatBox("/"..pedDeleteCommand.."",source,255,255,255,false) 
outputChatBox("----------------------",source,0,255,0,false) 
end 
  
addCommandHandler(helpCommand, pomocHelp) 
  
gResRoot = getResourceRootElement(getThisResource()) 
function loadAllpeds () 
  local root = xmlLoadFile ("peds.xml") 
  local pedroot = xmlFindChild (root,"peds",0) 
  if (pedroot) then 
    allpeds = {} 
    for i,v in ipairs (xmlNodeGetChildren(pedroot)) do 
      local x = xmlNodeGetAttribute (v,"x") 
      local y = xmlNodeGetAttribute (v,"y") 
      local z = xmlNodeGetAttribute (v,"z") 
      local nazwa = xmlNodeGetAttribute (v,"name") 
      local number = xmlNodeGetAttribute (v,"num") 
      local skin = xmlNodeGetAttribute (v,"skin") 
      local rot = xmlNodeGetAttribute (v,"rot") 
      local int = xmlNodeGetAttribute (v,"int") 
      local dim = xmlNodeGetAttribute (v,"dim") 
        local ped = createPed (tonumber(skin),tonumber(x),tonumber(y),tonumber(z)) 
        setPedRotation(ped,tonumber(rot)) 
        setElementData (ped,"pedNumber",tonumber(number)) 
        setElementData (ped,"message",tostring(nazwa)) 
        setElementData (ped,"message2","bPed\nID: "..tostring(number)) 
        setElementInterior (ped, tonumber(int)) 
        setElementDimension (ped, tonumber(dim)) 
    --  outputDebugString ("Ped " .. tostring(nazwa) .. " [iD " .. tostring(number) .. "] loaded!") 
    end 
  end 
end 
addEventHandler("onResourceStart",gResRoot, loadAllpeds) 
  
  
addEvent("createped",true) 
  
  
function getPedCount () 
  local root = xmlLoadFile ("peds.xml") 
  local pedsRoot = xmlFindChild (root,"peds",0) 
  local allpeds = xmlNodeGetChildren (pedsRoot) 
  peds = 0 
  for i,v in ipairs (allpeds) do 
    peds = peds+1 
  end 
  xmlUnloadFile (root) 
  return peds 
end 
  
addEventHandler ("createped", getRootElement(), 
function(name, skin, rot, intx, inty, intz, int, dim) 
  if (intx) and (not isPedInVehicle(source)) then 
    if (exports.global:isPlayerLeadAdmin(thePlayer)) then 
      local x,y,z = getElementPosition (source) 
      local pedCount = tonumber(getPedCount()) 
      local root = xmlLoadFile ("peds.xml") 
      local pedsRoot = xmlFindChild (root,"peds",0) 
      local newPed = xmlCreateChild (pedsRoot,"ped") 
      xmlNodeSetAttribute (newPed,"num",pedCount) 
      xmlNodeSetAttribute (newPed,"x",intx) 
      xmlNodeSetAttribute (newPed,"y",inty) 
      xmlNodeSetAttribute (newPed,"z",intz) 
      xmlNodeSetAttribute (newPed,"name",name) 
      xmlNodeSetAttribute (newPed,"skin",skin) 
      xmlNodeSetAttribute (newPed,"rot",rot) 
      xmlNodeSetAttribute (newPed,"int",int) 
      xmlNodeSetAttribute (newPed,"dim",dim) 
      triggerClientEvent("showInfoFromPedSystem", source, "*"..pedCreateText2.." "..pedCount.." !", 255, 150, 0) 
      outputChatBox ("*"..pedCreateText.." "..pedCount.." !",source,255,100,0,true)   
      xmlSaveFile (root)    
      xmlUnloadFile (root)    
      reloadPeds () 
      setTimer ( loadAllpeds, 2000, 1 ) 
    else 
      triggerClientEvent("showInfoFromPedSystem", source, pedAccessDeined2, 255, 0, 0) 
      outputChatBox (pedAccessDeined,source,255,200,0,false) 
    end 
  else 
    triggerClientEvent("showInfoFromPedSystem", source, pedCreateError2, 255, 0, 0) 
    outputChatBox (pedCreateError,thePlayer,255,0,0,false) 
  end 
end) 
  
function showWindow (thePlayer, commandName ) 
    if (exports.global:isPlayerLeadAdmin(thePlayer)) then 
    triggerClientEvent ( thePlayer, "showWindow2", thePlayer ) 
    triggerClientEvent("showInfoFromPedSystem", thePlayer, pedCreatorOpen, 255, 255, 0) 
    end 
end 
addCommandHandler ( pedCreatorCommand, showWindow ) 
  
function showWindow2 ( thePlayer) 
    if (exports.global:isPlayerLeadAdmin(thePlayer)) then 
    triggerClientEvent ( thePlayer, "showWindow", thePlayer ) 
    end 
end 
  
function destroyPed ( thePlayer, commandName, pedNumber ) 
    if (exports.global:isPlayerLeadAdmin(thePlayer)) then 
    if ( pedNumber ) then 
    local root = xmlLoadFile ("peds.xml") 
    local pedroot = xmlFindChild (root,"peds",0) 
    if (pedroot) then 
    for i,v in ipairs (xmlNodeGetChildren(pedroot)) do 
      local xmlnumber = xmlNodeGetAttribute (v,"num") 
      if ( xmlnumber == pedNumber ) then 
      xmlDestroyNode ( v ) 
      xmlSaveFile ( root ) 
      xmlUnloadFile ( root ) 
      reloadPeds () 
      triggerClientEvent("showInfoFromPedSystem", thePlayer, "*"..deletePedInfo2.." "..pedNumber.." !", 255, 255, 0) 
      outputChatBox("*"..deletePedInfo.." "..pedNumber.." !",source, 255, 0, 0,true) 
      setTimer ( loadAllpeds, 2000, 1 ) 
      break  
      end 
     end 
     end 
     else 
    triggerClientEvent("showInfoFromPedSystem", deletePedError2, 255, 255, 0) 
     outputChatBox ( deletePedError, thePlayer, 255,100,0 ) 
     end 
     end 
end 
addCommandHandler ( pedDeleteCommand, destroyPed ) 
  
  
function reloadPeds () 
    for i,v in ipairs ( getElementsByType("ped")) do 
    local data = getElementData ( v, "pedNumber" )  
    if ( data ) then 
    destroyElement ( v ) 
    end 
    end 
end 

client.lua:

alpa = 150 
  
function dodaj() 
alpa = alpa + 5 
end 
  
--timer1 = setTimer(dodaj,100,0) 
  
function odejmuj() 
alpa = alpa - 5 
end 
  
--timer2 = setTimer(odejmuj,100,0) 
  
function lolek() 
if alpa <= 150 then 
setTimer(dodaj,100,0) 
end 
if alpa == 250 then 
setTimer(odejmuj,100,0) 
return 
end 
end 
  
addEventHandler("onClientRender",getRootElement(),lolek) 
  
  
function renderIng( ) 
    local x, y, z = getCameraMatrix( ) 
    local dimension = getElementDimension( localPlayer ) 
    for key, pickup in ipairs ( getElementsByType( "pickup", resourceRoot ) ) do 
        if getElementDimension( pickup ) == dimension then 
            local px, py, pz = getElementPosition( pickup ) 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = getElementData( pickup, "message" )     
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 0.7, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 0.7 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        --dxDrawRectangle( sx - w / 2 - 5, sy - h / 2 - 5, w + 10, h + 10, tocolor( 0, 0, 0, 200 ) ) 
                        dxDrawText( tostring( text ), sx + 1, sy + 1, sx + 1, sy + 1, tocolor(0, 0, 0, alpa), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                        dxDrawText( tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 255 ), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                    end 
                end 
            end 
        end 
    end 
    for key, marker in ipairs ( getElementsByType( "marker", resourceRoot ) ) do 
        if getElementDimension( marker ) == dimension then 
            local px, py, pz = getElementPosition( marker ) 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = getElementData( marker, "message" )     
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 1.7, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 1.7 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        --dxDrawRectangle( sx - w / 2 - 5, sy - h / 2 - 5, w + 10, h + 10, tocolor( 0, 0, 0, 200 ) ) 
                        dxDrawText( tostring( text ), sx + 1, sy + 1, sx + 1, sy + 1, tocolor(0, 0, 0, alpa), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                        dxDrawText( tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 255 ), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                    end 
                end 
            end 
        end 
    end 
    for key, playerek in ipairs ( getElementsByType( "player", resourceRoot ) ) do 
        if getElementDimension( playerek ) == dimension then 
            local px, py, pz = getElementPosition( playerek ) 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = getElementData( playerek, "message" )   
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 1.1, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 1.1 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        --dxDrawRectangle( sx - w / 2 - 5, sy - h / 2 - 1, w + 10, h, tocolor( 0, 0, 0, 200 ) ) 
                        dxDrawText( tostring( text ), sx + 1, sy + 1, sx + 1, sy + 1, tocolor(0, 0, 0, alpa), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                        dxDrawText( tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 255 ), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                    end 
                end 
            end 
        end 
    end  
    for key, ped in ipairs ( getElementsByType( "ped", resourceRoot ) ) do 
        if getElementDimension( ped ) == dimension then 
            local px, py, pz = getElementPosition( ped ) 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = getElementData( ped, "message" )    
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 1.1, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 1.1 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        --dxDrawRectangle( sx - w / 2 - 5, sy - h / 2 - 1, w + 10, h, tocolor( 0, 0, 0, 200 ) ) 
                        dxDrawText( tostring( text ), sx + 1, sy + 1, sx + 1, sy + 1, tocolor( 0, 0, 0, alpa), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                        dxDrawText( tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, alpa ), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                    end 
                end 
            end 
        end 
    end  
    for key, vehicle in ipairs ( getElementsByType( "vehicle", resourceRoot ) ) do 
        if getElementDimension( vehicle ) == dimension then 
            local px, py, pz = getElementPosition( vehicle ) 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = getElementData( vehicle, "message" )    
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 1.1, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 1.1 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        --dxDrawRectangle( sx - w / 2 - 5, sy - h / 2 - 1, w + 10, h, tocolor( 0, 0, 0, 200 ) ) 
                        dxDrawText( tostring( text ), sx + 1, sy + 1, sx + 1, sy + 1, tocolor(0, 0, 0, alpa), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                        dxDrawText( tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 255 ), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                    end 
                end 
            end 
        end 
    end          
end 
addEventHandler( "onClientRender", getRootElement( ),renderIng) 
  
function renderIng2( ) 
    local x, y, z = getCameraMatrix( ) 
    local dimension = getElementDimension( localPlayer ) 
    for key, pickup in ipairs ( getElementsByType( "pickup", resourceRoot ) ) do 
        if getElementDimension( pickup ) == dimension then 
            local px, py, pz = getElementPosition( pickup ) 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = getElementData( pickup, "message2" )    
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 0.7, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 0.7 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        --dxDrawRectangle( sx - w / 2 - 5, sy - h / 2 - 5, w + 10, h + 10, tocolor( 0, 0, 0, 200 ) ) 
                        dxDrawText( "\n\n\n"..tostring( text ), sx + 1, sy + 1, sx + 1, sy + 1, tocolor( 0, 0, 0, 50 ), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                        dxDrawText( "\n\n\n"..tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 100 ), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                    end 
                end 
            end 
        end 
    end 
    for key, marker in ipairs ( getElementsByType( "marker", resourceRoot ) ) do 
        if getElementDimension( marker ) == dimension then 
            local px, py, pz = getElementPosition( marker ) 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = getElementData( marker, "message2" )    
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 1.7, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 1.7 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        --dxDrawRectangle( sx - w / 2 - 5, sy - h / 2 - 5, w + 10, h + 10, tocolor( 0, 0, 0, 200 ) ) 
                        dxDrawText( "\n\n\n"..tostring( text ), sx + 1, sy + 1, sx + 1, sy + 1, tocolor( 0, 0, 0, 50 ), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                        dxDrawText( "\n\n\n"..tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 100 ), math.abs(distance-25) / 13, "default-bold", "center", "center" )                 end 
                end 
            end 
        end 
    end 
    for key, playerek in ipairs ( getElementsByType( "player", resourceRoot ) ) do 
        if getElementDimension( playerek ) == dimension then 
            local px, py, pz = getElementPosition( playerek ) 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = getElementData( playerek, "message2" )  
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 1.1, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 1.1 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        --dxDrawRectangle( sx - w / 2 - 5, sy - h / 2 - 1, w + 10, h, tocolor( 0, 0, 0, 200 ) ) 
                        dxDrawText( "\n\n\n"..tostring( text ), sx + 1, sy + 1, sx + 1, sy + 1, tocolor( 0, 0, 0, 50 ), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                        dxDrawText( "\n\n\n"..tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 100 ), math.abs(distance-25) / 13, "default-bold", "center", "center" )                 end 
                end 
            end 
        end 
    end  
    for key, ped in ipairs ( getElementsByType( "ped", resourceRoot ) ) do 
        if getElementDimension( ped ) == dimension then 
            local px, py, pz = getElementPosition( ped ) 
            local distance = getDistanceBetweenPoints3D( x, y, z, px, py, pz ) 
            if distance <= 20 then 
                local text = getElementData( ped, "message2" )   
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 1.1, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 1.1 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        --dxDrawRectangle( sx - w / 2 - 5, sy - h / 2 - 1, w + 10, h, tocolor( 0, 0, 0, 200 ) ) 
                        dxDrawText( "\n\n\n"..tostring( text ), sx + 1, sy + 1, sx + 1, sy + 1, tocolor( 0, 0, 0, math.abs(distance-20) ), math.abs(distance-25) / 15, "default-bold", "center", "center" ) 
                        dxDrawText( "\n\n\n"..tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, math.abs(distance-20)*2 ), math.abs(distance-25) / 15, "default-bold", "center", "center" )                 end 
                end 
            end 
end 
end 
    for key, vehicle in ipairs ( getElementsByType( "vehicle", resourceRoot ) ) do 
        if getElementDimension( vehicle ) == dimension then 
            local px, py, pz = getElementPosition( vehicle ) 
            local distance = getDistanceBetweenPoints3D( px, py, pz, x, y, z ) 
            if distance <= 20 then 
                local text = getElementData( vehicle, "message2" )   
                if text and ( distance < 2 or isLineOfSightClear( x, y, z, px, py, pz + 1.1, true, true, true, true, false, false, true, localPlayer ) ) then 
                    local sx, sy = getScreenFromWorldPosition( px, py, pz + 1.1 ) 
                    if sx and sy then 
                        local w = dxGetTextWidth( tostring( text ) ) 
                        local h = ( text and 2 or 1 ) * dxGetFontHeight( ) 
                        --dxDrawRectangle( sx - w / 2 - 5, sy - h / 2 - 1, w + 10, h, tocolor( 0, 0, 0, 200 ) ) 
                        dxDrawText( "\n\n\n"..tostring( text ), sx + 1, sy + 1, sx + 1, sy + 1, tocolor( 0, 0, 0, 50 ), math.abs(distance-25) / 13, "default-bold", "center", "center" ) 
                        dxDrawText( "\n\n\n"..tostring( text ), sx, sy, sx, sy, tocolor( 255, 255, 255, 100 ), math.abs(distance-25) / 13, "default-bold", "center", "center" )                 end 
                end 
            end 
        end 
    end      
end  
addEventHandler( "onClientRender", getRootElement( ),renderIng2) 

gui.lua

function guiClicked() 
    if (source == closeButton) then  
        guiSetVisible ( createPedWindow, false ) 
        showCursor ( false ) 
        unbindKey ( "mouse2","down", showCursor12 ) 
        guiSetInputEnabled ( false ) 
    elseif (source == getpedPosButton) then  
        local x,y,z = getElementPosition ( getLocalPlayer()) 
        local r = getPedRotation ( getLocalPlayer()) 
        local int = getElementInterior ( getLocalPlayer()) 
        local dim = getElementDimension ( getLocalPlayer()) 
        local skin = getElementModel ( getLocalPlayer()) 
        local name = getPlayerName ( getLocalPlayer()) 
        guiSetText ( pedXEdit, x ) 
        guiSetText ( pedYEdit, y ) 
        guiSetText ( pedZEdit, z ) 
        guiSetText ( pedREdit, r ) 
        guiSetText ( pedIntEdit, int ) 
        guiSetText ( pedDimEdit, dim ) 
        guiSetText ( skinEdit, skin ) 
        guiSetText ( nameEdit, name ) 
    elseif (source == createPedButton) then  
        local name = guiGetText (nameEdit) 
        local intx = guiGetText (pedXEdit) 
        local inty = guiGetText (pedYEdit) 
        local intz = guiGetText (pedZEdit) 
        local rot = guiGetText (pedREdit) 
        local skin = guiGetText (skinEdit) 
        local int = guiGetText (pedIntEdit) 
        local dim = guiGetText (pedDimEdit) 
        if not ( name == "" ) or ( intx == "" ) and ( inty == "" ) and ( intz == "" ) and ( rot == "" ) or ( skin == "" ) or ( skin == "Skin" ) then 
        triggerServerEvent ( "createped", getLocalPlayer(), name, skin, rot, intx, inty, intz, int, dim ) 
        end 
    end 
end 
addEventHandler ( "onClientGUIClick", getRootElement(), guiClicked) 
  
createPedWindow = guiCreateWindow(81, 163, 304, 297, "Creaza un NPC", false) 
  
skinLabel = guiCreateLabel(10, 23, 31, 25, "Skin:", false,createPedWindow) 
guiLabelSetColor(skinLabel,255,255,255) 
guiLabelSetVerticalAlign(skinLabel,"top") 
guiLabelSetHorizontalAlign(skinLabel,"left",false) 
guiSetFont(skinLabel,"default-bold-small") 
  
skinEdit = guiCreateEdit(42, 23, 252, 25, "ID Skin", false,createPedWindow) 
  
nameLabel = guiCreateLabel(10, 48, 31, 25, "Nume:", false,createPedWindow) 
guiLabelSetColor(nameLabel,255,255,255) 
guiLabelSetVerticalAlign(nameLabel,"top") 
guiLabelSetHorizontalAlign(nameLabel,"left",false) 
guiSetFont(nameLabel,"default-bold-small") 
  
pedXLabel =  guiCreateLabel(10, 92, 15, 21, "X:", false, createPedWindow) 
guiLabelSetColor(pedXLabel,255,255,0) 
guiLabelSetVerticalAlign(pedXLabel,"top") 
guiLabelSetHorizontalAlign(pedXLabel,"left",false) 
guiSetFont(pedXLabel,"default-bold-small") 
  
pedYLabel = guiCreateLabel(10, 117, 15, 21, "Y:", false, createPedWindow) 
guiLabelSetColor(pedYLabel,255,255,0) 
guiLabelSetVerticalAlign(pedYLabel,"top") 
guiLabelSetHorizontalAlign(pedYLabel,"left",false) 
guiSetFont(pedYLabel,"default-bold-small") 
  
pedZLabel = guiCreateLabel(10, 142, 15, 21, "Z:", false,createPedWindow) 
guiLabelSetColor(pedZLabel,255,255,0) 
guiLabelSetVerticalAlign(pedZLabel,"top") 
guiLabelSetHorizontalAlign(pedZLabel,"left",false) 
guiSetFont(pedZLabel,"default-bold-small") 
  
pedRLabel = guiCreateLabel(10, 167, 15, 18, "R:", false,createPedWindow) 
guiLabelSetColor(pedRLabel,255,255,0) 
guiLabelSetVerticalAlign(pedRLabel,"top") 
guiLabelSetHorizontalAlign(pedRLabel,"left",false) 
guiSetFont(pedRLabel,"default-bold-small") 
  
pedIntLabel = guiCreateLabel(10, 195, 53, 21, "Interior:", false,createPedWindow) 
guiLabelSetColor(pedRLabel,0,255,255) 
guiLabelSetVerticalAlign(pedRLabel,"top") 
guiLabelSetHorizontalAlign(pedRLabel,"left",false) 
guiSetFont(pedRLabel,"default-bold-small") 
  
pedDimLabel = guiCreateLabel(10, 219, 63, 21, "Dimensiune:", false,createPedWindow) 
guiLabelSetColor(pedRLabel,0,255,255) 
guiLabelSetVerticalAlign(pedRLabel,"top") 
guiLabelSetHorizontalAlign(pedRLabel,"left",false) 
guiSetFont(pedRLabel,"default-bold-small") 
  
  
nameEdit = guiCreateEdit(42, 48, 252, 25, "Nume NPC", false,createPedWindow) 
  
pedXEdit = guiCreateEdit(25, 88, 269, 25, "", false, createPedWindow) 
  
pedYEdit = guiCreateEdit(25, 113, 269, 25, "", false, createPedWindow) 
  
pedZEdit = guiCreateEdit(25, 138, 269, 25, "", false, createPedWindow) 
  
pedREdit = guiCreateEdit(25, 163, 269, 25, "", false, createPedWindow) 
  
pedIntEdit = guiCreateEdit(63, 192, 71, 24, "", false, createPedWindow) 
  
pedDimEdit = guiCreateEdit(73, 216, 71, 24, "", false, createPedWindow) 
  
  
getpedPosButton =  guiCreateButton(9, 70, 285, 18, "Ia Pozitia Mea", false,createPedWindow) 
  
createPedButton = guiCreateButton(149, 192, 145, 54, "CREAZA", false,createPedWindow) 
  
closeButton = guiCreateButton(9, 263, 38, 24, "X", false,createPedWindow) 
  
 authorLabel = guiCreateLabel(123, 254, 171, 33, "", false, createPedWindow) 
        guiLabelSetColor(authorLabel, 241, 238, 0) 
        guiLabelSetHorizontalAlign(authorLabel, "right", false) 
        guiLabelSetVerticalAlign(authorLabel, "bottom")     
  
guiSetVisible ( createPedWindow, false ) 
  
function showWindow (commandName)    
    guiSetVisible ( createPedWindow, true ) 
    showCursor ( true ) 
    bindKey ( "mouse2","down", showCursor12 ) 
end 
addEvent ( "showWindow2", true ) 
addEventHandler ( "showWindow2", getRootElement(), showWindow ) 
  
  
function showCursor12 () 
    if ( isCursorShowing() == true ) then 
    showCursor ( false ) 
    else 
    showCursor ( true ) 
    end 
end 
  
addEventHandler ("onClientMouseEnter",getRootElement(), 
function () 
if source == createPedWindow or source == nameEdit then 
 guiSetInputEnabled ( true ) 
end 
end) 
  
addEventHandler ("onClientMouseLeave",getRootElement(), 
function () 
if source == createPedWindow or source == nameEdit then 
 guiSetInputEnabled ( false ) 
end 
end) 
  
  
  
  

Link to comment

I can't really understand the wiki o.O

How can I load the position, skin, etc? Like this code that loads data from XML...

function loadAllpeds () 
  local root = xmlLoadFile ("peds.xml") 
  local pedroot = xmlFindChild (root,"peds",0) 
  if (pedroot) then 
    allpeds = {} 
    for i,v in ipairs (xmlNodeGetChildren(pedroot)) do 
      local x = xmlNodeGetAttribute (v,"x") 
      local y = xmlNodeGetAttribute (v,"y") 
      local z = xmlNodeGetAttribute (v,"z") 
      local nazwa = xmlNodeGetAttribute (v,"name") 
      local number = xmlNodeGetAttribute (v,"num") 
      local skin = xmlNodeGetAttribute (v,"skin") 
      local rot = xmlNodeGetAttribute (v,"rot") 
      local int = xmlNodeGetAttribute (v,"int") 
      local dim = xmlNodeGetAttribute (v,"dim") 
        local ped = createPed (tonumber(skin),tonumber(x),tonumber(y),tonumber(z)) 
        setPedRotation(ped,tonumber(rot)) 
        setElementData (ped,"pedNumber",tonumber(number)) 
        setElementData (ped,"message",tostring(nazwa)) 
        setElementData (ped,"message2","bPed\nID: "..tostring(number)) 
        setElementInterior (ped, tonumber(int)) 
        setElementDimension (ped, tonumber(dim)) 
    --  outputDebugString ("Ped " .. tostring(nazwa) .. " [iD " .. tostring(number) .. "] loaded!") 
    end 
  end 
end 
addEventHandler("onResourceStart",gResRoot, loadAllpeds) 

But I want to load all that from the mysql database.

Link to comment

I'm useing mySQL module then i can write example for you whit it :)

First install it:

https://wiki.multitheftauto.com/wiki/Mysql

And you need a mysql server(xammp for homemade server)

  
host = "127.0.0.1" -- host ( this is the Localhost now) 
username = "root" -- Database Username 
password = "" -- Database Password (in xammp no pass) 
db = "accounts" -- Database ( Where you got your tables ) 
  
handler = mysql_connect( host, username, password, db ) 
  
function getPlayerDatasFromSQL () 
    pName = getPlayerName(source) 
    playerData_q = mysql_query(handler,"SELECT * FROM accounts WHERE AccountName = '"..pName.."';") 
    playerData_assoc = mysql_fetch_assoc(playerData_q) -- Whit it you can use the queryed datas from the player 
    setElementHealth ( source, playerData_assoc['hp'] ) -- Use like this 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), getPlayerDatasFromSQL) 

Link to comment

How do I load the X,Y,Z,Dimension,Interior, Skin and Name of the npc from a table? And I want to load all the colums.

function loadNpcs () 
    npcsData_q = mysql_query(handler,"SELECT * FROM npc WHERE x='" .. mysql:escape_string(x1) .. "', y='" .. mysql:escape_string(y1) .. "', z='" .. mysql:escape_string(z1) .. "', skin='" .. mysql:escape_string(getElementModel(thePlayer)) .. "'") 
    npcsData_assoc = mysql_fetch_assoc(playerData_q)  
end 
addEventHandler ( "onPlayerJoin", getRootElement(), getPlayerDatasFromSQL) 
addEventHandler("onResourceStart",gResRoot, loadAllpeds) 

Link to comment
local ped_q = mysql_query(handler,"SELECT * FROM npc") -- you need query all the npcs 
  
if (ped_q) then 
  while true do -- do it whit all the npc 
    local ped_assoc= mysql_fetch_assoc(kocsi_q) 
    if (not ped_assoc) then break end 
    local pedtext = "ped" 
    local thePed = pedtext .. ped_assoc['ID'] -- this isn't the ped model id just an auto increted number in mysql. Whit this you can identify your ped 
  
    thePed = createPed ( ped_assoc['model'], ped_assoc['x'], ped_assoc['y'], ped_assoc['z'] ) 
    setElementData (thePed, "idPed", ped_assoc['ID']) -- i offer you to set in the ped his id then you can always identify it 
  end 
  mysql_free_result(kocsi_q) -- Free the result 
end 

Link to comment

Dugasz, I see that you are good at mysql, can you make me a table using this code please? This is the first time I have to handle with tables and such...

addEventHandler( "onResourceStart", resourceRoot, 
    function( ) 
        -- check for our table to exist 
        if not exports.sql:create_table( '3dtext', 
            { 
                { name = 'textID', type = 'int(10) unsigned', auto_increment = true, primary_key = true }, 
                { name = 'text', type = 'text' }, 
                { name = 'x', type = 'float' }, 
                { name = 'y', type = 'float' }, 
                { name = 'z', type = 'float' }, 
                { name = 'interior', type = 'tinyint(3) unsigned' }, 
                { name = 'dimension', type = 'int(10) unsigned' }, 
            } ) then cancelEvent( ) return end 

Link to comment

This code must make this table, but i think you haven't got the sql resources. Then go in phpmyadmin open a database, click to the sql menu and paste it and run:

CREATE TABLE IF NOT EXISTS `3dtext` ( 
  `textID` int(10) NOT NULL AUTO_INCREMENT, 
  `text` text COLLATE utf8_hungarian_ci NOT NULL, 
  `x` float NOT NULL, 
  `y` float NOT NULL, 
  `z` float NOT NULL, 
  `interior` int(10) NOT NULL, 
  `dimension` int(10) NOT NULL, 
  PRIMARY KEY (`textID`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_hungarian_ci AUTO_INCREMENT=1 ; 
  

Link to comment

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