"PointsToUnlock" For vehicles? [Solved]
Moderator: Moderators
-
JazzMaster
- Master Sergeant

- Posts: 166
- Joined: Sun Mar 31, 2013 2:56 pm
- Projects :: Cato Neimoidia- Invasion
- xbox live or psn: No gamertag set
"PointsToUnlock" For vehicles? [Solved]
I'm trying to figure out if you can set a point limit to enter a vehicle, so a human player can't enter the vehicle until you reach a certain amount of points. Is this possible? I would preferably want it to only effect human players so AI can enter the vehicle as they want.
Last edited by JazzMaster on Fri Nov 21, 2014 2:29 pm, edited 1 time in total.
- Locutus
- 1st Lieutenant

- Posts: 420
- Joined: Fri Jun 04, 2010 10:08 am
- Projects :: Stargate Battlefront Pegasus
- Location: Germany
- Contact:
Re: "PointsToUnlock" For vehicles?
I don't think there's an easy way to do that.
As far as I know there is no way to find out how many points a player has so I think you need to create a custom OnObjectKill function that counts the kills for each human.
Then you can use OnCharacterEnterVehicle() and check whether IsCharacterHuman() and if counted_points < character[0].kills then kick the player (ExitVehicle(character)).
As far as I know there is no way to find out how many points a player has so I think you need to create a custom OnObjectKill function that counts the kills for each human.
Then you can use OnCharacterEnterVehicle() and check whether IsCharacterHuman() and if counted_points < character[0].kills then kick the player (ExitVehicle(character)).
-
jedimoose32
- Field Commander

- Posts: 938
- Joined: Thu Jan 24, 2008 12:41 am
- Projects :: Engineering Degree
- Location: The Flatlands of Canada
Re: "PointsToUnlock" For vehicles?
I'm amazed that there's no built-in way to track player points. Yet another quirk of ZeroEngine I suppose. 
-
JazzMaster
- Master Sergeant

- Posts: 166
- Joined: Sun Mar 31, 2013 2:56 pm
- Projects :: Cato Neimoidia- Invasion
- xbox live or psn: No gamertag set
Re: "PointsToUnlock" For vehicles?
Ah well thanks, Locutus. So the game can track kills, but not points? That's a bit odd. I guess i'm going to have to read up on some mission scripting tutorials since "if/then" scripting is something i haven't attempted yet. Could I base the amount of kills needed to make a player able to enter a vehicle off of the amount of certain vehicles you destroy rather than just overall kills. So if you destroy x amount of flyers, then a specific vehicle becomes available to enter?
-
jedimoose32
- Field Commander

- Posts: 938
- Joined: Thu Jan 24, 2008 12:41 am
- Projects :: Engineering Degree
- Location: The Flatlands of Canada
Re: "PointsToUnlock" For vehicles?
Time to dive into the wonderful magical world of lua.
Locutus knows way more about lua than I do, so he will probably have to correct me on a few points but here I go:
If I'm not mistaken you would name the spawners for that vehicle you want the player to kill, something (e.g. "killthisveh1", "killthisveh2", etc). Also name the spawners for the vehicle you want locked (e.g. "mylockedveh1", "mylockedveh2", etc).
Then in function ScriptPostLoad somewhere you would say, local counted_points = 0. Then on a new line put OnObjectKillName(pointsfunction, "killthisveh1"), and the same for killthisveh2, etc. This tells the game to run pointsfunction each time a vehicle spawned from killthisveh1 (or 2, or the others) is destroyed.
Somewhere just above/below that, put OnCharacterEnterVehicle(kickfunction, "mylockedveh1"). This tells the game to run kickfunction each time any character enters the "locked" vehicle.
Down below, between the end of ScriptPostLoad and the start of ScriptInit, make a function called pointsfunction, which adds the points to the human player. Inside this function you would put Locutus's IsCharacterHuman() check, and if that is true then counted_points = counted_points + 1.
Now below this new function you just made, make another new function called kickfunction. This one will kick out humans who do not have enough of these counted_points. Do the IsCharacterHuman() check. If that is true then if counted_points < 10 (or whatever you want the target number to be) then ExitVehicle(character).
I hope this makes sense, and that I didn't miss anything. Anyone can feel free to forcibly correct me if I've messed it up.
If I'm not mistaken you would name the spawners for that vehicle you want the player to kill, something (e.g. "killthisveh1", "killthisveh2", etc). Also name the spawners for the vehicle you want locked (e.g. "mylockedveh1", "mylockedveh2", etc).
Then in function ScriptPostLoad somewhere you would say, local counted_points = 0. Then on a new line put OnObjectKillName(pointsfunction, "killthisveh1"), and the same for killthisveh2, etc. This tells the game to run pointsfunction each time a vehicle spawned from killthisveh1 (or 2, or the others) is destroyed.
Somewhere just above/below that, put OnCharacterEnterVehicle(kickfunction, "mylockedveh1"). This tells the game to run kickfunction each time any character enters the "locked" vehicle.
Down below, between the end of ScriptPostLoad and the start of ScriptInit, make a function called pointsfunction, which adds the points to the human player. Inside this function you would put Locutus's IsCharacterHuman() check, and if that is true then counted_points = counted_points + 1.
Now below this new function you just made, make another new function called kickfunction. This one will kick out humans who do not have enough of these counted_points. Do the IsCharacterHuman() check. If that is true then if counted_points < 10 (or whatever you want the target number to be) then ExitVehicle(character).
I hope this makes sense, and that I didn't miss anything. Anyone can feel free to forcibly correct me if I've messed it up.
- Maveritchell
- Jedi Admin

