Jump to content

RP Game Mode Help/Progress topic "RPG Server (ALPHA STAGE)"


Recommended Posts

  • Replies 142
  • Created
  • Last Reply

Top Posters In This Topic

function createTeamsOnStart () 
  
        teamCivilians = createTeam ( "Civilians", 194, 194, 194 ) 
        teamCops = createTeam ( "Cops", 101, 101, 215 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),  
  
createTeamsOnStart  ) --we attach the function to this resource's root element  
  
function assignNewTeam ( source, commandName ) 
  setPlayerTeam ( source, Cops ) 
end 
addCommandHandler ( "command", assignNewTeam ) 

Ok here is the current team script, the "createTeamsOnStart" works but not the "assignNewTeam" why?

Ok, i changed

  setPlayerTeam ( source, Cops ) 

to

  setPlayerTeam ( source, teamCops ) 

Now it works!

Edited by Guest
Link to comment

Ok here is the current team script, the "createTeamsOnStart" works but not the "assignNewTeam" why?

plz help!

should be:

  
function assignNewTeam ( source, commandName ) 
  setPlayerTeam ( source, teamCops) -- the team "Cops" doesn't exist according to your code, teamCops does, however. 
end 
addCommandHandler ( "command", assignNewTeam ) -- if "command" is what you type in the console, in order to activate the function, shouldn't the word be more be something more descriptive such as "assignToCops" ? 
  

Link to comment

Ok here is the current team script, the "createTeamsOnStart" works but not the "assignNewTeam" why?

plz help!

should be:

  
function assignNewTeam ( source, commandName ) 
  setPlayerTeam ( source, teamCops) -- the team "Cops" doesn't exist according to your code, teamCops does, however. 
end 
addCommandHandler ( "command", assignNewTeam ) -- if "command" is what you type in the console, in order to activate the function, shouldn't the word be more be something more descriptive such as "assignToCops" ? 
  

LOL i just did that without seeing your post, i just guessed :D i'm so happy my first 10 lines of lua works :')

Link to comment

Ok, heres is an update of the team script...

function createTeamsOnStart () 
  
        teamCivilians = createTeam ( "Civilians", 194, 194, 194 ) 
        teamCops = createTeam ( "Cops", 101, 101, 215 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) --we attach the function to this resource's root element  
  
function assignNewTeam ( source, commandName ) 
  setPlayerTeam ( source, teamCops ) 
end 
addCommandHandler ( "command", assignNewTeam ) 
  
function assignCivilian ( source, commandName ) 
  setPlayerTeam ( source, teamCivilians ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) 
  
function setCivilian ( source, commandName ) 
  setPlayerTeam ( source, teamCivilians ) 
end 
addCommandHandler ( "civilian", setCivilian ) 

Everything but

function assignCivilian ( source, commandName ) 
  setPlayerTeam ( source, teamCivilians ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) 

works, i want to make it so when a player joins it puts him in teamCivilian.

Can you find the errors?

Link to comment

I think so:

function assignCivilian ( source, commandName ) 
  setPlayerTeam ( source, teamCivilians ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) 

source==nil. Why? OnPlayerJoin has NO PARAMETERS! Still, you did list source, commandName. But they'll just be nil. (for as far as I know...)

Solution? Remove source,commandName in line 1.

Link to comment
I think so:
function assignCivilian ( source, commandName ) 
  setPlayerTeam ( source, teamCivilians ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) 

source==nil. Why? OnPlayerJoin has NO PARAMETERS! Still, you did list source, commandName. But they'll just be nil. (for as far as I know...)

Solution? Remove source,commandName in line 1.

Ok, it works but i still get a warning but that's not important :)

Link to comment

Ok, this is my current job on the script

