Jump to content

My Questions about scripting.


matucha123

Recommended Posts

How crate multiply table (in other languages 2d, 3d arrays)?

I want something like that:

spwanPoints[team][key]["x"] = x 
spwanPoints[team][key]["y"] = y 
spwanPoints[team][key]["z"] = z 
spwanPoints[team][key]["r"] = r  

Tried:

spwanPoints = {keyss = {valuses={}}} 

Error:

maploader_s.lua:28: attempt to index field '?' (a nil value)
Edited by Guest
Link to comment

I dont want that indexes is predefined, i want what indexes names is set while runinning script:

Server full script

spawnPoints = {} 
spawnPoints["Team1"] = {} 
spawnPoints["Team1"][1] = {} 
  
  
--[[addEventHandler( "onPlayerWasted", root, 
    function() 
        setTimer( spawnPlayer, 2000, 1, source, get("startx"),get("starty"), get("startz"), get("startrot")) 
    end 
)]] 
  
function loadMap(startedMap) 
    mapRoot = getResourceRootElement(startedMap) 
    loadSpawns( ) 
end 
  
addEventHandler("onGamemodeMapStart", root, loadMap) 
  
function loadSpawns() 
    local spawn = getElementsByType("minispawnpoint", mapRoot) 
    local x,y,z,r, team 
    --spawnPoints["Team1"] = {} 
    --spawnPoints["Team2"] = {} 
    for key, value in pairs(spawn) do 
        x = getElementData(value, "posX") 
        y = getElementData(value, "posY") 
        z = getElementData(value, "posZ") 
        r = getElementData(value, "rotZ") 
        team = getElementData(value, "team") 
        spawnPoints[team][key]["x"] = x 
        spawnPoints[team][key]["y"] = y 
        spawnPoints[team][key]["z"] = z 
        spawnPoints[team][key]["r"] = r    
    end 
end 
  
  
addEventHandler("onPlayerJoin", root,  
    function () 
    fadeCamera(source,true) 
    setCameraTarget(source, source) 
    spawnPlayer(source,spawnPoints["Team1"][1]["x"], spawnPoints["Team1"][1]["y"],spawnPoints["Team1"]["z"] ) 
    end 
)    
  

Link to comment

Yeah for now random would be OK. Later I will add random spawns for different teams. BTW map file:

"MiniMissions,editor_main"> 
    "minispwanpoint (2)" team="Team1" rotZ="0" model="0" posX="2480.1999511719" posY="-1658.6999511719" posZ="13.300000190735" rotX="0" rotY="0">
    "minispwanpoint (3)" team="Team2" rotZ="0" model="0" interior="0" posX="2467" posY="-1657.6999511719" posZ="13.300000190735" rotX="0" rotY="0">

  

Link to comment

Server

addEventHandler( 'onGamemodeMapStart', root, 
    function( startedMap ) 
        local spawns = getElementsByType( 'minispawnpoint', resourceRoot ) 
        for _,v in pairs( getElementsByType 'player' ) do 
            local random = math.random ( #spawns ) 
            local posX = getElementData( spawns[ random ], 'posX' )  
            local posY = getElementData( spawns[ random ], 'posY' )  
            local posZ = getElementData( spawns[ random ], 'posZ' ) 
            local team = getElementData( spawns[ random ], 'team' ) 
            local rot = getElementData( spawns[ random ], 'rot' ) or getElementData( spawns[ random ], 'rotZ' ) or 0 
            spawnPlayer( v,posX,posY,posZ,rot, 0,0,0,getTeamFromName( team ) ) 
        end 
    end 
)    
  
addEventHandler( 'onPlayerJoin',root, 
    function( ) 
        local spawns = getElementsByType( 'minispawnpoint', resourceRoot ) 
        local random = math.random ( #spawns ) 
        local posX = getElementData( spawns[ random ], 'posX' )  
        local posY = getElementData( spawns[ random ], 'posY' )  
        local posZ = getElementData( spawns[ random ], 'posZ' ) 
        local team = getElementData( spawns[ random ], 'team' ) 
        local rot = getElementData( spawns[ random ], 'rot' ) or getElementData( spawns[ random ], 'rotZ' ) or 0 
        spawnPlayer( source,posX,posY,posZ,rot, 0,0,0,getTeamFromName( team ) ) 
    end 
)    
  
  

Updated.

But i think you need create 2 type elements( for 2 teams ).

Example:redspawnpoint,greenspawnpoint.

And loop it.

Link to comment

OK. I have questions about edf. Lets say in setting I chose gametype, and elements (like spawnpoint, marker and etc) change, lets say in gamemode settings I enter that there would be 3 teams. Is it possible that in definitions would be 3 teams after changing? now teams is created like this:

EDF

"team" type="selection:Team1,Team2"  default="TeamA" /> 

Link to comment

for multidimensional arrays you need to define a new table in a main table, and put contents in it.

you can pre-create it only if you know the size at the start.

example:

  
local spawnPoints = {} 
for _,team in ipairs(getElementsByType("team")) do 
  local name = getTeamName(team) 
  spawnPoints[name]={} 
  spawnPoints[name].x=x 
  spawnPoints[name].y=y 
  spawnPoints[name].z=z 
end 
  

Link to comment

How read settings from map meta?

    "MiniMissions" type="map" version="1.0.0">
    "MiniMiss.map" dimension="0">
    
        "#greenteamskins" value='[ "0" ]'>
        "#greenteamcolor" value='[ "#00FF00FF" ]'>
        "#maxplayers" value="[ 128 ]">
        "#gamespeed" value="[ 1 ]">
        "#greenteamob" value='[ "Kill other teams" ]'>
        "#respawndissable" value="[ 0 ]">
        "#minplayers" value="[ 0 ]">
        "#weather" value="[ 0 ]">
        "#gravity" value="[ 0.008000 ]">
        "#waveheight" value="[ 0 ]">
        "#greenteamname" value='[ "Green team" ]'>
        "#locked_time" value="[ false ]">
        "#duration" value="[ 600 ]">
        "#time" value="12:0">
    
  

Let's say I need "#greenteamname" name

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