- Posts: 7366
- Joined: Mon Aug 21, 2006 11:03 pm
Re: "PointsToUnlock" For vehicles?
It'd be a lot simpler to limit vehicles to one unit class, which can itself be set to unlock based on points. That's a bit of a learning curve for the user, though.
If you're limiting yourself to single-player, it would be a lot better to simply assign human players to their own teams and then just check team points (which is retrievable with Lua callbacks).
If you're limiting yourself to single-player, it would be a lot better to simply assign human players to their own teams and then just check team points (which is retrievable with Lua callbacks).
-
JazzMaster
- Master Sergeant

- Posts: 166
- Joined: Sun Mar 31, 2013 2:56 pm
- Projects :: Cato Neimoidia- Invasion
- xbox live or psn: No gamertag set
Re: "PointsToUnlock" For vehicles?
So i tried following what you've said jedimoose, although I know for a fact I have the pointfunction and kickfunctions wrong. and i also have some munge errors.
My ***g_Diet Dr. Pepper LUA (space map set up)
munge errors:
My ***g_Diet Dr. Pepper LUA (space map set up)
Hidden/Spoiler:
Hidden/Spoiler:
-
jedimoose32
- Field Commander

- Posts: 938
- Joined: Thu Jan 24, 2008 12:41 am
- Projects :: Engineering Degree
- Location: The Flatlands of Canada
Re: "PointsToUnlock" For vehicles?
Neither of your functions get closed properly. Each one is missing an 'end'. Fixing that should get rid of the munge errors. Here:
Also I seem to remember you need an argument in IsCharacterHuman()... meaning that it would look like IsCharacterHuman(character) or similar. Let me use Zerted's handy example finder to see what the campaign scripts use, and I'll come back to let you know by editing this post.
Edit: Okay, in DEAg_c.lua this is how IsCharacterHuman is handled (it's used to determine whether the game will show the objective popup, play the music, etc):
So here's my adaptation of that, to serve your script:
Edit 2: Changed argument of ExitVehicle() in above code to be correct (should just be the character, not the name of the vehicle). To be clear, I am basing most of this on theory. I'm genuinely curious to see if/how this works for you, so I might paste this code into my test map for fun.
Edit 3: I realized I messed up syntax terribly with function(character). I believe you can remove both 'function(character)'s and remove each corresponding 'end'.
Hidden/Spoiler:
Edit: Okay, in DEAg_c.lua this is how IsCharacterHuman is handled (it's used to determine whether the game will show the objective popup, play the music, etc):
Hidden/Spoiler:
Code: Select all
function pointsfunction()
function(character)
if IsCharacterHuman(character) then
counted_points = counted_points + 1
end
end
end
function kickfunction()
function(character)
if IsCharacterHuman(character) then
if counted_points < 5 then
ExitVehicle(character)
end
end
end
end
Edit 3: I realized I messed up syntax terribly with function(character). I believe you can remove both 'function(character)'s and remove each corresponding 'end'.
-
JazzMaster
- Master Sergeant

- Posts: 166
- Joined: Sun Mar 31, 2013 2:56 pm
- Projects :: Cato Neimoidia- Invasion
- xbox live or psn: No gamertag set
Re: "PointsToUnlock" For vehicles?
Okay i tried it out and you were right about removing the function(character) and their end lines. I got no munge errors, but the vehicle thats supposed to be locked doesn't kick me out at all before i reach the limit or after. I couldnt tell if the pointfunction was working because of that.
-
jedimoose32
- Field Commander

- Posts: 938
- Joined: Thu Jan 24, 2008 12:41 am
- Projects :: Engineering Degree
- Location: The Flatlands of Canada
Re: "PointsToUnlock" For vehicles?
I've been testing this in my test map for the past little while. Here is what my code currently looks like (fairly different from what I posted earlier, but I'm making progress):
I have a speederbike and a hovertank on the map. I can ride the bike, but the tank kicks me out. YAY! However, even after I kill the speederbike 5 times the tank still kicks me out. Working on figuring that out right now.
EDIT: Got it.
Turns out the solution is very different from what I originally thought.
All of that is INSIDE ScriptPostLoad. Naming the spawners is now unimportant. Just replace the names of my vehicles with the appropriate ones in your map. If you want multiple vehicle classes to count toward counted_points when they are destroyed simply add 'or's
as needed.
Hidden/Spoiler:
EDIT: Got it.
Turns out the solution is very different from what I originally thought.
Hidden/Spoiler:
Code: Select all
if IsCharacterHuman(killer) and GetEntityClass(object) == GetEntityClassPtr("imp_hover_speederbike") or GetEntityClass(object) == GetEntityClassPtr("name_of_other_vehicle_type")-
JazzMaster
- Master Sergeant

- Posts: 166
- Joined: Sun Mar 31, 2013 2:56 pm
- Projects :: Cato Neimoidia- Invasion
- xbox live or psn: No gamertag set
Re: "PointsToUnlock" For vehicles? [solved]
Worked liked a charm!! Thank you so much Jedimoose for taking the time to help me with this.
Would this work in multiplayer? I tried it online but it crashed, but it would crash before this was added anyways and could be caused by something else. I have the new updated bf2 .exe that fixes the online mode installed currently.
Would this work in multiplayer? I tried it online but it crashed, but it would crash before this was added anyways and could be caused by something else. I have the new updated bf2 .exe that fixes the online mode installed currently.
-
jedimoose32
- Field Commander

- Posts: 938
- Joined: Thu Jan 24, 2008 12:41 am
- Projects :: Engineering Degree
- Location: The Flatlands of Canada
Re: "PointsToUnlock" For vehicles?
It should, yes. I don't know too much about what makes a script multiplayer compatible but I do know that this doesn't mess with sides, teams, unit stats, etc. As far as I understand it, the litmus test is "will it change any stock content?" And the answer here is no. 
- Locutus
- 1st Lieutenant

- Posts: 420
- Joined: Fri Jun 04, 2010 10:08 am
- Projects :: Stargate Battlefront Pegasus
- Location: Germany
- Contact:
Re: "PointsToUnlock" For vehicles?
I can't find any particular issues which should prevent the code from working in multiplayer, however, keep in mind that you're not counting the kill points for each individual player.
As soon as "the humans" (as a group) have killed a certain amount of vehicles all of them will be able to use the vehicle.
You have to keep track of the stats for every player and update the player status on every spawn (because players can join and leave the map any time).
I recommend you take a look at the source code of the hunger games mod (search for it here in the forums) as it provides a good example.
As soon as "the humans" (as a group) have killed a certain amount of vehicles all of them will be able to use the vehicle.
You have to keep track of the stats for every player and update the player status on every spawn (because players can join and leave the map any time).
I recommend you take a look at the source code of the hunger games mod (search for it here in the forums) as it provides a good example.
- [RDH]Zerted
- Gametoast Staff

- Posts: 2982
- Joined: Sun Feb 26, 2006 7:36 am
- Projects :: Bos Wars AI - a RTS game
- xbox live or psn: No gamertag set
- Location: USA
- Contact:
Re: "PointsToUnlock" For vehicles? [Solved]
You had to move the function inside ScriptPostLoad because you defined counted_points to be a local variable. Meaning it only exists for code inside that function. Everywhere else it was nil and "nil < 5" is an error. You should have gotten error messages about it in your debug log.
You haven't posted the full lua file (and you've said there are other errors), but if the problem is with this part of the code (comment it all out and see if the map stops crashing), then I'd guess it's due to counted_points. Players joining at different times will have different counted_points values leading to some calling ExitVehicle and some not. Though I'm not entirely sure that's an issue (I'd test it to be sure, but I don't have SWBF2 installed anymore). If it is the issue, then you'd only want to server/host running the counted_points related code. It's ScriptCB_AmHost() or something like that.
An alternative is to use the v1.3 feature that jumps you into the player list for a moment (the function designed to give you player names). That has kill stats right? You can get the data from that. The only issues is that you don't want to use it too often. How often is too often? I never tested that
Maybe limit it to the server/host only as well.
You haven't posted the full lua file (and you've said there are other errors), but if the problem is with this part of the code (comment it all out and see if the map stops crashing), then I'd guess it's due to counted_points. Players joining at different times will have different counted_points values leading to some calling ExitVehicle and some not. Though I'm not entirely sure that's an issue (I'd test it to be sure, but I don't have SWBF2 installed anymore). If it is the issue, then you'd only want to server/host running the counted_points related code. It's ScriptCB_AmHost() or something like that.
An alternative is to use the v1.3 feature that jumps you into the player list for a moment (the function designed to give you player names). That has kill stats right? You can get the data from that. The only issues is that you don't want to use it too often. How often is too often? I never tested that