function createTeamsOnStart () 
  
        teamCivilians = createTeam ( "Civilians", 194, 194, 194 ) 
        teamCops = createTeam ( "Cops", 101, 101, 215 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function assignNewTeam ( source, commandName ) 
  setPlayerTeam ( source, teamCops ) 
  giveWeapon ( source, 31, 10000 ) 
  giveWeapon ( source, 24, 10000 ) 
  giveWeapon ( source, 25, 10000 ) 
  giveWeapon ( source, 29, 10000 ) 
  giveWeapon ( source, 17, 10000 ) 
  giveWeapon ( source, 42, 10000 ) 
  setPlayerSkin ( source, 283 ) 
end 
addCommandHandler ( "secret", assignNewTeam ) 
  
function setCivilian ( source, commandName ) 
  setPlayerTeam ( source, teamCivilians ) 
  takeAllWeapons ( source ) 
  setPlayerSkin ( source, 0 ) 
end 
addCommandHandler ( "civilian", setCivilian ) 
  
function assignCivilian ( ) 
  setPlayerTeam ( source, teamCivilians ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) 

It works perfectly :)

Edited by Guest
Link to comment
Good! Work some more on it and you can post it in the resources list. :P

You might want to learn how XML and tables work if you make them public:

XML: HERE

Tables: HERE and HERE

If you want to keep it for yourself, I still recommend you look at them. (especially tables!)

Thanks, but i'm only 13 years old and haven't really understood what to use those tables for :) that xml maybe is good tho... :P

Link to comment

13 years old is no excuse. I'm really only a year older! ^^

Anyway, tables are like variables, but they can store more at a time. It's handy to use tables because you can make tables on top of your script, allowing users to edit it easily when you put it in the resources list. Or, you can do something like table destroyedVehicles, and that if you do destroyedVehicles[aVehicleElement], it'll check if it's present. If it is, it's destroyed. If it isn't, well guess. ^^

Tables aren't necessary in the beginning. But later on, you'll see the importance of knowing how to use them. That's why I recommend you to already learn XML and tables, so you don't have to right when you need them. ;)

EDIT: I just edited the xmlNodeGetValue and xmlNodeSetValue pages, so they might be a little different seen the documentation. But otherwise you looked at a lot of "blah"... ^^

Link to comment
13 years old is no excuse. I'm really only a year older! ^^
C00L! :twisted:

Can you help me making a /savepos command? I tried to but the best i could was

function savePosition ( source, commandName ) 
local playerPos = getElementPosition ( player ) 
local hFile = fileOpen("savedpositions.txt", false) 
if hFile then 
    fileWrite(hFile, "Coordinates: " .. playerPos ) 
    fileClose(hFile) 
end 
addCommandHandler ( "savepos", savePosition ) 
  
function makePositionFile ( source, commandName ) 
local newFile = fileCreate("savedpositions.txt") 
if newFile then 
    fileClose(newFile) 
end 
addCommandHandler ( "makeposfile", makePositionFile ) 

but i think something is wrong in there xD

Well g2g and sleep now, but i'll check your answer tomorrow :) (If you answered! 666 :evil: )

Link to comment
13 years old is no excuse. I'm really only a year older! ^^
C00L! :twisted:

Can you help me making a /savepos command? I tried to but the best i could was

function savePosition ( source, commandName ) 
local playerPos = getElementPosition ( player ) 
local hFile = fileOpen("savedpositions.txt", false) 
if hFile then 
    fileWrite(hFile, "Coordinates: " .. playerPos ) 
    fileClose(hFile) 
end 
addCommandHandler ( "savepos", savePosition ) 
  
function makePositionFile ( source, commandName ) 
local newFile = fileCreate("savedpositions.txt") 
if newFile then 
    fileClose(newFile) 
end 
addCommandHandler ( "makeposfile", makePositionFile ) 

but i think something is wrong in there xD

Well g2g and sleep now, but i'll check your answer tomorrow :) (If you answered! 666 :evil: )

