I have things in my map that you can search (kind of like dig sites) and each one has a 10% chance of giving you a weapon refill (max ammo for the weapon you are holding). Now this is the part i have for the max ammo:
Code Snippet
Plaintext
player = undefined; current_gun = player getcurrentweapon(); player GiveMaxAmmo( current_gun );
Now i dont just have those thrown together in my actual script, they are in the correct places. But why doesnt this work? I'm curious about what im missing or why the game wont read this. Does anyone know what i could use instead?
This is why. Your setting the player variable to undefined, AKA it doesn't exist.
So i would take out the player so its just "GiveMaxAmmo( current_gun );"? I wouldnt do the for() loop and give it to players[ i ] because wont that give it to every player? And that isnt what i want
So i would take out the player so its just "GiveMaxAmmo( current_gun );"?
No. You have to figure out which player you want to run the code on. If the code only runs after a player uses a trigger, you can use:
Code Snippet
Plaintext
<trig> waittill("trigger", player);
Quote
I wouldnt do the for() loop and give it to players[ i ] because wont that give it to every player?
Depends on whats inside the for() loop. If you filter the players out by using an if condition then the code will only run for that player. However if you have a trigger(see above) you don't and shouldn't do this. The player variable in the waittill above will automatically get the player that used the trigger for you.
Otherwise if you just have an for() loop with the max ammo code inside then yes, it would just give the ammo to all players.
No. You have to figure out which player you want to run the code on. If the code only runs after a player uses a trigger, you can use:
Code Snippet
Plaintext
<trig> waittill("trigger", player);
Depends on whats inside the for() loop. If you filter the players out by using an if condition then the code will only run for that player. However if you have a trigger(see above) you don't and shouldn't do this. The player variable in the waittill above will automatically get the player that used the trigger for you.
Otherwise if you just have an for() loop with the max ammo code inside then yes, it would just give the ammo to all players.
I'm confused about what you mean by adding the waittill( "trigger" , player ); function...because the player already has to use a trigger to search the location, so wouldnt adding another waittill( "trigger" , player ); make them have to hit it twice? I'm probably just stupid, but anyway here's the code i have:
So, everything else works fine on that, except the gun giving ammo part? Edit: I looked up and bare with me, Im not good scripter, but you can try adding at start undefined and then defining it at the function itself like:
So, everything else works fine on that, except the gun giving ammo part? Edit: I looked up and bare with me, Im not good scripter, but you can try adding at start undefined and then defining it at the function itself like:
I'm confused about what you mean by adding the waittill( "trigger" , player ); function...because the player already has to use a trigger to search the location, so wouldnt adding another waittill( "trigger" , player ); make them have to hit it twice? I'm probably just stupid, but anyway here's the code i have:
while(1) { trash_trig waittill( "trigger" , player );
if(level.has_key == false && player.score >= cost && isDefined(level.key_in_trash)) { player iprintln( "Searching..." ); player maps\_zombiemode_score::minus_to_player_score( cost ); wait 2; player iprintlnbold( "You found a key!" ); level.has_key = true; trash_trig delete(); } else if(player.score >= cost && !isDefined(level.key_in_trash) && rand == 1) // 10% chance of getting this { player iprintln( "Searching..." ); player maps\_zombiemode_score::minus_to_player_score( cost ); wait 2; player iprintlnbold( "Weapon Refill!" ); player GiveMaxAmmo( current_gun ); trash_trig delete(); } else if(player.score >= cost && !isDefined(level.key_in_trash) && rand != 1) // 90% chance of getting this { player iprintln( "Searching..." ); player maps\_zombiemode_score::minus_to_player_score( cost ); wait 2; player iprintlnbold( "No luck." ); trash_trig delete(); } else if(player.score < cost) { player maps\_zombiemode_perks::play_no_money_perk_dialog(); wait 0.1; continue; } } }
Eh no. I was just saying that because i had no idea what the rest of the function looked like. What you had before is fine, Just removed the player = undefined; right before you do the get weapon function and it should work.
Last Edit: June 18, 2015, 09:05:32 pm by daedra descent
for (i = 0; i < players.size; i++) { //if (whatever if function you need here) { // array_thread (players, ::full_ammo_on_hud, drop_item); players[i] thread full_ammo_on_hud( drop_item ); players[i] GiveMaxAmmo(players[i] GetCurrentWeapon()); } } }
for (i = 0; i < players.size; i++) { //if (whatever if function you need here) { // array_thread (players, ::full_ammo_on_hud, drop_item); players[i] thread full_ammo_on_hud( drop_item ); players[i] GiveMaxAmmo(players[i] GetCurrentWeapon()); } } }