I would really recommend XML or (My)SQL for this. But SQL is a bit difficult and MySQL modules were failed for me. xD So I recommend XML instead of .txt's.

So it should be something like: (have a good look at the lines with -- ! and compare with your script)

function savePosition(player) -- ! 
    local x,y,z=getElementPosition(player) 
    local xmlFile=xmlLoadFile("savedpositions.xml") or false 
    if xmlFile==false then -- ! 
        xmlFile=xmlCreateFile("savedpositions.xml","positions") 
        xmlFile=xmlLoadFile("savedpositions.xml") or false 
    end 
    if xmlFile then 
        local playerNode=xmlFindSubNode(xmlFile,getClientName(player),0) or false -- ! 
        if not playerNode then 
            playerNode=xmlCreateSubNode(xmlFile,getClientName(player)) 
            playerNode=xmlFindSubNode(xmlFile,getClientName(player),0) or false -- ! 
        end 
        if playerNode then 
            local success=xmlNodeSetAttribute(playerNode,"x",x) -- ! 
            xmlNodeSetAttribute(playerNode,"y",y) 
            xmlNodeSetAttribute(playerNode,"z",z) 
            if success then 
                outputChatBox("Position saved!",player,0,255,0) -- ! 
            end 
        end 
    end 
end 

Now it's the best that you read both the wiki and the script I gave you (untested!) to make a load version.

A little note: you might see: "or false" sometimes. Don't think: "Huh?", because this has a reason. If it does not succeed, I never like errors. I usually set up my own errors. ^^ Didn't do it now, (almost bedtime for me too) but I can add it later on. ;) If you still want to see if there are error messages in the meantime, remove "or false".

P.S. 50P was first :P You might want to try his code aswell since he's a more talented and experienced scripter than I am. ;)

EDIT: By the way, didn't he mean saving positions of players..?

Link to comment
you could what I do, and copy paste out of the console.

function getPos ( thePlayer ) 
  local x,y,z = getElementPosition ( thePlayer ) 
  outputChatBox ( x .. ", " .. y .. ", " .. z ) 
end 
addCommandHandler ( "position", getPos ) 

but i wanna save the position instead so i can look on it later :P

Link to comment

Ok, new progress on the "team script".

function createTeamsOnStart () 
  
        teamCivilians = createTeam ( "Civilians", 194, 194, 194 ) 
        teamCops = createTeam ( "Cops", 101, 101, 215 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function assignNewTeam ( source, commandName ) 
  setPlayerTeam ( source, teamCops ) 
  giveWeapon ( source, 31, 10000 ) 
  giveWeapon ( source, 24, 10000 ) 
  giveWeapon ( source, 25, 10000 ) 
  giveWeapon ( source, 29, 10000 ) 
  giveWeapon ( source, 17, 10000 ) 
  giveWeapon ( source, 42, 10000 ) 
  setPlayerSkin ( source, 283 ) 
  setElementPosition( player, 1552.4109, -1675.0485, 16.1953  ) 
  outputChatBox( "You are now logged in as a Los Santos Police Department officer", player, 0, 255, 0 ) 
end 
addCommandHandler ( "police", assignNewTeam ) 
  
function setCivilian ( source, commandName ) 
  setPlayerTeam ( source, teamCivilians ) 
  takeAllWeapons ( source ) 
  setPlayerSkin ( source, 0 ) 
  setElementPosition( player, 2230.8967, -1159.5858, 25.8268  ) 
  outputChatBox( "You are a civilian", player, 0, 255, 0 ) 
end 
addCommandHandler ( "civilian", setCivilian ) 
  
function assignCivilian ( ) 
  setPlayerTeam ( source, teamCivilians ) 
  setElementPosition( player, 2230.8967, -1159.5858, 25.8268  ) 
  outputChatBox( "You are a civilian", player, 0, 255, 0 ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), assignCivilian ) 

I will now test if my setElementPosition and the outputChatBox works :)

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